Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 774
plaisthos Avatar asked Nov 14 '11 13:11

plaisthos


People also ask

Is LLDB better than GDB?

Both GDB and LLDB are of course excellent debuggers without doubt. GDB is debugger part of the GNU project created to work along the GNU compiler. LLDB is debugger part of the LLVM project created to work along LLVM compiler. The majority of the commands are the same.

How do you set a breakpoint in LLDB?

In lldb you can set breakpoints by typing either break or b followed by information on where you want the program to pause. After the b command, you can put either: a function name (e.g., b my_subroutine ) a line number (e.g., b 12 )

What is breakpoint exception?

An exception breakpoint is a type of breakpoint that is created when some exception occurs in the code. On occurrence of such exception our application stops at that given condition causing the exception and we can access all variables in scope at that breakpoint.


2 Answers

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

like image 52
Jonas K Avatar answered Sep 22 '22 14:09

Jonas K


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++.

like image 31
Jason Molenda Avatar answered Sep 23 '22 14:09

Jason Molenda