public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Nathan Froyd <froydnj@codesourcery.com>
To: Joel Brobecker <brobecker@adacore.com>
Cc: JuYoung Kim <j0.kim@samsung.com>, Eli Zaretskii <eliz@gnu.org>,
	"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: Re: Re: [patch]change dwarf2_start_subfile() to adapt	inappropriate dir name
Date: Mon, 15 Nov 2010 18:05:00 -0000	[thread overview]
Message-ID: <20101115180513.GJ8544@codesourcery.com> (raw)
In-Reply-To: <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);
 

  reply	other threads:[~2010-11-15 18:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-15  6:25 JuYoung Kim
2010-11-15 16:58 ` Joel Brobecker
2010-11-15 18:05   ` Nathan Froyd [this message]
2010-11-15 18:34     ` Eli Zaretskii
2010-11-23 20:47     ` Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20101115180513.GJ8544@codesourcery.com \
    --to=froydnj@codesourcery.com \
    --cc=brobecker@adacore.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=j0.kim@samsung.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).