Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@

class KonanListSyntheticProvider(KonanObjectSyntheticProvider):
__possible_backing_properties = {'backing', '$this_asList', 'backingArray'}
__possible_size_properties = {'length'}

def __init__(self, valobj: lldb.SBValue, type_info: lldb.value):
self._backing: KonanArraySyntheticProvider = None # type: ignore
self._size: Optional[int] = None

super().__init__(valobj, type_info)

Expand All @@ -35,10 +37,14 @@ def update(self):
self._backing = backing

self._backing.update()
self._size = self._try_update_size()
return False

def num_children(self):
return self._backing.num_children()
if self._size is None:
return self._backing.num_children()
else:
return self._size

def has_children(self):
return True
Expand All @@ -50,7 +56,12 @@ def get_child_at_index(self, index):
return self._backing.get_child_at_index(index)

def to_string(self):
return self._backing.to_string()
if self._size is None:
return self._backing.to_string()
elif self._size == 1:
return '1 value'
else:
return '{} values'.format(self._size)

def _create_backing(self, index: int, name: str) -> Optional[KonanArraySyntheticProvider]:
address = self.get_child_address_at_index(index)
Expand All @@ -64,3 +75,19 @@ def _create_backing(self, index: int, name: str) -> Optional[KonanArraySynthetic
return None
else:
return KonanArraySyntheticProvider(backing_value, child_type_info)

def _try_update_size(self) -> Optional[int]:
for index, name in enumerate(self._children_names):
if name not in KonanListSyntheticProvider.__possible_size_properties:
continue
try:
value = super().get_child_at_index(index)
if value is None or not value.IsValid():
continue
size = value.GetValueAsSigned()
if size < 0:
continue
return int(size)
except BaseException:
continue
return None