From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24567 invoked by alias); 15 Nov 2010 18:05:24 -0000 Received: (qmail 24558 invoked by uid 22791); 15 Nov 2010 18:05:22 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 15 Nov 2010 18:05:16 +0000 Received: (qmail 26098 invoked from network); 15 Nov 2010 18:05:14 -0000 Received: from unknown (HELO localhost) (froydnj@127.0.0.2) by mail.codesourcery.com with ESMTPA; 15 Nov 2010 18:05:14 -0000 Date: Mon, 15 Nov 2010 18:05:00 -0000 From: Nathan Froyd To: Joel Brobecker Cc: JuYoung Kim , Eli Zaretskii , "gdb-patches@sourceware.org" Subject: Re: Re: [patch]change dwarf2_start_subfile() to adapt inappropriate dir name Message-ID: <20101115180513.GJ8544@codesourcery.com> References: <13428716.22191289802305139.JavaMail.weblogic@epml17> <20101115165834.GA4434@adacore.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20101115165834.GA4434@adacore.com> User-Agent: Mutt/1.5.17+20080114 (2008-01-14) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-11/txt/msg00178.txt.bz2 On Mon, Nov 15, 2010 at 08:58:34AM -0800, Joel Brobecker wrote: > [Would you like to be called "Kim", or "JuYoung"?] > > > I hope this code is proper to the standard, and no more to be fixed. > > Please, tell me what is the next step that I should do for applying to > > the real source code. > > For proper submission of patches to the GDB project, please take a look > at the file named gdb/CONTRIBUTE. For the patch, most of us prefer > unified diffs (use "diff -u" as opposed to "diff -c"). FWIW, we encountered this problem as well. This is the patch we used to fix it. It's very similar to the proposed patch, but slightly more complete. Tested with powerpc-linux-gnu. No regressions. -Nathan * dwarf2read.c (dwarf_maybe_concatenate): New function. (dwarf_decode_lines): Use it. (dwarf2_start_subfile): Likewise. Index: gdb/dwarf2read.c =================================================================== --- gdb/dwarf2read.c (revision 283114) +++ gdb/dwarf2read.c (revision 283115) @@ -8355,6 +8355,32 @@ check_cu_functions (CORE_ADDR address, s return fn->lowpc; } +/* Concatenate DIRNAME with FILENAME if FILENAME is not already + absolute. DIRNAME may be NULL; if so, FILENAME is returned. If the + return value is not equal to FILENAME, the caller is responsible for + free'ing it. */ + +static char * +dwarf_maybe_concatenate (char *dirname, char *filename) +{ + if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) + { + int dir_len = strlen (dirname); + char *concat_name; + + concat_name = concat (dirname, SLASH_STRING, filename, (char *) NULL); + + if (dirname[dir_len-1] == SLASH_STRING[0]) + memmove (concat_name+dir_len-1, concat_name+dir_len, + /* SLASH_STRING and trailing NULL */ + strlen (filename) + 1 + 1); + + return concat_name; + } + else + return filename; +} + /* Decode the Line Number Program (LNP) for the given line_header structure and CU. The actual information extracted and the type of structures created from the LNP depends on the value of PST. @@ -8633,25 +8659,22 @@ dwarf_decode_lines (struct line_header * { const struct file_entry fe = lh->file_names [file_index]; char *include_name = fe.name; + char *orig; char *dir_name = NULL; char *pst_filename = pst->filename; if (fe.dir_index) dir_name = lh->include_dirs[fe.dir_index - 1]; - if (!IS_ABSOLUTE_PATH (include_name) && dir_name != NULL) - { - include_name = concat (dir_name, SLASH_STRING, - include_name, (char *)NULL); - make_cleanup (xfree, include_name); - } - - if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) - { - pst_filename = concat (pst->dirname, SLASH_STRING, - pst_filename, (char *)NULL); - make_cleanup (xfree, pst_filename); - } + orig = include_name; + include_name = dwarf_maybe_concatenate (dir_name, include_name); + if (include_name != orig) + make_cleanup (xfree, include_name); + + orig = pst_filename; + pst_filename = dwarf_maybe_concatenate (pst->dirname, pst_filename); + if (pst_filename != orig) + make_cleanup (xfree, pst_filename); if (gdb_filename_cmp (include_name, pst_filename) != 0) dwarf2_create_include_psymtab (include_name, pst, objfile); @@ -8724,13 +8747,9 @@ dwarf2_start_subfile (char *filename, ch 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. */ + that represent full path names''. */ - if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) - fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); - else - fullname = filename; + fullname = dwarf_maybe_concatenate (dirname, filename); start_subfile (fullname, comp_dir);