136ac495dSmrg# -*- python -*- 2*8feb0f0bSmrg# Copyright (C) 2009-2020 Free Software Foundation, Inc. 336ac495dSmrg 436ac495dSmrg# This program is free software; you can redistribute it and/or modify 536ac495dSmrg# it under the terms of the GNU General Public License as published by 636ac495dSmrg# the Free Software Foundation; either version 3 of the License, or 736ac495dSmrg# (at your option) any later version. 836ac495dSmrg# 936ac495dSmrg# This program is distributed in the hope that it will be useful, 1036ac495dSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of 1136ac495dSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1236ac495dSmrg# GNU General Public License for more details. 1336ac495dSmrg# 1436ac495dSmrg# You should have received a copy of the GNU General Public License 1536ac495dSmrg# along with this program. If not, see <http://www.gnu.org/licenses/>. 1636ac495dSmrg 1736ac495dSmrgimport sys 1836ac495dSmrgimport gdb 1936ac495dSmrgimport os 2036ac495dSmrgimport os.path 2136ac495dSmrg 2236ac495dSmrgpythondir = '@pythondir@' 2336ac495dSmrglibdir = '@toolexeclibdir@' 2436ac495dSmrg 2536ac495dSmrg# This file might be loaded when there is no current objfile. This 2636ac495dSmrg# can happen if the user loads it manually. In this case we don't 2736ac495dSmrg# update sys.path; instead we just hope the user managed to do that 2836ac495dSmrg# beforehand. 2936ac495dSmrgif gdb.current_objfile () is not None: 3036ac495dSmrg # Update module path. We want to find the relative path from libdir 3136ac495dSmrg # to pythondir, and then we want to apply that relative path to the 3236ac495dSmrg # directory holding the objfile with which this file is associated. 3336ac495dSmrg # This preserves relocatability of the gcc tree. 3436ac495dSmrg 3536ac495dSmrg # Do a simple normalization that removes duplicate separators. 3636ac495dSmrg pythondir = os.path.normpath (pythondir) 3736ac495dSmrg libdir = os.path.normpath (libdir) 3836ac495dSmrg 3936ac495dSmrg prefix = os.path.commonprefix ([libdir, pythondir]) 4036ac495dSmrg # In some bizarre configuration we might have found a match in the 4136ac495dSmrg # middle of a directory name. 4236ac495dSmrg if prefix[-1] != '/': 4336ac495dSmrg prefix = os.path.dirname (prefix) + '/' 4436ac495dSmrg 4536ac495dSmrg # Strip off the prefix. 4636ac495dSmrg pythondir = pythondir[len (prefix):] 4736ac495dSmrg libdir = libdir[len (prefix):] 4836ac495dSmrg 4936ac495dSmrg # Compute the ".."s needed to get from libdir to the prefix. 5036ac495dSmrg dotdots = ('..' + os.sep) * len (libdir.split (os.sep)) 5136ac495dSmrg 5236ac495dSmrg objfile = gdb.current_objfile ().filename 5336ac495dSmrg dir_ = os.path.join (os.path.dirname (objfile), dotdots, pythondir) 5436ac495dSmrg 5536ac495dSmrg if not dir_ in sys.path: 5636ac495dSmrg sys.path.insert(0, dir_) 5736ac495dSmrg 5836ac495dSmrg# Call a function as a plain import would not execute body of the included file 5936ac495dSmrg# on repeated reloads of this object file. 6036ac495dSmrgfrom libstdcxx.v6 import register_libstdcxx_printers 6136ac495dSmrgregister_libstdcxx_printers(gdb.current_objfile()) 62