使gdb在成功终止时自动退出? [英] Make gdb quit automatically on successful termination?

查看:34
本文介绍了使gdb在成功终止时自动退出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了一个调试脚本,它通过调试器连续运行多个相关进程.我目前正在使用 -x 自动执行几个命令(例如 run).当被调试的进程成功终止时,如何让 gdb 自动退出?quit 命令添加到命令文件将导致该命令不仅在成功终止时被处理,而且当错误也发生时(我宁愿在那个时候接管).

I use a debugging script that runs several related processes in succession with the debugger. I'm currently using -x to execute several commands automatically (such as run). How can I make gdb quit automatically when the debugged process successfully terminates? Adding a quit command to the command file will cause that command to be handled not just on successful termination, but when errors occur also (when I'd rather take over at that point).

这里是正在发生的事情的摘录:

Here's an extract of what's going on:

+ gdb -return-child-result -x gdbbatch --args ./mkfs.cpfs /dev/loop0
GNU gdb (GDB) 7.1-ubuntu
Reading symbols from /home/matt/cpfs/mkfs.cpfs...done.

Program exited normally.
Breakpoint 2 at 0x805224f: file log.c, line 32.
(gdb)

gdbbatch的内容:

start
b cpfs_log if level >= WARNING

推荐答案

我想我已经找到了一个完整的解决方案来解决您在 如何让 gdb 在收到信号时发送外部通知?.这里的其他人似乎都没有提到或发现 gdb 钩子.

I think I have found a complete solution to your question in connection to looking for something similar in How to make gdb send an external notification on receiving a signal?. None of the other guys here seem to have mentioned or discovered gdb hooks.

根据 Matthew 关于 $_exitcode 的提示,现在这是我的 app/.gdbinit ,它完全实现了想要的行为;成功终止后正常退出并进入 gdb 提示符,发送电子邮件,其他一切:

Based on Matthew's tip about $_exitcode, this is now my app/.gdbinit that achieves exactly the behavior wanted; normal quit on successful termination and drop to gdb prompt, send email, whatnot on everything else:

set $_exitcode = -999
set height 0
handle SIGTERM nostop print pass
handle SIGPIPE nostop
define hook-stop
    if $_exitcode != -999
        quit
    else
        shell echo | mail -s "NOTICE: app has stopped on unhandled signal" root
    end
end
echo .gdbinit: running app

run

这篇关于使gdb在成功终止时自动退出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