views:

49

answers:

1

I can attach Visual Studio to an executable, and then my breakpoints get called.

What's going on under the hood? What mechanism allows my breakpoints to fire?

+1  A: 

There are two mechanisms that can be used to implement breakpoints:

  • hardware, by setting special registers in the processor. When encountering the instruction indicated in the special registers as breakpoint, an exception is thrown, which is caught by the debugger.
  • software, by replacing instructions by "int 3" instructions (see http://en.wikipedia.org/wiki/INT_(x86_instruction)). The "int 3" instruction also interrupts the flow of the application, which is caught by the debugger. To continue the application, the debugger will temporarily put back the original instruction.

See http://en.wikipedia.org/wiki/Breakpoint for more information.

Patrick
Which is visual studio using,soft or hard?
I'm sure that Visual Studio uses hard breakpoints (I once got the error message: the hardware does not support monitoring the requested number of bytes). Not sure about soft break points, but I assume VS also uses these.
Patrick