Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

not stopping all threads in gdb

Tags:

c

gdb

pthreads

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.

like image 375
azraiyl Avatar asked Sep 08 '10 09:09

azraiyl


People also ask

What happens when a program stops under GDB?

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.

How does GDB monitor threading?

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.

How do I debug a multi-thread program in gdb?

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

Does GDB notice when a non-current thread's activity changes the expression?

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.


1 Answers

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!
like image 198
Michael Foukarakis Avatar answered Oct 03 '22 23:10

Michael Foukarakis