public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
From: jkratoch@sourceware.org
To: archer-commits@sourceware.org
Subject: [SCM]  jankratochvil/gdbserverbuildid2: buildid
Date: Wed, 29 Jul 2015 20:55:00 -0000	[thread overview]
Message-ID: <20150729205511.28973.qmail@sourceware.org> (raw)

The branch, jankratochvil/gdbserverbuildid2 has been updated
  discards  51282bfd4e5ef67dc87a025955cb75891ae3d638 (commit)
  discards  5c924531a91c3f3de15c78fd9391c227ada306bc (commit)
  discards  b71f23819e18a21e20dc683ed9b0f41eab41b242 (commit)
       via  c15b4dc5da134d1fc80131d025459adab9edb071 (commit)
       via  9673d0d64e72e2dbc7455d3700bf3793c8bf104c (commit)
       via  0d4cc1d76b5a4c7f472a998a71f50f87f8371955 (commit)
       via  62757e6e09df9aaa5a6b5c5681e71ce1ebd67a91 (commit)
       via  12d35640805beb504883f5e811a773c2a458fb68 (commit)
       via  9cb0c0a45bbf0797a69b9e4ea1b1c4059a7af9ec (commit)
       via  b6bfeca5e45c1a91923f89195e95adb41e672acf (commit)
      from  51282bfd4e5ef67dc87a025955cb75891ae3d638 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit c15b4dc5da134d1fc80131d025459adab9edb071
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date:   Tue Jul 28 22:13:31 2015 +0200

    buildid

commit 9673d0d64e72e2dbc7455d3700bf3793c8bf104c
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date:   Tue Jul 28 22:12:52 2015 +0200

    buildidproto

commit 0d4cc1d76b5a4c7f472a998a71f50f87f8371955
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date:   Wed Jul 29 21:38:45 2015 +0200

    buildidtobfd

commit 62757e6e09df9aaa5a6b5c5681e71ce1ebd67a91
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date:   Wed Jul 29 19:52:47 2015 +0200

    buildidforcemove

commit 12d35640805beb504883f5e811a773c2a458fb68
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date:   Sat Jul 25 23:11:36 2015 +0200

    openp

commit 9cb0c0a45bbf0797a69b9e4ea1b1c4059a7af9ec
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date:   Wed Jul 29 22:49:17 2015 +0200

    filelib

commit b6bfeca5e45c1a91923f89195e95adb41e672acf
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date:   Wed Jul 29 22:47:55 2015 +0200

    targetfd

-----------------------------------------------------------------------

Summary of changes:
 gdb/build-id.c |   97 ++++++++++++++++++++++++++++++++++++++---------------
 gdb/build-id.h |    3 ++
 gdb/solib.c    |  101 ++++++++++++++++++++++++++++++++------------------------
 gdb/source.c   |   30 ++++-------------
 gdb/source.h   |    5 +--
 5 files changed, 140 insertions(+), 96 deletions(-)

First 500 lines of diff:
diff --git a/gdb/build-id.c b/gdb/build-id.c
index c89cd55..636d5c3 100644
--- a/gdb/build-id.c
+++ b/gdb/build-id.c
@@ -26,6 +26,22 @@
 #include "objfiles.h"
 #include "filenames.h"
 #include "gdbcore.h"
+#include "gdbcmd.h"
+#include "source.h"
+
+/* Boolean for command 'set validate-build-id'.  */
+int validate_build_id = 1;
+
+/* Implement 'show validate-build-id'.  */
+
+static void
+show_validate_build_id (struct ui_file *file, int from_tty,
+			struct cmd_list_element *c, const char *value)
+{
+  fprintf_filtered (file, _("Validation a build-id matches to load a shared "
+			    "library is %s.\n"),
+		    value);
+}
 
 /* See build-id.h.  */
 
@@ -65,20 +81,23 @@ build_id_verify (bfd *abfd, size_t check_len, const bfd_byte *check)
   return retval;
 }
 
