本文介绍了有没有办法让gdb在每次开始时重复相同的指令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在用gdb调试一个程序。
我必须反复启动gdb并执行相同的步骤:

设置一个断点,
run,
打印一个变量,
退出



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



预先感谢!

解决方案

您可以通过 -x文件选项或 -ex命令选项来完成。从:

   - 命令文件
-x文件
从文件文件执行命令。该文件的内容与源命令完全一样。请参阅命令文件。
-eval-command命令
-ex命令
执行单个gdb命令。
此选项可能会多次用于调用多个命令。它也可以根据需要与`-command'交错。

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


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

这篇关于有没有办法让gdb在每次开始时重复相同的指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 01:54