From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11163 invoked by alias); 18 Apr 2006 14:00:57 -0000 Received: (qmail 11154 invoked by uid 22791); 18 Apr 2006 14:00:56 -0000 X-Spam-Check-By: sourceware.org Received: from fra-del-03.spheriq.net (HELO fra-del-03.spheriq.net) (195.46.51.99) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 18 Apr 2006 14:00:53 +0000 Received: from fra-out-03.spheriq.net (fra-out-03.spheriq.net [195.46.51.131]) by fra-del-03.spheriq.net with ESMTP id k3IDvrMi015089 for ; Tue, 18 Apr 2006 14:00:49 GMT Received: from fra-cus-01.spheriq.net (fra-cus-01.spheriq.net [195.46.51.37]) by fra-out-03.spheriq.net with ESMTP id k3IDpjjS010249 for ; Tue, 18 Apr 2006 13:51:46 GMT Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by fra-cus-01.spheriq.net with ESMTP id k3IDpf50012104 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=OK); Tue, 18 Apr 2006 13:51:44 GMT Received: from zeta.dmz-eu.st.com (ns2.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 22473DA45; Tue, 18 Apr 2006 13:51:41 +0000 (GMT) Received: from mail1.cro.st.com (mail1.cro.st.com [164.129.40.131]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id D160747AEE; Tue, 18 Apr 2006 13:51:40 +0000 (GMT) Received: from crx549.cro.st.com (crx549.cro.st.com [164.129.44.49]) by mail1.cro.st.com (MOS 3.5.8-GR) with ESMTP id CHF29191 (AUTH "frederic riss"); Tue, 18 Apr 2006 15:51:40 +0200 (CEST) Subject: Re: [RFC] Don't lose compilation directory in Dwarf2 line-tables From: Frederic RISS To: Daniel Jacobowitz Cc: Jim Blandy , GDB Patches In-Reply-To: <20060418130432.GC10130@nevyn.them.org> References: <1144927446.14807.561.camel@crx549.cro.st.com> <8f2776cb0604131049i69e9b20fv78e60c023f245e56@mail.gmail.com> <1144999942.14807.721.camel@crx549.cro.st.com> <8f2776cb0604140041o63c56c2xa9113d3c4ee259d@mail.gmail.com> <1145002976.14807.744.camel@crx549.cro.st.com> <20060414140449.GA14270@nevyn.them.org> <1145026289.14807.816.camel@crx549.cro.st.com> <1145363529.14807.848.camel@crx549.cro.st.com> <20060418130432.GC10130@nevyn.them.org> Content-Type: multipart/mixed; boundary="=-TK9XDsX7CgnVJV2eXw0v" Date: Tue, 18 Apr 2006 14:00:00 -0000 Message-Id: <1145368299.14807.889.camel@crx549.cro.st.com> Mime-Version: 1.0 X-Mailer: Evolution 2.6.0 X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2006-04/txt/msg00240.txt.bz2 --=-TK9XDsX7CgnVJV2eXw0v Content-Type: text/plain Content-Transfer-Encoding: 7bit Content-length: 1484 On Tue, 2006-04-18 at 09:04 -0400, Daniel Jacobowitz wrote: > On Tue, Apr 18, 2006 at 02:32:09PM +0200, Frederic RISS wrote: > > 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? > > The problem with using xfullpath is that it requires the file to exist I realized that after having sent the patch. > and already be found; as long as we are consistent, it's not too > fragile, because we're checking against our own output. I just made that comment because of the testsuite breakage that ensued from modifying dirname before the loop... which seemed to imply that the mechanism was fragile. > > + > > + 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); > > Comment formatting again (and "processing"). But this is really nasty. > Why not free it before we return? We don't return dirname, and > start_subfile takes a copy. I kind of copied it from the end of decode_dwarf_lines where make_cleanups are used for the same kind of things. Thanks for your review, I'm attaching an updated patch. Fred. --=-TK9XDsX7CgnVJV2eXw0v Content-Disposition: attachment; filename=dwarf2-keep-compdir.patch Content-Type: text/x-patch; name=dwarf2-keep-compdir.patch; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-length: 3558 2006-04-18 Frederic Riss * 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 15:34:47.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,8 +6735,10 @@ 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) { + char *dir = dirname; + /* If the filename isn't absolute, try to match an existing subfile with the full pathname. */ @@ -6757,7 +6758,18 @@ dwarf2_start_subfile (char *filename, ch } xfree (fullname); } - start_subfile (filename, dirname); + + /* Make the dirname as absolute as possible. */ + + if (dirname == NULL) + dir = comp_dir; + else if (!IS_ABSOLUTE_PATH (dirname) && comp_dir != NULL) + dir = concat (comp_dir, SLASH_STRING, dirname, (char *)NULL); + + start_subfile (filename, dir); + + if (dirname != NULL && dir != dirname) + xfree(dir); } static void --=-TK9XDsX7CgnVJV2eXw0v--