File find-separate-debug-file.diff of Package gdb

Index: gdb/symfile.c
===================================================================
RCS file: /cvs/src/src/gdb/symfile.c,v
retrieving revision 1.205
diff -u -a -p -u -p -a -r1.205 gdb/symfile.c
--- gdb/symfile.c	5 Jun 2008 19:21:55 -0000	1.205
+++ gdb/symfile.c	10 Jun 2008 09:56:34 -0000
@@ -1414,12 +1414,13 @@ find_separate_debug_file (struct objfile
     return NULL;
 
   dir = xstrdup (objfile->name);
+  canon_name = lrealpath (dir);
 
   /* Strip off the final filename part, leaving the directory name,
      followed by a slash.  Objfile names should always be absolute and
      tilde-expanded, so there should always be a slash in there
      somewhere.  */
-  for (i = strlen(dir) - 1; i >= 0; i--)
+  for (i = strlen (dir) - 1; i >= 0; i--)
     {
       if (IS_DIR_SEPARATOR (dir[i]))
 	break;
@@ -1427,8 +1428,20 @@ find_separate_debug_file (struct objfile
   gdb_assert (i >= 0 && IS_DIR_SEPARATOR (dir[i]));
   dir[i+1] = '\0';
 
+  if (canon_name)
+    {
+      for (i = strlen (canon_name) - 1; i >= 0; i--)
+	{
+	  if (IS_DIR_SEPARATOR (canon_name[i]))
+	    break;
+	}
+      gdb_assert (i >= 0 && IS_DIR_SEPARATOR (canon_name[i]));
+      canon_name[i+1] = '\0';
+    }
+
   debugfile = alloca (strlen (debug_file_directory) + 1
-                      + strlen (dir)
+                      + (canon_name != NULL && strlen (canon_name) > strlen (dir)
+			 ? strlen (canon_name) : strlen (dir))
                       + strlen (DEBUG_SUBDIRECTORY)
                       + strlen ("/")
                       + strlen (basename)
@@ -1440,6 +1453,8 @@ find_separate_debug_file (struct objfile
 
   if (separate_debug_file_exists (debugfile, crc32))
     {
+      if (canon_name)
+	xfree (canon_name);
       xfree (basename);
       xfree (dir);
       return xstrdup (debugfile);
@@ -1453,6 +1468,8 @@ find_separate_debug_file (struct objfile
 
   if (separate_debug_file_exists (debugfile, crc32))
     {
+      if (canon_name)
+	xfree (canon_name);
       xfree (basename);
       xfree (dir);
       return xstrdup (debugfile);
@@ -1461,11 +1478,13 @@ find_separate_debug_file (struct objfile
   /* Then try in the global debugfile directory.  */
   strcpy (debugfile, debug_file_directory);
   strcat (debugfile, "/");
-  strcat (debugfile, dir);
+  strcat (debugfile, canon_name ? canon_name : dir);
   strcat (debugfile, basename);
 
   if (separate_debug_file_exists (debugfile, crc32))
     {
+      if (canon_name)
+	xfree (canon_name);
       xfree (basename);
       xfree (dir);
       return xstrdup (debugfile);
@@ -1473,7 +1492,6 @@ find_separate_debug_file (struct objfile
 
   /* If the file is in the sysroot, try using its base path in the
      global debugfile directory.  */
-  canon_name = lrealpath (dir);
   if (canon_name
       && strncmp (canon_name, gdb_sysroot, strlen (gdb_sysroot)) == 0
       && IS_DIR_SEPARATOR (canon_name[strlen (gdb_sysroot)]))
openSUSE Build Service is sponsored by