Samuel Jacob's Weblog

Just another technical blog

Archive for the ‘lldb’ Category

LLDB Backtrace formatting

without comments

lldb can be configured to print backtraces with syntax highlighting. Here is how to setup lldb to do that

Consider the following source level debugging session,

$ cat test.c
static void crash_me()
    char *c = 0;
    *c = 0;

static void recursive_call(int value)
    if (value == 0) {
    recursive_call(value - 1);

int main(int argc, char argv[])
$ gcc -g3 -O3 test.c
$ lldb a.out
(lldb) run 0 1 2 3 4 5

Without color syntax the backtrace would look like the following.

Normal backtrace with out any makeup

Normal backtrace with out any makeup

Since lldb supports ANSI escape sequence, the escape sequences can be used to color the backtrace output which makes output more readable. Here is the link to official lldb page describing this feature –

Here is my backtrace setting and example

(lldb) settings set frame-format "frame #${frame.index}: ${frame.pc}{ \x1b\x5b36m${module.file.basename}\x1b\x5b39m{` \x1b\x5b33m${} \x1b\x5b39m${function.pc-offset}}}{ at ${line.file.basename}:${line.number}}\n"

Backtrace with color

Backtrace with color

Similarly thread format cant be colorized so that ‘thread list‘ would look neat.

(lldb) settings set thread-format "\x1b\x5b42;1mthread #${thread.index}: tid = ${}{, ${frame.pc}}{ \x1b\x5b31m${module.file.basename}\x1b\x5b39m{`${}${function.pc-offset}}}{ at ${line.file.basename}:${line.number}}{, name = '\x1b\x5b34m${}}\x1b\x5b39m{, queue = '${thread.queue}}{, stop reason = ${thread.stop-reason}}{\nReturn value: ${thread.return-value}}\x1b\x5b0m\n"

Reference to ANSI escape sequence –

Written by samueldotj

July 22nd, 2013 at 9:20 pm

Posted in C,Debugger,lldb