From patchwork Tue Jun 16 09:42:45 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Benson X-Patchwork-Id: 7198 Received: (qmail 89359 invoked by alias); 16 Jun 2015 09:42:55 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 89341 invoked by uid 89); 16 Jun 2015 09:42:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 16 Jun 2015 09:42:53 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id A42EB2B64AE; Tue, 16 Jun 2015 09:42:52 +0000 (UTC) Received: from blade.nx (ovpn-116-89.ams2.redhat.com [10.36.116.89]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t5G9gqp3017642; Tue, 16 Jun 2015 05:42:52 -0400 Received: from blade.nx (localhost [127.0.0.1]) by blade.nx (Postfix) with ESMTP id 9814B263000; Tue, 16 Jun 2015 10:42:51 +0100 (BST) From: Gary Benson To: gdb-patches@sourceware.org Cc: =?UTF-8?q?C=C3=A9dric=20Buissart?= Subject: [PATCH 2/5] Pre-strip now-unnecessary trailing directory separators Date: Tue, 16 Jun 2015 10:42:45 +0100 Message-Id: <1434447768-17328-3-git-send-email-gbenson@redhat.com> In-Reply-To: <1434447768-17328-1-git-send-email-gbenson@redhat.com> References: <1434447768-17328-1-git-send-email-gbenson@redhat.com> X-IsSubscribed: yes 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. */