[issue8380] Port of the gdb7 debugging hooks to the "py3k" branch
report at bugs.python.org
Tue Apr 13 00:09:33 CEST 2010
New submission from Dave Malcolm <dmalcolm at redhat.com>:
I'm attaching a patch for the py3k branch to port the gdb hooks to Python 3.
The libpython.py code installed to python-gdb.py "knows" about the internal details of the Python within the tree. This patch makes the necessary changes to that code for the internals of Python 3, rather than Python 2.
Note that libpython.py is intended to run inside a gdb linked against libpython2, and so libpython.py is still Python 2 code; however I've updated it to expect the so-called "inferior process" to be Python 3:
* Py_TPFLAGS_STRING_SUBCLASS becomes Py_TPFLAGS_BYTES_SUBCLASS
* PyStringObjectPtr becomes PyBytesObjectPtr
* change PyObjectPtr to correctly locate "ob_size": with Python 2 variable-sized subclasses we could simply look it up as a field of the subclass struct, but for Python 3 the field may be in an ob_base member, or in an ob_base.ob_base member. We have to cast to a PyVarObject* to find it
* PyIntObject went away; PyBoolObject is now a subclass of PyLongObject
* writing out frames needed a slight rewrite with the change from co_filename and co_name from PyStringObject* to PyUnicodeObject*
This makes the "proxy values" concept a bit awkward; for example a "str" in the inferior Python 3 process looks like a "unicode" to the gdb Python 2 process. This and the int->long change required a lot of minor updating to expected values in the selftests.
The test_gdb.py and gdb_sample.py code _are_ for Python 3. I've assumed that all output is in UTF-8 for now.
For Python 2, I was testing the code by putting a breakpoint on PyObject_Print, and printing objects, as a convenient hook for scraping gdb's stdout.
PyObject_Print still exists in Python 3, but isn't used by the "print" implementation, so I needed a handy function that I could put a breakpoint on, and invoke from the Python side: I looked for something with METH_O that isn't called by site.py and doesn't require an import. I chose the "id" builtin, which corresponds to Python/ceval.c:builtin_id ()
Some minor 2to3-style fixes were also needed in the test code
All of the selftests are currently commented out to keep the buildbot clean (apparently from a merge from trunk), and I've kept them commented out. They all pass on my machine with:
make -j4 ; ./python -Wd ./Lib/test/regrtest.py -v test_gdb
This also contains a port of the (partial?) fix for issue 8330 from trunk's r79986 that doesn't seem to have been merged to py3k (it needed a fair amount of rewriting).
components: Demos and Tools
nosy: dmalcolm, loewis
stage: patch review
title: Port of the gdb7 debugging hooks to the "py3k" branch
versions: Python 3.2, Python 3.3
Added file: http://bugs.python.org/file16902/port-gdb7-hooks-to-py3k.patch
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list