public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM]  jankratochvil/gdbserverbuildid2: openp
@ 2015-07-27 16:37 jkratoch
  0 siblings, 0 replies; 2+ messages in thread
From: jkratoch @ 2015-07-27 16:37 UTC (permalink / raw)
  To: archer-commits

The branch, jankratochvil/gdbserverbuildid2 has been updated
  discards  0dc7ee5d050052454ba752481d49f785235b49cb (commit)
       via  899c90e45fd688516a2bf5c56d2df6076f80de1d (commit)
       via  839d94bf2fcbec69cde88238f29007a7aa7cbcb4 (commit)
       via  885b8f5289e40cff7c47c7117dcd88209271c566 (commit)
      from  0dc7ee5d050052454ba752481d49f785235b49cb (commit)

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

- Log -----------------------------------------------------------------
commit 899c90e45fd688516a2bf5c56d2df6076f80de1d
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date:   Sat Jul 25 23:11:36 2015 +0200

    openp

commit 839d94bf2fcbec69cde88238f29007a7aa7cbcb4
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date:   Tue Jul 21 16:33:53 2015 +0200

    tripleparam

commit 885b8f5289e40cff7c47c7117dcd88209271c566
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date:   Sat Jul 25 22:48:02 2015 +0200

    sysroots

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

Summary of changes:
 gdb/gdb_bfd.c |    2 +-
 gdb/gdb_bfd.h |    2 +
 gdb/solib.c   |  187 +++++++++++++++++++++++++++++++++++++++-----------------
 3 files changed, 133 insertions(+), 58 deletions(-)

First 500 lines of diff:
diff --git a/gdb/gdb_bfd.c b/gdb/gdb_bfd.c
index 1781d80..6b65425 100644
--- a/gdb/gdb_bfd.c
+++ b/gdb/gdb_bfd.c
@@ -158,7 +158,7 @@ gdb_bfd_has_target_filename (struct bfd *abfd)
 
 /* Return the system error number corresponding to ERRNUM.  */
 
-static int
+int
 fileio_errno_to_host (int errnum)
 {
   switch (errnum)
diff --git a/gdb/gdb_bfd.h b/gdb/gdb_bfd.h
index 8fbdf36..2ec8285 100644
--- a/gdb/gdb_bfd.h
+++ b/gdb/gdb_bfd.h
@@ -169,4 +169,6 @@ int gdb_bfd_count_sections (bfd *abfd);
 
 int gdb_bfd_requires_relocations (bfd *abfd);
 
+int fileio_errno_to_host (int errnum);
+
 #endif /* GDB_BFD_H */
diff --git a/gdb/solib.c b/gdb/solib.c
index f69e212..d50f883 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -46,6 +46,8 @@
 #include "filesystem.h"
 #include "gdb_bfd.h"
 #include "filestuff.h"
+#include "build-id.h"
+#include "gdb/fileio.h"
 
 /* Architecture-specific operations.  */
 
@@ -157,25 +159,78 @@ struct solib_find_result
   char *errmsg;
 };
 
