How do breakpoints work in C++ code?

前端 未结 4 1575
刺人心
刺人心 2020-12-07 16:59

How do breakpoints work in C++ code? Are they special instructions inserted in between some assembler instructions when the code is compiled? Or is there something else in p

4条回答
  •  渐次进展
    2020-12-07 17:11

    Single stepping is implemented at (assembler) code level not at C++ level. The debugger knows how to map the C++ code lines to code addresses.

    There are different implementations. There are CPUs that support debugging with breakpoint registers. When the execution reaches the address in the breakpoint register, the CPU executes a breakpoint exception.

    A different approach is to patch the code for the time of execution with a special instruction, at best a one-byte instruction. At x86 systems that usually int 3.

    The first approach allows breakpoints in ROM, the second allows more breakpoints at the same time.

提交回复
热议问题