Skip to content

Instantly share code, notes, and snippets.

@mayoff
Created June 18, 2013 04:58
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save mayoff/5802760 to your computer and use it in GitHub Desktop.
Save mayoff/5802760 to your computer and use it in GitHub Desktop.
An lldb command that prints the description of the exception being raised, when run while the target is stopped at the first instruction of objc_exception_throw. Many thanks to Enrico Granata and Sean Callanan for basically writing this to my specifications at WWDC 2013.
command script import ~/Library/lldb/sniff_objc_exception_throw.py
import lldb
def GetFirstArgumentAsValue(target, frame):
# Note: I assume the PC is at the first instruction of the function, before the stack and registers have been modified.
if target.triple.startswith('x86_64'):
return frame.regs[0].GetChildMemberWithName("rdi")
elif target.triple.startswith('i386'):
espValue = frame.regs[0].GetChildMemberWithName("esp")
address = espValue.GetValueAsUnsigned() + target.addr_size
return espValue.CreateValueFromAddress('arg0', address, target.FindFirstType('id'))
else:
return frame.regs[0].GetChildMemberWithName("r0")
def command(debugger, user_input, result, unused):
target = debugger.GetSelectedTarget()
frame = target.GetProcess().GetSelectedThread().GetFrameAtIndex(0)
description = GetFirstArgumentAsValue(target, frame).GetObjectDescription()
if description is None:
output = "I couldn't get the description of the exception being thrown."
else:
output = "Description of exception being thrown: " + repr(description)
result.PutCString(output)
return None
def __lldb_init_module(debugger, unused):
debugger.HandleCommand('command script add --function sniff_objc_exception_throw.command sniff_objc_exception_throw')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment