Breakpoints are used for debugging while processor is executing a sequence / program. A breakpoint is a signal that tells the debugger to temporarily suspend execution of your program at a certain point. When execution is suspended at a breakpoint, your program is said to be in break mode. Entering break mode does not stop or end the execution of your program; execution can be resumed at any time.
Breakpoints provide a powerful tool that enables you to suspend execution where and when you need to. Rather than stepping through your code line by line or instruction by instruction, you can allow your program to run until it hits a breakpoint, and then start to debug. This speeds up the debugging process. Without this ability, it would be almost impossible to debug a large program. Usually at a breakpoint, processor starts executing a exception handler & it can resume from there. All elements of program remain (functions, variables, memory, state) but any further activity is suspended till program resumes.
Hardware Breakpoints:
Hardware breakpoints are like "memory breakpoint"; When instruction tries to read/ write/ execute a particular address in memory or I/Os.
HW breakpoints require special hardware support. Implemented through Debug registers, which allow upto x number of breakpoints (e.g. 4 for x86). You store addresses in these registers. Special exception is executed when processor sees this address and xfers control to exception.
Limitation - there is only limited number of HW breakpoints you can set
Given that on x86, you can only have four hardware breakpoints active at once, why would anyone possibly want to use them?
Well, the main strength of hardware breakpoints is that you can use them to halt on non-execution accesses to memory locations. This is actually an extremely useful capability; for example, if you were debugging a memory corruption problem where an initial instance of corruption eventually causes a crash, your initial reaction would probably be something on the lines of “gee, if I know who caused the corruption in the first place, this would be much, much easier to debug” – and this is exactly what hardware breakpoints let you do. In essence, you can use a hardware breakpoint to tell the processor to stop when a specific variable (address) is read or read/written to.
You can also use hardware breakpoints to break in on code execution as well, although in the typical case, it is more common to use software breakpoints for that purpose due to the relaxed restrictions on how many breakpoints you may have active at once.
Sunday, January 29, 2012
Subscribe to:
Posts (Atom)