Bug 9600 - Calling a function that has a throw, but an out of frame exception handler via inferior function call results in sigabrt delivery to inferior
Summary: Calling a function that has a throw, but an out of frame exception handler vi...
Alias: None
Product: gdb
Classification: Unclassified
Component: c++ (show other bugs)
Version: 6.8
: P3 enhancement
Target Milestone: 7.2
Assignee: Not yet assigned to anyone
Depends on:
Reported: 2008-08-05 17:28 UTC by Phil Muldoon
Modified: 2011-11-15 14:43 UTC (History)
2 users (show)

See Also:
Last reconfirmed:

infthrow.cxx (261 bytes, application/octet-stream)
, Phil Muldoon

Note You need to log in before you can comment on or make changes to this bug.
Description Phil Muldoon 2008-08-05 17:28:01 UTC
[Converted from Gnats 2495]

Please see attached test case C++ file. The test case has three functions

call_none () - basic test of inferior function call. Print then return.

call_throw_with_inframe_handler () - test where an exception is thrown and caught locally, within the same frame.

call_throw_no_inframe_handler () - test where an exception is thrown, but not caught locally. The catch for this is in main().

Output from GDB:

g++ -g infthrow.cxx -o infthrow

gdb infthrow

(gdb) b main
Breakpoint 1 at 0x400b8c: file infthrow.cxx, line 31.

(gdb) r
Starting program: /home/pmuldoon/exceptions/infthrow

Breakpoint 1, main () at infthrow.cxx:31
31	  call_throw_with_inframe_handler ();

(gdb) print call_throw_with_inframe_handler() 
Throw exception with the handler in another frame.
Local exception handled.
$1 = void

(gdb) print call_none() 
Do nothing.
$2 = void

(gdb) print call_throw_no_inframe_handler() 
throw exception with the handler in another frame
terminate called after throwing an instance of 'int'

Program received signal SIGABRT, Aborted.
0x0000003c49e32215 in raise () from /lib64/libc.so.6
The program being debugged was signaled while in a function called from GDB.
GDB remains in the frame where the signal was received.
To change this behavior use "set unwindonsignal on"
Evaluation of the expression containing the function (call_throw_no_inframe_handler()) will be abandoned.

It appears that when __cxa_throw calls __Unwind_RaiseException it is returning _URC_END_OF_STACK which means it cannot find a matching handler in any frame. This is probably due to the mechanics of inferior function calls. As a result, it cannot find the handler in main() and this defaults to the default C++ handler which calls abort.

Comment 1 Tom Tromey 2011-11-15 14:43:11 UTC
The patch for this went in a while ago.