Getting GDB to save a list of breakpoints Getting GDB to save a list of breakpoints c c

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.


This answer is outdated. GDB now supports saving directly. See this answer.

You can use logging:

(gdb) b mainBreakpoint 1 at 0x8049329(gdb) info breakNum     Type           Disp Enb Address    What1       breakpoint     keep y   0x08049329 <main+16>(gdb) set logging file breaks.txt(gdb) set logging onCopying output to breaks.txt.(gdb) info breakNum     Type           Disp Enb Address    What1       breakpoint     keep y   0x08049329 <main+16>(gdb) q

The file breaks.txt now contains:

Num     Type           Disp Enb Address    What1       breakpoint     keep y   0x08049329 <main+16>

Writing an AWK script that transforms that into a format useful for the .gdbinit or a --command file is easy. Or you may even make the script emit separate --eval-command's to the GDB command line...

Adding this small macro to .gdbinit will help you do it:

# Call with dump_breaks file.txtdefine dump_breaks    set logging file $arg0    set logging redirect on    set logging on    info breakpoints    set logging off    set logging redirect offend


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.