turboscrew
turboscrew

Reputation: 676

How are SW breakpoints handled by gdb-stub/server

How are SW breakpoints handled (conceptually) by gdb stub or server (I assume client stub and server handle them in pretty much same way)? I'm interested in a 'bare metal' target where the gdb stub/server runs, and both breakpoints and single stepping use software interrupts.

My actual questions:

When a breakpoint is hit, how is the stored instruction run so that the breakpoint can be 're-installed' and the (saved) machine status (including register contents) is not changed from the moment of hitting the breakpoint? =>When is the breakpoint re-installed and how? Between breakpoint hit and entering the command interpreter, or during the next single step or coninue?

Also how does single-stepping over breakpoint work such that the original non-breakpoint instruction gets executed, and the breakpoint still remains there after being single-stepped over?

[edit] Forgot: the document "GDB Internals" seems to be missing that info - and actually the whole subchapter about single stepping in the "Algorithms" chapter.

[edit2] Ah, I seem to need stronger glasses: The 'Internals'-manual says: "When the user says to continue, GDB will restore the original instruction, single-step, re-insert the trap, and continue on."

The single stepping over breakpoint, however, is still open question.

Upvotes: 0

Views: 333

Answers (1)

Employed Russian
Employed Russian

Reputation: 213375

The single stepping over breakpoint, however, is still open question.

It's done exactly the same way as continue, except for the last step ("and continue on"). That is:

  1. Process stops. GDB "looks around", discovers that $ip points to one of its breakpoints.
  2. User issues continue, next, step or stepi command.
  3. Restore original instruction (i.e. remove the breakpoint)
  4. Single-step process
  5. Re-insert breakpoint
  6. Continue (this is done for continue but not for next, step or stepi).
  7. For stepi, return control to the user (we are already at the next instruction due to step 4 above). For next, continue single-stepping until we reach a line in source that is not the same line we were on at step 1 above.

Upvotes: 1

Related Questions