Search code examples
gdbpthreadspretty-print

Make gdb show thread names on 'apply all' operations


I'm debugging an app with many threads, so I've named them using prctl. This works great with gdb's info threads option, but it would be nice if thread * apply all operations showed it as well. Any way to coerce gdb to do this?

(gdb) info threads
  Id   Target Id         Frame 
  ...
  3    Thread 0x7ffff6ffe700 (LWP 30048) "poll_uart_threa" 0x00007ffff78eb823 in select ()
    at ../sysdeps/unix/syscall-template.S:82
  2    Thread 0x7ffff77ff700 (LWP 30047) "signal hander" do_sigwait (set=<optimized out>, 
    sig=0x7ffff77feed8)
    at ../nptl/sysdeps/unix/sysv/linux/../../../../../sysdeps/unix/sysv/linux/sigwait.c:65
* 1    Thread 0x7ffff7fcc700 (LWP 30046) "simulator" __lll_lock_wait ()
    at ../nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:132

Pointer, PID {well, thread ID, but LWP threads == processes, ish}, and name

(gdb) thread apply all bt
...
Thread 3 (Thread 0x7ffff6ffe700 (LWP 30048)):
#0  0x00007ffff78eb823 in select () at ../sysdeps/unix/syscall-template.S:82
#1  0x0000000000403bb3 in poll_uart_thread (unused=0x0) at uart.c:96
#2  0x00007ffff7bc4e9a in start_thread (arg=0x7ffff6ffe700) at pthread_create.c:308
#3  0x00007ffff78f24bd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:112
#4  0x0000000000000000 in ?? ()

Thread 2 (Thread 0x7ffff77ff700 (LWP 30047)):
<call stack>
#2  0x0000000000417a89 in sig_thread (arg=0x7fffffffbb60) at simulator.c:879
#3  0x00007ffff7bc4e9a in start_thread (arg=0x7ffff77ff700) at pthread_create.c:308
#4  0x00007ffff78f24bd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:112
#5  0x0000000000000000 in ?? ()

Thread 1 (Thread 0x7ffff7fcc700 (LWP 30046)):
<call stack>
#9  0x00000000004182e3 in simulator (flash_file=0x7fffffffe0e4 "../programs/blink.bin")
    at simulator.c:1005
#10 0x0000000000401f14 in main (argc=3, argv=0x7fffffffdd48) at cli.c:167

While I can find the name by hunting the call stack, it'd be nice / convenient / etc if it would print in the summary line, which here only has PID and pointer.


Solution

  • There's no easy way, you have to patch GDB. It's a simple patch, you can find it here.