From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25167 invoked by alias); 21 Apr 2006 08:35:10 -0000 Received: (qmail 25157 invoked by uid 22791); 21 Apr 2006 08:35:09 -0000 X-Spam-Check-By: sourceware.org Received: from fra-del-02.spheriq.net (HELO fra-del-02.spheriq.net) (195.46.51.98) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 21 Apr 2006 08:35:06 +0000 Received: from fra-out-01.spheriq.net (fra-out-01.spheriq.net [195.46.51.129]) by fra-del-02.spheriq.net with ESMTP id k3L8Yhgc003686 for ; Fri, 21 Apr 2006 08:34:48 GMT Received: from fra-cus-02.spheriq.net (fra-cus-02.spheriq.net [195.46.51.38]) by fra-out-01.spheriq.net with ESMTP id k3L8YgOn027076 for ; Fri, 21 Apr 2006 08:34:43 GMT Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by fra-cus-02.spheriq.net with ESMTP id k3L8Ye1U023295 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=OK); Fri, 21 Apr 2006 08:34:41 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 5461EDA44; Fri, 21 Apr 2006 08:34:40 +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 10572488F0; Fri, 21 Apr 2006 08:34: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 CHF94464 (AUTH "frederic riss"); Fri, 21 Apr 2006 10:34:38 +0200 (CEST) Subject: Re: [RFC] Don't lose compilation directory in Dwarf2 line-tables From: Frederic RISS To: Jim Blandy Cc: Daniel Jacobowitz , GDB Patches In-Reply-To: <8f2776cb0604201809l68067aey47fa372a2468c8ea@mail.gmail.com> 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> <1145368299.14807.889.camel@crx549.cro.st.com> <8f2776cb0604201809l68067aey47fa372a2468c8ea@mail.gmail.com> Content-Type: multipart/mixed; boundary="=-IgGtUIxc6OMy712d93DU" Date: Fri, 21 Apr 2006 08:35:00 -0000 Message-Id: <1145608477.14807.1018.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/msg00311.txt.bz2 --=-IgGtUIxc6OMy712d93DU Content-Type: text/plain Content-Transfer-Encoding: 7bit Content-length: 1257 On Thu, 2006-04-20 at 18:09 -0700, Jim Blandy wrote: > So, Frederic, your last patch doesn't introduce any new problems that > I can see, and it does solve the problem you set out to solve > originally (losing comp_dir), but if you're willing go around one more > time, we can try to add the info consistently: OK, here we go. > - Leave the comparison loop alone, as in your last patch. > - If dwarf2_start_subfile does have to start a subfile itself, always > pass comp_dir as start_subfile's second argument, whether it's NULL or > not (because this is what we do when calling start_symtab), and > concatenate dirname, if it's non-null, with filename to get > start_subfile's first argument. I think this means that 'fullname' > always gets used, so you can hoist that computation and its xfree out > of the 'if'. But then, the loop in dwarf2_start_subfile doesn't serve any purpose, because the loop at the beginning of start_subfile proper will do the same work. Or maybe I'm missing something? > Either way, this definitely needs a comment. If you'd like to write > up one yourself, great; if not, that's fine; I'll put one in after > your patch goes in. Attached is a new patch that adds comments and removes the superfluous loop. How's that? --=-IgGtUIxc6OMy712d93DU 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: 4620 2006-04-21 Frederic Riss * dwarf2read.c (dwarf2_start_subfile): Change prototype to accept compilation directory as last argument. Always pass comp_dir as second argument to start_subfile and prepend dirname to the filename when necessary. Remove now superfluous search for pre-existing subfile. (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-21 10:02:08.000000000 +0200 @@ -846,7 +846,7 @@ 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 @@ 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 @@ 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 @@ /* 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. @@ -6733,31 +6732,35 @@ files.files[1].dir: /srcdir The line number information for list0.c has to end up in a single - subfile, so that `break /srcdir/list0.c:1' works as expected. */ - -static void -dwarf2_start_subfile (char *filename, char *dirname) -{ - /* If the filename isn't absolute, try to match an existing subfile - with the full pathname. */ + subfile, so that `break /srcdir/list0.c:1' works as expected. + start_subfile will ensure that this happens provided that we pass the + concatenation of files.files[1].dir and files.files[1].name as the + subfile's name. */ + +static void +dwarf2_start_subfile (char *filename, char *dirname, char *comp_dir) +{ + char *fullname; + + /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). + `start_symtab' will always pass the contents of DW_AT_comp_dir as + second argument to start_subfile. To be consistent, we do the + same here. In order not to lose the line information directory, + we concatenate it to the filename when it makes sense. + Note that the Dwarf3 standard says (speaking of filenames in line + information): ``The directory index is ignored for file names + that represent full path names''. Thus ignoring dirname in the + `else' branch below isn't an issue. */ if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) - { - struct subfile *subfile; - char *fullname = concat (dirname, "/", filename, (char *)NULL); + fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); + else + fullname = filename; - for (subfile = subfiles; subfile; subfile = subfile->next) - { - if (FILENAME_CMP (subfile->name, fullname) == 0) - { - current_subfile = subfile; - xfree (fullname); - return; - } - } - xfree (fullname); - } - start_subfile (filename, dirname); + start_subfile (fullname, comp_dir); + + if (fullname != filename) + xfree (fullname); } static void --=-IgGtUIxc6OMy712d93DU--