0

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?

keyboard
  • 2,137
  • 1
  • 20
  • 32

1 Answers1

2

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.

Jim Ingham
  • 25,260
  • 2
  • 55
  • 63
  • Wow this sounds awesome. Probably with this trick I could also find out the module name of the AVAudioPlayer that's causing the issue and just disable this single thing manually....I have never used lldb with Python script, so I'll take some time to fiddle with this and try to get it to run... – keyboard Oct 13 '16 at 23:24
  • I got it working. I used a mixture of your solution and the solution in this post: http://stackoverflow.com/questions/14370632/ignore-certain-exceptions-when-using-xcodes-all-exceptions-breakpoint I used debugger.SetAsync(True) debugger.HandleCommand("continue") to skip the breakpoint. Not quite sure if this is any worse than what you suggested ;) But it's possible to add the script in Xcode like the other guy suggests. – keyboard Oct 14 '16 at 21:57
  • I've set it up to skip any breakpoints caused by "AudioToolbox". Is it possible to get even more specific and only skip this certain issue? Is it maybe possible to find out the current function or something like this? – keyboard Oct 14 '16 at 21:59