Breakpoints are one of the coolest feature supported by most popular Debuggers like GDB. But how a breakpoint works ? What code modifications does the compiler do to achieve the breakpoint? Are there any special hardware features used to support breakpoints?
The debugger gets the information about the signal, and checks the value of the Traced process instruction pointer (i.e., where the trap occurred). If the IP address is in its breakpoint list, that means it's a debugger breakpoint (otherwise, it's a fault in the process, just pass the signal and let it crash).
If a breakpoint is reached, or a signal not related to stepping occurs before count steps, stepping stops right away. Continue to the next source line in the current (innermost) stack frame. This is similar to step , but function calls that appear within the line of code are executed without stopping.
Trace-based debugging is traditional and the most common debugging technique used in most debugging tools today. Trace-based debugging is predicated on the concept of breakpoints. A breakpoint is a pausing or stopping point added to the program to examine the state of program execution up until that point.
Compiler does not need to "modify" the binary in any way to support the breakpoints. However it is important, that:
The rest of work is then performed by debugger itself.
To put a break point first we have to add some special information in to the binary .We use the flag -g while compiling the c source files to include this info.The Software debugger actually use this info to put break points.The best example for hardware break point support is in VxWorks as I have experienced. Basically at the break point the processor halts.So internally any step which will give an exception to processor can be used to put a software break point.While a Hardware break point works by matching the address stored in Hardware registers to cause an exception.So Hardware break point is very powerful but it is heavily architecture dependent.
A very good explanation is here What is the difference between hardware and software breakpoints? A good intro with Processor related information is given here http://processors.wiki.ti.com/index.php/How_Do_Breakpoints_Work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With