有没有办法让gdb在每次重启时重复相同的指令?

时间:2011-08-25 18:54:20

标签: gdb

我目前正在使用gdb调试程序。 我必须一遍又一遍地启动gdb并执行相同的步骤:

设置断点, 跑, 打印变量, 退出

有没有办法让gdb自动为我做这件事?可能是一个可以作为参数附加的脚本吗?

提前致谢!

2 个答案:

答案 0 :(得分:5)

您可以通过-x file选项或-ex command选项执行此操作。来自Gdb manual

-command file
-x file
Execute commands from file file. The contents of this file is evaluated exactly as the source command would. See Command files. 
-eval-command command
-ex command
Execute a single gdb command.
This option may be used multiple times to call multiple commands. It may also be interleaved with `-command' as required.

          gdb -ex 'target sim' -ex 'load' \
             -x setbreakpoints -ex 'run' a.out

答案 1 :(得分:0)

interwebs在文件名是.gdbrc还是.gdbin方面有所不同,但是GDB会在启动时从你的主目录中读取这个文件,它可以提供任何GDB命令(包括设置断点)。

另请查看http://www.andrews.edu/~seidel/gdb.help