-struct solib_find_result
+static const char *
+solib_find_result_filename_get (const struct solib_find_result *result)
+{
+  if (result->abfd != NULL)
+    return bfd_get_filename (result->abfd);
+  gdb_assert (result->filename != NULL);
+  return result->filename;
+}
+
+static void
+solib_find_result_init (struct solib_find_result *result)
+{
+  memset (result, 0, sizeof (*result));
+  result->fd = -1;
+}
+
+static void
+solib_find_result_free (struct solib_find_result *result)
+{
+  if (result->fd != -1)
+    {
+      if (is_target_filename (solib_find_result_filename_get (result)))
+	{
+	  int target_errno;
+
+	  target_fileio_close (result->fd, &target_errno);
+	}
+      else
+	close (result->fd);
+    }
+  gdb_bfd_unref (result->abfd);
+  xfree (result->filename);
+  xfree (result->errmsg);
+}
+
+static int
+solib_find_result_is_valid (const struct solib_find_result *result)
+{
+  return result->abfd != NULL || result->filename != NULL;
+}
+
+static char *
+solib_find_result_convert_to_filename (struct solib_find_result result)
+{
+  char *retval;
+
+  if (!solib_find_result_is_valid (&result))
+    retval = NULL;
+  else
+    retval = xstrdup (solib_find_result_filename_get (&result));
+  solib_find_result_free (&result);
+  return retval;
+}
+
+static struct solib_find_result
 solib_find_result_from_filename (const char *filename, size_t build_idsz,
 				 const gdb_byte *build_id)
 {
   struct solib_find_result result;
 
-  memset (result, 0, sizeof (*result));
-  result->fd = -1;
+  solib_find_result_init (&result);
 
   if (build_idsz)
     {
-      result.abfd = gdb_bfd_open (filename, gnutarget, fd);
+      result.abfd = gdb_bfd_open (filename, gnutarget, -1);
       if (result.abfd == NULL)
 	{
-	  result->errmsg = xstrdup (bfd_errmsg (bfd_get_error ()));
+	  result.errmsg = xstrdup (bfd_errmsg (bfd_get_error ()));
 	  return result;
 	}
 
-      if (!build_id_verify (abfd, build_id_len, build_id))
+      if (!build_id_verify (result.abfd, build_idsz, build_id))
 	{
 	  gdb_bfd_unref (result.abfd);
 	  result.abfd = NULL;
@@ -186,7 +241,7 @@ solib_find_result_from_filename (const char *filename, size_t build_idsz,
     {
       int target_errno;
 
-      result->filename = xstrdup (filename);
+      result.filename = xstrdup (filename);
       result.fd = target_fileio_open (current_inferior (),
 				      filename + strlen (TARGET_SYSROOT_PREFIX),
 				      FILEIO_O_RDONLY, 0,
@@ -199,8 +254,8 @@ solib_find_result_from_filename (const char *filename, size_t build_idsz,
     }
   else
     {
-      result->filename = xstrdup (filename);
-      result.fd = gdb_open_cloexec (name, O_RDONLY | O_BINARY, 0);
+      result.filename = xstrdup (filename);
+      result.fd = gdb_open_cloexec (filename, O_RDONLY | O_BINARY, 0);
       if (result.fd == -1)
 	{
 	  result.errmsg = xstrdup (safe_strerror (errno));
@@ -210,50 +265,16 @@ solib_find_result_from_filename (const char *filename, size_t build_idsz,
   return result;
 }
 
-const char *
-solib_find_result_filename_get (const struct solib_find_result *result)
-{
-  if (result->abfd != NULL)
-    return bfd_get_filename (result->abfd);
-  gdb_assert (result->filename != NULL);
-  return result->filename;
-}
-
-void
-solib_find_result_free (struct solib_find_result *result)
-{
-  if (result->fd != -1)
-    {
-      if (is_target_filename (solib_find_result_filename_get (result)))
-	{
-	  int target_errno;
-
-	  target_fileio_close (result.fd, &target_errno);
-	}
-      else
-	close (fd);
-    }
-  gdb_bfd_unref (result->abfd);
-  xfree (result->filename);
-  xfree (result->errmsg);
-}
-
-int
-solib_find_result_is_valid (const struct solib_find_result *result)
-{
-  return result->abfd != NULL || result->filename != NULL;
-}
-
 static struct solib_find_result
-solib_find_1 (char *in_pathname, size_t build_idsz, const gdb_byte *build_id,
-	      int *fd, int is_solib)
+solib_find_2 (char *in_pathname, size_t build_idsz, const gdb_byte *build_id,
+	      int *fd, int is_solib, const char *sysroot_orig)
 {
   const struct target_so_ops *ops = solib_ops (target_gdbarch ());
   int found_file = -1;
   char *temp_pathname = NULL;
   const char *fskind = effective_target_file_system_kind ();
   struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
-  char *sysroot = gdb_sysroot;
+  char *sysroot;
   int prefix_len, orig_prefix_len;
   struct solib_find_result result;
 
@@ -263,20 +284,20 @@ solib_find_1 (char *in_pathname, size_t build_idsz, const gdb_byte *build_id,
      filesystem.  This ensures that the same search algorithm is used
      for all local files regardless of whether a "target:" prefix was
      used.  */
-  if (is_target_filename (sysroot) && target_filesystem_is_local ())
-    sysroot += strlen (TARGET_SYSROOT_PREFIX);
+  if (is_target_filename (sysroot_orig) && target_filesystem_is_local ())
+    sysroot_orig += strlen (TARGET_SYSROOT_PREFIX);
 
   /* Strip any trailing slashes from the absolute prefix.  */
-  prefix_len = orig_prefix_len = strlen (sysroot);
+  prefix_len = orig_prefix_len = strlen (sysroot_orig);
 
-  while (prefix_len > 0 && IS_DIR_SEPARATOR (sysroot[prefix_len - 1]))
+  while (prefix_len > 0 && IS_DIR_SEPARATOR (sysroot_orig[prefix_len - 1]))
     prefix_len--;
 
   if (prefix_len == 0)
     sysroot = NULL;
   else if (prefix_len != orig_prefix_len)
     {
-      sysroot = savestring (sysroot, prefix_len);
+      sysroot = savestring (sysroot_orig, prefix_len);
       make_cleanup (xfree, sysroot);
     }
 
@@ -350,10 +371,10 @@ solib_find_1 (char *in_pathname, size_t build_idsz, const gdb_byte *build_id,
       if (fd != NULL)
 	*fd = -1;
       do_cleanups (old_chain);
-      return temp_pathname;
+      return solib_find_result_from_filename (temp_pathname, build_idsz, build_id);
     }
 
-  result = solib_find_result_from_filename (temp_pathname);
+  result = solib_find_result_from_filename (temp_pathname, build_idsz, build_id);
   if (solib_find_result_is_valid (&result))
     return result;
 
@@ -473,7 +494,53 @@ solib_find_1 (char *in_pathname, size_t build_idsz, const gdb_byte *build_id,
   else
     *fd = found_file;
 
-  return temp_pathname;
+  return solib_find_result_from_filename (temp_pathname, build_idsz, build_id);
+}
+
+static struct solib_find_result
+solib_find_1 (char *in_pathname, size_t build_idsz, const gdb_byte *build_id,
+	      int *fd, int is_solib)
+{
+  VEC (char_ptr) *sysroot_vec = dirnames_to_char_ptr_vec (gdb_sysroot);
+  struct cleanup *back_to = make_cleanup_free_char_ptr_vec (sysroot_vec);
+  struct solib_find_result retval;
+  char *sysroot;
+  int ix;
+
+  /* Handle ambiguous "target:" split by dirnames_to_char_ptr_vec.  */
+  if (DIRNAME_SEPARATOR == ':')
+    for (ix = 0; ix < VEC_length (char_ptr, sysroot_vec);)
+      {
+	char *s = VEC_index (char_ptr, sysroot_vec, ix);
+
+	if (strcmp (s, "target") != 0)
+	  {
+	    ++ix;
+	    continue;
+	  }
+	VEC_ordered_remove (char_ptr, sysroot_vec, ix);
+	xfree (s);
+	if (ix == VEC_length (char_ptr, sysroot_vec))
+	  VEC_safe_push (char_ptr, sysroot_vec, xstrdup ("target:"));
+	else
+	  xfree (VEC_replace (char_ptr, sysroot_vec, ix,
+			      concat ("target:",
+				      VEC_index (char_ptr, sysroot_vec, ix),
+				      NULL)));
+      }
+
+  solib_find_result_init (&retval);
+  for (ix = 0; VEC_iterate (char_ptr, sysroot_vec, ix, sysroot); ++ix)
+    {
+      retval = solib_find_2 (in_pathname, build_idsz, build_id, fd, is_solib,
+                             sysroot);
+      if (solib_find_result_is_valid (&retval))
+	break;
+      solib_find_result_free (&retval);
+    }
+
+  do_cleanups (back_to);
+  return retval;
 }
 
 /* Return the full pathname of the main executable, or NULL if not
@@ -487,7 +554,8 @@ 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_result_convert_to_filename
+				   (solib_find_1 (in_pathname, 0, NULL, fd, 0));
 
   if (result == NULL)
     {
@@ -501,7 +569,8 @@ 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_result_convert_to_filename
+				  (solib_find_1 (new_pathname, 0, NULL, fd, 0));
 	}
     }
 
@@ -546,7 +615,11 @@ 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_result_convert_to_filename (
+  solib_find_1 (in_pathname, build_idsz, build_id, fd, 1)
+)
+  ;
 }
 
 /* Open and return a BFD for the shared library PATHNAME.  If FD is not -1,


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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [SCM]  jankratochvil/gdbserverbuildid2: openp
@ 2015-07-27 22:36 jkratoch
  0 siblings, 0 replies; 2+ messages in thread
From: jkratoch @ 2015-07-27 22:36 UTC (permalink / raw)
  To: archer-commits

The branch, jankratochvil/gdbserverbuildid2 has been updated
  discards  899c90e45fd688516a2bf5c56d2df6076f80de1d (commit)
       via  e0fb2d2446411b7ec5c9e073747b8418cb2681e3 (commit)
       via  f7f5ba4195fa5a37633b3ca8bd9fc33c8e30d266 (commit)
       via  0093337b616b186ff5b8d9de718fe31e15329496 (commit)
       via  ad63586bce2bef4de340275a51ec83acecd509cf (commit)
       via  5e7045a421afe153fdaf3b6303326d5941f7be3b (commit)
      from  899c90e45fd688516a2bf5c56d2df6076f80de1d (commit)

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

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

    openp

commit f7f5ba4195fa5a37633b3ca8bd9fc33c8e30d266
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date:   Mon Jul 27 23:01:54 2015 +0200

    openpnullpathname

commit 0093337b616b186ff5b8d9de718fe31e15329496
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date:   Mon Jul 27 20:11:55 2015 +0200

    openpmode

commit ad63586bce2bef4de340275a51ec83acecd509cf
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date:   Mon Jul 27 22:42:55 2015 +0200

    openppath

commit 5e7045a421afe153fdaf3b6303326d5941f7be3b
Author: Jan Kratochvil <jan.kratochvil@redhat.com>
Date:   Mon Jul 27 23:15:48 2015 +0200

    openpenum

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

Summary of changes:
 gdb/cli/cli-cmds.c |    7 +-
 gdb/defs.h         |   13 ++-
 gdb/dwarf2read.c   |    6 +-
 gdb/exec.c         |   80 +++------------
 gdb/nto-tdep.c     |   11 +-
 gdb/nto-tdep.h     |    2 +-
 gdb/solib.c        |  173 +++--------------------------
 gdb/solist.h       |    3 +-
 gdb/source.c       |  307 +++++++++++++++++++++++++++++++++++++++++++---------
 gdb/source.h       |   25 +++++
 gdb/symfile.c      |   11 +-
 gdb/utils.c        |    9 ++
 gdb/utils.h        |    2 +
 13 files changed, 354 insertions(+), 295 deletions(-)

First 500 lines of diff:
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 2ec2dd3..4723f1f 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -499,7 +499,7 @@ find_and_open_script (const char *script_file, int search_path,
   char *file;
   int fd;
   struct cleanup *old_cleanups;
-  int search_flags = OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH;
+  int search_flags = OPF_TRY_CWD_FIRST;
 
   file = tilde_expand (script_file);
   old_cleanups = make_cleanup (xfree, file);
@@ -509,8 +509,7 @@ find_and_open_script (const char *script_file, int search_path,
 
   /* Search for and open 'file' on the search path used for source
      files.  Put the full location in *FULL_PATHP.  */
-  fd = openp (source_path, search_flags,
-	      file, O_RDONLY, full_pathp);
+  fd = openp (source_path, search_flags, file, full_pathp);
 
   if (fd == -1)
     {
@@ -522,6 +521,8 @@ find_and_open_script (const char *script_file, int search_path,
 
   do_cleanups (old_cleanups);
 
+  *full_pathp = gdb_realpath_and_xfree (*full_pathp);
+
   *streamp = fdopen (fd, FOPEN_RT);
   if (*streamp == NULL)
     {
diff --git a/gdb/defs.h b/gdb/defs.h
index a555da1..59db425 100644
--- a/gdb/defs.h
+++ b/gdb/defs.h
@@ -316,11 +316,16 @@ extern const char *pc_prefix (CORE_ADDR);
 /* From source.c */
 
 /* See openp function definition for their description.  */
-#define OPF_TRY_CWD_FIRST     0x01
-#define OPF_SEARCH_IN_PATH    0x02
-#define OPF_RETURN_REALPATH   0x04
+enum openp_flags
+{
+  OPF_TRY_CWD_FIRST   = (1 << 0),
+  OPF_SEARCH_IN_PATH  = (1 << 1),
+  OPF_IS_BFD          = (1 << 2),
+};
+
+extern int openp (const char *, enum openp_flags, const char *, char **);
 
-extern int openp (const char *, int, const char *, int, char **);
+extern bfd *openp_bfd (const char *path, enum openp_flags opts, const char *string);
 
 extern int source_full_path_of (const char *, char **);
 
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 91c6a8f..dffcd1f 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -10470,14 +10470,14 @@ try_open_dwop_file (const char *file_name, int is_dwp, int search_cwd)
   else
     search_path = xstrdup (debug_file_directory);
 
-  flags = OPF_RETURN_REALPATH;
+  flags = 0;
   if (is_dwp)
     flags |= OPF_SEARCH_IN_PATH;
-  desc = openp (search_path, flags, file_name,
-		O_RDONLY | O_BINARY, &absolute_name);
+  desc = openp (search_path, flags, file_name, &absolute_name);
   xfree (search_path);
   if (desc < 0)
     return NULL;
+  absolute_name = gdb_realpath_and_xfree (absolute_name);
 
   sym_bfd = gdb_bfd_open (absolute_name, gnutarget, desc);
   xfree (absolute_name);
diff --git a/gdb/exec.c b/gdb/exec.c
index f1b1049..631861b 100644
--- a/gdb/exec.c
+++ b/gdb/exec.c
@@ -216,84 +216,30 @@ exec_file_attach (const char *filename, int from_tty)
     }
   else
     {
-      int load_via_target = 0;
-      char *scratch_pathname, *canonical_pathname;
-      int scratch_chan;
       struct target_section *sections = NULL, *sections_end = NULL;
       char **matching;
 
-      if (is_target_filename (filename))
-	{
-	  if (target_filesystem_is_local ())
-	    filename += strlen (TARGET_SYSROOT_PREFIX);
-	  else
-	    load_via_target = 1;
-	}
-
-      if (load_via_target)
+      exec_bfd = openp_bfd (getenv ("PATH"), OPF_TRY_CWD_FIRST, filename);
+#if defined(__GO32__) || defined(_WIN32) || defined(__CYGWIN__)
+      if (exec_bfd == NULL)
 	{
-	  /* gdb_bfd_fopen does not support "target:" filenames.  */
-	  if (write_files)
-	    warning (_("writing into executable files is "
-		       "not supported for %s sysroots"),
-		     TARGET_SYSROOT_PREFIX);
+	  char *exename = alloca (strlen (filename) + 5);
 
-	  scratch_pathname = xstrdup (filename);
-	  make_cleanup (xfree, scratch_pathname);
-
-	  scratch_chan = -1;
-
-	  canonical_pathname = scratch_pathname;
+	  strcat (strcpy (exename, filename), ".exe");
+	  exec_bfd = openp_bfd (getenv ("PATH"), OPF_TRY_CWD_FIRST, exename);
 	}
-      else
-	{
-	  scratch_chan = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST,
-				filename, write_files ?
-				O_RDWR | O_BINARY : O_RDONLY | O_BINARY,
-				&scratch_pathname);
-#if defined(__GO32__) || defined(_WIN32) || defined(__CYGWIN__)
-	  if (scratch_chan < 0)
-	    {
-	      char *exename = alloca (strlen (filename) + 5);
-
-	      strcat (strcpy (exename, filename), ".exe");
-	      scratch_chan = openp (getenv ("PATH"), OPF_TRY_CWD_FIRST,
-				    exename, write_files ?
-				    O_RDWR | O_BINARY
-				    : O_RDONLY | O_BINARY,
-				    &scratch_pathname);
-	    }
 #endif
-	  if (scratch_chan < 0)
-	    perror_with_name (filename);
-
-	  make_cleanup (xfree, scratch_pathname);
-
-	  /* gdb_bfd_open (and its variants) prefers canonicalized
-	     pathname for better BFD caching.  */
-	  canonical_pathname = gdb_realpath (scratch_pathname);
-	  make_cleanup (xfree, canonical_pathname);
-	}
-
-      if (write_files && !load_via_target)
-	exec_bfd = gdb_bfd_fopen (canonical_pathname, gnutarget,
-				  FOPEN_RUB, scratch_chan);
-      else
-	exec_bfd = gdb_bfd_open (canonical_pathname, gnutarget, scratch_chan);
-
-      if (!exec_bfd)
-	{
-	  error (_("\"%s\": could not open as an executable file: %s."),
-		 scratch_pathname, bfd_errmsg (bfd_get_error ()));
-	}
+      if (exec_bfd == NULL)
+	error (_("\"%s\": could not open as an executable file: %s."),
+	       filename, bfd_errmsg (bfd_get_error ()));
 
       /* gdb_realpath_keepfile resolves symlinks on the local
 	 filesystem and so cannot be used for "target:" files.  */
       gdb_assert (exec_filename == NULL);
-      if (load_via_target)
+      if (is_target_filename (filename))
 	exec_filename = xstrdup (bfd_get_filename (exec_bfd));
       else
-	exec_filename = gdb_realpath_keepfile (scratch_pathname);
+	exec_filename = gdb_realpath_keepfile (filename);
 
       if (!bfd_check_format_matches (exec_bfd, bfd_object, &matching))
 	{
@@ -301,7 +247,7 @@ exec_file_attach (const char *filename, int from_tty)
 	     it.  */
 	  exec_close ();
 	  error (_("\"%s\": not in executable format: %s"),
-		 scratch_pathname,
+		 filename,
 		 gdb_bfd_errmsg (bfd_get_error (), matching));
 	}
 
@@ -311,7 +257,7 @@ exec_file_attach (const char *filename, int from_tty)
 	     it.  */
 	  exec_close ();
 	  error (_("\"%s\": can't find the file sections: %s"),
-		 scratch_pathname, bfd_errmsg (bfd_get_error ()));
+		 filename, bfd_errmsg (bfd_get_error ()));
 	}
 
       exec_bfd_mtime = bfd_get_mtime (exec_bfd);
diff --git a/gdb/nto-tdep.c b/gdb/nto-tdep.c
index ba3c845..7c8b4ce 100644
--- a/gdb/nto-tdep.c
+++ b/gdb/nto-tdep.c
@@ -82,7 +82,7 @@ nto_map_arch_to_cputype (const char *arch)
 }
 
 int
-nto_find_and_open_solib (char *solib, unsigned o_flags, char **temp_pathname)
+nto_find_and_open_solib (char *solib, char **temp_pathname)
 {
   char *buf, *arch_path, *nto_root;
   const char *endian;
@@ -127,20 +127,21 @@ nto_find_and_open_solib (char *solib, unsigned o_flags, char **temp_pathname)
 	     arch_path);
 
   base = lbasename (solib);
-  ret = openp (buf, OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH, base, o_flags,
-	       temp_pathname);
+  ret = openp (buf, OPF_TRY_CWD_FIRST, base, temp_pathname);
   if (ret < 0 && base != solib)
     {
       xsnprintf (arch_path, arch_len, "/%s", solib);
-      ret = open (arch_path, o_flags, 0);
+      ret = open (arch_path, O_RDONLY | O_BINARY);
       if (temp_pathname)
 	{
 	  if (ret >= 0)
-	    *temp_pathname = gdb_realpath (arch_path);
+	    *temp_pathname = xstrdup (arch_path);
 	  else
 	    *temp_pathname = NULL;
 	}
     }
+  if (ret >= 0)
+    *temp_pathname = gdb_realpath_and_xfree (*temp_pathname);
   return ret;
 }
 
diff --git a/gdb/nto-tdep.h b/gdb/nto-tdep.h
index bd85d2a..1f8045a 100644
--- a/gdb/nto-tdep.h
+++ b/gdb/nto-tdep.h
@@ -154,7 +154,7 @@ void nto_relocate_section_addresses (struct so_list *,
 
 int nto_map_arch_to_cputype (const char *);
 
-int nto_find_and_open_solib (char *, unsigned, char **);
+int nto_find_and_open_solib (char *, char **);
 
 enum gdb_osabi nto_elf_osabi_sniffer (bfd *abfd);
 
diff --git a/gdb/solib.c b/gdb/solib.c
index d50f883..a7ef780 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -46,8 +46,7 @@
 #include "filesystem.h"
 #include "gdb_bfd.h"
 #include "filestuff.h"
-#include "build-id.h"
-#include "gdb/fileio.h"
+#include "source.h"
 
 /* Architecture-specific operations.  */
 
@@ -151,120 +150,6 @@ show_solib_search_path (struct ui_file *file, int from_tty,
    * machines since a sysroot will almost always be set.
 */
 
-struct solib_find_result
-{
-  bfd *abfd;
-  char *filename;
-  int fd;
-  char *errmsg;
-};
-
-static const char *
-solib_find_result_filename_get (const struct solib_find_result *result)
-{
-  if (result->abfd != NULL)
-    return bfd_get_filename (result->abfd);
-  gdb_assert (result->filename != NULL);
-  return result->filename;
-}
-
-static void
-solib_find_result_init (struct solib_find_result *result)
-{
-  memset (result, 0, sizeof (*result));
-  result->fd = -1;
-}
-
-static void
-solib_find_result_free (struct solib_find_result *result)
-{
-  if (result->fd != -1)
-    {
-      if (is_target_filename (solib_find_result_filename_get (result)))
-	{
-	  int target_errno;
-
-	  target_fileio_close (result->fd, &target_errno);
-	}
-      else
-	close (result->fd);
-    }
-  gdb_bfd_unref (result->abfd);
-  xfree (result->filename);
-  xfree (result->errmsg);
-}
-
-static int
-solib_find_result_is_valid (const struct solib_find_result *result)
-{
-  return result->abfd != NULL || result->filename != NULL;
-}
-
-static char *
-solib_find_result_convert_to_filename (struct solib_find_result result)
-{
-  char *retval;
-
-  if (!solib_find_result_is_valid (&result))
-    retval = NULL;
-  else
-    retval = xstrdup (solib_find_result_filename_get (&result));
-  solib_find_result_free (&result);
-  return retval;
-}
-
-static struct solib_find_result
-solib_find_result_from_filename (const char *filename, size_t build_idsz,
-				 const gdb_byte *build_id)
-{
-  struct solib_find_result result;
-
-  solib_find_result_init (&result);
-
-  if (build_idsz)
-    {
-      result.abfd = gdb_bfd_open (filename, gnutarget, -1);
-      if (result.abfd == NULL)
-	{
-	  result.errmsg = xstrdup (bfd_errmsg (bfd_get_error ()));
-	  return result;
-	}
-
-      if (!build_id_verify (result.abfd, build_idsz, build_id))
-	{
-	  gdb_bfd_unref (result.abfd);
-	  result.abfd = NULL;
-	  return result;
-	}
-    }
-  else if (is_target_filename (filename))
-    {
-      int target_errno;
-
-      result.filename = xstrdup (filename);
-      result.fd = target_fileio_open (current_inferior (),
-				      filename + strlen (TARGET_SYSROOT_PREFIX),
-				      FILEIO_O_RDONLY, 0,
-				      &target_errno);
-      if (result.fd == -1)
-	{
-	  result.errmsg = xstrdup (safe_strerror (fileio_errno_to_host (target_errno)));
-	  return result;
-	}
-    }
-  else
-    {
-      result.filename = xstrdup (filename);
-      result.fd = gdb_open_cloexec (filename, O_RDONLY | O_BINARY, 0);
-      if (result.fd == -1)
-	{
-	  result.errmsg = xstrdup (safe_strerror (errno));
-	  return result;
-	}
-    }
-  return result;
-}
-
 static struct solib_find_result
 solib_find_2 (char *in_pathname, size_t build_idsz, const gdb_byte *build_id,
 	      int *fd, int is_solib, const char *sysroot_orig)
@@ -371,10 +256,10 @@ solib_find_2 (char *in_pathname, size_t build_idsz, const gdb_byte *build_id,
       if (fd != NULL)
 	*fd = -1;
       do_cleanups (old_chain);
-      return solib_find_result_from_filename (temp_pathname, build_idsz, build_id);
+      return solib_find_result_from_filename (temp_pathname, build_idsz, build_id, 1 /* is_bfd */ );
     }
 
-  result = solib_find_result_from_filename (temp_pathname, build_idsz, build_id);
+  result = solib_find_result_from_filename (temp_pathname, build_idsz, build_id, 1 /* is_bfd */);
   if (solib_find_result_is_valid (&result))
     return result;
 
@@ -451,40 +336,37 @@ solib_find_2 (char *in_pathname, size_t build_idsz, const gdb_byte *build_id,
   /* If not found, and we're looking for a solib, search the
      solib_search_path (if any).  */
   if (is_solib && found_file < 0 && solib_search_path != NULL)
-    found_file = openp (solib_search_path,
-			OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH,
-			in_pathname, O_RDONLY | O_BINARY, &temp_pathname);
+    found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST,
+			in_pathname, &temp_pathname);
 
   /* If not found, and we're looking for a solib, next search the
      solib_search_path (if any) for the basename only (ignoring the
      path).  This is to allow reading solibs from a path that differs
      from the opened path.  */
   if (is_solib && found_file < 0 && solib_search_path != NULL)
-    found_file = openp (solib_search_path,
-			OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH,
-			target_lbasename (fskind, in_pathname),
-			O_RDONLY | O_BINARY, &temp_pathname);
+    found_file = openp (solib_search_path, OPF_TRY_CWD_FIRST,
+			target_lbasename (fskind, in_pathname), &temp_pathname);
 
   /* If not found, and we're looking for a solib, try to use target
      supplied solib search method.  */
   if (is_solib && found_file < 0 && ops->find_and_open_solib)
-    found_file = ops->find_and_open_solib (in_pathname, O_RDONLY | O_BINARY,
-					   &temp_pathname);
+    found_file = ops->find_and_open_solib (in_pathname, &temp_pathname);
 
   /* If not found, next search the inferior's $PATH environment variable.  */
   if (found_file < 0 && sysroot == NULL)
     found_file = openp (get_in_environ (current_inferior ()->environment,
 					"PATH"),
-			OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH, in_pathname,
-			O_RDONLY | O_BINARY, &temp_pathname);
+			OPF_TRY_CWD_FIRST, in_pathname, &temp_pathname);
 
   /* If not found, and we're looking for a solib, next search the
      inferior's $LD_LIBRARY_PATH environment variable.  */
   if (is_solib && found_file < 0 && sysroot == NULL)
     found_file = openp (get_in_environ (current_inferior ()->environment,
 					"LD_LIBRARY_PATH"),
-			OPF_TRY_CWD_FIRST | OPF_RETURN_REALPATH, in_pathname,
-			O_RDONLY | O_BINARY, &temp_pathname);
+			OPF_TRY_CWD_FIRST, in_pathname, &temp_pathname);
+
+  if (found_file >= 0)
+    temp_pathname = gdb_realpath_and_xfree (temp_pathname);
 
   if (fd == NULL)
     {
@@ -494,40 +376,21 @@ solib_find_2 (char *in_pathname, size_t build_idsz, const gdb_byte *build_id,
   else
     *fd = found_file;
 
-  return solib_find_result_from_filename (temp_pathname, build_idsz, build_id);
+  return solib_find_result_from_filename (temp_pathname, build_idsz, build_id, 1 /* is_bfd */);
 }
 
 static struct solib_find_result
 solib_find_1 (char *in_pathname, size_t build_idsz, const gdb_byte *build_id,
 	      int *fd, int is_solib)
 {
-  VEC (char_ptr) *sysroot_vec = dirnames_to_char_ptr_vec (gdb_sysroot);
-  struct cleanup *back_to = make_cleanup_free_char_ptr_vec (sysroot_vec);
+  VEC (char_ptr) *sysroot_vec;
+  struct cleanup *back_to;
   struct solib_find_result retval;
   char *sysroot;
   int ix;
 
-  /* Handle ambiguous "target:" split by dirnames_to_char_ptr_vec.  */
-  if (DIRNAME_SEPARATOR == ':')
-    for (ix = 0; ix < VEC_length (char_ptr, sysroot_vec);)
-      {
-	char *s = VEC_index (char_ptr, sysroot_vec, ix);
-
-	if (strcmp (s, "target") != 0)
-	  {
-	    ++ix;
-	    continue;
-	  }
-	VEC_ordered_remove (char_ptr, sysroot_vec, ix);
-	xfree (s);
-	if (ix == VEC_length (char_ptr, sysroot_vec))
-	  VEC_safe_push (char_ptr, sysroot_vec, xstrdup ("target:"));
-	else
-	  xfree (VEC_replace (char_ptr, sysroot_vec, ix,
-			      concat ("target:",
-				      VEC_index (char_ptr, sysroot_vec, ix),
-				      NULL)));
-      }
+  sysroot_vec = dirnames_to_char_ptr_vec_target_exc (gdb_sysroot);
+  back_to = make_cleanup_free_char_ptr_vec (sysroot_vec);
 
   solib_find_result_init (&retval);
   for (ix = 0; VEC_iterate (char_ptr, sysroot_vec, ix, sysroot); ++ix)
diff --git a/gdb/solist.h b/gdb/solist.h
index 20aec81..eb6160d 100644
--- a/gdb/solist.h
+++ b/gdb/solist.h
@@ -147,8 +147,7 @@ struct target_so_ops
        If TEMP_PATHNAME is non-NULL: If the file is successfully opened a


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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-07-27 22:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-27 16:37 [SCM] jankratochvil/gdbserverbuildid2: openp jkratoch
2015-07-27 22:36 jkratoch

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).