Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Gary Benson <gbenson@redhat.com>
To: gdb-patches@sourceware.org
Cc: "Cédric Buissart" <cedric.buissart@gmail.com>
Subject: [PATCH 2/5] Pre-strip now-unnecessary trailing directory separators
Date: Tue, 16 Jun 2015 09:42:00 -0000	[thread overview]
Message-ID: <1434447768-17328-3-git-send-email-gbenson@redhat.com> (raw)
In-Reply-To: <1434447768-17328-1-git-send-email-gbenson@redhat.com>

Prior to the previous commit find_separate_debug_file required that
its DIR argument had a trailing directory separator.  This is no
longer necessary, and makes it difficult to check whether dir and
canon_dir are the same as canon_dir usually does not have a trailing
separator.  This commit updates find_separate_debug_file's caller to
not supply DIR with a trailing separator.  The next commit in the
series relies on this to avoid trying the same location twice.

gdb/ChangeLog:

	* gdb/symfile.c (find_separate_debug_file): Update comment.
	(terminate_after_last_dir_separator): Replaced with...
	(terminate_at_last_dir_separator): New function.
	(find_separate_debug_file_by_debuglink): Use the above.
---
 gdb/ChangeLog |    7 +++++++
 gdb/symfile.c |   19 ++++++++++---------
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/gdb/symfile.c b/gdb/symfile.c
index 799133a..77aaeed 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1523,7 +1523,6 @@ show_debug_file_directory (struct ui_file *file, int from_tty,
    where the original file resides (may not be the same as
    dirname(objfile->name) due to symlinks), and DEBUGLINK as the file we are
    looking for.  CANON_DIR is the "realpath" form of DIR.
-   DIR must contain a trailing '/'.
    Returns the path of the file with separate debug info, of NULL.  */
 
 static char *
@@ -1593,12 +1592,12 @@ find_separate_debug_file (const char *dir,
   return NULL;
 }
 
-/* Modify PATH to contain only "[/]directory/" part of PATH.
-   If there were no directory separators in PATH, PATH will be empty
+/* Terminate PATH at the final directory separator.  If PATH
+   contains no directory separators then PATH will be an empty
    string on return.  */
 
 static void
-terminate_after_last_dir_separator (char *path)
+terminate_at_last_dir_separator (char *path)
 {
   int i;
 
@@ -1606,10 +1605,12 @@ terminate_after_last_dir_separator (char *path)
      followed by a slash.  The directory can be relative or absolute.  */
   for (i = strlen(path) - 1; i >= 0; i--)
     if (IS_DIR_SEPARATOR (path[i]))
-      break;
+      {
+	path[i] = '\0';
+	return;
+      }
 
-  /* If I is -1 then no directory is present there and DIR will be "".  */
-  path[i + 1] = '\0';
+  path[0] = '\0';
 }
 
 /* Find separate debuginfo for OBJFILE (using .gnu_debuglink section).
@@ -1636,7 +1637,7 @@ find_separate_debug_file_by_debuglink (struct objfile *objfile)
   cleanups = make_cleanup (xfree, debuglink);
   dir = xstrdup (objfile_name (objfile));
   make_cleanup (xfree, dir);
-  terminate_after_last_dir_separator (dir);
+  terminate_at_last_dir_separator (dir);
   canon_dir = lrealpath (dir);
 
   debugfile = find_separate_debug_file (dir, canon_dir, debuglink,
@@ -1659,7 +1660,7 @@ find_separate_debug_file_by_debuglink (struct objfile *objfile)
 	  if (symlink_dir != NULL)
 	    {
 	      make_cleanup (xfree, symlink_dir);
-	      terminate_after_last_dir_separator (symlink_dir);
+	      terminate_at_last_dir_separator (symlink_dir);
 	      if (strcmp (dir, symlink_dir) != 0)
 		{
 		  /* Different directory, so try using it.  */
-- 
1.7.1


  parent reply	other threads:[~2015-06-16  9:42 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-16  9:42 [PATCH 0/5] Separate debugfile improvements Gary Benson
2015-06-16  9:42 ` [PATCH 1/5] Introduce build_debug_file_name Gary Benson
2015-06-16 14:47   ` Eli Zaretskii
2015-06-17  9:47     ` Gary Benson
2015-06-17 16:42       ` Eli Zaretskii
2015-06-18 10:55         ` Gary Benson
2015-06-18 12:11           ` Eli Zaretskii
2015-06-19  8:32             ` Gary Benson
2015-07-01 11:05   ` Pedro Alves
2015-07-02 11:18     ` Gary Benson
2015-07-02 11:38       ` Pedro Alves
2015-07-02 13:53         ` Gary Benson
2015-07-25 16:20   ` Jan Kratochvil
2015-06-16  9:42 ` [PATCH 3/5] Update how find_separate_debug_file handles CANON_DIR argument Gary Benson
2015-07-01 11:13   ` Pedro Alves
2015-06-16  9:42 ` Gary Benson [this message]
2015-07-01 13:45   ` [PATCH 2/5] Pre-strip now-unnecessary trailing directory separators Pedro Alves
2015-06-16  9:48 ` [PATCH 4/5] Add "target:" filename handling to find_separate_debug_file Gary Benson
2015-07-01 13:35   ` Pedro Alves
2015-07-23 14:33     ` Gary Benson
2015-07-24 10:28       ` Gary Benson
2015-07-24 11:54         ` Gary Benson
2015-07-25 18:15   ` Jan Kratochvil
2015-06-16  9:50 ` [PATCH 5/5] Also look for debug files in gdb_sysroot Gary Benson
2015-07-01 13:45   ` Pedro Alves
2015-06-23  8:44 ` [PING][PATCH 0/5] Separate debugfile improvements Gary Benson

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=1434447768-17328-3-git-send-email-gbenson@redhat.com \
    --to=gbenson@redhat.com \
    --cc=cedric.buissart@gmail.com \
    --cc=gdb-patches@sourceware.org \
    /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