1Frame and Thread Format 2======================= 3 4.. contents:: 5 :local: 6 7LLDB has a facility to allow users to define the format of the information that 8generates the descriptions for threads and stack frames. Typically when your 9program stops at a breakpoint you will get two lines that describes why your 10thread stopped and where: 11 12:: 13 14 * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1 15 frame #0: test`main at test.c:5 16 17Stack backtraces frames also have a similar information line: 18 19:: 20 21 (lldb) thread backtrace 22 * thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1 23 frame #0: 0x0000000100000e85 a.out`main + 4 at test.c:19 24 frame #1: 0x0000000100000e40 a.out`start + 52 25 26The two format strings that govern the printing in these output forms can 27currently be set using the settings set command: 28 29:: 30 31 (lldb) settings set thread-stop-format STRING 32 (lldb) settings set frame-format STRING 33 34The first of these is an abbreviated thread output, that just contains data 35about the thread, and not the stop frame. It will always get used in situations 36where the frame output follows immediately, so that information would be 37redundant. The second is the frame printing. 38 39There is another thread format used for commands like thread list where the 40thread information isn't followed by frame info. In that case, it is convenient 41to have frame zero information in the thread output. That format is set by: 42 43:: 44 45 (lldb) settings set thread-format STRING 46 47 48Format Strings 49-------------- 50 51So what is the format of the format strings? Format strings can contain plain 52text, control characters and variables that have access to the current program 53state. 54 55Normal characters are any text that doesn't contain a ``{``, ``}``, ``$``, or 56``\`` character. 57 58Variable names are found in between a ``${`` prefix, and end with a ``}`` 59suffix. In other words, a variable looks like ``${frame.pc}``. 60 61Variables 62--------- 63 64A complete list of currently supported format string variables is listed below: 65 66+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 67| **Variable Name** | **Description** | 68+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 69| ``file.basename`` | The current compile unit file basename for the current frame. | 70+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 71| ``file.fullpath`` | The current compile unit file fullpath for the current frame. | 72+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 73| ``language`` | The current compile unit language for the current frame. | 74+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 75| ``frame.index`` | The frame index (0, 1, 2, 3...) | 76+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 77| ``frame.no-debug`` | Evaluates to true if the frame has no debug info. | 78+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 79| ``frame.pc`` | The generic frame register for the program counter. | 80+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 81| ``frame.sp`` | The generic frame register for the stack pointer. | 82+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 83| ``frame.fp`` | The generic frame register for the frame pointer. | 84+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 85| ``frame.flags`` | The generic frame register for the flags register. | 86+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 87| ``frame.reg.NAME`` | Access to any platform specific register by name (replace ``NAME`` with the name of the desired register). | 88+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 89| ``function.name`` | The name of the current function or symbol. | 90+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 91| ``function.name-with-args`` | The name of the current function with arguments and values or the symbol name. | 92+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 93| ``function.name-without-args`` | The name of the current function without arguments and values (used to include a function name in-line in the ``disassembly-format``) | 94+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 95| ``function.mangled-name`` | The mangled name of the current function or symbol. | 96+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 97| ``function.pc-offset`` | The program counter offset within the current function or symbol | 98+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 99| ``function.addr-offset`` | The offset in bytes of the current function, formatted as " + dddd" | 100+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 101| ``function.concrete-only-addr-offset-no-padding`` | Similar to ``function.addr-offset`` except that there are no spaces in the output (e.g. "+dddd") and the offset is computed from the nearest concrete function -- inlined functions are not included | 102+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 103| ``function.changed`` | Will evaluate to true when the line being formatted is a different symbol context from the previous line (may be used in ``disassembly-format`` to print the new function name on a line by itself at the start of a new function). Inlined functions are not considered for this variable | 104+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 105| ``function.initial-function`` | Will evaluate to true if this is the start of the first function, as opposed to a change of functions (may be used in ``disassembly-format`` to print the function name for the first function being disassembled) | 106+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 107| ``line.file.basename`` | The line table entry basename to the file for the current line entry in the current frame. | 108+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 109| ``line.file.fullpath`` | The line table entry fullpath to the file for the current line entry in the current frame. | 110+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 111| ``line.number`` | The line table entry line number for the current line entry in the current frame. | 112+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 113| ``line.start-addr`` | The line table entry start address for the current line entry in the current frame. | 114+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 115| ``line.end-addr`` | The line table entry end address for the current line entry in the current frame. | 116+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 117| ``module.file.basename`` | The basename of the current module (shared library or executable) | 118+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 119| ``module.file.fullpath`` | The basename of the current module (shared library or executable) | 120+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 121| ``process.file.basename`` | The basename of the file for the process | 122+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 123| ``process.file.fullpath`` | The fullname of the file for the process | 124+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 125| ``process.id`` | The process ID native to the system on which the inferior runs. | 126+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 127| ``process.name`` | The name of the process at runtime | 128+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 129| ``thread.id`` | The thread identifier for the current thread | 130+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 131| ``thread.index`` | The unique one based thread index ID which is guaranteed to be unique as threads come and go. | 132+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 133| ``thread.name`` | The name of the thread if the target OS supports naming threads | 134+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 135| ``thread.queue`` | The queue name of the thread if the target OS supports dispatch queues | 136+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 137| ``thread.stop-reason`` | A textual reason why the thread stopped. If the thread have a recognized frame, this displays its recognized stop reason. Otherwise, gets the stop info description. | 138+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 139| ``thread.stop-reason-raw`` | A textual reason why the thread stopped. Always returns stop info description. | 140+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 141| ``thread.return-value`` | The return value of the latest step operation (currently only for step-out.) | 142+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 143| ``thread.completed-expression`` | The expression result for a thread that just finished an interrupted expression evaluation. | 144+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 145| ``target.arch`` | The architecture of the current target | 146+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 147| ``script.target:python_func`` | Use a Python function to generate a piece of textual output | 148+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 149| ``script.process:python_func`` | Use a Python function to generate a piece of textual output | 150+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 151| ``script.thread:python_func`` | Use a Python function to generate a piece of textual output | 152+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 153| ``script.frame:python_func`` | Use a Python function to generate a piece of textual output | 154+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 155| ``current-pc-arrow`` | Prints either ``->`` or `` `` if the current pc value is matched (used in ``disassembly-format``) | 156+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 157| ``addr-file-or-load`` | Formats an address either as a load address, or if process has not yet been launched, as a load address (used in ``disassembly-format``) | 158+---------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 159 160Control Characters 161------------------ 162 163Control characters include ``{``, ``}``, and ``\``. 164 165The ``{`` and ``}`` are used for scoping blocks, and the ``\`` character allows 166you to desensitize control characters and also emit non-printable characters. 167 168Desensitizing Characters in the Format String 169--------------------------------------------- 170 171The backslash control character allows your to enter the typical ``\a``, 172``\b``, ``\f``, ``\n``, ``\r``, ``\t``, ``\v``, ``\\``, characters and along 173with the standard octal representation ``\0123`` and hex ``\xAB`` characters. 174This allows you to enter escape characters into your format strings and will 175allow colorized output for terminals that support color. 176 177Scoping 178------- 179 180Many times the information that you might have in your prompt might not be 181available and you won``t want it to print out if it isn``t valid. To take care 182of this you can enclose everything that must resolve into a scope. A scope is 183starts with ``{`` and ends with ``}``. For example in order to only display the 184current frame line table entry basename and line number when the information is 185available for the current frame: 186 187:: 188 189 "{ at {$line.file.basename}:${line.number}}" 190 191 192Broken down this is: 193 194- The start the scope: ``{`` , 195- format whose content will only be displayed if all information is available: ``at {$line.file.basename}:${line.number}`` 196- end the scope: ``}`` 197 198Making the Frame Format 199----------------------- 200 201The information that we see when stopped in a frame: 202 203:: 204 205 frame #0: 0x0000000100000e85 a.out`main + 4 at test.c:19 206 207can be displayed with the following format: 208 209:: 210 211 "frame #${frame.index}: ${frame.pc}{ ${module.file.basename}`${function.name}{${function.pc-offset}}}{ at ${line.file.basename}:${line.number}}\n" 212 213This breaks down to: 214 215- Always print the frame index and frame PC: ``frame #${frame.index}: ${frame.pc}``, 216- only print the module followed by a tick if there is a valid module for the current frame: ``{ ${module.file.basename}`}``, 217- print the function name with optional offset: ``{${function.name}{${function.pc-offset}}}``, 218- print the line info if it is available: ``{ at ${line.file.basename}:${line.number}}``, 219- then finish off with a newline: ``\n``. 220 221Making Your own Formats 222----------------------- 223 224When modifying your own format strings, it is useful to start with the default 225values for the frame and thread format strings. These can be accessed with the 226``settings show`` command: 227 228:: 229 230 (lldb) settings show thread-format 231 thread-format (format-string) = "thread #${thread.index}: tid = ${thread.id%tid}{, ${frame.pc}}{ ${module.file.basename}{`${function.name-with-args}{${frame.no-debug}${function.pc-offset}}}}{ at ${line.file.basename}:${line.number}}{, name = '${thread.name}'}{, queue = '${thread.queue}'}{, activity = '${thread.info.activity.name}'}{, ${thread.info.trace_messages} messages}{, stop reason = ${thread.stop-reason}}{\nReturn value: ${thread.return-value}}{\nCompleted expression: ${thread.completed-expression}}\n" 232 (lldb) settings show frame-format 233 frame-format (format-string) = "frame #${frame.index}:{ ${frame.no-debug}${frame.pc}}{ ${module.file.basename}{`${function.name-with-args}{${frame.no-debug}${function.pc-offset}}}}{ at ${line.file.basename}:${line.number}}{${function.is-optimized} [opt]}\n" 234 235When making thread formats, you will need surround any of the information that 236comes from a stack frame with scopes ({ frame-content }) as the thread format 237doesn't always want to show frame information. When displaying the backtrace 238for a thread, we don't need to duplicate the information for frame zero in the 239thread information: 240 241:: 242 243 (lldb) thread backtrace 244 thread #1: tid = 0x2e03, stop reason = breakpoint 1.1 2.1 245 frame #0: 0x0000000100000e85 a.out`main + 4 at test.c:19 246 frame #1: 0x0000000100000e40 a.out`start + 52 247 248The frame related variables are: 249 250- ``${file.*}`` 251- ``${frame.*}`` 252- ``${function.*}`` 253- ``${line.*}`` 254- ``${module.*}`` 255 256 257Looking at the default format for the thread, and underlining the frame 258information: 259 260:: 261 262 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 263 264 265We can see that all frame information is contained in scopes so that when the 266thread information is displayed in a context where we only want to show thread 267information, we can do so. 268 269For both thread and frame formats, you can use ${script.target:python_func}, 270${script.process:python_func} and ${script.thread:python_func} (and of course 271${script.frame:python_func} for frame formats) In all cases, the signature of 272python_func is expected to be: 273 274:: 275 276 def python_func(object,unused): 277 ... 278 return string 279 280Where object is an instance of the SB class associated to the keyword you are 281using. 282 283e.g. Assuming your function looks like: 284 285:: 286 287 def thread_printer_func (thread,unused): 288 return "Thread %s has %d frames\n" % (thread.name, thread.num_frames) 289 290And you set it up with: 291 292:: 293 294 (lldb) settings set thread-format "${script.thread:thread_printer_func}" 295 296you would see output like: 297 298:: 299 300 * Thread main has 21 frames 301 302