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: openp
Date: Mon, 27 Jul 2015 22:36:00 -0000	[thread overview]
Message-ID: <20150727223630.116330.qmail@sourceware.org> (raw)

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.


             reply	other threads:[~2015-07-27 22:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-27 22:36 jkratoch [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-07-27 16:37 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=20150727223630.116330.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).