In GDB debugging C++ code: I have 15 breakpoints strategically set, but I don't want any of them to activate until I've hit breakpoint #2. Is there any run-until-breakpoint-n command in GDB?
I find myself doing one of two things instead:
Delete all other breakpoints so that #2 is all that exists, run, re-add all breakpoints; or
Run and repeatedly continue
past all breaks until I see the first break at #2.
I want something like run-until 2
that will ignore all other breakpoints except #2, but not delete them. Does this exist? Does anyone else have a better way to deal with this?
Just press c. It will continue execution until the next breakpoint.
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.
Controlling Executioncontinue (shorthand: c ) will resume execution until the next breakpoint is hit or the program exits.
As of version 7.0 GDB supports python scripting. I wrote a simple script that will temporary disable all enabled breakpoints except the one with specified number and execute GDB run
command.
Add the following code to the .gdbinit
file:
python
import gdb
class RunUntilCommand(gdb.Command):
"""Run until breakpoint and temporary disable other ones"""
def __init__ (self):
super(RunUntilCommand, self).__init__ ("run-until",
gdb.COMMAND_BREAKPOINTS)
def invoke(self, bp_num, from_tty):
try:
bp_num = int(bp_num)
except (TypeError, ValueError):
print "Enter breakpoint number as argument."
return
all_breakpoints = gdb.breakpoints() or []
breakpoints = [b for b in all_breakpoints
if b.is_valid() and b.enabled and b.number != bp_num and
b.visible == gdb.BP_BREAKPOINT]
for b in breakpoints:
b.enabled = False
gdb.execute("run")
for b in breakpoints:
b.enabled = True
RunUntilCommand()
end
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