* dwarf2.c (concat_filename): Apply DW_AT_comp_dir if dir table
authorAlan Modra <amodra@gmail.com>
Sun, 17 Sep 2006 02:44:38 +0000 (02:44 +0000)
committerAlan Modra <amodra@gmail.com>
Sun, 17 Sep 2006 02:44:38 +0000 (02:44 +0000)
entry isn't absolute.

bfd/ChangeLog
bfd/dwarf2.c

index 023b241e1c4d44f4239f175193363e631a6dcd18..d2a392fb93a67ae3ac9dbac7535e679f4e62ebd7 100644 (file)
@@ -1,3 +1,9 @@
+2006-09-17  Anton Blanchard  <anton@samba.org>
+           Alan Modra  <amodra@bigpond.net.au>
+
+       * dwarf2.c (concat_filename): Apply DW_AT_comp_dir if dir table
+       entry isn't absolute.
+
 2006-09-17  Mei Ligang  <ligang@sunnorth.com.cn>
 
        * cpu-score.c: New file.
index b05711435908ce5d2f1b2a79dcb35773c1191c59..059e90334d81708f347497f52bebf760881ece9e 100644 (file)
@@ -874,24 +874,45 @@ concat_filename (struct line_info_table *table, unsigned int file)
 
   filename = table->files[file - 1].name;
 
-  if (! IS_ABSOLUTE_PATH (filename))
+  if (!IS_ABSOLUTE_PATH (filename))
     {
-      char *dirname = (table->files[file - 1].dir
-                      ? table->dirs[table->files[file - 1].dir - 1]
-                      : table->comp_dir);
+      char *dirname = NULL;
+      char *subdirname = NULL;
+      char *name;
+      size_t len;
 
-      /* Not all tools set DW_AT_comp_dir, so dirname may be unknown.
-        The best we can do is return the filename part.  */
-      if (dirname != NULL)
+      if (table->files[file - 1].dir)
+       subdirname = table->dirs[table->files[file - 1].dir - 1];
+
+      if (!subdirname || !IS_ABSOLUTE_PATH (subdirname))
+       dirname = table->comp_dir;
+
+      if (!dirname)
        {
-         unsigned int len = strlen (dirname) + strlen (filename) + 2;
-         char * name;
+         dirname = subdirname;
+         subdirname = NULL;
+       }
 
+      if (!dirname)
+       return strdup (filename);
+
+      len = strlen (dirname) + strlen (filename) + 2;
+
+      if (subdirname)
+       {
+         len += strlen (subdirname) + 1;
+         name = bfd_malloc (len);
+         if (name)
+           sprintf (name, "%s/%s/%s", dirname, subdirname, filename);
+       }
+      else
+       {
          name = bfd_malloc (len);
          if (name)
            sprintf (name, "%s/%s", dirname, filename);
-         return name;
        }
+
+      return name;
     }
 
   return strdup (filename);