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.
Hi-angel
source share