From patchwork Tue Jun 16 09:42:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gary Benson X-Patchwork-Id: 7201 Received: (qmail 109697 invoked by alias); 16 Jun 2015 09:48:00 -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 109686 invoked by uid 89); 16 Jun 2015 09:48:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=no 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:47:59 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 279D1B1FB1; Tue, 16 Jun 2015 09:42:53 +0000 (UTC) Received: from blade.nx (ovpn-116-89.ams2.redhat.com [10.36.116.89]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t5G9gqev011113; Tue, 16 Jun 2015 05:42:52 -0400 Received: from blade.nx (localhost [127.0.0.1]) by blade.nx (Postfix) with ESMTP id C907C26301F; 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 4/5] Add "target:" filename handling to find_separate_debug_file Date: Tue, 16 Jun 2015 10:42:47 +0100 Message-Id: <1434447768-17328-5-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 This commit updates find_separate_debug_file to handle filenames prefixed with "target:". The same-directory and DEBUG_SUBDIRECTORY locations are checked with the prefix if supplied. The debugdir location is checked both with and without the prefix if one is supplied. This makes GDB able to fetch separate debug files from remote targets and from inferiors in containers. gdb/ChangeLog: * gdb/symfile.c (build_debug_file_name): New argument "prefix". (find_separate_debug_file): Separate TARGET_SYSROOT_PREFIX from dir. In debugdir loop, also try location prepended with dir's prefix if one was supplied. --- gdb/ChangeLog | 7 +++++++ gdb/symfile.c | 47 +++++++++++++++++++++++++++++++++++++---------- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/gdb/symfile.c b/gdb/symfile.c index bae144e..0cc940a 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1434,16 +1434,17 @@ separate_debug_file_exists (const char *name, unsigned long crc, /* Build the filename of a separate debug file from an arbitrary number of components. Returns an xmalloc'd string that must be be freed by the caller. The final argument of this function - must be NULL to mark the end the argument list. */ + must be NULL to mark the end the argument list. PREFIX will + be prepended to the result with no directory separator. */ static char * -build_debug_file_name (const char *first, ...) +build_debug_file_name (const char *prefix, const char *first, ...) { va_list ap; const char *arg, *last; VEC (char_ptr) *args = NULL; struct cleanup *back_to = make_cleanup_free_char_ptr_vec (args); - int bufsiz = 0; + int bufsiz = strlen (prefix); char *buf, *tmp; int i; @@ -1495,7 +1496,7 @@ build_debug_file_name (const char *first, ...) bufsiz += 1; /* Terminator. */ buf = xmalloc (bufsiz); - buf[0] = '\0'; + strcpy (buf, prefix); for (i = 0; VEC_iterate (char_ptr, args, i, tmp); i++) strcat (buf, tmp); gdb_assert (bufsiz == strlen (buf) + 1); @@ -1537,15 +1538,25 @@ find_separate_debug_file (const char *dir, struct cleanup *back_to; int ix; const char *altdir = NULL; + const char *no_prefix = ""; + const char *dir_prefix = no_prefix; + + /* Separate TARGET_SYSROOT_PREFIX from directory. */ + if (is_target_filename (dir)) + { + dir_prefix = TARGET_SYSROOT_PREFIX; + dir += strlen (dir_prefix); + } /* First try in the same directory as the original file. */ - debugfile = build_debug_file_name (dir, debuglink, NULL); + debugfile = build_debug_file_name (dir_prefix, dir, debuglink, NULL); if (separate_debug_file_exists (debugfile, crc32, objfile)) return debugfile; xfree (debugfile); /* Then try in the subdirectory named DEBUG_SUBDIRECTORY. */ - debugfile = build_debug_file_name (dir, DEBUG_SUBDIRECTORY, + debugfile = build_debug_file_name (dir_prefix, dir, + DEBUG_SUBDIRECTORY, debuglink, NULL); if (separate_debug_file_exists (debugfile, crc32, objfile)) return debugfile; @@ -1575,8 +1586,24 @@ find_separate_debug_file (const char *dir, for (ix = 0; VEC_iterate (char_ptr, debugdir_vec, ix, debugdir); ++ix) { - debugfile = build_debug_file_name (debugdir, dir, debuglink, - NULL); + /* First try with TARGET_SYSROOT_PREFIX if that's how DIR was + supplied. */ + if (dir_prefix != no_prefix) + { + debugfile = build_debug_file_name (dir_prefix, debugdir, dir, + debuglink, NULL); + if (separate_debug_file_exists (debugfile, crc32, objfile)) + { + do_cleanups (back_to); + return debugfile; + } + xfree (debugfile); + } + + /* Try the same location but without TARGET_SYSROOT_PREFIX + (i.e. on the local filesystem). */ + debugfile = build_debug_file_name (no_prefix, debugdir, dir, + debuglink, NULL); if (separate_debug_file_exists (debugfile, crc32, objfile)) { do_cleanups (back_to); @@ -1586,8 +1613,8 @@ find_separate_debug_file (const char *dir, if (altdir != NULL) { - debugfile = build_debug_file_name (debugdir, altdir, - debuglink, NULL); + debugfile = build_debug_file_name (no_prefix, debugdir, + altdir, debuglink, NULL); if (separate_debug_file_exists (debugfile, crc32, objfile)) { do_cleanups (back_to);