diff -r a429d29eafbf Lib/test/test_gdb.py --- a/Lib/test/test_gdb.py Mon Nov 21 13:38:59 2016 +0000 +++ b/Lib/test/test_gdb.py Tue Nov 22 00:39:55 2016 +0900 @@ -8,15 +8,12 @@ import subprocess import sys import sysconfig import unittest import locale -# FIXME: issue #28023 -raise unittest.SkipTest("FIXME: issue #28023, compact dict (issue #27350) broke python-gdb.py") - # Is this Python configured to support threads? try: import _thread except ImportError: _thread = None @@ -293,15 +290,14 @@ self.assertGdbRepr(None) def test_dicts(self): 'Verify the pretty-printing of dictionaries' self.assertGdbRepr({}) self.assertGdbRepr({'foo': 'bar'}, "{'foo': 'bar'}") - # PYTHONHASHSEED is need to get the exact item order - if not sys.flags.ignore_environment: - self.assertGdbRepr({'foo': 'bar', 'douglas': 42}, "{'douglas': 42, 'foo': 'bar'}") + # Python preserves insertion order since 3.6 + self.assertGdbRepr({'foo': 'bar', 'douglas': 42}, "{'foo': 'bar', 'douglas': 42}") def test_lists(self): 'Verify the pretty-printing of lists' self.assertGdbRepr([]) self.assertGdbRepr(list(range(5))) @@ -816,12 +812,13 @@ # Verify with "py-bt-full": gdb_output = self.get_stack_trace(cmd, cmds_after_breakpoint=['break update_refs', 'continue', 'py-bt-full'], ) self.assertIn('Garbage-collecting', gdb_output) + @unittest.skip("FIXME: builtin method is not shown in py-bt and py-bt-full") @unittest.skipIf(python_is_optimized(), "Python was compiled with optimizations") # Some older versions of gdb will fail with # "Cannot find new threads: generic error" # unless we add LD_PRELOAD=PATH-TO-libpthread.so.1 as a workaround @unittest.skipUnless(_thread, diff -r a429d29eafbf Tools/gdb/libpython.py --- a/Tools/gdb/libpython.py Mon Nov 21 13:38:59 2016 +0000 +++ b/Tools/gdb/libpython.py Tue Nov 22 00:39:55 2016 +0900 @@ -663,14 +663,15 @@ ''' Yields a sequence of (PyObjectPtr key, PyObjectPtr value) pairs, analogous to dict.iteritems() ''' keys = self.field('ma_keys') values = self.field('ma_values') - for i in safe_range(keys['dk_size']): - ep = keys['dk_entries'].address + i + entries, nentries = self._get_entries(keys) + for i in safe_range(nentries): + ep = entries[i] if long(values): pyop_value = PyObjectPtr.from_pyobject_ptr(values[i]) else: pyop_value = PyObjectPtr.from_pyobject_ptr(ep['me_value']) if not pyop_value.is_null(): pyop_key = PyObjectPtr.from_pyobject_ptr(ep['me_key']) @@ -704,12 +705,35 @@ first = False pyop_key.write_repr(out, visited) out.write(': ') pyop_value.write_repr(out, visited) out.write('}') + def _get_entries(self, keys): + dk_size = int(keys['dk_size']) + try: + # <= Python 3.5 + return keys['dk_entries'], dk_size + except gdb.error: + # >= Python 3.6 + pass + + if dk_size <= 0xFF: + offset = dk_size + elif dk_size <= 0xFFFF: + offset = 2 * dk_size + elif dk_size <= 0xFFFFFFFF: + offset = 4 * dk_size + else: + offset = 8 * dk_size + + ent_ptr_t = gdb.lookup_type('PyDictKeyEntry').pointer() + ent_addr = int(keys['dk_indices']['as_1'].address) + offset + return gdb.Value(ent_addr).cast(ent_ptr_t), int(keys['dk_nentries']) + + class PyListObjectPtr(PyObjectPtr): _typename = 'PyListObject' def __getitem__(self, i): # Get the gdb.Value for the (PyObject*) with the given index: field_ob_item = self.field('ob_item')