0

I am trying to track the source of a std::exception, in basic_string::erase, I wrapped all the locations where I am calling erase directly in try/catch and am not seeing any of these catch blocks be hit, so it must be being called internally from another basic_string method. The exception appears to be the result of a race condition in the code i am working with, so it is very difficult to reproduce, any thoughts on how I could detect and or get a stack trace from this exception? btw this is c++ code on an x86 linux box.

Thank you

NSA
  • 5,689
  • 8
  • 37
  • 48
  • If `basic_string::erase` is throwing an exception due to a race condition, I fail to see why you need the source of the exception. Remove the race condition. – Mooing Duck Oct 04 '12 at 18:34
  • The standard says that `basic_string::erase` throws: out_of_range if pos > size(). – Joseph Mansfield Oct 04 '12 at 18:34
  • Are you using an erase call in a race condition? – Simon Germain Oct 04 '12 at 18:36
  • @MooingDuck: Presumably the OP doesn't know what the race condition *is*, only that there seems to be one, and (s)he hopes that tracking down the location of the exception will help identify it. (See [*De dicto* and *de re* on Wikipedia](http://en.wikipedia.org/wiki/De_dicto_and_de_re).) – ruakh Oct 04 '12 at 18:36
  • Are you positive that it's an exception, and not an assertion? – ildjarn Oct 04 '12 at 19:02
  • @ildjarn : yes i am positive it was an exception – NSA Oct 07 '12 at 18:55
  • @ruakh correctomundo! Thank you all for your help, the answer below actually helped me solve this problem I was able to use breaking on all thows in conjunction with gdb breakpoint functions to capture why this was happening and then resolve it. – NSA Oct 07 '12 at 18:55
  • @Mooing Duck thank you for the obvious suggestion, but with out finding the source of the exception I didn't know what was involved in the race condition that was causing this. – NSA Oct 07 '12 at 18:57

1 Answers1

4

You should try

(gdb) catch throw

Then gdb will trigger breakpoint each time exception is thrown. You'll see a callstack.

EDIT: This post is a good bunch of tricks for debugging exceptions: GDB: How to break when a specific exception type is thrown?

Community
  • 1
  • 1
Al W
  • 476
  • 3
  • 15