Skip to content

Commit

Permalink
gdb: take libstdc++ pretty printers from host, not external/
Browse files Browse the repository at this point in the history
libstdc++ comes with a python script to help gdb pretty-print some useful
C++ types (unique_ptr, vector, etc.). Our current gdb script takes this
script from external/, but unfortunately the script we have in external/
is from Fedora 20, written for Python 2, while some systems' gdb have
Python 3 so this script doesn't work.

The more sensible thing to do - given that we're already using (by default)
the build machine's libstdc++, and its gdb, is to run the script installed
on the build machine. This is what this patch does, unfortunately in an
ugly way and not a very robust way (namely, if two versions of
libstdc++ are installed, it picks one arbitrarily). But I can't figure
out a cleaner way to do this.

Fixes cloudius/gcc-bin/#1

Signed-off-by: Nadav Har'El <[email protected]>
Signed-off-by: Pekka Enberg <[email protected]>
  • Loading branch information
nyh authored and Pekka Enberg committed Apr 22, 2015
1 parent e63c2c9 commit 46b6191
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions scripts/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
import os, os.path
import heapq
import fnmatch
from glob import glob
from collections import defaultdict

Expand Down Expand Up @@ -1012,12 +1013,31 @@ def continue_handler(event):
gdb.events.cont.connect(continue_handler)

def setup_libstdcxx():
gcc = external + '/gcc.bin'
sys.path += [gcc + '/usr/share/gdb/auto-load/usr/lib64',
glob(gcc + '/usr/share/gcc-*/python')[0],
]
main = glob(gcc + '/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.*.py')[0]
exec(compile(open(main).read(), main, 'exec'))
# A libstdc++ installation is normally acommpanied by a python script
# like /usr/share/gdb/auto-load/usr/lib64/libstdc++.so.6.0.20-gdb.py
# to be loaded into gdb and helps pretty-print various STL types in gdb.
# Normally, this script is automatically loaded by gdb when the
# "libstdc++.so.6.0.20" shared object is loaded into the debugger.
# But because OSv is statically linked, we miss that auto-loading, so we
# need to look for, and run, this script explicitly.
sys.path += [glob('/usr/share/gcc-*/python')[0]]
for base, dirnames, filenames in os.walk(gdb.PYTHONDIR + '/../auto-load'):
for filename in fnmatch.filter(filenames, 'libstdc++.so.*-gdb.py'):
script = os.path.join(base, filename)
exec(compile(open(script).read(), script, 'exec'))
return
# The following commented code is similar, but takes the python script
# from external/ instead of the one installed on the system. This might
# be useful if "make build_env=external" was used. However, there's a
# snag - the Python script we have in external/ might not be compatible
# with the version of Python installed on the system (there's right now
# a transition between Python 2 and Python 3 making things difficult).
#gcc = external + '/gcc.bin'
#sys.path += [gcc + '/usr/share/gdb/auto-load/usr/lib64',
# glob(gcc + '/usr/share/gcc-*/python')[0],
# ]
#main = glob(gcc + '/usr/share/gdb/auto-load/usr/lib64/libstdc++.so.*.py')[0]
#exec(compile(open(main).read(), main, 'exec'))

def sig_to_string(sig):
'''Convert a tracepoing signature to a string'''
Expand Down

0 comments on commit 46b6191

Please sign in to comment.