-/* See build-id.h.  */
+/* Find and open a BFD given a build-id.  If no BFD can be found,
+   return NULL.  Use "" or ".debug" for SUFFIX.  The returned reference to the
+   BFD must be released by the caller.  */
 
-bfd *
-build_id_to_debug_bfd (size_t build_id_len, const bfd_byte *build_id)
+struct file_location
+build_id_to_file (size_t build_id_len, const bfd_byte *build_id,
+		  const char *suffix, int is_bfd)
 {
   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
-		 + 2 * build_id_len + (sizeof ".debug" - 1) + 1);
+		 + 2 * build_id_len + strlen (suffix) + 1);
 
   /* Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will
      cause "/.build-id/..." lookups.  */
@@ -92,8 +111,6 @@ build_id_to_debug_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];
@@ -107,32 +124,39 @@ build_id_to_debug_bfd (size_t build_id_len, const bfd_byte *build_id)
 	*s++ = '/';
       while (size-- > 0)
 	s += sprintf (s, "%02x", (unsigned) *data++);
-      strcpy (s, ".debug");
-
-      /* lrealpath() is expensive even for the usually non-existent files.  */
-      if (access (link, F_OK) == 0)
-	filename = lrealpath (link);
+      strcpy (s, suffix);
 
-      if (filename == NULL)
-	continue;
+      result = file_location_from_filename (link, is_bfd, build_id_len, build_id);
+      if (file_location_is_valid (&result))
+	{
+	  do_cleanups (back_to);
+	  return result;
+	}
+      file_location_free (&result);
+    }
 
-      /* 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);
+  file_location_init (&result);
+  return result;
+}
 
-      if (abfd == NULL)
-	continue;
+/* See build-id.h.  */
 
-      if (build_id_verify (abfd, build_id_len, build_id))
-	break;
+bfd *
+build_id_to_debug_bfd (size_t build_id_len, const bfd_byte *build_id)
+{
+  struct file_location result;
+  bfd *retval;
 
-      gdb_bfd_unref (abfd);
-      abfd = NULL;
+  result = build_id_to_file (build_id_len, build_id, ".debug", 1 /* is_bfd */);
+  if (result.abfd == NULL)
+    {
+      file_location_free (&result);
+      return NULL;
     }
-
-  do_cleanups (back_to);
-  return abfd;
+  gdb_bfd_ref (result.abfd);
+  retval = result.abfd;
+  file_location_free (&result);
+  return retval;
 }
 
 /* See build-id.h.  */
@@ -167,3 +191,22 @@ find_separate_debug_file_by_buildid (struct objfile *objfile)
     }
   return NULL;
 }
+
+extern initialize_file_ftype _initialize_build_id; /* -Wmissing-prototypes */
+
+void
+_initialize_build_id (void)
+{
+  add_setshow_boolean_cmd ("validate-build-id", class_support,
+			   &validate_build_id, _("\
+Set validation a build-id matches to load a shared library."), _("\
+SHow validation a build-id matches to load a shared library."), _("\
+Inferior shared library and symbol file may contain unique build-id.\n\
+If both build-ids are present but they do not match then this setting\n\
+enables (off) or disables (on) loading of such symbol file.\n\
+Loading non-matching symbol file may confuse debugging including breakage\n\
+of backtrace output."),
+			   NULL,
+			   show_validate_build_id,
+			   &setlist, &showlist);
+}
diff --git a/gdb/build-id.h b/gdb/build-id.h
index bea761b..5fd7043 100644
--- a/gdb/build-id.h
+++ b/gdb/build-id.h
@@ -30,6 +30,7 @@ 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, int is_bfd);
 
 /* 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
@@ -45,4 +46,6 @@ extern bfd *build_id_to_debug_bfd (size_t build_id_len,
 
 extern char *find_separate_debug_file_by_buildid (struct objfile *objfile);
 
+extern int validate_build_id;
+
 #endif /* BUILD_ID_H */
