Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not break into gdb debugger when facing unexpected exception #1030

Open
hiiwave opened this issue Sep 30, 2017 · 14 comments
Open

Could not break into gdb debugger when facing unexpected exception #1030

hiiwave opened this issue Sep 30, 2017 · 14 comments

Comments

@hiiwave
Copy link

hiiwave commented Sep 30, 2017

Description

It's in fact the same issue as #586, where unexpected exceptions in the tests don't break into the gdb debugger with arguments -b --break. According to @horenmar at #418, it should have been implemented in commits b634e59, 25d0177, e1c4a4b. However it still does not work as expected.

Steps to reproduce

Follow the same steps in #586, the test reproducing this is as follows:

#define CATCH_CONFIG_MAIN
#include "catch.hpp"

TEST_CASE("exception") { throw "nobody expects the Spanish inquisition"; }

By compiling and running it under gdb:

g++ -g -std=c++0x tst.cpp && gdb --args ./a.out -b
Reading symbols from ./a.out...done.
(gdb) r
Starting program: a.out -b

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.out is a Catch v2.0.0-develop.4 host application.
Run with -? for options

-------------------------------------------------------------------------------
exception
-------------------------------------------------------------------------------
tst.cpp:4
...............................................................................

tst.cpp:4: FAILED:
due to unexpected exception with message:
  nobody expects the Spanish inquisition

===============================================================================
test cases: 1 | 1 failed
assertions: 1 | 1 failed

the expected SIGTRAP doesn't happen.

Extra information

  • Catch version: v2.0.0-develop.4 (also tried the single-header version on master)
  • Operating System: Ubuntu 16.04
  • Compiler+version: gcc version 5.4.0 (also tried clang version 3.8.0-2ubuntu4)
@horenmar
Copy link
Member

So far, breaking into debugger happens only for failed assertions. This means that this

#define CATCH_CONFIG_MAIN
#include "catch.hpp"

int throws() {
    throw 1;
    return 1;
}

TEST_CASE("A") {
    REQUIRE(throws() == 2);
}

will break on the exception*, but your original code won't.

Looking over #586, it is a separate issue from the one closed by me, but since it was closed by its creator back in 2016, I never even noticed it existing. I'll take a look at what it would take to implement this for unexpected exceptions outside of assertions, but the usual caveat emptor applies: the backlog of potential features is much bigger than the amount of available time.

* Actually on the assertion failure

@hiiwave
Copy link
Author

hiiwave commented Sep 30, 2017

I see. It's my carelessness that I didn't notice that #586 was indeed a separate issue from #418. Hence so far I think the best way to debug with unexpected exception would be using catch throw in gdb itself. Thank you really much for your concern.

@philsquared
Copy link
Collaborator

@hiiwave does this conclude this issue for you?

@philsquared philsquared added the Resolved - pending review Issue waiting for feedback from the original author label Oct 13, 2017
@hiiwave
Copy link
Author

hiiwave commented Oct 15, 2017

I would say it's still preferable if breaking into debugger -b in Catch supports unexpected exceptions. Since the use of catch throw command in gdb has some side effects including that it also breaks at caught exceptions. @horenmar had clarified me that it's not a bug report but instead a feature request.

@horenmar horenmar removed the Resolved - pending review Issue waiting for feedback from the original author label Oct 15, 2017
@ax3l
Copy link
Contributor

ax3l commented Jan 4, 2019

I would love to use this feature as well.
In my case, I am refactoring a larger code base with existing unit tests. When testing the result, exceptions from the library itself are thrown in the tests which I would like to debug in gdb by breaking into it and investigating the current backtrace.

Unfortunately, Catch2 does not break with -a -b at these points and throws me back to printf debugging.

@ax3l
Copy link
Contributor

ax3l commented Jan 7, 2019

A current work-around with gdb can be to set breakpoints on all throws and iterate to the actual unexpected throw:

gdb --args ./CatchTest -a -b
(gdb) catch throw
(gdb) run

@tankorsmash
Copy link

That's a bummer. I'm on VS2013 and I'd love to be able to break on exceptions. I've got a std::out_of_range that I'd love to be able to break on.

@hsdk123
Copy link

hsdk123 commented Jun 23, 2019

I'm currently on VS2019 - would also love to have this as an option.

@mika-fischer
Copy link

I'd also like to see this. Otherwise it's unnecessarily difficult to unexpected exceptions.

@prat0088
Copy link

I will be changing testing frameworks because of this. It makes it unnecessarily very difficult to debug unexpected exceptions.

@jdumas
Copy link

jdumas commented Mar 2, 2022

Is there any chance to see this feature implemented in a future version of Catch2? I've been hitting this limitation a couple of times, and it would really help debugging for sure.

@ziereis
Copy link

ziereis commented Dec 20, 2023

how is this still not a thing? very disappointing

@lordrebel
Copy link

any update?

@eullerborges
Copy link

Surprising this has been ignored for so long.

I'd like to point out that there is a better way around this than just having to go through all exceptions.
On gdb, break on the exception by counting them:

(gdb) catch throw
Catchpoint 1 (throw)
(gdb) ignore 1 1000
Will ignore next 1000 crossings of breakpoint 1.

(gdb) r
[...] Crashes

(gdb) info b
Num     Type           Disp Enb Address            What
1       catchpoint     keep y                      exception throw
        catchpoint already hit 49 times
        ignore next 951 hits
(gdb) # Ignore N-1 crossings of the catchpoint (N=49 above)
(gdb) ignore 1 48
Will ignore next 48 crossings of breakpoint 1.

(gdb) # Run again!
(gdb) r
[...] gdb will stop at the point the exception that terminates the test is thrown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests