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

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

问题描述

我使用运行在调试器连续几个相关工艺调试脚本。我目前使用 -x 来自动执行多个命令(如运行)。 我怎样才能让GDB自动退出时调试的进程成功终止?添加退出命令来命令文件将导致该命令可以不处理刚上成功的终止,但也会出现错误时(我宁愿在这一点上接管)。

下面是发生了什么事情的摘录:

 + GDB -return孩子-结果-x gdbbatch --args ./mkfs.cpfs的/ dev / LOOP0
GNU GDB(GDB)7.1的Ubuntu
阅读从/home/matt/cpfs/mkfs.cpfs...done符号。程序正常退出。
在0x805224f断点2:文件log.c 32行。
(GDB)

目录 gdbbatch

启动
b cpfs_log如果级别> =警告


解决方案

GDB套 $ _退出code 当程序成功结束。您可以使用那 - 在你的脚本开始时,只有退出在结束时,如果它已经改变了它设置为一个不可能的值:

 设置$ _exit code = -999
#...

#...
如果$ _exit code!= -999
  放弃
结束

(设置 $ _退出code 来一个不可能的值是有点难看,但它否则将无法在所有如果程序不终止定义,而且似乎没有要问的任何明显的方法这个变量定义的?在条件)。

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)

Contents of gdbbatch:

start
b cpfs_log if level >= WARNING

解决方案

gdb sets $_exitcode when the program successfully terminates. You can make use of that - set it to an unlikely value at the start of your script, and only quit at the end if it has changed:

set $_exitcode = -999
# ...
run
# ...
if $_exitcode != -999
  quit
end

(Setting $_exitcode to an unlikely value is a bit ugly, but it will otherwise not be defined at all if the program doesn't terminate, and there doesn't seem to be any obvious way of asking "is this variable defined?" in a conditional.)

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

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