This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: FYI: two libstdc++ pretty-printer hook fixes


I'm checking this in.

This fixes two bugs in the libstdc++ pretty-printer hook file.

First, now the hook file will not immediately fail if there is no
current objfile.  This is not a normal situation, but a user might
want to read the hook file manually, and it is nice if we allow this.
This assumes that the user has set sys.path himself.

Second, we now use os.path.normpath to normalize paths.  This fixes a
problem reported by Jonathan Wakely, where we had libdir set to
$prefix/lib/../lib64.  The '..' confused the existing relativization
code.

The patch is pretty ugly as it mostly consists of reindentation.

Tom

2009-06-17  Tom Tromey  <tromey@redhat.com>

	* python/hook.in: Do not fail when there is no current objfile.
	Use os.path.normpath.

Index: python/hook.in
===================================================================
--- python/hook.in	(revision 148625)
+++ python/hook.in	(working copy)
@@ -22,33 +22,38 @@
 pythondir = '@pythondir@'
 libdir = '@toolexeclibdir@'
 
-# Update module path.  We want to find the relative path from libdir
-# to pythondir, and then we want to apply that relative path to the
-# directory holding the objfile with which this file is associated.
-# This preserves relocatability of the gcc tree.
+# This file might be loaded when there is no current objfile.  This
+# can happen if the user loads it manually.  In this case we don't
+# update sys.path; instead we just hope the user managed to do that
+# beforehand.
+if gdb.current_objfile () is not None:
+    # Update module path.  We want to find the relative path from libdir
+    # to pythondir, and then we want to apply that relative path to the
+    # directory holding the objfile with which this file is associated.
+    # This preserves relocatability of the gcc tree.
 
-# Do a simple normalization that removes duplicate separators.
-pythondir = os.path.join (*['/'] + pythondir.split (os.sep))
-libdir = os.path.join (*['/'] + libdir.split (os.sep))
+    # Do a simple normalization that removes duplicate separators.
+    pythondir = os.path.normpath (pythondir)
+    libdir = os.path.normpath (libdir)
 
-prefix = os.path.commonprefix ([libdir, pythondir])
-# In some bizarre configuration we might have found a match in the
-# middle of a directory name.
-if prefix[-1] != '/':
-    prefix = os.path.dirname (prefix)
+    prefix = os.path.commonprefix ([libdir, pythondir])
+    # In some bizarre configuration we might have found a match in the
+    # middle of a directory name.
+    if prefix[-1] != '/':
+        prefix = os.path.dirname (prefix)
 
-# Strip off the prefix.
-pythondir = pythondir[len (prefix):]
-libdir = libdir[len (prefix):]
+    # Strip off the prefix.
+    pythondir = pythondir[len (prefix):]
+    libdir = libdir[len (prefix):]
 
-# Compute the ".."s needed to get from libdir to the prefix.
-dotdots = ('..' + os.sep) * len (libdir.split (os.sep))
+    # Compute the ".."s needed to get from libdir to the prefix.
+    dotdots = ('..' + os.sep) * len (libdir.split (os.sep))
 
-objfile = gdb.current_objfile ().filename
-dir = os.path.join (os.path.dirname (objfile), dotdots, pythondir)
+    objfile = gdb.current_objfile ().filename
+    dir = os.path.join (os.path.dirname (objfile), dotdots, pythondir)
 
-if not dir in sys.path:
-    sys.path.insert(0, dir)
+    if not dir in sys.path:
+        sys.path.insert(0, dir)
 
 # Load the pretty-printers.
 from libstdcxx.v6.printers import register_libstdcxx_printers


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]