gdb: Python 3 incompatible with libstdc++ pretty printers.

Bug #1258642 reported by Rüdiger Sonderfeld
50
This bug affects 11 people
Affects Status Importance Assigned to Milestone
gcc-4.8 (Ubuntu)
Confirmed
Undecided
Unassigned
gdb (Ubuntu)
Confirmed
High
Unassigned

Bug Description

gdb is now linked against python 3 but python 3 is incompatible with libstdc++'s pretty printers:

Traceback (most recent call last):
  File "<string>", line 4, 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/ruediger/.gdbinit:7: Error in sourced command file:
Error while executing Python code.

There is a proposed patch but it wasn't upstreamed yet: http://<email address hidden>/msg65185.html

I'd propose either to continue using python2 for gdb, fixing the details to get the patch upstream, or use a patched version downstream for now.

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in gdb (Ubuntu):
status: New → Confirmed
Revision history for this message
Martin Olsson (mnemo) wrote :

I have the same for trivial hello world program written in go

go build prog.go
gdb prog

  File "/usr/share/go/src/pkg/runtime/runtime-gdb.py", line 358
    print s, ptr['goid'], "%8s" % sts[long((ptr['status']))], blk.function
          ^
SyntaxError: invalid syntax

---

When gdb is switched to use python3 in plugins, then the packaged plugins need to be updated correspondingly as well. Please don't just switch it in gdb and leave stuff like C++ and go pretty printing packages broken.

Changed in gdb (Ubuntu):
importance: Undecided → High
Revision history for this message
Tomasz Ziętkiewicz (tomek-zietkiewicz) wrote :

There are 2 workarounds for this:
1. Convert printers.py to python3 yourself:

$ cd /usr/share/gcc-4.8/python/libstdcxx/v6/
$ 2to3 -w printers.py

2. Use this patch: http://gcc.gnu.org/ml/libstdc++/2013-10/msg00243.html

Revision history for this message
John Weldon (johnweldon4) wrote :

@tomek-zietkiewicz I don't have that folder or file on my machine(/usr/share/gcc-4.8, printers.py), but I'm getting the same error.

Is that because I have the packaged binary version of gdb?

If so, is there a workaround in that case, or do I need to build the gdb package from source to fix this?

Revision history for this message
Ryan Tandy (rtandy) wrote :

John: The patch is for that particular file. If you get the same error from a different file then you need a different patch.

What's the full path to the file you get the error from? If it comes from a package, that package needs a bug filed against it; if it's a script you supplied, you should contact the script's author about it.

Revision history for this message
John Weldon (johnweldon4) wrote :

Thanks Ryan;
You're right. I'll try to fix the specific file I saw the error in. My error was:

S 11:11:34 [0]$ gdb juju.test
GNU gdb (GDB) 7.6.1-ubuntu
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /mnt/build/go/src/launchpad.net/juju-core/juju.test...done.
  File "/usr/share/go/src/pkg/runtime/runtime-gdb.py", line 358
    print s, ptr['goid'], "%8s" % sts[long((ptr['status']))], blk.function
          ^
SyntaxError: invalid syntax
(gdb)

Revision history for this message
Ryan Tandy (rtandy) wrote :

John, the pretty-printer for go is covered by bug 1283626, and it sounds like 2to3 is able to convert that file automatically. Hope that helps.

Adding gcc-4.8 to this bug since that's where the STL pretty-printer comes from, and I think it's more likely to be fixed there than by reverting gdb back to linking against python2.

Revision history for this message
John Weldon (johnweldon4) wrote :

Fwiw, running `2to3 -w /usr/share/go/src/pkg/runtime/runtime-gdb.py" fixed my issue.

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in gcc-4.8 (Ubuntu):
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.