[Python-checkins] cpython (merge 3.6 -> default): Issue #28023: Fix python-gdb.py didn't support new dict implementation

inada.naoki python-checkins at python.org
Tue Nov 22 05:43:59 EST 2016


https://hg.python.org/cpython/rev/c51045920410
changeset: 105332:c51045920410
parent: 105330:2a14385710dc
parent: 105331:4f6fb9e47f6b
user: INADA Naoki <songofacandy at gmail.com>
date: Tue Nov 22 19:43:11 2016 +0900
summary:
 Issue #28023: Fix python-gdb.py didn't support new dict implementation
files:
 Lib/test/test_gdb.py | 9 +++------
 Misc/NEWS | 2 ++
 Tools/gdb/libpython.py | 28 ++++++++++++++++++++++++++--
 3 files changed, 31 insertions(+), 8 deletions(-)
diff --git a/Lib/test/test_gdb.py b/Lib/test/test_gdb.py
--- a/Lib/test/test_gdb.py
+++ b/Lib/test/test_gdb.py
@@ -11,9 +11,6 @@
 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
@@ -296,9 +293,8 @@
 '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'
@@ -819,6 +815,7 @@
 )
 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
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -493,6 +493,8 @@
 Tools/Demos
 -----------
 
+- Issue #28023: Fix python-gdb.py didn't support new dict implementation.
+
 - Issue #15369: The pybench and pystone microbenchmark have been removed from
 Tools. Please use the new Python benchmark suite
 https://github.com/python/performance which is more reliable and includes a
diff --git a/Tools/gdb/libpython.py b/Tools/gdb/libpython.py
--- a/Tools/gdb/libpython.py
+++ b/Tools/gdb/libpython.py
@@ -666,8 +666,9 @@
 '''
 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:
@@ -707,6 +708,29 @@
 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'
 
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /