【问题标题】:Is there a way to let the gdb repeat the same instrcutions on every start again?有没有办法让 gdb 在每次启动时重复相同的指令?
【发布时间】:2011-08-25 18:54:20
【问题描述】:

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

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

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

提前致谢!

【问题讨论】:

    标签: gdb


    【解决方案1】:

    您可以通过-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
    

    【讨论】:

      【解决方案2】:

      文件名是 .gdbrc 还是 .gdbinit 不同,但 GDB 会在启动时从你的主目录读取这个文件,它可以给出任何 GDB 命令(包括设置断点)。

      还可以查看http://www.andrews.edu/~seidel/gdb.help

      【讨论】:

      • 刚刚检查了手册页以查看文件的名称,它是 .gdbinit 你可以告诉 gdb 用 -n 或 -nx 忽略它无论如何,对于我的目的,有一个更好的方法我只是在手册页中找到(对不起!): -x FILE, -command=FILE 从文件 file 执行 GDB 命令。可以在该文件中写入解释器执行的命令,每行一个。
      • 这个答案是错误的:GDB 不会读取.gdbrc 也不会读取.gdbin。它读取.gdbinit
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多