Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v12 23/32] build_id_to_bfd: Make it return file_location
Date: Fri, 21 Aug 2015 21:23:00 -0000	[thread overview]
Message-ID: <20150821212314.6673.5641.stgit@host1.jankratochvil.net> (raw)
In-Reply-To: <20150821212006.6673.35100.stgit@host1.jankratochvil.net>

Hi,

refactor build_id_to_bfd so that it returns file_location.


Jan


gdb/ChangeLog
2015-08-20  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* 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


  parent reply	other threads:[~2015-08-21 21:23 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-21 21:20 [PATCH v12 00/32] Validate binary before use Jan Kratochvil
2015-08-21 21:20 ` [PATCH v12 04/32] Move linux_find_memory_regions_full & co Jan Kratochvil
2015-08-21 21:20 ` [PATCH v12 05/32] gdbserver build-id attribute generator Jan Kratochvil
2015-08-22  7:17   ` Eli Zaretskii
2015-08-21 21:20 ` [PATCH v12 01/32] Create empty common/linux-maps.[ch] and common/target-utils.[ch] Jan Kratochvil
2015-08-21 21:20 ` [PATCH v12 03/32] Prepare linux_find_memory_regions_full & co. for move Jan Kratochvil
2015-08-21 21:20 ` [PATCH v12 02/32] Move gdb_regex* to common/ Jan Kratochvil
2015-08-21 21:21 ` [PATCH v12 12/32] Code cleanup: Remove openp parameter mode Jan Kratochvil
2015-08-21 21:21 ` [PATCH v12 06/32] Validate symbol file using build-id Jan Kratochvil
2015-08-22  7:23   ` Eli Zaretskii
2015-08-22 19:19     ` Jan Kratochvil
2015-08-21 21:21 ` [PATCH v12 10/32] Code cleanup: Add enum for openp_flags Jan Kratochvil
2015-08-21 21:21 ` [PATCH v12 08/32] Permit multiple sysroot directories Jan Kratochvil
2015-08-22  7:31   ` Eli Zaretskii
2015-08-22 19:24     ` Jan Kratochvil
2015-08-21 21:21 ` [PATCH v12 11/32] Code cleanup: Remove OPF_RETURN_REALPATH Jan Kratochvil
2015-08-21 21:21 ` [PATCH v12 07/32] Code cleanup: Make solib_find_1 variable const Jan Kratochvil
2015-08-21 21:22 ` [PATCH v12 18/32] Refactor openp() to return file_location Jan Kratochvil
2015-08-25 19:07   ` [PATCH v13 " Jan Kratochvil
2015-08-21 21:22 ` [PATCH v12 15/32] gdb_bfd_open_from_target: Support real fd Jan Kratochvil
2015-08-21 21:22 ` [PATCH v12 13/32] Code cleanup: openp parameter filename_opened is never NULL Jan Kratochvil
2015-08-21 21:22 ` [PATCH v12 19/32] solib_find: Make it use file_location Jan Kratochvil
2015-08-21 21:22 ` [PATCH v12 20/32] symfile_bfd_open: Make it use openp_bfd() Jan Kratochvil
2015-08-21 21:22 ` [PATCH v12 14/32] Provide new gdb_bfd_open_from_target Jan Kratochvil
2015-08-21 21:22 ` [PATCH v12 17/32] Add file_location utility functions Jan Kratochvil
2015-08-21 21:22 ` [PATCH v12 09/32] Change sysroot to ":target:" Jan Kratochvil
2015-08-21 21:22 ` [PATCH v12 16/32] gdb_bfd_open_from_target: Optionally do not close fd Jan Kratochvil
2015-08-21 21:23 ` [PATCH v12 26/32] solib_bfd_open: Optimize opening twice Jan Kratochvil
2015-08-21 21:23 ` [PATCH v12 27/32] build_id_verify: Make it more verbose Jan Kratochvil
2015-08-21 21:23 ` [PATCH v12 24/32] solib_find: Search also by build-id Jan Kratochvil
2015-08-21 21:23 ` [PATCH v12 22/32] Add dummy build-id params to prototypes Jan Kratochvil
2015-08-21 21:23 ` Jan Kratochvil [this message]
2015-08-21 21:23 ` [PATCH v12 21/32] build_id_to_debug_bfd: Make it also non-.debug capable Jan Kratochvil
2015-08-21 21:23 ` [PATCH v12 25/32] Verify the build-id Jan Kratochvil
2015-08-21 21:24 ` [PATCH v12 29/32] testcase: Test also locating shlibs by build-id Jan Kratochvil
2015-08-21 21:24 ` [PATCH v12 28/32] Tests for validate symbol file using build-id Jan Kratochvil
2015-08-21 21:24 ` [PATCH v12 31/32] Make only user-specified executable and symbol filenames sticky Jan Kratochvil
2015-08-21 21:24 ` [PATCH v12 30/32] Code cleanup: New hex2bin_allocate() Jan Kratochvil
2015-08-21 21:24 ` [PATCH v12 32/32] Support build-id for main executables Jan Kratochvil
2015-09-02  3:57 ` [PATCH v12 00/32] Validate binary before use Doug Evans
2015-09-02  7:41   ` Jan Kratochvil
2015-09-02 14:58     ` Doug Evans
2015-09-02 15:14       ` Jan Kratochvil
2015-09-02 15:22         ` Doug Evans
2015-09-02 19:12           ` Jan Kratochvil
2015-09-15  1:37             ` Doug Evans

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150821212314.6673.5641.stgit@host1.jankratochvil.net \
    --to=jan.kratochvil@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox