GDB normally stops all threads if a breakpoint is reached (or Ctrl+C is pressed in the GDB shell). I'm aware that commands like scheduler-locking and schedule-multiple exists, but I see no possibility to let a defined thread run in the background while another is debugged.
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.
Also, GDB uses internal breakpoints in the thread library to monitor certain events such as thread creation and thread destruction. When such an event happens, a system call in another thread may return prematurely, even though your program does not appear to stop. Conversely, whenever you restart the program, all threads start executing.
GDB provides these facilities for debugging multi-thread programs: ‘ thread thread-id ’, a command to switch among threads ‘ info threads ’, a command to inquire about existing threads ‘ thread apply [thread-id-list | all] args ’, a command to apply a command to a list of threads
However, GDB may not notice when a non-current thread's activity changes the expression. HP-UX Warning: In multi-thread programs, software watchpoints have only limited usefulness. If GDB creates a software watchpoint, it can only watch the value of an expression in a single thread.
You can use set target-async on
to enable asynchronous mode, if your target supports it. Then, you can specify background execution with commands. For example,
continue&
can be used to run a single thread, and
interrupt [-a]
to suspend execution of a single thread, or the whole program.
In conjunction with non-stop mode, you can examine a single thread while others continue to run in the background:
# If using the CLI, pagination breaks non-stop.
set pagination off
# Finally, turn it on!
set non-stop on
# Before debugging is started!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With