bgoodr
bgoodr

Reputation: 2930

How to force GDB to start number breakpoints at 1

How can I force GDB to start its numbering of newly added breakpoints at 1, after I have deleted all breakpoints with the delete command?

I'm using this version of GDB: GNU gdb (GDB) 8.0.50.20171024-git

TL;DR Rationale

During complicated debug sessions, I have a separate command file that I use the source command to source back in, with the first line of that command being delete br. That does clear the breakpoints as it should. Then, in subsequent lines, I add the complicated breakpoints, but does not restart with breakpoint 1. That means that, during a the same debug session, and without exiting and restarting the whole GDB session again, GDB will continue numbering the breakpoints at the next integer after the last one that was added before, but then was deleted. Yes, I could restart the GDB session, sure, and that is a workaround, but that is suboptimal because it forces me to wait for GDB to reload the executable into core, and the executable is quite large (yes, that is indeed a problem, but is not the droids we are discussing right now). Then, I want to add, to that command file, commands to disable all breakpoints except the first one, then manually use continue to continue to the first breakpoint, and only then re-enable the subsequent breakpoints. Then once those are added in, I want to execute specifically the command (which shall be hardcoded into my wetware and never ever be changed): enable 2-20. Because then I want to discover some code, then use the disable 2-20 command (also hardcoded in my wetware) followed by the run command, and repeat ad infinitum, all without having to restart GDB.

Side note: Please do not ask me to program in GDB's Python. Yes, I know how. But I don't wanna. This should be something built-into plain 'ole GDB without any extra Python coding chores/requirements. But if you do have a Python based approach, I will reluctantly listen and so too maybe even accept it as the answer.

Upvotes: 1

Views: 380

Answers (1)

Chris Dodd
Chris Dodd

Reputation: 126518

Given your use-case described in your rationale, you're probably best off not trying to get the breakpoints assigned to specific numbers and instead use convenience vars to keep track of the breakpoint numbers.

Whenever you set a breakpoint, gdb will set $bpnum to the number of the breakpoint. You can save that value to another convenience var for later use. So your script would end up with something like:

break foo   # the first breakpoint you always want active
break bar   # the first you want to enable/disable
set $first_interesting = $bpnum
break baz   # some more interesting ones
break box
break bap
set $last_interesting = $bpnum

define ei
    enable $first_interesting-$last_interesting
end
document ei
    enable the interesting breakpoints
end
define di
    disable $first_interesting-$last_interesting
end
document di
    disable the interesting breakpoints
end

Now you just need to remember the commands ei/di in your wetware...

Upvotes: 1

Related Questions