From: Elena Zannoni Date: Fri, 4 Nov 2005 02:46:45 +0000 (+0000) Subject: 2005-11-03 Jim Blandy X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6a83a1e604d82e43cee0af4cd2957ca290083571;p=binutils-gdb.git 2005-11-03 Jim Blandy Checked in by Elena Zannoni * dwarf2read.c (file_full_name): Cope with file numbers that are out of range for the given line header. --- diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 6677156c330..12a67ff4c09 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2005-11-03 Jim Blandy + + Checked in by Elena Zannoni + + * dwarf2read.c (file_full_name): Cope with file numbers that are + out of range for the given line header. + 2005-11-03 Daniel Jacobowitz Checked in by Elena Zannoni diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 4b0b6bd8460..e7a423f0da1 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, "", 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); } }