Getting gdb to save a list of breakpoints?

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 dumping them into a file acceptable for input again? Sometimes in a debugging session, it is necessary to restart gdb after building up a set of breakpoints for testing.

Edit: the .gdbinit file has the same problem as --command. The info break command does not list commands, but rather a table for human consumption.

To elaborate, here is a sample from info break:

(gdb) info break
Num Type           Disp Enb Address    What
1   breakpoint     keep y   0x08048517 <foo::bar(void)+7>

从gdb 7.2开始,您现在可以使用save breakpoints命令。

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.

This answer is outdated, gdb now supports saving directly. See this answer.

You can use logging:

(gdb) b main
Breakpoint 1 at 0x8049329
(gdb) info break
Num     Type           Disp Enb Address    What
1       breakpoint     keep y   0x08049329 <main+16>
(gdb) set logging file breaks.txt
(gdb) set logging on
Copying output to breaks.txt.
(gdb) info break
Num     Type           Disp Enb Address    What
1       breakpoint     keep y   0x08049329 <main+16>
(gdb) q

The file breaks.txt now contains:

Num     Type           Disp Enb Address    What
1       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.txt
define dump_breaks
    set logging file $arg0
    set logging redirect on
    set logging on
    info breakpoints
    set logging off
    set logging redirect off
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.

链接地址: http://www.djcxy.com/p/24310.html

上一篇: GDB:运行到特定的断点

下一篇: 让gdb保存一个断点列表?