X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/3903760236c30e3b5ace7a4eefac3a269d68957c..a991bd8d3e7fe02dbca0644054bab73c5b75324a:/tools/lldbmacros/utils.py?ds=sidebyside diff --git a/tools/lldbmacros/utils.py b/tools/lldbmacros/utils.py old mode 100644 new mode 100755 index fbb0494bc..6039f2048 --- a/tools/lldbmacros/utils.py +++ b/tools/lldbmacros/utils.py @@ -140,7 +140,16 @@ def Cast(obj, target_type): """ return cast(obj, target_type) - +def ContainerOf(obj, target_type, field_name): + """ Type cast an object to another C type from a pointer to a field. + params: + obj - core.value object representing some C construct in lldb + target_type - str : ex 'struct thread' + - lldb.SBType : + field_name - the field name within the target_type obj is a pointer to + """ + return containerof(obj, target_type, field_name) + def loadLLDB(): """ Util function to load lldb python framework in case not available in common include paths. """ @@ -398,7 +407,7 @@ def dsymForUUID(uuid): """ import subprocess import plistlib - output = subprocess.check_output(["/usr/local/bin/dsymForUUID", uuid]) + output = subprocess.check_output(["/usr/local/bin/dsymForUUID", "--copyExecutable", uuid]) if output: # because of #plist = plistlib.readPlistFromString(output) @@ -461,3 +470,16 @@ def print_hex_data(data, begin_offset=0, desc=""): char_buf = "" print "{:08x} {: <50s} |{: <16s}|".format(begin_offset + index - 16, hex_buf, char_buf) return + +def Ones(x): + return (1 << x)-1 + +def StripPAC(x, TySz): + sign_mask = 1 << 55 + ptr_mask = Ones(64-TySz) + pac_mask = ~ptr_mask + sign = x & sign_mask + if sign: + return (x | pac_mask) + 2**64 + else: + return x & ptr_mask