Say I create two breakpoints, 2 and 3. Breakpoint 3 is on line 10, which is executed frequently through the program. How can I configure 3 to break only after 2 has been hit once?
Setting breakpoints A breakpoint is like a stop sign in your code -- whenever gdb gets to a breakpoint it halts execution of your program and allows you to examine it. To set breakpoints, type "break [filename]:[linenumber]". For example, if you wanted to set a breakpoint at line 55 of main.
With the clear command you can delete breakpoints according to where they are in your program. With the delete command you can delete individual breakpoints, watchpoints, or catchpoints by specifying their breakpoint numbers.
You can use a watchpoint to stop execution whenever the value of an expression changes, without having to predict a particular place where this may happen. Depending on your system, watchpoints may be implemented in software or hardware.
GDB normally ignores breakpoints when it resumes execution, until at least one instruction has been executed. If it did not do this, you would be unable to proceed past a breakpoint without first disabling the breakpoint. This rule applies whether or not the breakpoint already existed when your program stopped.
with a simple example:
void bp2() { };
void bp1() { bp2(); }
int main()
{
bp2();
bp1();
return 0;
}
we can create a breakpoint which only triggers when bp2 is called through bp1 with something like the following:
break bp1
break bp2
commands 1
silent
enable 2
c
end
commands 2
disable 2
end
disable 2
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