2005-11-03 Jim Blandy <jimb@redhat.com>
authorElena Zannoni <ezannoni@kwikemart.cygnus.com>
Fri, 4 Nov 2005 02:46:45 +0000 (02:46 +0000)
committerElena Zannoni <ezannoni@kwikemart.cygnus.com>
Fri, 4 Nov 2005 02:46:45 +0000 (02:46 +0000)
        Checked in by Elena Zannoni  <ezannoni@redhat.com>

       * dwarf2read.c (file_full_name): Cope with file numbers that are
       out of range for the given line header.

gdb/ChangeLog
gdb/dwarf2read.c

index 6677156..12a67ff 100644 (file)
@@ -1,3 +1,10 @@
+2005-11-03  Jim Blandy  <jimb@redhat.com>
+
+        Checked in by Elena Zannoni  <ezannoni@redhat.com>     
+
+       * dwarf2read.c (file_full_name): Cope with file numbers that are
+       out of range for the given line header.
+
 2005-11-03  Daniel Jacobowitz  <dan@codesourcery.com>
 
         Checked in by Elena Zannoni  <ezannoni@redhat.com>
index 4b0b6bd..e7a423f 100644 (file)
@@ -8795,32 +8795,51 @@ dwarf_alloc_die (void)
 static char *
 file_full_name (int file, struct line_header *lh, const char *comp_dir)
 {
-  struct file_entry *fe = &lh->file_names[file - 1];
+  /* Is the file number a valid index into the line header's file name
+     table?  Remember that file numbers start with one, not zero.  */
+  if (1 <= file && file <= lh->num_file_names)
+    {
+      struct file_entry *fe = &lh->file_names[file - 1];
   
-  if (IS_ABSOLUTE_PATH (fe->name))
-    return xstrdup (fe->name);
+      if (IS_ABSOLUTE_PATH (fe->name))
+        return xstrdup (fe->name);
+      else
+        {
+          const char *dir;
+          int dir_len;
+          char *full_name;
+
+          if (fe->dir_index)
+            dir = lh->include_dirs[fe->dir_index - 1];
+          else
+            dir = comp_dir;
+
+          if (dir)
+            {
+              dir_len = strlen (dir);
+              full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
+              strcpy (full_name, dir);
+              full_name[dir_len] = '/';
+              strcpy (full_name + dir_len + 1, fe->name);
+              return full_name;
+            }
+          else
+            return xstrdup (fe->name);
+        }
+    }
   else
     {
-      const char *dir;
-      int dir_len;
-      char *full_name;
+      /* The compiler produced a bogus file number.  We can at least
+         record the macro definitions made in the file, even if we
+         won't be able to find the file by name.  */
+      char fake_name[80];
+      sprintf (fake_name, "<bad macro file number %d>", file);
 
-      if (fe->dir_index)
-        dir = lh->include_dirs[fe->dir_index - 1];
-      else
-        dir = comp_dir;
+      complaint (&symfile_complaints, 
+                 _("bad file number in macro information (%d)"),
+                 file);
 
-      if (dir)
-        {
-          dir_len = strlen (dir);
-          full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1);
-          strcpy (full_name, dir);
-          full_name[dir_len] = '/';
-          strcpy (full_name + dir_len + 1, fe->name);
-          return full_name;
-        }
-      else
-        return xstrdup (fe->name);
+      return xstrdup (fake_name);
     }
 }