Is it possible to stop a single thread during debug in Linux?

假装没事ソ 提交于 2021-02-06 09:59:05

问题


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 1

  • If using the CLI, pagination breaks non-stop:
    set pagination off

  • Turn 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 on

  • Disable selection of non-stop mode:
    set non-stop off

  • Show 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!