OK, info break lists the breakpoints, but not in a format that would work well with reusing them using the --command as in this question. Does GDB have a method for
The problem is that setting a breakpoint is context sensitive. What if you have two static functions named foo?
If you are already debugging one of the modules that defines foo, then GDB will assume you meant that one. But if you just dump "break foo" into a file and then read that file at start-up, it will not be clear which function foo you mean.
Perhaps this:
save breakpoints [filename]
I found the following addition to a previous answer useful to save/load the breakpoints to a specific file.
As in the previous answer, add the following code to the file ~/.gdbinit
# Save breakpoints to a file
define bsave
if $argc != 1
help bsave
else
save breakpoints $arg0
end
end
document bsave
Saves all current defined breakpoints to the defined file in the PWD
Usage: bsave <filename>
end
# Loads breakpoints from a file
define bload
if $argc != 1
help bload
else
source $arg0
end
end
document bload
Loads all breakpoints from the defined file in the PWD
Usage: bload <filename>
end
Put your GDB commands and breakpoints in a .gdbinit file just as you might type them at the gdb>
prompt, and GDB will automatically load and run them on startup. This is a per-directory file, so you can have different files for different projects.
Extension to the answer from Johannes: you could automatically reformat the output of info break
into a valid GDB command file:
.gdbinit:
define bsave
shell rm -f brestore.txt
set logging file brestore.txt
set logging on
info break
set logging off
# Reformat on-the-fly to a valid gdb command file
shell perl -n -e 'print "break $1\n" if /^\d+.+?(\S+)$/g' brestore.txt > brestore.gdb
end
document bsave
store actual breakpoints
end
Afterwards you have a valid commandfile in brestore.gdb
.
This worked for me when the application is compiled with -g
.
I also successfully tested it with GDB v6.8 on Ubuntu 9.10 (Karmic Koala).