lldb: Breakpoint on exceptions (equivalent of gdb's catch throw)
Asked Answered
O

4

63

I am trying to use lldb for c++ debugging and I want to halt if an exception is thrown, like gdb's catch throw, and I cannot find an equivalent in the lldb documentation.

Octarchy answered 14/11, 2011 at 13:36 Comment(0)
J
63

In Xcode, you can set an Exception breakpoint (View > Navigators > Show Breakpoint Navigator, hit the + button in the bottom of the breakpoint list window to add a new breakpoint).

If you're using command line lldb, put a breakpoint on __cxa_throw for C++ exception throws, objc_exception_throw for Objective-C exception throws.

For all c++ exceptions: break set -E C++.

Joubert answered 7/10, 2012 at 10:43 Comment(6)
for all c++ exceptions: break set -E c++Octarchy
ah, I missed the -E option to breakpoint set! Thanks for noting it.Joubert
The '-F' and '-E' variants weren't working for me, but 'breakpoint -n __cxa_throw' did work (for all exceptions), as well as 'breakpoint -n <exception-name>' (for specific exceptions).Handed
"-E objc" also works if you want Objective-C exceptions.Metamorphic
break set -E c++ didn't work for me (perhaps because I'm using real GNU g++ instead of Apple's clang++?), but break set -n __cxa_throw did. @AnthonyHall's comment is lacking set.Macaronic
I want to break immediately after throwing. break set -E c++ breaks on the rethrow statement. __cxa_throw works for me. Thank you.Valvate
P
84

Use breakpoint set -E c++ to break on all exceptions and breakpoint set -F std::range_error to break on a specific exception.

Purposeful answered 19/3, 2014 at 10:30 Comment(1)
I found that breakpoint set -F std::regex_error did not work for me. That does a full string match on function name and is thus fragile. However, breakpoint set -r regex_error, breaking on any function matching regex_error as a regex (targeting its constructor) did work.Crescin
J
63

In Xcode, you can set an Exception breakpoint (View > Navigators > Show Breakpoint Navigator, hit the + button in the bottom of the breakpoint list window to add a new breakpoint).

If you're using command line lldb, put a breakpoint on __cxa_throw for C++ exception throws, objc_exception_throw for Objective-C exception throws.

For all c++ exceptions: break set -E C++.

Joubert answered 7/10, 2012 at 10:43 Comment(6)
for all c++ exceptions: break set -E c++Octarchy
ah, I missed the -E option to breakpoint set! Thanks for noting it.Joubert
The '-F' and '-E' variants weren't working for me, but 'breakpoint -n __cxa_throw' did work (for all exceptions), as well as 'breakpoint -n <exception-name>' (for specific exceptions).Handed
"-E objc" also works if you want Objective-C exceptions.Metamorphic
break set -E c++ didn't work for me (perhaps because I'm using real GNU g++ instead of Apple's clang++?), but break set -n __cxa_throw did. @AnthonyHall's comment is lacking set.Macaronic
I want to break immediately after throwing. break set -E c++ breaks on the rethrow statement. __cxa_throw works for me. Thank you.Valvate
T
0

I think breakpoint set -w <boolean> is the correct answer, you can use help breakpoint set to see the document.

Toitoiboid answered 29/11, 2014 at 15:49 Comment(0)
P
0

You can enter

breakpoint set -E c++

into LLDB to do this.

But if you want to configure LLDB to always do this, open ~/.lldbinit and put the same line into that file.

Parfitt answered 8/1 at 5:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.