Skip to content

Instantly share code, notes, and snippets.

Revisions

  1. @chendo chendo revised this gist Oct 9, 2013. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions ignore_specified_objc_exceptions.py
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,8 @@ def getRegister(target):
    return "rdi"
    elif target.triple.startswith('i386'):
    return "eax"
    elif target.triple.startswith('arm64'):
    return "x0"
    else:
    return "r0"

  2. @chendo chendo revised this gist Oct 9, 2013. 1 changed file with 20 additions and 4 deletions.
    24 changes: 20 additions & 4 deletions ignore_specified_objc_exceptions.py
    Original file line number Diff line number Diff line change
    @@ -8,20 +8,37 @@
    def getRegister(target):
    if target.triple.startswith('x86_64'):
    return "rdi"
    elif target.triple.startswith('i386'):
    return "eax"
    else:
    return "r0"

    def callMethodOnException(frame, register, method):
    return frame.EvaluateExpression("(NSString *)[(NSException *)${0} {1}]".format(register, method)).GetObjectDescription()

    def command(debugger, user_input, result, unused):
    def filterException(debugger, user_input, result, unused):
    target = debugger.GetSelectedTarget()
    frame = target.GetProcess().GetSelectedThread().GetFrameAtIndex(0)

    if frame.symbol.name != 'objc_exception_throw':
    # We can't handle anything except objc_exception_throw
    return None

    filters = shlex.split(user_input)

    register = getRegister(target)


    for filter in filters:
    method, regexp_str = filter.split(":", 1)
    value = frame.EvaluateExpression("(NSString *)[(NSException *)${0} {1}]".format(register, method)).GetObjectDescription()
    value = callMethodOnException(frame, register, method)

    if value is None:
    output = "Unable to grab exception from register {0} with method {1}; skipping...".format(register, method)
    result.PutCString(output)
    result.flush()
    continue

    regexp = re.compile(regexp_str)

    if regexp.match(value):
    @@ -39,5 +56,4 @@ def command(debugger, user_input, result, unused):
    return None

    def __lldb_init_module(debugger, unused):
    debugger.HandleCommand('command script add --function ignore_specified_objc_exceptions.command ignore_specified_objc_exceptions')

    debugger.HandleCommand('command script add --function ignore_specified_objc_exceptions.filterException ignore_specified_objc_exceptions')
  3. @chendo chendo revised this gist Sep 30, 2013. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion ignore_specified_objc_exceptions.py
    Original file line number Diff line number Diff line change
    @@ -21,7 +21,7 @@ def command(debugger, user_input, result, unused):

    for filter in filters:
    method, regexp_str = filter.split(":", 1)
    value = frame.EvaluateExpression("(NSString *)[(NSException *)$" + register + " " + method + "]").GetObjectDescription()
    value = frame.EvaluateExpression("(NSString *)[(NSException *)${0} {1}]".format(register, method)).GetObjectDescription()
    regexp = re.compile(regexp_str)

    if regexp.match(value):
    @@ -40,3 +40,4 @@ def command(debugger, user_input, result, unused):

    def __lldb_init_module(debugger, unused):
    debugger.HandleCommand('command script add --function ignore_specified_objc_exceptions.command ignore_specified_objc_exceptions')

  4. @chendo chendo revised this gist Sep 30, 2013. 1 changed file with 10 additions and 3 deletions.
    13 changes: 10 additions & 3 deletions ignore_specified_objc_exceptions.py
    Original file line number Diff line number Diff line change
    @@ -4,16 +4,24 @@

    # This script allows Xcode to selectively ignore Obj-C exceptions
    # based on any selector on the NSException instance


    def getRegister(target):
    if target.triple.startswith('x86_64'):
    return "rdi"
    else:
    return "r0"


    def command(debugger, user_input, result, unused):
    target = debugger.GetSelectedTarget()
    frame = target.GetProcess().GetSelectedThread().GetFrameAtIndex(0)
    filters = shlex.split(user_input)

    register = getRegister(target)

    for filter in filters:
    method, regexp_str = filter.split(":", 1)
    value = frame.EvaluateExpression("(NSString *)[(NSException *)$rdi " + method + "]").GetObjectDescription()
    value = frame.EvaluateExpression("(NSString *)[(NSException *)$" + register + " " + method + "]").GetObjectDescription()
    regexp = re.compile(regexp_str)

    if regexp.match(value):
    @@ -32,4 +40,3 @@ def command(debugger, user_input, result, unused):

    def __lldb_init_module(debugger, unused):
    debugger.HandleCommand('command script add --function ignore_specified_objc_exceptions.command ignore_specified_objc_exceptions')

  5. @chendo chendo created this gist Sep 30, 2013.
    35 changes: 35 additions & 0 deletions ignore_specified_objc_exceptions.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    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')