【发布时间】:2011-08-25 18:54:20
【问题描述】:
我目前正在用 gdb 调试一个程序。 我必须一遍又一遍地启动 gdb 并执行相同的步骤:
设置断点, 跑, 打印一个变量, 退出
有没有办法让 gdb 自动为我做这件事?可能是一个可以作为参数附加的脚本?
提前致谢!
【问题讨论】:
标签: gdb
我目前正在用 gdb 调试一个程序。 我必须一遍又一遍地启动 gdb 并执行相同的步骤:
设置断点, 跑, 打印一个变量, 退出
有没有办法让 gdb 自动为我做这件事?可能是一个可以作为参数附加的脚本?
提前致谢!
【问题讨论】:
标签: gdb
您可以通过-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
【讨论】:
文件名是 .gdbrc 还是 .gdbinit 不同,但 GDB 会在启动时从你的主目录读取这个文件,它可以给出任何 GDB 命令(包括设置断点)。
【讨论】:
.gdbrc 也不会读取.gdbin。它将读取.gdbinit