Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdb catchpoint for uncaught C++ exceptions only?

I can tell the gdb debugger to stop as soon as any C++ exception is thrown by setting a catchpoint with the gdb command

catch throw

However, is there any way to only stop at uncaught C++ exceptions (like in C# or Java)? This would make it much easier to find bugs in some situations.

Thanks!

like image 897
emkey08 Avatar asked Apr 19 '11 15:04

emkey08


1 Answers

If an exception is uncaught, the special library function terminate() is automatically called. Terminate is actually a pointer to a function and default value is the Standard C library function abort(). You may be able to set a breakpoint on the call to the abort() function and identify the location of the uncaught exception from there.

break abort
...
run
...
bt

You can install your own terminate() function by using std::set_terminate(). You should be able to set a breakpoint on your terminate function in gdb. You may be able to generate a stack backtrace from your terminate() function and this backtrace may help in identifying the location of the exception. Additional details are provided here.

like image 57
jschmier Avatar answered Oct 21 '22 11:10

jschmier