Let's say I'm debugging a multithreaded program with GDB.
I stopped on a breakpoint in one thread; thread I enter next 3
(or step 3
or smth similar); at this time the other thread hits a breakpoint, GDB switches to that one (scheduler-locking
is off).
Is it guaranteed that the 1st thread did not run more than 3 lines at the time of the 2nd breakpoint stop?
Is it impossible that the 1st thread runs 2 lines, GDB switches to the 2nd one, then the 1st one runs 1000 more lines, then GDB stops on a breakpoint (in the 2nd thread)?
I'm not sure I can devise this from the docs.
CodePudding user response:
In your situation the first thread will never do more than 3 next
operations.
Internally GDB will be set up the breakpoints required to ensure that the first thread performs a single next
, then set all threads running. GDB will then wait for a thread to stop.
If the first thread stops then GDB will setup for the second next
and start the first thread running again.
Repeat for the third next
. Once that is complete all threads will be stopped and control returns to the user.
However, at any point in this process another thread might stop for some other reason. If that happens GDB will request that all threads stop, and control will be passed back to the user.
However, due to the first thread already being setup for a next
, the furthest that the thread can proceed is up to the end of its current next
operation.