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.

classification
Title: Tools/gdb/libpython.py does not support GDB linked against Python 3
Type: behavior Stage: resolved
Components: Demos and Tools Versions: Python 3.3, Python 3.4, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: dcoles, dmalcolm, doko, jtaylor, pitrou, python-dev
Priority: high Keywords: patch

Created on 2013-10-20 09:24 by dcoles, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
gdb_py3.patch pitrou, 2013-10-20 19:40 review
gdb_py3.patch dcoles, 2013-10-21 01:23 review
python27-gdb_py3.patch dcoles, 2013-10-21 07:26 review
Messages (15)
msg200554 - (view) Author: David Coles (dcoles) * Date: 2013-10-20 09:24
Tools/gdb/libpython.py is currently Python 3 incompatible. Unfortunately recent versions of gdb (such as the one provided in Ubuntu 13.10) may be linked against Python 3 rather than Python 2, breaking debugging support.

Most of the issues appear to be trivial issues such as the print statement syntax and removal of functions like xrange, unichr and long.
msg200581 - (view) Author: Matthias Klose (doko) * (Python committer) Date: 2013-10-20 13:35
should go into 2.7 as well.
msg200617 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-10-20 19:11
Do you want to provide a patch? It's hard for someone with a py2-linked gcc to make sure that the libpython pluging works properly.
msg200619 - (view) Author: David Coles (dcoles) * Date: 2013-10-20 19:17
Sure thing. I've got a patch attached to https://bugs.launchpad.net/ubuntu/+source/gdb/+bug/1241668 but want to make sure that it doesn't break things on the py2-linked version.
msg200621 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-10-20 19:40
Can you please try the attached updated patch?
msg200679 - (view) Author: David Coles (dcoles) * Date: 2013-10-21 01:23
I ended up with a very similar looking patch - and so merged my changes into Pitrou's patch.

I also had a go at fixing up the `test_gdb` unit test, which revealed a few more string/unicode issues. Finally tracked them down to the `write_unicode` function. Sadly the `write` function in GDB's Python API only accepts unicode strings, hence we must pre-backslash escape for C-string encoding (either Python's default encoding or utf-8 in Python 3.1+) then turn it back into a unicode string again to avoid a TypeError. Yuck.

The patch almost applies on Python 2.7, but needs a little bit of massaging due to slight differences in Tools/gdb/libpython.py. Need to test the new unicode changes haven't broken anything and then I'll upload a patch for Python 2.7.
msg200706 - (view) Author: David Coles (dcoles) * Date: 2013-10-21 07:26
And here's the patch for Python 2.7.

The result of testing is as follows:
- python (default) against py2-linked gdb: All tests pass
- python (2.7) against py2-linked gdb: `test_long` fails.
- python (default) against py3-linked gdb: All tests pass
- python (2.7) against py3-linked gdb: `test_long`, `test_strings` and `test_unicode` fail.

`test_long` has been removed from the default branch, in addition gdb doesn't seem to distinguish printing 0 from 0L. `test_strings` likely fails since Python 3 will print printable unicode characters (like "\xff") while Python 2 will not. `test_unicode` likely fails due to the 'u' prefix on unicode strings in Python 2. This kind of behavior is pretty much expected when cross-testing gdb.
msg200716 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-10-21 08:22
I've added a review comment to the 3.3 version of the patch.
msg202179 - (view) Author: Julian Taylor (jtaylor) Date: 2013-11-04 23:45
I tested the latest patch (python27-gdb_py3.patch) with ubuntu 13.10 gdb compiled against python3.3, while it fixes the syntax errors it does not fix the functionality.
E.g. one gets this error on breakpoints:

Python Exception <class 'gdb.error'> There is no member named length.: 
Breakpoint 3, PyTuple_Size (op=) at ../Objects/tupleobject.c:127

and the objects are not printed in their string representation as they should be with the plugin.
msg202182 - (view) Author: Julian Taylor (jtaylor) Date: 2013-11-05 00:11
on further investigation I seem to have screwed up patching the files. Patching properly they do work. Sorry for the noise.
msg204050 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-11-23 16:40
New changeset 9f2a0043396b by Antoine Pitrou in branch 'default':
Issue #19308: fix the gdb plugin on gdbs linked with Python 3
http://hg.python.org/cpython/rev/9f2a0043396b
msg204051 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-11-23 16:44
New changeset 752db82b7933 by Antoine Pitrou in branch '3.3':
Issue #19308: fix the gdb plugin on gdbs linked with Python 3
http://hg.python.org/cpython/rev/752db82b7933
msg204057 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-11-23 17:19
New changeset ef4636faf8bd by Antoine Pitrou in branch '2.7':
Issue #19308: fix the gdb plugin on gdbs linked with Python 3
http://hg.python.org/cpython/rev/ef4636faf8bd
msg204061 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-11-23 17:23
I've committed updated patches to all 3 branches (+ some later fixups). Gonna wait for the buildbots' outcome.
msg204104 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-11-23 20:48
The buildbots look ok now.
History
Date User Action Args
2022-04-11 14:57:52adminsetgithub: 63507
2013-11-23 20:48:46pitrousetstatus: open -> closed

messages: + msg204104
2013-11-23 17:23:50pitrousetresolution: fixed
messages: + msg204061
stage: patch review -> resolved
2013-11-23 17:19:43python-devsetmessages: + msg204057
2013-11-23 16:44:14python-devsetmessages: + msg204051
2013-11-23 16:40:45python-devsetnosy: + python-dev
messages: + msg204050
2013-11-05 00:11:41jtaylorsetmessages: + msg202182
2013-11-04 23:45:27jtaylorsetnosy: + jtaylor
messages: + msg202179
2013-10-21 08:22:14pitrousetmessages: + msg200716
2013-10-21 07:26:22dcolessetfiles: + python27-gdb_py3.patch

messages: + msg200706
2013-10-21 01:23:50dcolessetfiles: + gdb_py3.patch

messages: + msg200679
2013-10-20 19:40:24pitrousetfiles: + gdb_py3.patch
messages: + msg200621

keywords: + patch
type: behavior
stage: patch review
2013-10-20 19:17:20dcolessetmessages: + msg200619
2013-10-20 19:11:29pitrousetpriority: normal -> high
nosy: + pitrou
messages: + msg200617

2013-10-20 13:35:06dokosetnosy: + doko

messages: + msg200581
versions: + Python 2.7
2013-10-20 09:36:02ned.deilysetnosy: + dmalcolm
2013-10-20 09:24:14dcolescreate