Skip to content

Commit

Permalink
Fix synthetic childern print
Browse files Browse the repository at this point in the history
  • Loading branch information
olonho authored and vvlevchenko committed Jul 16, 2018
1 parent 5dcb891 commit 95e641c
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions llvmDebugInfoC/src/scripts/konan_lldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@ def __init__(self, valobj):
8: lambda address, _: "(void *){:#x}".format(address),
# TODO: or 1?
9: lambda address, error: self.__read_memory(address, "<?", 4, error)}
self._types = [
valobj.GetType().GetBasicType(lldb.eBasicTypeVoid).GetPointerType(),
valobj.GetType(),
valobj.GetType().GetBasicType(lldb.eBasicTypeChar),
valobj.GetType().GetBasicType(lldb.eBasicTypeShort),
valobj.GetType().GetBasicType(lldb.eBasicTypeInt),
valobj.GetType().GetBasicType(lldb.eBasicTypeLongLong),
valobj.GetType().GetBasicType(lldb.eBasicTypeFloat),
valobj.GetType().GetBasicType(lldb.eBasicTypeDouble),
valobj.GetType().GetBasicType(lldb.eBasicTypeVoid).GetPointerType(),
valobj.GetType().GetBasicType(lldb.eBasicTypeBool)
]


def update(self):
self._children_count = int(evaluate("(int)Konan_DebugGetFieldCount({})".format(self._ptr)).GetValue())
Expand All @@ -119,6 +132,9 @@ def __read_memory(self, address, fmt, size, error):
content = self._process.ReadMemory(address, size, error)
return struct.unpack(fmt, content)[0] if error.Success() else "error: {:#x}".format(address)

def _read_type(self, index):
return self._types[int(evaluate("(int)Konan_DebugGetFieldType({}, {})".format(self._ptr, index)).GetValue())]


class KonanStringSyntheticProvider(KonanHelperProvider):
def __init__(self, valobj):
Expand Down Expand Up @@ -185,8 +201,12 @@ def get_child_at_index(self, index):
if index < 0 or index >= self._children_count:
return None
error = lldb.SBError()
value = self._read_value(index, error)
return value if error.Success() else None
type = self._read_type(index)
base = evaluate("(long){})".format(self._ptr)).unsigned
address = evaluate("(long)Konan_DebugGetFieldAddress({}, (int){})".format(self._ptr, index)).unsigned
child = self._valobj.CreateChildAtOffset(self._children[index], address - base, type)
child.SetSyntheticChildrenGenerated(True)
return child if error.Success() else None

# TODO: fix cyclic structures stringification.
def to_string(self):
Expand All @@ -199,6 +219,7 @@ def __init__(self, valobj):
super(KonanArraySyntheticProvider, self).__init__(valobj)
if self._ptr is None:
return
valobj.SetSyntheticChildrenGenerated(True)
self.update()

def update(self):
Expand Down

0 comments on commit 95e641c

Please sign in to comment.