Search code examples
gdbbreakpointsconditional-breakpoint

gdb disable breakpoint in particular thread


Is it possible to disable gdb breakpoints on a per-thread basis?

I have a breakpoint which triggers every 100 milliseconds in the background worker thread. But I need to debug the same location in any other threads. So it would be cool to disable breakpoint only in the background worker thread. Is it possible?

Maybe I can disable thread by adding some specially crafted condition to this breakpoint when I know thread's number?


Solution

  • Gdb provides two convenience variables, $_thread and $_gthread (the latter being pretty new), which can be used in conditions to refer to the current thread.

    So, once the worker thread has started, you can use info thread to find its number. Then you can change your breakpoint (supposing for this example that it is breakpoint 2) like:

    (gdb) cond 2 $_thread != 57