如何在窗口上设置gdb,以便它不允许断言失败的程序终止?我打算检查程序中的堆栈跟踪和变量。
例如,在gdb中运行使用MinGW'g++ -g test.cpp -o test
'编译的test.cpp程序:
#include <cassert>
int main(int argc, char ** argv) { assert(1==2); return 0; }
得到:
$ gdb test.exe
GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-mingw32"...
(gdb) r
Starting program: f:\code/test.exe
[New thread 4616.0x1200]
Error: dll starting at 0x77030000 not found.
Error: dll starting at 0x75f80000 not found.
Error: dll starting at 0x77030000 not found.
Error: dll starting at 0x76f30000 not found.
Assertion failed: 1==2, file test.cpp, line 2
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
Program exited with code 03.
(gdb)
我希望能够阻止程序立即终止,就像Visual Studio的调试器和Linux上的gdb一样。我做了一个搜索,发现了捕获信号的一些东西,但我似乎无法找到关于如何设置gdb来做到这一点的好帖子。
只需在退出时设置断点:
(gdb) b exit
发现断点可以放在.gdbinit
文件中,其中包含以下行:
set breakpoint pending on
b exit
这消除了为Windows输入yes的需要。
使用最近的(2017年3月)msys2与gcc 6.3和gdb 7.12.1你应该使用:
break _exit
即使用_exit
而不是exit
。我希望这也适用于其他情况,因为我预计exit
将调用_exit
实际退出。