user198729
user198729

Reputation: 63626

How does debugging work in Visual Studio?

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?

Upvotes: 11

Views: 2531

Answers (1)

Patrick
Patrick

Reputation: 23619

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.

Upvotes: 4

Related Questions