keyboard
keyboard

Reputation: 2355

Xcode All Exceptions Breakpoint - Ignore Certain C++ Exception

I'm coding in C++ for iOS, using certain iOS Frameworks like AVAudioPlayer. I know that these can trigger C++ exceptions internally and it's perfectly fine, since they catch and handle them.

I would like to use the All Exceptions Breakpoint in Xcode to break on Crash-Issues in my own C++ code, but to ignore that AVAudioPlayer's C++ exceptions (and basically all other catched exceptions).

How can I achieve that?

Upvotes: 0

Views: 1263

Answers (1)

Jim Ingham
Jim Ingham

Reputation: 27110

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.

Upvotes: 2

Related Questions