如何确保GDB终止命令文件错误?

发布于 2025-01-29 22:26:25 字数 433 浏览 3 评论 0原文

我想使用命令文件自动化GDB调试会话,但要确保GDB每次终止。

这是文档中描述的问题:

任何命令中的错误终止了命令文件的执行和 控制返回控制台。

就我而言,如果有错误,我希望脚本继续或终止GDB。即不要让它返回控制台(并让我手动退出)。例如,请参见下面

echo Starting GDB script\n
set confirm off
set pagination off
echo Connecting to target\n
target remote localhost:1234
thread 1
thread 2 # <-- This command will produce an error, and stop the script from terminating GDB
k
q

I want to automate a GDB debug session using command files but want to make sure GDB terminates every time.

This is a problem as described in the documentation :

An error in any command terminates execution of the command file and
control is returned to the console.

In my case I want the script to either continue or terminate GDB if there is an error. I.e. dont let it return to console (and make me quit manually). E.g. see below

echo Starting GDB script\n
set confirm off
set pagination off
echo Connecting to target\n
target remote localhost:1234
thread 1
thread 2 # <-- This command will produce an error, and stop the script from terminating GDB
k
q

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Saygoodbye 2025-02-05 22:26:26

在我的情况下,如果有错误,我希望脚本继续或终止GDB。即不要让它返回控制台(并让我手动退出)。

使用-batch参数调用GDB,它将忽略脚本错误。

例子:

$ gdb -q -batch -ex 'start' -ex 'thread 2' -ex 'print foo' -ex kill  ./a.out
Temporary breakpoint 1 at 0x112d

Temporary breakpoint 1, 0x000055555555512d in main ()
Unknown thread 2.
No symbol "foo" in current context.
[Inferior 1 (process 2359421) killed]

In my case I want the script to either continue or terminate GDB if there is an error. I.e. dont let it return to console (and make me quit manually).

Invoke GDB with -batch argument, and it will ignore script errors.

Example:

$ gdb -q -batch -ex 'start' -ex 'thread 2' -ex 'print foo' -ex kill  ./a.out
Temporary breakpoint 1 at 0x112d

Temporary breakpoint 1, 0x000055555555512d in main ()
Unknown thread 2.
No symbol "foo" in current context.
[Inferior 1 (process 2359421) killed]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文