This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC] Don't lose compilation directory in Dwarf2 line-tables


Hi Jim,

Attached a patch implementing your suggestion. Some notes:
I first tried to put the concatenation of comp_dir and dirname at the
top of dwarf2_start_subfile (like suggested), but this caused failures
in the testsuite: changing dirname at the beginning of the function
changes the semantics of the loop that tries to match dirname'/'filename
against existing subfiles. The subfile for the current compilation unit
wasn't matched correctly (DW_AT_name = $srcdir/file.c, lineinfo.dirname
= $srcdir, lineinfo.filename = file.c  where $srcdir is a relative
path). Putting the dirname ``absolutification'' after the loop solves
it, but it looks a bit more hackish.

OK to commit?

All this file matching seems quite fragile, and the current approach
will get it wrong sometimes. Shouldn't the loop in dwarf2_start_subfile
be killed in favor of a search using both xfullpath(dirname'/'filename)
at the start of buildsym.c::start_subfile?
2006-04-18  Frederic Riss  <frederic.riss@st.com>

	* dwarf2read.c (dwarf2_start_subfile): Change prototype to accept
	compilation directory as last argument. Prepend the passed comp_dir 
	to dirname when necessary.
	(dwarf_decode_lines): Pass the compilation directory to 
	dwarf2_start_subfile.


--- dwarf2read.c.orig	2006-04-13 11:17:40.000000000 +0200
+++ dwarf2read.c	2006-04-18 13:53:13.000000000 +0200
@@ -846,7 +846,7 @@ static struct line_header *(dwarf_decode
 static void dwarf_decode_lines (struct line_header *, char *, bfd *,
 				struct dwarf2_cu *, struct partial_symtab *);
 
-static void dwarf2_start_subfile (char *, char *);
+static void dwarf2_start_subfile (char *, char *, char *);
 
 static struct symbol *new_symbol (struct die_info *, struct type *,
 				  struct dwarf2_cu *);
@@ -6529,13 +6529,12 @@ dwarf_decode_lines (struct line_header *
 	     directory and file name numbers in the statement program
 	     are 1-based.  */
           struct file_entry *fe = &lh->file_names[file - 1];
-          char *dir;
+          char *dir = NULL;
 
           if (fe->dir_index)
             dir = lh->include_dirs[fe->dir_index - 1];
-          else
-            dir = comp_dir;
-	  dwarf2_start_subfile (fe->name, dir);
+
+	  dwarf2_start_subfile (fe->name, dir, comp_dir);
 	}
 
       /* Decode the table.  */
@@ -6627,17 +6626,16 @@ dwarf_decode_lines (struct line_header *
                    0-based, but the directory and file name numbers in
                    the statement program are 1-based.  */
                 struct file_entry *fe;
-                char *dir;
+                char *dir = NULL;
 
                 file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read);
                 line_ptr += bytes_read;
                 fe = &lh->file_names[file - 1];
                 if (fe->dir_index)
                   dir = lh->include_dirs[fe->dir_index - 1];
-                else
-                  dir = comp_dir;
+
                 if (!decode_for_pst_p)
-                  dwarf2_start_subfile (fe->name, dir);
+                  dwarf2_start_subfile (fe->name, dir, comp_dir);
               }
 	      break;
 	    case DW_LNS_set_column:
@@ -6717,7 +6715,8 @@ dwarf_decode_lines (struct line_header *
 
 /* Start a subfile for DWARF.  FILENAME is the name of the file and
    DIRNAME the name of the source directory which contains FILENAME
-   or NULL if not known.
+   or NULL if not known.  COMP_DIR is the compilation directory for the
+   linetable's compilation unit or NULL if not known.
    This routine tries to keep line numbers from identical absolute and
    relative file names in a common subfile.
 
@@ -6736,7 +6735,7 @@ dwarf_decode_lines (struct line_header *
    subfile, so that `break /srcdir/list0.c:1' works as expected.  */
 
 static void
-dwarf2_start_subfile (char *filename, char *dirname)
+dwarf2_start_subfile (char *filename, char *dirname, char *comp_dir)
 {
   /* If the filename isn't absolute, try to match an existing subfile
      with the full pathname.  */
@@ -6757,6 +6756,19 @@ dwarf2_start_subfile (char *filename, ch
 	}
       xfree (fullname);
     }
+
+  /* Make the dirname as absolute as possible. */
+
+  if (dirname == NULL)
+    dirname = comp_dir;
+  else
+    if (!IS_ABSOLUTE_PATH (dirname) && comp_dir != NULL)
+      {
+	dirname = concat (comp_dir, SLASH_STRING, dirname, (char *)NULL);
+	/* do_cleanups is called after line info procesing */
+	make_cleanup (xfree, dirname);
+      }
+
   start_subfile (filename, dirname);
 }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]