Skip to content

Commit

Permalink
PrettyPrinter: Check if match is valid before accessing group (#3920)
Browse files Browse the repository at this point in the history
  • Loading branch information
Finkman authored Jan 14, 2023
1 parent 4c6cde7 commit da6b908
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions tools/gdb_pretty_printer/nlohmann-json.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ def to_string(self):
return self.val

def json_lookup_function(val):
m = ns_pattern.fullmatch(val.type.strip_typedefs().name)
name = m.group('name')
if name and name.startswith('basic_json<') and name.endswith('>'):
m = ns_pattern.fullmatch(str(val['m_type']))
t = m.group('name')
if t and t.startswith('detail::value_t::'):
try:
union_val = val['m_value'][t.removeprefix('detail::value_t::')]
if union_val.type.code == gdb.TYPE_CODE_PTR:
return gdb.default_visualizer(union_val.dereference())
else:
return JsonValuePrinter(union_val)
except Exception:
return JsonValuePrinter(val['m_type'])
if m := ns_pattern.fullmatch(str(val.type.strip_typedefs().name)):
name = m.group('name')
if name and name.startswith('basic_json<') and name.endswith('>'):
m = ns_pattern.fullmatch(str(val['m_type']))
t = m.group('name')
if t and t.startswith('detail::value_t::'):
try:
union_val = val['m_value'][t.removeprefix('detail::value_t::')]
if union_val.type.code == gdb.TYPE_CODE_PTR:
return gdb.default_visualizer(union_val.dereference())
else:
return JsonValuePrinter(union_val)
except Exception:
return JsonValuePrinter(val['m_type'])

gdb.pretty_printers.append(json_lookup_function)

0 comments on commit da6b908

Please sign in to comment.