How to Add Exception Breakpoint in Xcode

Debugging uncaught exception in Xcode

In Xcode,

  1. go to Breakpoint navigator on the left pane.
  2. Click '+' at the bottom.
  3. Choose 'Add exception Breakpoint...'
  4. Let the default selections there and click 'Done'.

Rerun the app and see if execution stops at the line which causing this exception.

Xcode All Exceptions Breakpoint - Ignore Certain C++ Exception

There isn't a way to do this using the Xcode breakpoint settings.

You can do this in lldb using a Python breakpoint command on the C++ exception breakpoint. Your callback would look up the stack to the point where the exception is thrown, and check that the throwing code is in your shared library, and auto-continue from the breakpoint or not.

The section in:

http://lldb.llvm.org/python-reference.html

on running a script when a breakpoint is hit will give you some details about how to do this.

For instance, you could put:

module_name = "TheNameOfYourExecutableOrSharedLibrary"
def bkpt_cmd (frame, loc, dict):
global module_name
thread = frame.GetThread()
frame_1 = thread.GetFrameAtIndex(1)
module = frame_1.GetModule()
name = module.GetFileSpec().GetFilename()
if module_name in name:
return True
return False

in a file called ~/bkpt_cmd.py. Then in the lldb console, do:

(lldb) br s -E c++
Breakpoint 1: no locations (pending).
(lldb) command script import ~/bkpt_cmd.py
(lldb) br com add -F bkpt_cmd.bkpt_cmd

This will set a C++ exception breakpoint that only triggers when the raising frame is in the shared library called "TheNameOfYourExecutableOrSharedLibrary"...

BTW, if you put the following def in your .py file:

def __lldb_init_module(debugger, internal_dict):

it will get run when the command script import command is executed, so you could use this to add the breakpoint and the command to the breakpoint at one go. I'll leave that as an exercise for the reader.

Note also, this will work when running lldb within Xcode, but you'll want to make your own exception breakpoint as shown above, since Xcode has a different way of handling the commands for the breakpoints it manages.

Xcode throws an exception in Main() in iOS 8 with 'all exceptions' breakpoint

As stated in the comments, you should turn off catching the C++ exceptions by editing your All Exceptions breakpoint.

In order to do that, right click on your breakpoint and change Exception from All to Objective-C:

change All to Objective-C

Exceptions in C++ code are part of normal app functionality. However, exception breakpoint is not catching unhandled but every raised exceptions, even when they're handled correctly later on, hence the stop in execution.



Related Topics



Leave a reply



Submit