OSDN Git Service

PR libstdc++/40289:
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / python / hook.in
1 # -*- python -*-
2 # Copyright (C) 2009 Free Software Foundation, Inc.
3
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 import sys
18 import gdb
19 import os
20 import os.path
21
22 pythondir = '@pythondir@'
23 libdir = '@toolexeclibdir@'
24
25 # Update module path.  We want to find the relative path from libdir
26 # to pythondir, and then we want to apply that relative path to the
27 # directory holding the objfile with which this file is associated.
28 # This preserves relocatability of the gcc tree.
29
30 # Do a simple normalization that removes duplicate separators.
31 pythondir = os.path.join (*['/'] + pythondir.split (os.sep))
32 libdir = os.path.join (*['/'] + libdir.split (os.sep))
33
34 prefix = os.path.commonprefix ([libdir, pythondir])
35 # In some bizarre configuration we might have found a match in the
36 # middle of a directory name.
37 if prefix[-1] != '/':
38     prefix = os.path.dirname (prefix)
39
40 # Strip off the prefix.
41 pythondir = pythondir[len (prefix):]
42 libdir = libdir[len (prefix):]
43
44 # Compute the ".."s needed to get from libdir to the prefix.
45 dotdots = ('..' + os.sep) * len (libdir.split (os.sep))
46
47 objfile = gdb.current_objfile ().filename
48 dir = os.path.join (os.path.dirname (objfile), dotdots, pythondir)
49
50 if not dir in sys.path:
51     sys.path.insert(0, dir)
52
53 # Load the pretty-printers.
54 from libstdcxx.v6.printers import register_libstdcxx_printers
55 register_libstdcxx_printers (gdb.current_objfile ())