"""
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.
"""
# modify the list to show we loaded this
_dsymlist[uuid] = True
-def loadDSYM(uuid, load_address):
+def loadDSYM(uuid, load_address, sections=[]):
""" Load an already added symbols to a particular load address
params: uuid - str - uuid string
load_address - int - address where to load the symbols
"""
if uuid not in _dsymlist:
return False
- cmd_str = "target modules load --uuid %s --slide %d" % ( uuid, load_address)
- debuglog(cmd_str)
+ if not sections:
+ cmd_str = "target modules load --uuid %s --slide %d" % ( uuid, load_address)
+ debuglog(cmd_str)
+ else:
+ cmd_str = "target modules load --uuid {} ".format(uuid)
+ sections_str = ""
+ for s in sections:
+ sections_str += " {} {:#0x} ".format(s.name, s.vmaddr)
+ cmd_str += sections_str
+ debuglog(cmd_str)
+
lldb.debugger.HandleCommand(cmd_str)
+ return True
+
def RunShellCommand(command):
""" Run a shell command in subprocess.
"""
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 <rdar://12713712>
#plist = plistlib.readPlistFromString(output)
except ImportError:
retval = False
return retval
+
+def print_hex_data(data, begin_offset=0, desc=""):
+ """ print on stdout "hexdump -C < data" like output
+ params:
+ data - bytearray or array of int where each int < 255
+ begin_offset - int offset that should be printed in left column
+ desc - str optional description to print on the first line to describe data
+ """
+ if desc:
+ print "{}:".format(desc)
+ index = 0
+ total_len = len(data)
+ hex_buf = ""
+ char_buf = ""
+ while index < total_len:
+ hex_buf += " {:02x}".format(data[index])
+ if data[index] < 0x20 or data[index] > 0x7e:
+ char_buf += "."
+ else:
+ char_buf += "{:c}".format(data[index])
+ index += 1
+ if index and index < total_len and index % 8 == 0:
+ hex_buf += " "
+ if index > 1 and index < total_len and (index % 16) == 0:
+ print "{:08x} {: <50s} |{: <16s}|".format(begin_offset + index - 16, hex_buf, char_buf)
+ hex_buf = ""
+ 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