2

I am running Ubuntu 16.04 with gdb version 7.11.1-0ubuntu1~16.5. When I upgraded g++ to g++-6.4 (Ubuntu 6.4.0-17ubuntu1~16.04), gdb started giving python errors like:

Python Exception <class 'TypeError'> expected string or bytes-like object: 
Error while executing Python code.

whenever I try to print a class or an STL object during debugging. I determined that only gdb-8 supports g++-6.4, so I tried to build gdb-8.1 from the instructions on http://www.linuxfromscratch.org/blfs/view/cvs/general/gdb.html, but gdb-8.1 requires python 2.7.15, and just installing gdb-8.1 without upgrading python (installed version is 2.7.12) did not solve the printing issues.

Following the accepted answer at How do I install the latest Python 2.7.X or 3.X on Ubuntu?, I tried to install python 2.7.15 from the deadsnakes ppa. But, mysteriously, python 2.7.xx is not even listed on the ppa page (https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa), even though 2.3, 2.4, 2.5, 2.6 are all available. Then, I tried to build it manually based on instructions at http://www.linuxfromscratch.org/blfs/view/svn/general/python2.html, but it turns out that python 2.7.15 gets installed in a separate location (/usr/local/bin etc.) and does not replace python 2.7.12. So the gdb printing errors are still present.

Is there a way to completely replace the installed python 2.7.12? Even if I can use the correct python binary file, I will have to change the library location for the dev files to that from the new version and may be rebuild gdb-8.1 against those python-dev files. Because otherwise, I see errors such as:

Traceback (most recent call last):
 File "/usr/share/gdb/python/gdb/__init__.py", line 144, in auto_load_packages
   __import__(modname)
 File "/usr/share/gdb/python/gdb/command/pretty_printers.py", line 19, in <module>
   import copy
 File "/usr/lib/python2.7/copy.py", line 52, in <module>
   import weakref
 File "/usr/lib/python2.7/weakref.py", line 14, in <module>
   from _weakref import (
ImportError: cannot import name _remove_dead_weakref

when I start gdb. If nothing helps, I might have to upgrade (not desirable) to Ubuntu-18.04 which ships with python 2.7.15rc and gdb-7, though gdb-8 experimental version is available from the repositories.

Similar questions to this have not been as specific and haven't helped me solve the problem.

Sagar Jha
  • 1,073

0 Answers0