Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the breakpoint number from gdb

Tags:

gdb

I am writing gdb command scripts to simplify the debugging. One of the problems I have is that I am setting a breakpoint, and I want to disable it afterwards, and only enable it after another breakpoint is hit.

What I want to do is this

$my_break_number = break SomeFile.cpp:231
disable $my_break_number

but unfortunately gdb doesn't work this way. I have read the manual, but I cannot find any information on how to do this. Hopefully there is some information I have missed.

like image 256
daramarak Avatar asked Dec 06 '22 14:12

daramarak


2 Answers

gdb will automatically set a convenience variable $bpnum with the last set breakpoint number.

You can possibly use that after setting a breakpoint to disable it (I haven't tested when a breakpoint is ambiguous and creates multiple breakpoints, I think it will work and disable all breakpoint locations created.)

see: http://sourceware.org/gdb/current/onlinedocs/gdb/Set-Breaks.html#Set-Breaks

if you need to use the breakpoint number from commands, that is probably not what you want, but it works for the question as specified.

like image 96
matt Avatar answered Dec 09 '22 03:12

matt


It sounds like you may want to use the Python GDB scripting, which gives you a lot better programmatic access to breakpoints than what is possible with "regular" command scripts.

like image 37
Employed Russian Avatar answered Dec 09 '22 02:12

Employed Russian