Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging MinGW program with gdb on Windows, not terminating at assert failure

How do I set up gdb on window so that it does not allow a program with assertion failure to terminate? I intend to check the stack trace and variables in the program.

For example, running this test.cpp program compiled with MinGW 'g++ -g test.cpp -o test' in gdb:

#include <cassert>
int main(int  argc, char ** argv) { assert(1==2); return 0; }

Gives:

$ 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)

I would like to be able to stop the program from terminating immediately, like how Visual Studio's debugger and gdb on Linux does it. I have done a search and found some stuff on trapping signals but I can't seem to find a good post on how to set up gdb to do this.

like image 348
devil Avatar asked Apr 24 '10 17:04

devil


3 Answers

Using recent (March 2017) msys2 with gcc 6.3 and gdb 7.12.1 you should use:

break _exit

i.e. use _exit and not exit. I expect this also to work in other cases as I expect that exit will call _exit to actually exit.

like image 150
Klamer Schutte Avatar answered Nov 07 '22 12:11

Klamer Schutte


Found out that the breakpoint can be put in the .gdbinit file with the lines:

set breakpoint pending on
b exit

This removes the need to enter yes for windows.

like image 7
devil Avatar answered Nov 07 '22 10:11

devil


Just set a breakpoint on exit:

(gdb) b exit

like image 6
Paul R Avatar answered Nov 07 '22 10:11

Paul R