MBober
MBober

Reputation: 1105

Halt gdb on thread switching

Is there any way I can make gdb halt every time when the pthread being executed changes?

Say I have two POSIX threads (thread A and thread B) running and I want gdb to halt when thread A is being suspended and thread B continues execution (and the other way around).

Upvotes: 2

Views: 750

Answers (1)

Employed Russian
Employed Russian

Reputation: 213375

I want gdb to halt when thread A is being suspended and thread B continues execution

Your question assumes a single-core computer, which are exceedingly rare nowadays.

If you have a multi-core CPU, then both A and B will execute simultaneously, and your question makes no sense.

Even assuming that you are executing on a single-core CPU, the feature you are asking for would (I expect) be mostly useless: a typical multi-threaded program would switch between two threads for tens of thousands of times before reaching any "interesting" code. Surely you don't want to continue 10,000 times?

When debugging multi-threaded code, usually you want to assert that various invariants hold throughout the program execution. Setting breakpoints and single-stepping rarely helps in multi-threaded debugging.

Upvotes: 4

Related Questions