diff --git a/scripts/loader.py b/scripts/loader.py index 91fd6dbd50..0008606d4e 100644 --- a/scripts/loader.py +++ b/scripts/loader.py @@ -4,6 +4,7 @@ import re import os, os.path import heapq +import fnmatch from glob import glob from collections import defaultdict @@ -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'''