This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[PATCH 2/5] Pre-strip now-unnecessary trailing directory separators
- From: Gary Benson <gbenson at redhat dot com>
- To: gdb-patches at sourceware dot org
- Cc: CÃdric Buissart <cedric dot buissart at gmail dot com>
- Date: Tue, 16 Jun 2015 10:42:45 +0100
- Subject: [PATCH 2/5] Pre-strip now-unnecessary trailing directory separators
- Authentication-results: sourceware.org; auth=none
- References: <1434447768-17328-1-git-send-email-gbenson at redhat dot 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