GDB TO LLDB COMMAND MAP
2014-07-10 20:15
218 查看
LLDB has a facility to allow users to define the format of the information that generates the descriptions for threads and stack frames. Typically when your program stops at a breakpoint you will get a line that describes why your thread stopped:
Stack backtraces frames also have a similar information line:
The two format strings can currently be set using the settings set command:
So what is the format of the format strings? Format strings can contain plain text, control characters and variables that have access to the current program state.
Normal characters are any text that doesn't contain a
Variable names are found in between a
A complete list of currently supported format string variables is listed below:
Control characters include
The '{' and '}' are used for scoping blocks, and the '\' character allows you to desensitize control characters and also emit non-printable characters.
The backslash control character allows your to enter the typical
characters and along with the standard octal representation
terminals that support color.
Many times the information that you might have in your prompt might not be available and you won't want it to print out if it isn't valid. To take care of this you can enclose everything that must resolve into a scope. A scope is starts
with
Broken down this is:
The start the scope
format whose content will only be displayed if all information is available:
end the scope:
The information that we see when stopped in a frame:
can be displayed with the following format:
This breaks down to:
Always print the frame index and frame PC:
only print the module followed by a tick if there is a valid module for the current frame:
print the function name with optional offset:
print the line info if it is available:
then finish off with a newline:
When modifying your own format strings, it is useful to start with the default values for the frame and thread format strings. These can be accessed with the
When making thread formats, you will need surround any of the information that comes from a stack frame with scopes ({ frame-content }) as the thread format doesn't always want to show frame information. When displaying
the backtrace for a thread, we don't need to duplicate the information for frame zero in the thread information:
The frame related variables are:
Looking at the default format for the thread, and underlining the frame information:
We can see that all frame information is contained in scopes so that when the thread information is displayed in a context where we only want to show thread information, we can do so.
For both thread and frame formats, you can use ${target.script:python_func}, ${process.script:python_func} and ${thread.script:python_func} (and of course ${frame.script:python_func} for frame formats)
In all cases, the signature of python_func is expected to be:
Where object is an instance of the SB class associated to the keyword you are using.
e.g. Assuming your function looks like
And you set it up with
* thread #1: tid = 0x2e03, 0x0000000100000e85 a.out`main + 4, stop reason = breakpoint 1.1
Stack backtraces frames also have a similar information line:
(lldb) thread backtrace thread #1: tid = 0x2e03, stop reason = breakpoint 1.1 frame #0: 0x0000000100000e85 a.out`main + 4 at test.c:19 frame #1: 0x0000000100000e40 a.out`start + 52
The two format strings can currently be set using the settings set command:
(lldb) settings set frame-format STRING (lldb) settings set thread-format STRING
FORMAT STRINGS
So what is the format of the format strings? Format strings can contain plain text, control characters and variables that have access to the current program state.Normal characters are any text that doesn't contain a
'{',
'}',
'$', or
'\'character.
Variable names are found in between a
"${"prefix, and end with a
"}"suffix. In other words, a variable looks like
"${frame.pc}".
VARIABLES
A complete list of currently supported format string variables is listed below:Variable Name | Description |
file.basename | The current compile unit file basename for the current frame. |
file.fullpath | The current compile unit file fullpath for the current frame. |
frame.index | The frame index (0, 1, 2, 3...) |
frame.pc | The generic frame register for the program counter. |
frame.sp | The generic frame register for the stack pointer. |
frame.fp | The generic frame register for the frame pointer. |
frame.flags | The generic frame register for the flags register. |
frame.reg.NAME | Access to any platform specific register by name (replace NAME with the name of the desired register). |
function.name | The name of the current function or symbol. |
function.name-with-args | The name of the current function with arguments and values or the symbol name. |
function.pc-offset | The program counter offset within the current function or symbol |
line.file.basename | The line table entry basename to the file for the current line entry in the current frame. |
line.file.fullpath | The line table entry fullpath to the file for the current line entry in the current frame. |
line.number | The line table entry line number for the current line entry in the current frame. |
line.start-addr | The line table entry start address for the current line entry in the current frame. |
line.end-addr | The line table entry end address for the current line entry in the current frame. |
module.file.basename | The basename of the current module (shared library or executable) |
module.file.fullpath | The basename of the current module (shared library or executable) |
process.file.basename | The basename of the file for the process |
process.file.fullpath | The fullname of the file for the process |
process.id | The process ID native to the system on which the inferior runs. |
process.name | The name of the process at runtime |
thread.id | The thread identifier for the current thread |
thread.index | The unique one based thread index ID which is guaranteed to be unique as threads come and go. |
thread.name | The name of the thread if the target OS supports naming threads |
thread.queue | The queue name of the thread if the target OS supports dispatch queues |
thread.stop-reason | A textual reason each thread stopped |
thread.return-value | The return value of the latest step operation (currently only for step-out.) |
thread.completed-expression | The expression result for a thread that just finished an interrupted expression evaluation. |
target.arch | The architecture of the current target |
target.script:python_func | Use a Python function to generate a piece of textual output |
process.script:python_func | Use a Python function to generate a piece of textual output |
thread.script:python_func | Use a Python function to generate a piece of textual output |
frame.script:python_func | Use a Python function to generate a piece of textual output |
CONTROL CHARACTERS
Control characters include '{',
'}', and
'\'.
The '{' and '}' are used for scoping blocks, and the '\' character allows you to desensitize control characters and also emit non-printable characters.
DESENSITIZING CHARACTERS IN THE FORMAT STRING
The backslash control character allows your to enter the typical "\a",
"\b",
"\f",
"\n",
"\r",
"\t",
"\v",
"\\",
characters and along with the standard octal representation
"\0123"and hex
"\xAB"characters. This allows you to enter escape characters into your format strings and will allow colorized output for
terminals that support color.
SCOPING
Many times the information that you might have in your prompt might not be available and you won't want it to print out if it isn't valid. To take care of this you can enclose everything that must resolve into a scope. A scope is startswith
'{'and ends with
'}'. For example in order to only display the current frame line table entry basename and line number when the information is available for the current frame:
"{ at {$line.file.basename}:${line.number}}"
Broken down this is:
The start the scope
"{"
format whose content will only be displayed if all information is available:
"at {$line.file.basename}:${line.number}"
end the scope:
"}"
MAKING THE FRAME FORMAT
The information that we see when stopped in a frame:frame #0: 0x0000000100000e85 a.out`main + 4 at test.c:19
can be displayed with the following format:
"frame #${frame.index}: ${frame.pc}{ ${module.file.basename}`${function.name}{${function.pc-offset}}}{ at ${line.file.basename}:${line.number}}\n"
This breaks down to:
Always print the frame index and frame PC:
"frame #${frame.index}: ${frame.pc}"
only print the module followed by a tick if there is a valid module for the current frame:
"{ ${module.file.basename}`}"
print the function name with optional offset:
"{${function.name}{${function.pc-offset}}}"
print the line info if it is available:
"{ at ${line.file.basename}:${line.number}}"
then finish off with a newline:
"\n"
MAKING YOUR OWN FORMATS
When modifying your own format strings, it is useful to start with the default values for the frame and thread format strings. These can be accessed with the"settings show"command:
(lldb)
settings show thread-format thread-format (string) = 'thread #${thread.index}: tid = ${thread.id}{, ${frame.pc}}{ ${module.file.basename}`${function.name}{${function.pc-offset}}}{, stop reason = ${thread.stop-reason}}{, name = ${thread.name}}{, queue = ${thread.queue}}\n' (lldb) settings show frame-format frame-format (string) = 'frame #${frame.index}: ${frame.pc}{ ${module.file.basename}`${function.name}{${function.pc-offset}}}{ at ${line.file.basename}:${line.number}}\n'
When making thread formats, you will need surround any of the information that comes from a stack frame with scopes ({ frame-content }) as the thread format doesn't always want to show frame information. When displaying
the backtrace for a thread, we don't need to duplicate the information for frame zero in the thread information:
(lldb) thread backtrace thread #1: tid = 0x2e03, stop reason = breakpoint 1.1 2.1 frame #0: 0x0000000100000e85 a.out`main + 4 at test.c:19 frame #1: 0x0000000100000e40 a.out`start + 52
The frame related variables are:
${file.*}
${frame.*}
${function.*}
${line.*}
${module.*}
Looking at the default format for the thread, and underlining the frame information:
'thread #${thread.index}: tid = ${thread.id}{, ${frame.pc}}{${module.file.basename}`${function.name}{${function.pc-offset}}}{, stop reason = ${thread.stop-reason}}{, name = ${thread.name}}{, queue = ${thread.queue}}\n'
We can see that all frame information is contained in scopes so that when the thread information is displayed in a context where we only want to show thread information, we can do so.
For both thread and frame formats, you can use ${target.script:python_func}, ${process.script:python_func} and ${thread.script:python_func} (and of course ${frame.script:python_func} for frame formats)
In all cases, the signature of python_func is expected to be:
def python_func(object,unused): ... return string
Where object is an instance of the SB class associated to the keyword you are using.
e.g. Assuming your function looks like
def thread_printer_func (thread,unused): return "Thread %s has %d frames\n" % (thread.name, thread.num_frames)
And you set it up with
(lldb) settings set thread-format "${thread.script:thread_printer_func}"you would see output like:
* Thread main has 21 frames
相关文章推荐
- LLDB TO GDB COMMAND MAP LLDB TO GDB COMMAND MAP[转]
- GDB LLDB COMMAND MAP
- Xcode做ios开发时 message sent to deallocated instance问题的解决方法(gdb和lldb)
- message sent to deallocated instance问题的解决方法(gdb和lldb)
- message sent to deallocated instance问题的解决方法(gdb和lldb)
- message sent to deallocated instance问题的解决方法(gdb和lldb)
- message sent to deallocated instance问题的解决方法(gdb和lldb)
- PostgreSQL——Psql Command to Attach Gdb to Backend
- How to map SCN with Timestamp before 10g [ID 365536.1]
- spark convert RDD[Map] to DataFrame
- 【DB2】If 'db2' is not a typo you can run the following command to lookup the package that contains the binary: command-not-found db2 bash: db2: command not found
- mapviewer deploy to Weblogic
- Map of Public Vulnerability to Advisory/Alert
- Python multiprocessing.Pool: when to use apply, apply_async or map?
- Error:error: linker command failed with exit code 1 (use -v to see invocation)
- 添加第三方类库造成的linker command failed with exit code 1 (use -v to see invocation)的错误调试
- hibernate setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP)
- a while-switch to read input command
- cookieToMap方法
- How to terminate gdbserver——(gdb) monitor exit