Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion Lib/test/test_gdb/test_pretty_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@ def test_dicts(self):
self.assertGdbRepr({})
self.assertGdbRepr({'foo': 'bar'}, "{'foo': 'bar'}")
# Python preserves insertion order since 3.6
self.assertGdbRepr({'foo': 'bar', 'douglas': 42}, "{'foo': 'bar', 'douglas': 42}")
self.assertGdbRepr({'foo': 'bar', 'douglas': 42},
"{'foo': 'bar', 'douglas': 42}")

# frozendict
self.assertGdbRepr(frozendict(),
"frozendict({})")
self.assertGdbRepr(frozendict({'foo': 'bar', 'douglas': 42}),
"frozendict({'foo': 'bar', 'douglas': 42})")

def test_lists(self):
'Verify the pretty-printing of lists'
Expand Down
13 changes: 12 additions & 1 deletion Tools/gdb/libpython.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ def subclass_from_type(cls, t):
'frame': PyFrameObjectPtr,
'set' : PySetObjectPtr,
'frozenset' : PySetObjectPtr,
'frozendict' : PyDictObjectPtr,
'builtin_function_or_method' : PyCFunctionObjectPtr,
'method-wrapper': wrapperobject,
}
Expand Down Expand Up @@ -815,12 +816,20 @@ def proxyval(self, visited):
return result

def write_repr(self, out, visited):
tp_name = self.safe_tp_name()
is_frozendict = (tp_name == "frozendict")

# Guard against infinite loops:
if self.as_address() in visited:
out.write('{...}')
if is_frozendict:
out.write(tp_name + '({...})')
else:
out.write('{...}')
return
visited.add(self.as_address())

if is_frozendict:
out.write(tp_name + '(')
out.write('{')
first = True
for pyop_key, pyop_value in self.iteritems():
Expand All @@ -831,6 +840,8 @@ def write_repr(self, out, visited):
out.write(': ')
pyop_value.write_repr(out, visited)
out.write('}')
if is_frozendict:
out.write(')')

@staticmethod
def _get_entries(keys):
Expand Down
Loading