From 7421a730ce531322f49d24f0b0c39e72b668cf45 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Sun, 17 Sep 2006 02:44:38 +0000 Subject: [PATCH] * dwarf2.c (concat_filename): Apply DW_AT_comp_dir if dir table entry isn't absolute. --- bfd/ChangeLog | 6 ++++++ bfd/dwarf2.c | 41 +++++++++++++++++++++++++++++++---------- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 023b241e1c4..d2a392fb93a 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2006-09-17 Anton Blanchard + Alan Modra + + * dwarf2.c (concat_filename): Apply DW_AT_comp_dir if dir table + entry isn't absolute. + 2006-09-17 Mei Ligang * cpu-score.c: New file. diff --git a/bfd/dwarf2.c b/bfd/dwarf2.c index b0571143590..059e90334d8 100644 --- a/bfd/dwarf2.c +++ b/bfd/dwarf2.c @@ -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); -- 2.30.2