|
|
@ -221,48 +221,41 @@ class PrettyPrintTests(DebuggerTests): |
|
|
gdb_output = self.get_stack_trace('id(42)') |
|
|
gdb_output = self.get_stack_trace('id(42)') |
|
|
self.assertTrue(BREAKPOINT_FN in gdb_output) |
|
|
self.assertTrue(BREAKPOINT_FN in gdb_output) |
|
|
|
|
|
|
|
|
def get_python_repr(self, val): |
|
|
|
|
|
args = [sys.executable, '-c', 'print(repr(%a))' % (val,)] |
|
|
|
|
|
env = os.environ.copy() |
|
|
|
|
|
env['PYTHONHASHSEED'] = PYTHONHASHSEED |
|
|
|
|
|
output = subprocess.check_output(args, env=env, universal_newlines=True) |
|
|
|
|
|
return output.rstrip() |
|
|
|
|
|
|
|
|
|
|
|
def assertGdbRepr(self, val, exp_repr=None, cmds_after_breakpoint=None): |
|
|
def assertGdbRepr(self, val, exp_repr=None, cmds_after_breakpoint=None): |
|
|
# Ensure that gdb's rendering of the value in a debugged process |
|
|
# Ensure that gdb's rendering of the value in a debugged process |
|
|
# matches repr(value) in this process: |
|
|
# matches repr(value) in this process: |
|
|
gdb_repr, gdb_output = self.get_gdb_repr('id(' + ascii(val) + ')', |
|
|
gdb_repr, gdb_output = self.get_gdb_repr('id(' + ascii(val) + ')', |
|
|
cmds_after_breakpoint) |
|
|
cmds_after_breakpoint) |
|
|
if not exp_repr: |
|
|
if not exp_repr: |
|
|
exp_repr = self.get_python_repr(val) |
|
|
|
|
|
|
|
|
exp_repr = repr(val) |
|
|
self.assertEqual(gdb_repr, exp_repr, |
|
|
self.assertEqual(gdb_repr, exp_repr, |
|
|
('%r did not equal expected %r; full output was:\n%s' |
|
|
('%r did not equal expected %r; full output was:\n%s' |
|
|
% (gdb_repr, exp_repr, gdb_output))) |
|
|
% (gdb_repr, exp_repr, gdb_output))) |
|
|
|
|
|
|
|
|
def test_int(self): |
|
|
def test_int(self): |
|
|
'Verify the pretty-printing of various int values' |
|
|
'Verify the pretty-printing of various int values' |
|
|
self.assertGdbRepr(42, '42') |
|
|
|
|
|
self.assertGdbRepr(0, '0') |
|
|
|
|
|
self.assertGdbRepr(-7, '-7') |
|
|
|
|
|
self.assertGdbRepr(1000000000000, '1000000000000') |
|
|
|
|
|
self.assertGdbRepr(-1000000000000000, '-1000000000000000') |
|
|
|
|
|
|
|
|
self.assertGdbRepr(42) |
|
|
|
|
|
self.assertGdbRepr(0) |
|
|
|
|
|
self.assertGdbRepr(-7) |
|
|
|
|
|
self.assertGdbRepr(1000000000000) |
|
|
|
|
|
self.assertGdbRepr(-1000000000000000) |
|
|
|
|
|
|
|
|
def test_singletons(self): |
|
|
def test_singletons(self): |
|
|
'Verify the pretty-printing of True, False and None' |
|
|
'Verify the pretty-printing of True, False and None' |
|
|
self.assertGdbRepr(True, 'True') |
|
|
|
|
|
self.assertGdbRepr(False, 'False') |
|
|
|
|
|
self.assertGdbRepr(None, 'None') |
|
|
|
|
|
|
|
|
self.assertGdbRepr(True) |
|
|
|
|
|
self.assertGdbRepr(False) |
|
|
|
|
|
self.assertGdbRepr(None) |
|
|
|
|
|
|
|
|
def test_dicts(self): |
|
|
def test_dicts(self): |
|
|
'Verify the pretty-printing of dictionaries' |
|
|
'Verify the pretty-printing of dictionaries' |
|
|
self.assertGdbRepr({}, '{}') |
|
|
|
|
|
self.assertGdbRepr({'foo': 'bar'}) |
|
|
|
|
|
self.assertGdbRepr({'foo': 'bar', 'douglas': 42}) |
|
|
|
|
|
|
|
|
self.assertGdbRepr({}) |
|
|
|
|
|
self.assertGdbRepr({'foo': 'bar'}, "{'foo': 'bar'}") |
|
|
|
|
|
self.assertGdbRepr({'foo': 'bar', 'douglas': 42}, "{'douglas': 42, 'foo': 'bar'}") |
|
|
|
|
|
|
|
|
def test_lists(self): |
|
|
def test_lists(self): |
|
|
'Verify the pretty-printing of lists' |
|
|
'Verify the pretty-printing of lists' |
|
|
self.assertGdbRepr([], '[]') |
|
|
|
|
|
self.assertGdbRepr(list(range(5)), '[0, 1, 2, 3, 4]') |
|
|
|
|
|
|
|
|
self.assertGdbRepr([]) |
|
|
|
|
|
self.assertGdbRepr(list(range(5))) |
|
|
|
|
|
|
|
|
def test_bytes(self): |
|
|
def test_bytes(self): |
|
|
'Verify the pretty-printing of bytes' |
|
|
'Verify the pretty-printing of bytes' |
|
|
@ -320,9 +313,9 @@ class PrettyPrintTests(DebuggerTests): |
|
|
'Verify the pretty-printing of sets' |
|
|
'Verify the pretty-printing of sets' |
|
|
if (gdb_major_version, gdb_minor_version) < (7, 3): |
|
|
if (gdb_major_version, gdb_minor_version) < (7, 3): |
|
|
self.skipTest("pretty-printing of sets needs gdb 7.3 or later") |
|
|
self.skipTest("pretty-printing of sets needs gdb 7.3 or later") |
|
|
self.assertGdbRepr(set()) |
|
|
|
|
|
self.assertGdbRepr(set(['a', 'b'])) |
|
|
|
|
|
self.assertGdbRepr(set([4, 5, 6])) |
|
|
|
|
|
|
|
|
self.assertGdbRepr(set(), 'set()') |
|
|
|
|
|
self.assertGdbRepr(set(['a', 'b']), "{'a', 'b'}") |
|
|
|
|
|
self.assertGdbRepr(set([4, 5, 6]), "{4, 5, 6}") |
|
|
|
|
|
|
|
|
# Ensure that we handle sets containing the "dummy" key value, |
|
|
# Ensure that we handle sets containing the "dummy" key value, |
|
|
# which happens on deletion: |
|
|
# which happens on deletion: |
|
|
@ -335,9 +328,9 @@ id(s)''') |
|
|
'Verify the pretty-printing of frozensets' |
|
|
'Verify the pretty-printing of frozensets' |
|
|
if (gdb_major_version, gdb_minor_version) < (7, 3): |
|
|
if (gdb_major_version, gdb_minor_version) < (7, 3): |
|
|
self.skipTest("pretty-printing of frozensets needs gdb 7.3 or later") |
|
|
self.skipTest("pretty-printing of frozensets needs gdb 7.3 or later") |
|
|
self.assertGdbRepr(frozenset()) |
|
|
|
|
|
self.assertGdbRepr(frozenset(['a', 'b'])) |
|
|
|
|
|
self.assertGdbRepr(frozenset([4, 5, 6])) |
|
|
|
|
|
|
|
|
self.assertGdbRepr(frozenset(), 'frozenset()') |
|
|
|
|
|
self.assertGdbRepr(frozenset(['a', 'b']), "frozenset({'a', 'b'})") |
|
|
|
|
|
self.assertGdbRepr(frozenset([4, 5, 6]), "frozenset({4, 5, 6})") |
|
|
|
|
|
|
|
|
def test_exceptions(self): |
|
|
def test_exceptions(self): |
|
|
# Test a RuntimeError |
|
|
# Test a RuntimeError |
|
|
|