GDB pre-make 监视和命令

GDB pre-make watches and commands

我正在尝试创建一个包含所有 watchesdefine command 的单独文件,以便在开始调试之前加载到 gdb 中。我想象它像这样工作

    #debug.info

    watch i

    define sumA
       print $arg0 + $arg1 + $arg2
    end

    b 30

然后我只用它作为参数执行program.out。 我想象它看起来像这样

gdb program -s debug.info

我一直在 man gdb 中查找,但似乎找不到。你能帮忙吗?

感谢您的宝贵时间。

要从文件中读取命令,您必须使用 -x 而不是 -s

来自手册页:

   -command=file
   -x file
       Execute GDB commands from file file.

-s 载入一个符号文件。如果您使用 -g 编译,通常您的程序已经包含了所有符号。您可以将应用程序和符号拆分为单独的文件,但这通常不是您想要的。