diff --git a/gdb/solib.c b/gdb/solib.c
index 15900c7..e5c1272 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -47,6 +47,9 @@
 #include "gdb_bfd.h"
 #include "filestuff.h"
 #include "source.h"
+#include "build-id.h"
+
+static struct file_location solib_find_file (char *in_pathname, int is_bfd, size_t build_idsz, const gdb_byte *build_id);
 
 /* Architecture-specific operations.  */
 
@@ -154,7 +157,7 @@ static struct file_location
 solib_find_3 (char *in_pathname, int is_bfd, int is_solib, const char *sysroot_orig, size_t build_idsz, const gdb_byte *build_id)
 {
   const struct target_so_ops *ops = solib_ops (target_gdbarch ());
-  char *temp_pathname = NULL;
+  char *temp_pathname;
   const char *fskind = effective_target_file_system_kind ();
   struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
   char *sysroot;
@@ -312,7 +315,16 @@ solib_find_3 (char *in_pathname, int is_bfd, int is_solib, const char *sysroot_o
 
   /* We try to find the library in various ways.  */
 
-  temp_pathname = NULL;
+  if (build_idsz != 0)
+    {
+      result = build_id_to_file (build_idsz, build_id, "", is_bfd);
+      if (file_location_is_valid (&result))
+	{
+	  do_cleanups (old_chain);
+	  return result;
+	}
+      file_location_free (&result);
+    }
 
   /* If the search in gdb_sysroot failed, and the path name is
      absolute at this point, make it relative.  (openp will try and open the
@@ -449,7 +461,7 @@ solib_find_1 (char *in_pathname, size_t build_idsz, const gdb_byte *build_id,
 char *
 exec_file_find (char *in_pathname, int *fd)
 {
-  char *result = solib_find_1 (in_pathname, 0, NULL, fd, 0);
+  char *result = solib_find_1 (in_pathname, 0 /* build_idsz */, NULL, fd, 0 /* is_solib */);
 
   if (result == NULL)
     {
@@ -463,7 +475,7 @@ exec_file_find (char *in_pathname, int *fd)
 	  strcpy (new_pathname, in_pathname);
 	  strcat (new_pathname, ".exe");
 
-	  result = solib_find_1 (new_pathname, 0, NULL, fd, 0);
+	  result = solib_find_1 (new_pathname, 0 /* build_idsz */, NULL, fd, 0 /* is_solib */);
 	}
     }
 
@@ -478,9 +490,8 @@ exec_file_find (char *in_pathname, int *fd)
    The search algorithm used is described in solib_find_1's comment
    above.  */
 
-char *
-solib_find (char *in_pathname, size_t build_idsz, const gdb_byte *build_id,
-	    int *fd)
+static struct file_location
+solib_find_file (char *in_pathname, int is_bfd, size_t build_idsz, const gdb_byte *build_id)
 {
   const char *solib_symbols_extension
     = gdbarch_solib_symbols_extension (target_gdbarch ());
@@ -508,7 +519,34 @@ solib_find (char *in_pathname, size_t build_idsz, const gdb_byte *build_id,
 	}
     }
 
-  return solib_find_1 (in_pathname, build_idsz, build_id, fd, 1);
+  return solib_find_2 (in_pathname, is_bfd, 1 /* is_solib */, build_idsz, build_id);
+}
+
+char *
+solib_find (char *in_pathname, size_t build_idsz, const gdb_byte *build_id,
+	    int *fd)
+{
+  struct file_location file = solib_find_file (in_pathname, 0 /* is_bfd */, build_idsz, build_id);
+  char *retval;
+
+  if (!file_location_is_valid (&file))
+    {
+      retval = NULL;
+      if (fd != NULL)
+	*fd = -1;
+    }
+  else
+    {
+      retval = xstrdup (file.filename);
+      if (fd != NULL)
+	{
+	  gdb_assert (file.fd != -1);
+	  *fd = file.fd;
+	  file.fd = -1;
+	}
+    }
+  file_location_free (&file);
+  return retval;
 }
 
 /* Open and return a BFD for the shared library PATHNAME.  If FD is not -1,
@@ -544,25 +582,30 @@ solib_bfd_fopen (char *pathname, int fd)
 bfd *
 solib_bfd_open (char *pathname, size_t build_idsz, const gdb_byte *build_id)
 {
-  char *found_pathname;
-  int found_file;
+  struct file_location file;
   bfd *abfd;
   const struct bfd_arch_info *b;
 
   /* Search for shared library file.  */
