开发者

Is there a way to let the gdb repeat the same instrcutions on every start again?

I am currently debugging a program with gdb. I have to start gdb over and over again and do the same steps:

set a breakpoint, run, print a variable, quit

Is there a way to let gdb do that automatically for me? Probably a script that could be 开发者_开发问答attached as a parameter?

Thanks in advance!


You can do it either by -x file option or by -ex command option. From 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


The interwebs differ on whether the name of the file is .gdbrc or .gdbinit, but GDB will read this file from your home directory on start-up, and it can give any GDB command (including setting breakpoints).

Also check out http://www.andrews.edu/~seidel/gdb.help

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