在Windows上使用gdb调试MinGW程序,断言失败时不终止程序

9

如何在Windows上设置gdb,以使其不允许具有断言失败的程序终止?我打算检查程序中的堆栈跟踪和变量。

例如,在gdb中运行使用MinGW编译的test.cpp程序'g++ -g test.cpp -o test':

#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以实现这一点。

3个回答

7

发现断点可以放在.gdbinit文件中,以下是相关代码:

set breakpoint pending on
b exit

这将不再需要在 Windows 中输入“是”。

6

只需在退出处设置断点:

(gdb) b exit


如何停止它询问: 在已加载的符号中未定义函数“exit”。 将断点设置为等待未来共享库加载?(y或[n])y 断点1(退出)等待中。 - devil

2

如果您使用的是最新的msys2(截至2017年3月),配备了gcc 6.3和gdb 7.12.1,则应该使用以下命令:

break _exit

即使用 _exit 而不是 exit。我认为这在其他情况下也适用,因为我预计 exit 将调用 _exit 来实际退出。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接