From patchwork Fri Aug 21 21:23:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kratochvil X-Patchwork-Id: 8371 Received: (qmail 117145 invoked by alias); 21 Aug 2015 21:23:22 -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 117102 invoked by uid 89); 21 Aug 2015 21:23:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_40, 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; Fri, 21 Aug 2015 21:23:17 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id F070D60 for ; Fri, 21 Aug 2015 21:23:15 +0000 (UTC) Received: from host1.jankratochvil.net (ovpn-116-22.ams2.redhat.com [10.36.116.22]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t7LLNEoQ016752 for ; Fri, 21 Aug 2015 17:23:15 -0400 Subject: [PATCH v12 23/32] build_id_to_bfd: Make it return file_location From: Jan Kratochvil To: gdb-patches@sourceware.org Date: Fri, 21 Aug 2015 23:23:14 +0200 Message-ID: <20150821212314.6673.5641.stgit@host1.jankratochvil.net> In-Reply-To: <20150821212006.6673.35100.stgit@host1.jankratochvil.net> References: <20150821212006.6673.35100.stgit@host1.jankratochvil.net> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-IsSubscribed: yes Hi, refactor build_id_to_bfd so that it returns file_location. Jan gdb/ChangeLog 2015-08-20 Jan Kratochvil * build-id.c: Include source.h. (build_id_to_bfd): Rename to ... (build_id_to_file): ... here, return file_location, add parameter opts, make it public. (build_id_to_debug_bfd): Use build_id_to_file. * build-id.h (build_id_to_file): New prototype. --- 0 files changed diff --git a/gdb/build-id.c b/gdb/build-id.c index 8b45fec..25ee606 100644 --- a/gdb/build-id.c +++ b/gdb/build-id.c @@ -27,6 +27,7 @@ #include "filenames.h" #include "gdbcore.h" #include "gdbcmd.h" +#include "source.h" /* Boolean for command 'set validate-build-id'. */ int validate_build_id = 1; @@ -84,15 +85,15 @@ build_id_verify (bfd *abfd, size_t check_len, const bfd_byte *check) return NULL. Use "" or ".debug" for SUFFIX. The returned reference to the BFD must be released by the caller. */ -static bfd * -build_id_to_bfd (size_t build_id_len, const bfd_byte *build_id, - const char *suffix) +struct file_location +build_id_to_file (size_t build_id_len, const bfd_byte *build_id, + const char *suffix, enum openp_flags opts) { char *link, *debugdir; VEC (char_ptr) *debugdir_vec; struct cleanup *back_to; int ix; - bfd *abfd = NULL; + struct file_location result; /* DEBUG_FILE_DIRECTORY/.build-id/ab/cdef */ link = alloca (strlen (debug_file_directory) + (sizeof "/.build-id/" - 1) + 1 @@ -110,8 +111,6 @@ build_id_to_bfd (size_t build_id_len, const bfd_byte *build_id, const gdb_byte *data = build_id; size_t size = build_id_len; char *s; - char *filename = NULL; - struct cleanup *inner; memcpy (link, debugdir, debugdir_len); s = &link[debugdir_len]; @@ -127,30 +126,18 @@ build_id_to_bfd (size_t build_id_len, const bfd_byte *build_id, s += sprintf (s, "%02x", (unsigned) *data++); strcpy (s, suffix); - /* lrealpath() is expensive even for the usually non-existent files. */ - if (access (link, F_OK) == 0) - filename = lrealpath (link); - - if (filename == NULL) - continue; - - /* We expect to be silent on the non-existing files. */ - inner = make_cleanup (xfree, filename); - abfd = gdb_bfd_open (filename, gnutarget, -1); - do_cleanups (inner); - - if (abfd == NULL) - continue; - - if (build_id_verify (abfd, build_id_len, build_id)) - break; - - gdb_bfd_unref (abfd); - abfd = NULL; + result = file_location_from_filename (link, opts | OPF_BFD_CANONICAL, + build_id_len, build_id); + if (file_location_is_valid (&result)) + { + do_cleanups (back_to); + return result; + } + file_location_free (&result); } - do_cleanups (back_to); - return abfd; + file_location_enoent (&result); + return result; } /* See build-id.h. */ @@ -158,7 +145,19 @@ build_id_to_bfd (size_t build_id_len, const bfd_byte *build_id, bfd * build_id_to_debug_bfd (size_t build_id_len, const bfd_byte *build_id) { - return build_id_to_bfd (build_id_len, build_id, ".debug"); + struct file_location result; + bfd *retval; + + result = build_id_to_file (build_id_len, build_id, ".debug", OPF_IS_BFD); + if (result.abfd == NULL) + { + file_location_free (&result); + return NULL; + } + gdb_bfd_ref (result.abfd); + retval = result.abfd; + file_location_free (&result); + return retval; } /* See build-id.h. */ diff --git a/gdb/build-id.h b/gdb/build-id.h index 63b9d8d..bb93df2 100644 --- a/gdb/build-id.h +++ b/gdb/build-id.h @@ -30,6 +30,9 @@ extern const struct bfd_build_id *build_id_bfd_get (bfd *abfd); extern int build_id_verify (bfd *abfd, size_t check_len, const bfd_byte *check); +extern struct file_location + build_id_to_file (size_t build_id_len, const bfd_byte *build_id, + const char *suffix, enum openp_flags opts); /* Find and open a BFD given a build-id. If no BFD can be found, return NULL. The returned reference to the BFD must be released by