Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug multi-threaded code in GDB?

I am trying to debug multi-threaded program with one thread that waits input from user. When I put a breakpoint at some function of other thread and run app, it switches into same breakpoint and then immediately at input thread, so app waits input from user and I can't do any command in gdb. I simply need see all stack before invoking same function. I can't make bt command in

like image 209
Slava Avatar asked Nov 20 '25 07:11

Slava


2 Answers

Does thread apply all bt answer your question?

like image 165
Jamey Sharp Avatar answered Nov 23 '25 02:11

Jamey Sharp


You can add commands to a breakpoint, see the manual. Something like this:

(gdb) break some_func
Breakpoint 2 at ...
(gdb) commands 2
Type commands for breakpoint(s) 2, one per line.
End with a line saying just "end".
>thread apply all bt full
>end
(gdb) cont
Continuing.
Breakpoint 2, ...
Thread 1 (Thread 0x....
...

Edit 0:

Oh, I'm guessing you get gdb printing this on you:

---Type <return> to continue, or q <return> to quit---

Just do the following before you do run (you can also stick this into .gdbinit file):

(gdb) set pagination off
like image 22
Nikolai Fetissov Avatar answered Nov 23 '25 03:11

Nikolai Fetissov