Command to pause a stream using GDB

I am a little new to GDB. I hope someone can help me with something that should be pretty simple, I used Google / docs, but I just missed something.

What is the “normal” way to debug streaming applications using GDB? I am using pthreads. I want to watch only one stream - the two options that I see are

a) tell the debugger to somehow attach to a specific thread, so step-by-step execution will not lead to the transition of threads to each context switch

b) inform the debugger of the suspension / release of any "uninteresting" threads

I would rather go on route b) - after reading the help for GDB, I don’t see a command for this, advice?

+8
c ++ c pthreads gdb
source share
2 answers

See the documentation for set scheduler-locking on .

Beware: if you pause other threads, and if one of them contains a lock, and if your interesting thread needs to be blocked at some point during the step, you are at a dead end.

What is the “normal” way to debug streaming applications?

You can never debug the correctness of the flow, you can only design it. In my experience, most of the debugging of streaming applications sets statements and investigates the state of the world when one of the statements is violated.

+8
source share

First, you need to enable convenience for multi-threaded behavior of the debugger with the following commands. I don’t know why it is disabled by default.

 set target-async 1 set non-stop on 

I personally put these commands in a .gdbinit file. They apply each of your commands only to the current focused thread. Note: the thread may work, so you need to pause it.

To see a focused thread, execute thread .

To switch to another stream, add a stream number, for example. thread 2 .

To view all topics with their numbers, select info thread .

To apply a command to a specific thread, execute something like a thread using the threadnum command. For example. thread apply 4 bt apply the backtrace command to thread apply all continue number 4. thread apply all continue continues all suspended threads.

There is a small problem though - many teams need a thread that needs to be paused. I know several ways to do this:

  • interrupt command: interrupts the execution of a thread, takes several threads to pause, breaks the focused one without an argument
  • Setting a breakpoint somewhere. Note that you can set a breakpoint for a specific thread so that other threads ignore it, for example, breaknnnnnnnnnnnnnnnum. For example. break 25 thread 4 .

You can also find it very useful that you can set the list of commands that will be executed when the breakpoint is reached through the commands command - for example, you can quickly print interesting values ​​and then continue execution.

+4
source share

All Articles