-  found_pathname = solib_find (pathname, build_idsz, build_id, &found_file);
-  if (found_pathname == NULL)
+  file = solib_find_file (pathname, 1 /* is_bfd */, build_idsz, build_id);
+  if (!file_location_is_valid (&file))
     {
       /* Return failure if the file could not be found, so that we can
 	 accumulate messages about missing libraries.  */
-      if (errno == ENOENT)
-	return NULL;
+      if (file.file_errno == ENOENT)
+	{
+	  file_location_free (&file);
+	  return NULL;
+	}
 
+      file_location_free (&file);
       perror_with_name (pathname);
     }
 
   /* Open bfd for shared library.  */
-  abfd = solib_bfd_fopen (found_pathname, found_file);
+  gdb_bfd_ref (file.abfd);
+  abfd = file.abfd;
+  file_location_free (&file);
 
   /* Check bfd format.  */
   if (!bfd_check_format (abfd, bfd_object))
@@ -582,20 +625,6 @@ solib_bfd_open (char *pathname, size_t build_idsz, const gdb_byte *build_id)
   return abfd;
 }
 
-/* Boolean for command 'set validate-build-id'.  */
-static int validate_build_id = 1;
-
-/* Implement 'show validate-build-id'.  */
-
-static void
-show_validate_build_id (struct ui_file *file, int from_tty,
-			struct cmd_list_element *c, const char *value)
-{
-  fprintf_filtered (file, _("Validation a build-id matches to load a shared "
-			    "library is %s.\n"),
-		    value);
-}
-
 /* Given a pointer to one of the shared objects in our list of mapped
    objects, use the recorded name to open a bfd descriptor for the
    object, build a section table, relocate all the section addresses
@@ -1826,18 +1855,4 @@ PATH and LD_LIBRARY_PATH."),
 				     reload_shared_libraries,
 				     show_solib_search_path,
 				     &setlist, &showlist);
-
-  add_setshow_boolean_cmd ("validate-build-id", class_support,
-			   &validate_build_id, _("\
-Set validation a build-id matches to load a shared library."), _("\
-SHow validation a build-id matches to load a shared library."), _("\
-Inferior shared library and symbol file may contain unique build-id.\n\
-If both build-ids are present but they do not match then this setting\n\
-enables (off) or disables (on) loading of such symbol file.\n\
-Loading non-matching symbol file may confuse debugging including breakage\n\
-of backtrace output."),
-			   NULL,
-			   show_validate_build_id,
-			   &setlist, &showlist);
-
 }
diff --git a/gdb/source.c b/gdb/source.c
index 7416f30..297c2f3 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -760,7 +760,6 @@ file_location_free (struct file_location *result)
     }
   gdb_bfd_unref (result->abfd);
   xfree (result->filename);
-  xfree (result->errmsg);
 }
 
 static void
@@ -775,19 +774,6 @@ file_location_is_valid (const struct file_location *result)
   return result->abfd != NULL || result->filename != NULL;
 }
 
-char *
-file_location_convert_to_filename (struct file_location result)
-{
-  char *retval;
-
-  if (!file_location_is_valid (&result))
-    retval = NULL;
-  else
-    retval = xstrdup (result.filename);
-  file_location_free (&result);
-  return retval;
-}
-
 struct file_location
 file_location_from_filename (const char *filename, int is_bfd, size_t build_idsz, const gdb_byte *build_id)
 {
@@ -825,7 +811,7 @@ file_location_from_filename (const char *filename, int is_bfd, size_t build_idsz
 				      &target_errno);
       if (result.fd == -1)
 	{
-	  result.errmsg = xstrdup (safe_strerror (fileio_errno_to_host (target_errno)));
+	  result.file_errno = fileio_errno_to_host (target_errno);
 	  discard_cleanups (back_to);
 	  return result;
 	}
@@ -837,13 +823,13 @@ file_location_from_filename (const char *filename, int is_bfd, size_t build_idsz
       result.fd = gdb_open_cloexec (filename, O_RDONLY | O_BINARY, 0);
       if (result.fd == -1)
 	{
-	  result.errmsg = xstrdup (safe_strerror (errno));
+	  result.file_errno = errno;
 	  discard_cleanups (back_to);
 	  return result;
 	}
     }
 
-  if (build_idsz == 0 && !is_bfd)
+  if ((build_idsz == 0 || !validate_build_id) && !is_bfd)
     {
       discard_cleanups (back_to);
       return result;
@@ -855,7 +841,7 @@ file_location_from_filename (const char *filename, int is_bfd, size_t build_idsz
       fd_dup = dup (result.fd);
       if (fd_dup == -1)
 	{
-	  result.errmsg = xstrdup (safe_strerror (errno));
+	  result.file_errno = errno;
 	  close (result.fd);
 	  result.fd = -1;
 	  discard_cleanups (back_to);
@@ -884,13 +870,13 @@ file_location_from_filename (const char *filename, int is_bfd, size_t build_idsz
   result.fd = -1;
   if (result.abfd == NULL)
     {
-      result.errmsg = xstrdup (bfd_errmsg (bfd_get_error ()));
+      result.bfderr = bfd_get_error ();
       do_cleanups (fd_dup_cleanup);
       discard_cleanups (back_to);
       return result;
     }
 
-  if (build_idsz == 0)
+  if (build_idsz == 0 || !validate_build_id)
     {
       gdb_assert (is_bfd);
       gdb_assert (fd_dup == -1);
@@ -952,13 +938,11 @@ openp_bfd (const char *path, enum openp_flags opts, const char *string)
   gdb_assert ((opts & OPF_IS_BFD) == 0);
 
   result = openp_result (path, opts | OPF_IS_BFD, string, 0, NULL);
-  gdb_assert (result.abfd == NULL);
-  if (result.fd == -1)
+  if (result.abfd == NULL)
     {
       file_location_free (&result);
       return NULL;
     }
-  gdb_assert (result.abfd != NULL);
   gdb_bfd_ref (result.abfd);
   retval = result.abfd;
   file_location_free (&result);
diff --git a/gdb/source.h b/gdb/source.h
index daaa217..c79090b 100644
--- a/gdb/source.h
+++ b/gdb/source.h
@@ -106,7 +106,8 @@ struct file_location
   bfd *abfd;
   char *filename;
   int fd;
-  char *errmsg;
+  int file_errno;
+  bfd_error_type bfderr;
 };
 
 extern void file_location_init (struct file_location *result);
@@ -115,8 +116,6 @@ extern void file_location_free (struct file_location *result);
 
 extern int file_location_is_valid (const struct file_location *result);
 
-extern char *file_location_convert_to_filename (struct file_location result);
-
 extern struct file_location file_location_from_filename (const char *filename, int is_bfd, size_t build_idsz, const gdb_byte *build_id);
 
 extern struct file_location openp_result (const char *path, enum openp_flags opts, const char *string, size_t build_idsz, const gdb_byte *build_id);


hooks/post-receive
--
Repository for Project Archer.


             reply	other threads:[~2015-07-29 20:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-29 20:55 jkratoch [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-07-28 21:00 jkratoch

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=20150729205511.28973.qmail@sourceware.org \
    --to=jkratoch@sourceware.org \
    --cc=archer-commits@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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).