GDB With Multiple Threads
GDB With Multiple Threads
Enquiring about existing threads: info threads, a command to inquire about existing
threads. The information displayed is:
1. the thread number assigned by gdb
2. the target systems thread identifier
3. the current stack frame summary for that thread
4. One thread information is preceeded by a *. This implies the current thread under
gdb
Try switching the current thread which is under gdbs control, e.g. if thread 2 needs to be
made the current thread, then
(gdb) thread 2
Try putting thread specific breakpoints. E.g. threadFunction is called by both threads 2
and 3. We can put the breakpoint on this function only for thread 3 as follows:
(gdb) b threadFunction thread 3
Whenever your program stops under gdb for any reason, all threads of execution stop, not
just the current thread. This allows you to examine the overall state of the program, including
switching between threads, without worrying that things may change underfoot.
Conversely, whenever you restart the program, all threads start executing. This is true
even when single-stepping with commands like step or next. Since thread scheduling is up to
your debugging targets operating system (not controlled by gdb), other threads may execute
more than one statement while the current thread completes a single step.
Remember, gdb does cause your multi-threaded program to behave differently than it would
without gdb.
For details on using gdb with a multiple threads program, refer the following sections in the
gdb manual:
1. Section 4.9: Debugging programs with multiple threads
2. Section 5.4: Stopping and starting multi-thread programs
3. Section 5.1.2: Watchpoints in programs with multiple threads