annotate libstdc++-v3/python/hook.in @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 # -*- python -*-
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
2 # Copyright (C) 2009-2020 Free Software Foundation, Inc.
111
kono
parents:
diff changeset
3
kono
parents:
diff changeset
4 # This program is free software; you can redistribute it and/or modify
kono
parents:
diff changeset
5 # it under the terms of the GNU General Public License as published by
kono
parents:
diff changeset
6 # the Free Software Foundation; either version 3 of the License, or
kono
parents:
diff changeset
7 # (at your option) any later version.
kono
parents:
diff changeset
8 #
kono
parents:
diff changeset
9 # This program is distributed in the hope that it will be useful,
kono
parents:
diff changeset
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
kono
parents:
diff changeset
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
kono
parents:
diff changeset
12 # GNU General Public License for more details.
kono
parents:
diff changeset
13 #
kono
parents:
diff changeset
14 # You should have received a copy of the GNU General Public License
kono
parents:
diff changeset
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
kono
parents:
diff changeset
16
kono
parents:
diff changeset
17 import sys
kono
parents:
diff changeset
18 import gdb
kono
parents:
diff changeset
19 import os
kono
parents:
diff changeset
20 import os.path
kono
parents:
diff changeset
21
kono
parents:
diff changeset
22 pythondir = '@pythondir@'
kono
parents:
diff changeset
23 libdir = '@toolexeclibdir@'
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 # This file might be loaded when there is no current objfile. This
kono
parents:
diff changeset
26 # can happen if the user loads it manually. In this case we don't
kono
parents:
diff changeset
27 # update sys.path; instead we just hope the user managed to do that
kono
parents:
diff changeset
28 # beforehand.
kono
parents:
diff changeset
29 if gdb.current_objfile () is not None:
kono
parents:
diff changeset
30 # Update module path. We want to find the relative path from libdir
kono
parents:
diff changeset
31 # to pythondir, and then we want to apply that relative path to the
kono
parents:
diff changeset
32 # directory holding the objfile with which this file is associated.
kono
parents:
diff changeset
33 # This preserves relocatability of the gcc tree.
kono
parents:
diff changeset
34
kono
parents:
diff changeset
35 # Do a simple normalization that removes duplicate separators.
kono
parents:
diff changeset
36 pythondir = os.path.normpath (pythondir)
kono
parents:
diff changeset
37 libdir = os.path.normpath (libdir)
kono
parents:
diff changeset
38
kono
parents:
diff changeset
39 prefix = os.path.commonprefix ([libdir, pythondir])
kono
parents:
diff changeset
40 # In some bizarre configuration we might have found a match in the
kono
parents:
diff changeset
41 # middle of a directory name.
kono
parents:
diff changeset
42 if prefix[-1] != '/':
kono
parents:
diff changeset
43 prefix = os.path.dirname (prefix) + '/'
kono
parents:
diff changeset
44
kono
parents:
diff changeset
45 # Strip off the prefix.
kono
parents:
diff changeset
46 pythondir = pythondir[len (prefix):]
kono
parents:
diff changeset
47 libdir = libdir[len (prefix):]
kono
parents:
diff changeset
48
kono
parents:
diff changeset
49 # Compute the ".."s needed to get from libdir to the prefix.
kono
parents:
diff changeset
50 dotdots = ('..' + os.sep) * len (libdir.split (os.sep))
kono
parents:
diff changeset
51
kono
parents:
diff changeset
52 objfile = gdb.current_objfile ().filename
kono
parents:
diff changeset
53 dir_ = os.path.join (os.path.dirname (objfile), dotdots, pythondir)
kono
parents:
diff changeset
54
kono
parents:
diff changeset
55 if not dir_ in sys.path:
kono
parents:
diff changeset
56 sys.path.insert(0, dir_)
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 # Call a function as a plain import would not execute body of the included file
kono
parents:
diff changeset
59 # on repeated reloads of this object file.
kono
parents:
diff changeset
60 from libstdcxx.v6 import register_libstdcxx_printers
kono
parents:
diff changeset
61 register_libstdcxx_printers(gdb.current_objfile())