This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author dmalcolm
Recipients dmalcolm, loewis
Date 2010-04-12.22:09:18
SpamBayes Score 3.2586156e-12
Marked as misclassified No
Message-id <1271110173.15.0.608430881051.issue8380@psf.upfronthosting.co.za>
In-reply-to
Content
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).
History
Date User Action Args
2010-04-12 22:09:33dmalcolmsetrecipients: + dmalcolm, loewis
2010-04-12 22:09:33dmalcolmsetmessageid: <1271110173.15.0.608430881051.issue8380@psf.upfronthosting.co.za>
2010-04-12 22:09:31dmalcolmlinkissue8380 messages
2010-04-12 22:09:28dmalcolmcreate