这个答案已经过时了。GDB 现在支持直接保存。看到这个答案。
您可以使用日志记录:
(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
文件breaks.txt 现在包含:
Num Type Disp Enb Address What
1 breakpoint keep y 0x08049329 <main+16>
编写一个 AWK 脚本将其转换为对文件.gdbinit
或--command
文件有用的格式很容易。或者你甚至可以让脚本--eval-command
向 GDB 命令行发出单独的 's ......
将这个小宏添加到.gdbinit将帮助您做到这一点:
# 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