-
-
Save danyowdee/8453386 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
command script import ~/Library/lldb/sniff_objc_exception_throw.py |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import lldb | |
def GetFirstArgumentAsValue(target, frame): | |
platform = target.triple | |
registers = frame.regs[0] | |
# Note: I assume the PC is at the first instruction of the function, before the stack and registers have been modified. | |
if platform.startswith('x86_64'): | |
return registers.GetChildMemberWithName("rdi") | |
elif platform.startswith('i386'): | |
espValue = registers.GetChildMemberWithName("esp") | |
address = espValue.GetValueAsUnsigned() + target.addr_size | |
return espValue.CreateValueFromAddress('arg0', address, target.FindFirstType('id')) | |
elif platform.startswith('arm64'): | |
return registers.GetChildMemberWithName("x0") | |
else: | |
return registers.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
arm64 has renamed the registers from r$ to x$.
Because this adds yet another branch, obtaining the platform, and register–tuple has been extracted to local variables.