Skip to content

Commit 666b618

Browse files
committed
Allow for old gdbs still using Python 2.
1 parent decf209 commit 666b618

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

Tools/gdb/libpython.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,21 @@ def print_traceback(self):
11131113
lineno,
11141114
self.co_name.proxyval(visited)))
11151115

1116+
def get_truncated_repr(self, maxlen):
1117+
'''
1118+
Get a repr-like string for the data, but truncate it at "maxlen" bytes
1119+
(ending the object graph traversal as soon as you do)
1120+
'''
1121+
out = TruncatedStringIO(maxlen)
1122+
try:
1123+
self.write_repr(out, set())
1124+
except StringTruncated:
1125+
# Truncation occurred:
1126+
return out.getvalue() + '...(truncated)'
1127+
1128+
# No truncation occurred:
1129+
return out.getvalue()
1130+
11161131
class PySetObjectPtr(PyObjectPtr):
11171132
_typename = 'PySetObject'
11181133

@@ -1779,7 +1794,7 @@ def print_summary(self):
17791794
if self.is_evalframe():
17801795
pyop = self.get_pyop()
17811796
if pyop:
1782-
line = PyObjectPtr.get_truncated_repr(pyop, MAX_OUTPUT_LEN)
1797+
line = pyop.get_truncated_repr(MAX_OUTPUT_LEN)
17831798
write_unicode(sys.stdout, '#%i %s\n' % (self.get_index(), line))
17841799
if not pyop.is_optimized_out():
17851800
line = pyop.current_line()

0 commit comments

Comments
 (0)