gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 17:33:55 26 4
gpt4 key购买 nike

如何在 window 上设置 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 来执行此操作的好帖子。

最佳答案

发现断点可以放在 .gdbinit 文件中:

set breakpoint pending on
b exit

这消除了为 windows 输入 yes 的需要。

关于c++ - 在 Windows 上使用 gdb 调试 MinGW 程序,而不是在断言失败时终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2705442/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com