views:

325

answers:

3

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&gt;
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.

A: 

Just set a breakpoint on exit:

(gdb) b exit

Paul R
how do I stop it from asking about:Function "exit" not defined in loaded symbols.Make breakpoint pending on future shared library load? (y or [n]) yBreakpoint 1 (exit) pending.
devil
+1  A: 

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.

devil
A: 

and if the program is a binary without any debug info? then what?

Artem Pylypchuk