aboutsummaryrefslogtreecommitdiff
path: root/gdb/dwarf2read.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/dwarf2read.c')
-rw-r--r--gdb/dwarf2read.c61
1 files changed, 40 insertions, 21 deletions
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 4b0b6bd..e7a423f 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -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);
}
}