Intercepting exceptions with the debugger

132 views
Skip to first unread message

nu quaquaraqua

unread,
Jul 8, 2019, 4:21:46 AM7/8/19
to Google C++ Testing Framework
Good morning,
when using gtest_main, how can we capture, show the back trace and inspect the state of an exception thrown inside a test with a debugger in the point where it occurred? 

Thanks,
quack

Matthew Woehlke

unread,
Jul 8, 2019, 10:37:31 AM7/8/19
to googletes...@googlegroups.com
https://lmgtfy.com/?q=break+on+exception

(Hint: on Linux, you probably want 'break __cxa_throw'. In VS and xcode,
there is apparently a menu action.)

I'll assume you already know how to obtain a backtrace from your debugger...

Matthew

Quaquaraqua

unread,
Jul 9, 2019, 6:51:13 AM7/9/19
to googletes...@googlegroups.com
right, found, there is an extra argument for the driver --gtest_catch_exceptions=0

geez, Matthew, to my defence it was on the last paragraph of the rather long & unindexed GoogleTest docs :-)

Thanks,
quack
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "Google C++ Testing Framework" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to googletestframe...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/googletestframework/1fa149b4-9cba-e5cd-b971-46cfb65f5771%40kitware.com.
> For more options, visit https://groups.google.com/d/optout.


--
Quaquaraqua <nuquaq...@gmail.com>

Matthew Woehlke

unread,
Jul 9, 2019, 10:56:29 AM7/9/19
to Quaquaraqua, googletes...@googlegroups.com
If that helps, great! However, I would have expected most techniques to
catch exceptions in debuggers (note: this is true for at least 'break
__cxa_throw') should break on *throw*, however, whether or not anything
catches the exception, i.e. gtest_catch_exceptions shouldn't matter.

OTOH I'm not sure if I understood your original question... Did you mean
"how can I stop gtest catching exceptions so that an exception causes a
'typical' abnormal termination which allows a debugger to be
attached?"... in which case, gtest_catch_exceptions is indeed what you
wanted.

Matthew

Quaquaraquà

unread,
Jul 10, 2019, 3:12:19 PM7/10/19
to googletes...@googlegroups.com
you're right, at the time I didn't actually think to "literally" break on an exception, I've realised this was an option only afterwards :P At the end that achieves the same effect in my case.

Yours,
quack

On Tue, 9 Jul 2019 10:56:24 -0400
--
Quaquaraquà <nuquaq...@gmail.com>
Reply all
Reply to author
Forward
0 new messages