tint: Fix gdb and lldb pretty printers for recently updated Hashset and Hashmap
Change-Id: If9aae44b6e58d3ba3be3463306f626ce8c23d4d0 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/108723 Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Ben Clayton <bclayton@chromium.org> Reviewed-by: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
parent
ca98b1b1b9
commit
c027f33cfd
|
@ -165,11 +165,11 @@ pp_set.add_printer(
|
|||
'UtilsVector', '^tint::utils::VectorRef<.*>$', UtilsVectorRefPrinter)
|
||||
|
||||
|
||||
class UtilsHashsetPrinter(Printer):
|
||||
'''Printer for Hashset<T, N, HASH, EQUAL>'''
|
||||
class UtilsHashmapBasePrinter(Printer):
|
||||
'''Base Printer for HashmapBase-derived types'''
|
||||
|
||||
def __init__(self, val):
|
||||
super(UtilsHashsetPrinter, self).__init__(val)
|
||||
super(UtilsHashmapBasePrinter, self).__init__(val)
|
||||
self.slice = UtilsVectorPrinter(self.val['slots_']).slice_printer()
|
||||
self.try_read_std_optional_func = self.try_read_std_optional
|
||||
|
||||
|
@ -185,26 +185,32 @@ class UtilsHashsetPrinter(Printer):
|
|||
for slot in range(0, self.slice.length()):
|
||||
v = self.slice.value_at(slot)
|
||||
if v['hash'] != 0:
|
||||
value = v['value']
|
||||
entry = v['entry']
|
||||
|
||||
# value is a std::optional, let's try to extract its value for display
|
||||
kvp = self.try_read_std_optional_func(slot, value)
|
||||
# entry is a std::optional, let's try to extract its value for display
|
||||
kvp = self.try_read_std_optional_func(slot, entry)
|
||||
if kvp is None:
|
||||
# If we failed, just output the slot and value as is, which will use
|
||||
# If we failed, just output the slot and entry as is, which will use
|
||||
# the default visualizer for each.
|
||||
kvp = slot, value
|
||||
kvp = slot, entry
|
||||
|
||||
yield str(kvp[0]), kvp[1]
|
||||
|
||||
def display_hint(self):
|
||||
return 'array'
|
||||
|
||||
def try_read_std_optional(self, slot, value):
|
||||
def try_read_std_optional(self, slot, entry):
|
||||
return None
|
||||
|
||||
|
||||
class UtilsHashsetPrinter(UtilsHashmapBasePrinter):
|
||||
'''Printer for Hashset<T, N, HASH, EQUAL>'''
|
||||
|
||||
def try_read_std_optional(self, slot, entry):
|
||||
try:
|
||||
# libstdc++
|
||||
v = value['_M_payload']['_M_payload']['_M_value']
|
||||
v = entry['_M_payload']['_M_payload']['_M_value']
|
||||
return slot, v
|
||||
# return str(kvp['key']), kvp['value']
|
||||
except:
|
||||
return None
|
||||
|
||||
|
@ -213,33 +219,16 @@ pp_set.add_printer(
|
|||
'UtilsHashset', '^tint::utils::Hashset<.*>$', UtilsHashsetPrinter)
|
||||
|
||||
|
||||
class UtilsHashmapPrinter(Printer):
|
||||
class UtilsHashmapPrinter(UtilsHashmapBasePrinter):
|
||||
'''Printer for Hashmap<K, V, N, HASH, EQUAL>'''
|
||||
|
||||
def __init__(self, val):
|
||||
super(UtilsHashmapPrinter, self).__init__(val)
|
||||
self.hash_set = UtilsHashsetPrinter(self.val['set_'])
|
||||
# Replace the lookup function so we can extract the key and value out of the std::optionals in the Hashset
|
||||
self.hash_set.try_read_std_optional_func = self.try_read_std_optional
|
||||
|
||||
def to_string(self):
|
||||
return self.hash_set.to_string()
|
||||
|
||||
def children(self):
|
||||
return self.hash_set.children()
|
||||
|
||||
def display_hint(self):
|
||||
return 'array'
|
||||
|
||||
def try_read_std_optional(self, slot, value):
|
||||
def try_read_std_optional(self, slot, entry):
|
||||
try:
|
||||
# libstdc++
|
||||
kvp = value['_M_payload']['_M_payload']['_M_value']
|
||||
kvp = entry['_M_payload']['_M_payload']['_M_value']
|
||||
return str(kvp['key']), kvp['value']
|
||||
except:
|
||||
pass
|
||||
# Failed, fall back on hash_set
|
||||
return self.hash_set.try_read_std_optional(slot, value)
|
||||
return None
|
||||
|
||||
|
||||
pp_set.add_printer(
|
||||
|
|
|
@ -297,8 +297,8 @@ class UtilsVectorRefPrinter(Printer):
|
|||
return self.slice_printer.get_child_at_index(index)
|
||||
|
||||
|
||||
class UtilsHashsetPrinter(Printer):
|
||||
'''Printer for Hashset<T, N, HASH, EQUAL>'''
|
||||
class UtilsHashmapBasePrinter(Printer):
|
||||
'''Base Printer for HashmapBase-derived types'''
|
||||
|
||||
def initialize(self):
|
||||
self.slice = UtilsVectorPrinter(
|
||||
|
@ -326,26 +326,33 @@ class UtilsHashsetPrinter(Printer):
|
|||
def get_child_at_index(self, index):
|
||||
slot = self.valid_slots[index]
|
||||
v = self.slice.value_at(slot)
|
||||
value = member(v, 'value')
|
||||
entry = member(v, 'entry')
|
||||
|
||||
# value is a std::optional, let's try to extract its value for display
|
||||
kvp = self.try_read_std_optional_func(slot, value)
|
||||
# entry is a std::optional, let's try to extract its value for display
|
||||
kvp = self.try_read_std_optional_func(slot, entry)
|
||||
if kvp is None:
|
||||
# If we failed, just output the slot and value as is, which will use
|
||||
# If we failed, just output the slot and entry as is, which will use
|
||||
# the default printer for std::optional.
|
||||
kvp = slot, value
|
||||
kvp = slot, entry
|
||||
|
||||
return kvp[1].CreateChildAtOffset('[{}]'.format(kvp[0]), 0, kvp[1].GetType())
|
||||
|
||||
def try_read_std_optional(self, slot, value):
|
||||
def try_read_std_optional(self, slot, entry):
|
||||
return None
|
||||
|
||||
|
||||
class UtilsHashsetPrinter(UtilsHashmapBasePrinter):
|
||||
'''Printer for Hashset<T, N, HASH, EQUAL>'''
|
||||
|
||||
def try_read_std_optional(self, slot, entry):
|
||||
try:
|
||||
# libc++
|
||||
v = value.EvaluateExpression('__val_')
|
||||
v = entry.EvaluateExpression('__val_')
|
||||
if v.name is not None:
|
||||
return slot, v
|
||||
|
||||
# libstdc++
|
||||
v = value.EvaluateExpression('_M_payload._M_payload._M_value')
|
||||
v = entry.EvaluateExpression('_M_payload._M_payload._M_value')
|
||||
if v.name is not None:
|
||||
return slot, v
|
||||
return None
|
||||
|
@ -353,45 +360,24 @@ class UtilsHashsetPrinter(Printer):
|
|||
return None
|
||||
|
||||
|
||||
class UtilsHashmapPrinter(Printer):
|
||||
class UtilsHashmapPrinter(UtilsHashsetPrinter):
|
||||
'''Printer for Hashmap<K, V, N, HASH, EQUAL>'''
|
||||
|
||||
def initialize(self):
|
||||
self.hash_set = UtilsHashsetPrinter(self.member('set_'))
|
||||
# Replace the lookup function so we can extract the key and value out of the std::optionals in the Hashset
|
||||
self.hash_set.try_read_std_optional_func = self.try_read_std_optional
|
||||
|
||||
def update(self):
|
||||
self.hash_set.update()
|
||||
|
||||
def get_summary(self):
|
||||
return self.hash_set.get_summary()
|
||||
|
||||
def num_children(self):
|
||||
return self.hash_set.num_children()
|
||||
|
||||
def has_children(self):
|
||||
return self.hash_set.has_children()
|
||||
|
||||
def get_child_at_index(self, index):
|
||||
return self.hash_set.get_child_at_index(index)
|
||||
|
||||
def try_read_std_optional(self, slot, value):
|
||||
def try_read_std_optional(self, slot, entry):
|
||||
try:
|
||||
# libc++
|
||||
val = value.EvaluateExpression('__val_')
|
||||
val = entry.EvaluateExpression('__val_')
|
||||
k = val.EvaluateExpression('key')
|
||||
v = val.EvaluateExpression('value')
|
||||
if k.name is not None and v.name is not None:
|
||||
return k.GetValue(), v
|
||||
|
||||
# libstdc++
|
||||
val = value.EvaluateExpression('_M_payload._M_payload._M_value')
|
||||
val = entry.EvaluateExpression('_M_payload._M_payload._M_value')
|
||||
k = val.EvaluateExpression('key')
|
||||
v = val.EvaluateExpression('value')
|
||||
if k.name is not None and v.name is not None:
|
||||
return k.GetValue(), v
|
||||
return None
|
||||
except:
|
||||
pass
|
||||
# Failed, fall back on hash_set
|
||||
return self.hash_set.try_read_std_optional(slot, value)
|
||||
return None
|
||||
|
|
Loading…
Reference in New Issue