Last active
November 8, 2016 15:43
-
-
Save mskvortsov/7b455d120619d581f2aa884d79032d18 to your computer and use it in GitHub Desktop.
This file contains 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 | |
import ctypes | |
class Array_SynthProvider: | |
def __init__(self, valobj, dict): | |
self.valobj = valobj | |
def num_children(self): | |
return self.num_components.GetValueAsUnsigned(0) | |
def get_child_index(self, name): | |
try: | |
return int(name.lstrip('[').rstrip(']')) | |
except: | |
return -1 | |
def get_child_at_index(self, index): | |
if index < 0: | |
return None | |
if index >= self.num_children(): | |
return None | |
try: | |
return self.data.CreateChildAtOffset('[' + str(index) + ']', index * self.data_size, self.data_type) | |
except: | |
return None | |
def update(self): | |
self.num_components = self.valobj.GetChildMemberWithName('m_NumComponents') | |
self.data = self.valobj.GetChildMemberWithName('m_Data') | |
self.data_type = self.data.GetType().GetArrayElementType() | |
self.data_size = self.data_type.GetByteSize() | |
def has_children(self): | |
return True | |
def String_SummaryProvider(valobj, unused): | |
length = valobj.GetChildMemberWithName('m_stringLength').GetValueAsUnsigned(0) | |
data = valobj.GetChildMemberWithName('m_firstChar').GetPointeeData(0, length) | |
error = lldb.SBError() | |
raw = data.ReadRawData(error, 0, 2 * length) | |
return '(System.Char[%d] *) "%s"' % (length, raw.decode('utf-16')) | |
def __lldb_init_module(dbg, dict): | |
dbg.HandleCommand('type category define CoreCLR') | |
dbg.HandleCommand('type synthetic add -w CoreCLR -l coreclr.Array_SynthProvider -x "\[,*\]$"') | |
dbg.HandleCommand('type summary add -w CoreCLR -F coreclr.String_SummaryProvider -e -x "^System\.String$"') | |
dbg.HandleCommand('type category enable CoreCLR') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment