This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: Re: [patch]change dwarf2_start_subfile() to adapt inappropriate dir name
- From: Nathan Froyd <froydnj at codesourcery dot com>
- To: Joel Brobecker <brobecker at adacore dot com>
- Cc: JuYoung Kim <j0 dot kim at samsung dot com>, Eli Zaretskii <eliz at gnu dot org>, "gdb-patches at sourceware dot org" <gdb-patches at sourceware dot org>
- Date: Mon, 15 Nov 2010 10:05:14 -0800
- Subject: Re: Re: [patch]change dwarf2_start_subfile() to adapt inappropriate dir name
- References: <13428716.22191289802305139.JavaMail.weblogic@epml17> <20101115165834.GA4434@adacore.com>
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);