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