Skip to content

Commit d7d2bc8

Browse files
committed
Issue #28023: Fix python-gdb.py didn't support new dict implementation
1 parent f50a85d commit d7d2bc8

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

Lib/test/test_gdb.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
import unittest
1212
import locale
1313

14-
# FIXME: issue #28023
15-
raise unittest.SkipTest("FIXME: issue #28023, compact dict (issue #27350) broke python-gdb.py")
16-
1714
# Is this Python configured to support threads?
1815
try:
1916
import _thread
@@ -296,9 +293,8 @@ def test_dicts(self):
296293
'Verify the pretty-printing of dictionaries'
297294
self.assertGdbRepr({})
298295
self.assertGdbRepr({'foo': 'bar'}, "{'foo': 'bar'}")
299-
# PYTHONHASHSEED is need to get the exact item order
300-
if not sys.flags.ignore_environment:
301-
self.assertGdbRepr({'foo': 'bar', 'douglas': 42}, "{'douglas': 42, 'foo': 'bar'}")
296+
# Python preserves insertion order since 3.6
297+
self.assertGdbRepr({'foo': 'bar', 'douglas': 42}, "{'foo': 'bar', 'douglas': 42}")
302298

303299
def test_lists(self):
304300
'Verify the pretty-printing of lists'
@@ -819,6 +815,7 @@ def test_gc(self):
819815
)
820816
self.assertIn('Garbage-collecting', gdb_output)
821817

818+
@unittest.skip("FIXME: builtin method is not shown in py-bt and py-bt-full")
822819
@unittest.skipIf(python_is_optimized(),
823820
"Python was compiled with optimizations")
824821
# Some older versions of gdb will fail with

Misc/NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ Core and Builtins
1313
Library
1414
-------
1515

16+
Tools/Demos
17+
-----------
18+
19+
- Issue #28023: Fix python-gdb.py didn't support new dict implementation.
20+
1621

1722
What's New in Python 3.6.0 beta 4
1823
=================================

Tools/gdb/libpython.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,8 +666,9 @@ def iteritems(self):
666666
'''
667667
keys = self.field('ma_keys')
668668
values = self.field('ma_values')
669-
for i in safe_range(keys['dk_size']):
670-
ep = keys['dk_entries'].address + i
669+
entries, nentries = self._get_entries(keys)
670+
for i in safe_range(nentries):
671+
ep = entries[i]
671672
if long(values):
672673
pyop_value = PyObjectPtr.from_pyobject_ptr(values[i])
673674
else:
@@ -707,6 +708,29 @@ def write_repr(self, out, visited):
707708
pyop_value.write_repr(out, visited)
708709
out.write('}')
709710

711+
def _get_entries(self, keys):
712+
dk_size = int(keys['dk_size'])
713+
try:
714+
# <= Python 3.5
715+
return keys['dk_entries'], dk_size
716+
except gdb.error:
717+
# >= Python 3.6
718+
pass
719+
720+
if dk_size <= 0xFF:
721+
offset = dk_size
722+
elif dk_size <= 0xFFFF:
723+
offset = 2 * dk_size
724+
elif dk_size <= 0xFFFFFFFF:
725+
offset = 4 * dk_size
726+
else:
727+
offset = 8 * dk_size
728+
729+
ent_ptr_t = gdb.lookup_type('PyDictKeyEntry').pointer()
730+
ent_addr = int(keys['dk_indices']['as_1'].address) + offset
731+
return gdb.Value(ent_addr).cast(ent_ptr_t), int(keys['dk_nentries'])
732+
733+
710734
class PyListObjectPtr(PyObjectPtr):
711735
_typename = 'PyListObject'
712736

0 commit comments

Comments
 (0)