| Breakpoints |
|
|
|
| Written by Yash |
| Wednesday, 19 November 2008 00:37 |
|
A breakpoint is a mechanism to pause the program execution for further analysis of a program during runtime. After pausing you can view variable values if they are valid in current context. This will also help you to check CPU registers, call stack, memory dump and other debugger supported features.
There are two types of breakpoint we can set:
x86 Hardware driven
This provides three methods to pause the execution and allow user to examine the code:
INT 3 (0xCC): This is a breakpoint interrupt provided by hardware which allows debugger to implement the handler and allow pausing the execution of code for further analysis. There are 2 ways to use this interrupt:
INT 1(0xCD01): This is a single step interrupt provided by hardware which allows to implement the handler and allow pausing the execution of code for further analysis. To get control in Single Step handler of debugger, we also need to set a flag of TF(Trap flag) in EFLAGS register. Once u gain control in handler, you need to reset the TF so that till you set it again it will not call your handler again and again recursively. Once you do all types of processing inside the handler, then you can set it back TF flag to get control for next instruction of a program which you are debugging. Debug registers: There are 8 debug registers from DB0 to DB7 and two model specific registers (MSR) and these Debug registers are provided by the hardware itself and CPU will act based on the Flags set in these registers. Debug registers holds the address of memory and I/O locations called breakpoints. These breakpoints are used to selected location in a program, data storage or I/O ports where developer want to pause a program execution and analyze the state of the program with the help of debugger. These debug registers are privileged instruction and the modifier code must be running in kernel mode. Hardware provides max only 4 breakpoints (DR0 to DR3).Each of these registers holds a liner address where the program execution should stop. These debug registers triggering is completely depends on DR6 and DR7 registers. Debuggers either they need to have kernel module to support this feature or Operating system should provide API’s to facilitate to use these hardware provided breakpoints in a Debugger. DR6 is used as a status registers to mention in what condition respective breakpoint should trigger. None of the flags of this registers will be cleared by CPU, only the callback of exception handler should clear it. Updating of this register happens only when debug exception is generated. This register contains following info:
DR7 is used as control register. This will enable or disable breakpoint and also sets breakpoint conditions. This register holds following info:
Software driven (Visual C/C++)
Debugger can implement breakpoints in its own style with the help of single step (INT 1) handler. Using the same method they will implement all conditional breakpoints. In each and every instruction they will check the conditions specified by the user and then if condition satisfies it will break it. This will affect the performance a bit since, for each and every instruction it should check for breakpoints and the conditions, but this is OK with the developer, since it is helping him to solve lot of problems. They can even take help of underlying hardware by using debug registers (DR0 to DR3) Read/Write facility to implement data breakpoints. Visual C++ supports following breakpoints with different conditions:
Line number should be relative to Function. Line number which you provide here should have valid code and you cannot mention to any blank line. You also need to select language if you are debugging program for more then one language.
Specify source filename along with line number. This line number is relative to source file. You can even specify to take different version of source file for this breakpoint.
If you want to check if some pointer is NULL, then enter expression as “ptrBuff == 0” and check “Is True” option, it breaks it when variable is 0. Enter expression in “Condition” field and check “Has changed” option for breaking into code when expression changes.
In each of Visual C++ versions the way you invoke these dialog box’s changes. But, it got only above provided options in conditional breakpoint sections
|
| Last Updated on Wednesday, 19 November 2008 22:45 |



0 Comments