Getting Gdb to Save a List of Breakpoints

Getting GDB to save a list of breakpoints

As of GDB 7.2 (2011-08-23) you can now use the save breakpoints command.

save breakpoints <filename>
Save all current breakpoint definitions to a file suitable for use
in a later debugging session. To read the saved breakpoint
definitions, use the `source' command.

Use source <filename> to restore the saved breakpoints from the file.

Where are gdb breakpoints saved?

where is the file saved?

If you didn't give it full pathname, the file would be saved in your current directory.

I can't remember what filename I had used.

man find may come handy. If you generally work in subdirectories of your $HOME, then find $HOME -type f -mtime -5 will find all files modified in the last 5 days.

How to save gdb setup information inside gdb session?

You can use GDB logging feature.
Below said options are available in GDB documentation.

https://sourceware.org/gdb/current/onlinedocs/gdb/Logging-Output.html#Logging-Output

set logging on
Enable logging.
set logging off
Disable logging.
set logging file file
Change the name of the current logfile. The default logfile is gdb.txt.
set logging overwrite [on|off]
By default, gdb will append to the logfile. Set overwrite if you want set logging on to overwrite the logfile instead.
set logging redirect [on|off]
By default, gdb output will go to both the terminal and the logfile. Set redirect if you want output to go only to the log file.
show logging
Show the current values of the logging settings.

How to force GDB to start number breakpoints at 1

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...

Save breakpoints in LLDB

As Jim Ingham said above, you currently cannot save breakpoints in lldb. However, there is a work around. You can load lldb commands from a command file as follows:

lldb -S <path_to_command_file>

You can have this in your command file:

file <path_to_binary>
breakpoint set --file file0.cc --line 22
breakpoint set --file file1.cc --line 237

The above command file will load the binary and set the breakpoints when lldb starts.

gdb alias for quick saving/loading of breakpoints

Can GDB have filenames in aliases?

Looks like no. It looks like aliases can't have any arguments to commands, not only filenames. This alias fails also:

(gdb) alias spe = set print elements 0
Invalid command to alias to: set print elements 0

Or am I looking for something other than an 'alias'?

Yes, you can use user-defined command instead:

(gdb) define savebps
Type commands for definition of "savebps".
End with a line saying just "end".
>save breakpoints .gdb_bps
>end
(gdb)
(gdb) define loadbps
Type commands for definition of "loadbps".
End with a line saying just "end".
>source .gdb_bps
>end
(gdb)

Is there a quick way to display the source code at a breakpoint in gdb?

You can use the list command to show sources. list takes a "linespec", which is gdb terminology for the kinds of arguments accepted by break. So, you can either pass it whatever argument you used to make the breakpoint in the first place (e.g., list function) or you can pass it the file and line shown by info b (e.g., list mysource.c:75).



Related Topics



Leave a reply



Submit