Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save neoneye/d292eccc1c1795f6d593 to your computer and use it in GitHub Desktop.
Save neoneye/d292eccc1c1795f6d593 to your computer and use it in GitHub Desktop.
This lldb script lets you selectively ignore Obj-C exceptions. See http://chen.do/blog/2013/09/30/selectively-ignoring-objective-c-exceptions-in-xcode/
import lldb
import re
import shlex
# This script allows Xcode to selectively ignore Obj-C exceptions
# based on any selector on the NSException instance
def command(debugger, user_input, result, unused):
target = debugger.GetSelectedTarget()
frame = target.GetProcess().GetSelectedThread().GetFrameAtIndex(0)
filters = shlex.split(user_input)
for filter in filters:
method, regexp_str = filter.split(":", 1)
value = frame.EvaluateExpression("(NSString *)[(NSException *)$rdi " + method + "]").GetObjectDescription()
regexp = re.compile(regexp_str)
if regexp.match(value):
output = "Skipping exception because exception's {0} ({1}) matches {2}".format(method, value, regexp_str)
result.PutCString(output)
result.flush()
# If we tell the debugger to continue before this script finishes,
# Xcode gets into a weird state where it won't refuse to quit LLDB,
# so we set async so the script terminates and hands control back to Xcode
debugger.SetAsync(True)
debugger.HandleCommand("continue")
return None
return None
def __lldb_init_module(debugger, unused):
debugger.HandleCommand('command script add --function ignore_specified_objc_exceptions.command ignore_specified_objc_exceptions')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment