From patchwork Mon Jan 28 20:47:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Baldwin X-Patchwork-Id: 31232 Received: (qmail 6295 invoked by alias); 28 Jan 2019 20:47:18 -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 6244 invoked by uid 89); 28 Jan 2019 20:47:18 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS, SPF_SOFTFAIL autolearn=ham version=3.3.2 spammy=HContent-Transfer-Encoding:8bit X-HELO: mail.baldwin.cx Received: from bigwig.baldwin.cx (HELO mail.baldwin.cx) (96.47.65.170) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 28 Jan 2019 20:47:16 +0000 Received: from ralph.baldwin.cx (ralph.baldwin.cx [66.234.199.215]) by mail.baldwin.cx (Postfix) with ESMTPSA id CC52610B68A for ; Mon, 28 Jan 2019 15:47:14 -0500 (EST) From: John Baldwin To: gdb-patches@sourceware.org Subject: [PATCH v2 3/4] Use child_path to determine if an object file is under a sysroot. Date: Mon, 28 Jan 2019 12:47:04 -0800 Message-Id: <5d84ed6197e95adfe4be5c547c2e0b5dddb0d26e.1548707934.git.jhb@FreeBSD.org> In-Reply-To: References: MIME-Version: 1.0 X-IsSubscribed: yes This fixes the case where the sysroot happens to end in a trailing '/'. Note that the path returned from child_path always skips over the directory separator at the start of the base path, so a separator must always be explicitly added before the base path. gdb/ChangeLog: * symfile.c (find_separate_debug_file): Use child_path to determine if an object file is under a sysroot. --- gdb/ChangeLog | 5 +++++ gdb/symfile.c | 12 +++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 93a2cebe1c..e65182d84d 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2019-01-28 John Baldwin + + * symfile.c (find_separate_debug_file): Use child_path to + determine if an object file is under a sysroot. + 2019-01-28 John Baldwin * Makefile.in (SUBDIR_UNITTESTS_SRCS): Add diff --git a/gdb/symfile.c b/gdb/symfile.c index b5802e20ad..ffcba1a090 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -57,6 +57,7 @@ #include "gdb_bfd.h" #include "cli/cli-utils.h" #include "common/byte-vector.h" +#include "common/pathstuff.h" #include "common/selftest.h" #include "cli/cli-style.h" #include "common/forward-scope-exit.h" @@ -1452,16 +1453,16 @@ find_separate_debug_file (const char *dir, if (separate_debug_file_exists (debugfile, crc32, objfile)) return debugfile; + const char *base_path; if (canon_dir != NULL - && filename_ncmp (canon_dir, gdb_sysroot, - strlen (gdb_sysroot)) == 0 - && IS_DIR_SEPARATOR (canon_dir[strlen (gdb_sysroot)])) + && (base_path = child_path (gdb_sysroot, canon_dir)) != NULL) { /* If the file is in the sysroot, try using its base path in the global debugfile directory. */ debugfile = target_prefix ? "target:" : ""; debugfile += debugdir.get (); - debugfile += (canon_dir + strlen (gdb_sysroot)); + debugfile += "/"; + debugfile += base_path; debugfile += "/"; debugfile += debuglink; @@ -1473,7 +1474,8 @@ find_separate_debug_file (const char *dir, debugfile = target_prefix ? "target:" : ""; debugfile += gdb_sysroot; debugfile += debugdir.get (); - debugfile += (canon_dir + strlen (gdb_sysroot)); + debugfile += "/"; + debugfile += base_path; debugfile += "/"; debugfile += debuglink;