Cookie
Cookie

Reputation: 12642

gdb catch throw and then ignore exceptions

I have a crash in a multi threaded application and for whatever reason I can't manage to catch the exception before the stack is partially unwound.

So now I am trying to catch it by connected with gdb and using catch throw. However, I am getting lots of other unrelated and caught exceptions. How can I ignore those?

I tried ignore 1 1000000, but this doesn't ignore just the exception currently focused, but ignores all catch throw exceptions.

Any ideas how I can ignore that particular one only? e.g. maybe by file and line number?

Upvotes: 2

Views: 2868

Answers (1)

Tom Tromey
Tom Tromey

Reputation: 22519

Since version 7.9, gdb has included some convenience functions like $_caller_is and $_any_caller_is. These can be used as conditions on a breakpoint to make it stop only when a certain call stack is seen.

So, for example, if you know the spot at which the exception is thrown, you could do something like:

(gdb) catch throw if $_any_caller_is("functionname")

However, if you know the throwing function, it seems to me that it would be simpler to just set a breakpoint at that particular throw.

Another option in some situations is to filter the exception by type. This functionality is built into catch throw since version 7.7. This form accepts a regular expression matching the type name:

(gdb) catch throw NameOfType

Upvotes: 2

Related Questions