问题
What I'd like to know is if it is possible, inside a debugging session in Linux, (read: gdb :)) to stop the execution of a single thread, leaving the other threads to run.
If someone is curious to know why keep reading: I wrote a software watchdog C++ class (using Qt). I tested it with a simple multithreaded program, but I'd like to test the code once I integrate it inside the real application as well. If I could stop a thread from the debugger, that will simplify this testing phase. :)
Cheers Sergio
回答1:
Use this sequence of commands before you run or attach to your program:
Enable the async interface:
set target-async 1If using the CLI, pagination breaks non-stop:
set pagination offTurn it on:
set non-stop on
Use these commands to manipulate the non-stop mode setting:
Enable selection of non-stop mode:
set non-stop onDisable selection of non-stop mode:
set non-stop offShow the current non-stop enabled setting:
show non-stop
References:
http://sourceware.org/gdb/onlinedocs/gdb/Non_002dStop-Mode.html#Non_002dStop-Mode
回答2:
You may use totalview debugger to do that
回答3:
If that little variation is OK, you could send the thread a STOP signal (not as a gdb command the gdb - that the variation) and debug everything else running. Signal CONT lets the thread continue.
来源:https://stackoverflow.com/questions/9110467/is-it-possible-to-stop-a-single-thread-during-debug-in-linux