如果程序成功,如何让gdb退出,如果程序崩溃会中断? [英] How to have gdb exit if program succeeds, break if program crashes?
问题描述
这是一个小黑客,但你可以这样做:
gdb --eval-command = run --eval-command = quit --args ./a.out
如果a.out正常终止,它会让您退出GDB。但是,如果你崩溃了,程序仍然是活跃的,所以GDB通常会提示你是否真的想退出一个活跃的劣势:
编程接收到的信号SIGABRT,中止。
0x00007ffff72dad05 in raise(sig = ...)at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
64 ../nptl/sysdeps/unix/sysv/linux /raise.c:没有这样的文件或目录。
在../nptl/sysdeps/unix/sysv/linux/raise.c
调试会话处于活动状态。
劣等1 [过程15126]将被杀死。
无论如何退出? (y或n)
像我说的,不漂亮,但它的作品,只要你避难没有关闭提示符以退出活动进程。可能还有一种方法可以使用gdb的 quit
命令:它需要一个数字参数,它是调试会话的退出代码。所以,也许你可以使用--eval-command =quit stuff,其中东西是一些GDB表达式,反映了劣势是否在运行。
I seem to have some kind of multithreading bug in my code that makes it crash once every 30 runs of its test suite. The test suite is non-interactive. I want to run my test suite in gdb, and have gdb exit normally if the program exits normally, or break (and show a debugging prompt) if it crashes. This way I can let the test suite run repeatedly, go grab a cup of coffee, come back, and be presented with a nice debugging prompt. How can I do this with gdb?
This is a little hacky but you could do:
gdb --eval-command=run --eval-command=quit --args ./a.out
If a.out terminates normally, it will just drop you out of GDB. But if you crash, the program will still be active, so GDB will typically prompt if you really want to quit with an active inferior:
Program received signal SIGABRT, Aborted.
0x00007ffff72dad05 in raise (sig=...) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
64 ../nptl/sysdeps/unix/sysv/linux/raise.c: No such file or directory.
in ../nptl/sysdeps/unix/sysv/linux/raise.c
A debugging session is active.
Inferior 1 [process 15126] will be killed.
Quit anyway? (y or n)
Like I said, not pretty, but it works, as long as you haven't toggled off the prompt to quit with an active process. There is probably a way to use gdb's quit
command too: it takes a numeric argument which is the exit code for the debugging session. So maybe you can use --eval-command="quit stuff", where stuff is some GDB expression that reflects whether the inferior is running or not.
这篇关于如果程序成功,如何让gdb退出,如果程序崩溃会中断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!