Bug 58962 - Pretty printers use obsolete Python syntax
Summary: Pretty printers use obsolete Python syntax
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.8.1
: P3 normal
Target Milestone: 4.8.4
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-01 14:26 UTC by Bruce Merry
Modified: 2014-08-28 16:28 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Patch to update raise statements to modern Python syntax (696 bytes, patch)
2013-11-01 14:26 UTC, Bruce Merry
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Bruce Merry 2013-11-01 14:26:33 UTC
Created attachment 31135 [details]
Patch to update raise statements to modern Python syntax

The pretty printers shipped with GCC 4.8.1 use the obsolete

raise ExceptionClass, argument

format for raising exceptions. Modern Python (not sure when it was introduced, but the Python 2.6 docs seems to support it so it has been around for a while) instead uses

raise ExceptionClass(arguments...)

and the old form is not supported in Python 3. The result is that when I try to load the pretty printers via .gdbinit in Ubuntu 13.10, I get this message:

Traceback (most recent call last):
  File "<string>", line 3, in <module>
  File "/usr/share/gcc-4.8/python/libstdcxx/v6/printers.py", line 54
    raise ValueError, "Cannot find type %s::%s" % (str(orig), name)
                    ^
SyntaxError: invalid syntax
/home/bruce/.gdbinit:7: Error in sourced command file:
Error while executing Python code.

I've attached a patch which changes the raise statements to use the new syntax. It's against the version shipped with Ubuntu 13.10 in libstdc++6-4.8-dbg; I haven't checked whether Ubuntu have added their own patches.
Comment 1 Bruce Merry 2013-11-01 14:31:34 UTC
I've now realised that this is actually just the tip of the iceberg - I suspect that libstdc++'s pretty printers aren't Python 3 ready, while Ubuntu is shipping a gdb linked to libython 3.3. Feel free to close if this is as expected.
Comment 2 GonzaloBonigo 2014-05-16 14:07:35 UTC
Please, assign it to me.
Comment 3 Daniel Gutson 2014-05-16 14:23:14 UTC
Please do not close this issue.(In reply to Bruce Merry from comment #1)
> I've now realised that this is actually just the tip of the iceberg - I
> suspect that libstdc++'s pretty printers aren't Python 3 ready, while Ubuntu
> is shipping a gdb linked to libython 3.3. Feel free to close if this is as
> expected.

Please don't close this issue, it is completely relevant since not only for ubuntu but for other distros too.

Syntax should work both with python versions 2 and 3 at ever possible.
Comment 4 Bruce Merry 2014-05-16 14:26:42 UTC
Incidentally, the workaround I have been using is to just run the script through 2to3. Since Python only tells you things have gone wrong when you execute the code I can't guarantee that this fixes everything, but I've yet to hit any further Python 2 vs 3 issues after doing this.
Comment 5 Jonathan Wakely 2014-07-11 13:43:42 UTC
Author: redi
Date: Fri Jul 11 13:43:07 2014
New Revision: 212453

URL: https://gcc.gnu.org/viewcvs?rev=212453&root=gcc&view=rev
Log:
2014-07-11  Samuel Bronson  <naesten@gmail.com>
	    Matthias Klose  <doko@ubuntu.com>

	PR libstdc++/58962
	* python/libstdcxx/v6/printers.py: Port to Python 2+3
	(imap): New compat function.
	(izip): Likewise.
	(Iterator): New mixin to allow writing iterators in Python 3 style
	regardless of which version we're running on.
	[Python3] (long) New compat alias for "int".
	* testsuite/lib/gdb-test.exp: Port to Python 2+3 (print syntax)

Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/python/libstdcxx/v6/printers.py
    trunk/libstdc++-v3/testsuite/lib/gdb-test.exp
Comment 6 Jonathan Wakely 2014-07-11 14:12:00 UTC
The trunk version of the printers should now work with both Python 2 and 3
Comment 7 Jonathan Wakely 2014-08-04 18:51:03 UTC
Author: redi
Date: Mon Aug  4 18:50:30 2014
New Revision: 213604

URL: https://gcc.gnu.org/viewcvs?rev=213604&root=gcc&view=rev
Log:
2014-08-04  Samuel Bronson  <naesten@gmail.com>

	Backport r212453 from trunk
	2014-07-11  Samuel Bronson  <naesten@gmail.com>
		    Matthias Klose  <doko@ubuntu.com>

	PR libstdc++/58962
	* python/libstdcxx/v6/printers.py: Port to Python 2+3
	(imap): New compat function.
	(izip): Likewise.
	(Iterator): New mixin to allow writing iterators in Python 3 style
	regardless of which version we're running on.
	[Python3] (long) New compat alias for "int".
	* testsuite/lib/gdb-test.exp: Port to Python 2+3 (print syntax)

	Backport r210625 from trunk
	2014-05-19  Jonathan Wakely  <jwakely@redhat.com>

	* python/libstdcxx/v6/printers.py: Use Python3 raise syntax.

Modified:
    branches/gcc-4_9-branch/libstdc++-v3/ChangeLog
    branches/gcc-4_9-branch/libstdc++-v3/python/libstdcxx/v6/printers.py
    branches/gcc-4_9-branch/libstdc++-v3/testsuite/lib/gdb-test.exp
Comment 8 Jonathan Wakely 2014-08-04 18:57:27 UTC
backported for 4.9.2
Comment 9 Jonathan Wakely 2014-08-28 16:22:54 UTC
Author: redi
Date: Thu Aug 28 16:22:21 2014
New Revision: 214682

URL: https://gcc.gnu.org/viewcvs?rev=214682&root=gcc&view=rev
Log:
2014-08-28  Samuel Bronson  <naesten@gmail.com>

	Backport r212453 from trunk
	2014-07-11  Samuel Bronson  <naesten@gmail.com>
		    Matthias Klose  <doko@ubuntu.com>

	PR libstdc++/58962
	* python/libstdcxx/v6/printers.py: Port to Python 2+3
	(imap): New compat function.
	(izip): Likewise.
	(Iterator): New mixin to allow writing iterators in Python 3 style
	regardless of which version we're running on.
	[Python3] (long) New compat alias for "int".
	* testsuite/lib/gdb-test.exp: Port to Python 2+3 (print syntax)

	Backport r210625 from trunk
	2014-05-19  Jonathan Wakely  <jwakely@redhat.com>

	* python/libstdcxx/v6/printers.py: Use Python3 raise syntax.

Modified:
    branches/gcc-4_8-branch/libstdc++-v3/ChangeLog
    branches/gcc-4_8-branch/libstdc++-v3/python/libstdcxx/v6/printers.py
    branches/gcc-4_8-branch/libstdc++-v3/testsuite/lib/gdb-test.exp