Convert "remote:" sysroots to "target:" and remove "remote:"
authorGary Benson <gbenson@redhat.com>
Thu, 2 Apr 2015 12:38:29 +0000 (13:38 +0100)
committerGary Benson <gbenson@redhat.com>
Thu, 2 Apr 2015 12:38:29 +0000 (13:38 +0100)
The functionality of "target:" sysroots is a superset of the
functionality of "remote:" sysroots.  This commit causes the
"set sysroot" command to rewrite "remote:" sysroots as "target:"
sysroots and replaces "remote:" specific code with "target:"
specific code where still necessary.

gdb/ChangeLog:

* remote.h (REMOTE_SYSROOT_PREFIX): Remove definition.
(remote_filename_p): Remove declaration.
(remote_bfd_open): Likewise.
* remote.c (remote_bfd_iovec_open): Remove function.
(remote_bfd_iovec_close): Likewise.
(remote_bfd_iovec_pread): Likewise.
(remote_bfd_iovec_stat): Likewise.
(remote_filename_p): Likewise.
(remote_bfd_open): Likewise.
* symfile.h (gdb_bfd_open_maybe_remote): Remove declaration.
* symfile.c (separate_debug_file_exists): Use gdb_bfd_open.
(gdb_bfd_open_maybe_remote): Remove function.
(symfile_bfd_open):  Replace remote filename check with
target filename check.
(reread_symbols): Use gdb_bfd_open.
* build-id.c (gdbcore.h): New include.
(build_id_to_debug_bfd): Use gdb_bfd_open.
* infcmd.c (attach_command_post_wait): Remove remote filename
check.
* solib.c (solib_find): Replace remote-specific handling with
target-specific handling.  Update comments where necessary.
(solib_bfd_open): Replace remote-specific handling with
target-specific handling.
(gdb_sysroot_changed): New function.
(_initialize_solib): Call the above when gdb_sysroot changes.
* windows-tdep.c (gdbcore.h): New include.
(windows_xfer_shared_library): Use gdb_bfd_open.

gdb/ChangeLog
gdb/build-id.c
gdb/remote.c
gdb/remote.h
gdb/solib.c
gdb/symfile.c
gdb/symfile.h
gdb/windows-tdep.c

index 35acfedfd932d133376409a56d9ce978b0c0ab08..95332356fbd25c26396df621a8674b023a1ad172 100644 (file)
@@ -1,3 +1,33 @@
+2015-04-02  Gary Benson <gbenson@redhat.com>
+
+       * remote.h (REMOTE_SYSROOT_PREFIX): Remove definition.
+       (remote_filename_p): Remove declaration.
+       (remote_bfd_open): Likewise.
+       * remote.c (remote_bfd_iovec_open): Remove function.
+       (remote_bfd_iovec_close): Likewise.
+       (remote_bfd_iovec_pread): Likewise.
+       (remote_bfd_iovec_stat): Likewise.
+       (remote_filename_p): Likewise.
+       (remote_bfd_open): Likewise.
+       * symfile.h (gdb_bfd_open_maybe_remote): Remove declaration.
+       * symfile.c (separate_debug_file_exists): Use gdb_bfd_open.
+       (gdb_bfd_open_maybe_remote): Remove function.
+       (symfile_bfd_open):  Replace remote filename check with
+       target filename check.
+       (reread_symbols): Use gdb_bfd_open.
+       * build-id.c (gdbcore.h): New include.
+       (build_id_to_debug_bfd): Use gdb_bfd_open.
+       * infcmd.c (attach_command_post_wait): Remove remote filename
+       check.
+       * solib.c (solib_find): Replace remote-specific handling with
+       target-specific handling.  Update comments where necessary.
+       (solib_bfd_open): Replace remote-specific handling with
+       target-specific handling.
+       (gdb_sysroot_changed): New function.
+       (_initialize_solib): Call the above when gdb_sysroot changes.
+       * windows-tdep.c (gdbcore.h): New include.
+       (windows_xfer_shared_library): Use gdb_bfd_open.
+
 2015-04-02  Gary Benson <gbenson@redhat.com>
 
        * gdb/gdb_bfd.h (TARGET_SYSROOT_PREFIX): New definition.
index 3a6ebb1cf349ac32b1b0a76380b583f1ca898844..8f7bbb4d9d00a0c2990c25e9e61aa390c7da9ea3 100644 (file)
@@ -26,6 +26,7 @@
 #include "symfile.h"
 #include "objfiles.h"
 #include "filenames.h"
+#include "gdbcore.h"
 
 /* See build-id.h.  */
 
@@ -118,7 +119,7 @@ build_id_to_debug_bfd (size_t build_id_len, const bfd_byte *build_id)
        continue;
 
       /* We expect to be silent on the non-existing files.  */
-      abfd = gdb_bfd_open_maybe_remote (filename);
+      abfd = gdb_bfd_open (filename, gnutarget, -1);
       if (abfd == NULL)
        continue;
 
index 43f3165122d98c2c0e86f4cb5d8286e1732fc433..69a67a85063f66e1949616166b8e30afa4a9a980 100644 (file)
@@ -10180,113 +10180,6 @@ remote_hostio_close_cleanup (void *opaque)
   remote_hostio_close (find_target_at (process_stratum), fd, &remote_errno);
 }
 
-
-static void *
-remote_bfd_iovec_open (struct bfd *abfd, void *open_closure)
-{
-  const char *filename = bfd_get_filename (abfd);
-  int fd, remote_errno;
-  int *stream;
-
-  gdb_assert (remote_filename_p (filename));
-
-  fd = remote_hostio_open (find_target_at (process_stratum),
-                          filename + 7, FILEIO_O_RDONLY, 0, &remote_errno);
-  if (fd == -1)
-    {
-      errno = remote_fileio_errno_to_host (remote_errno);
-      bfd_set_error (bfd_error_system_call);
-      return NULL;
-    }
-
-  stream = xmalloc (sizeof (int));
-  *stream = fd;
-  return stream;
-}
-
-static int
-remote_bfd_iovec_close (struct bfd *abfd, void *stream)
-{
-  int fd = *(int *)stream;
-  int remote_errno;
-
-  xfree (stream);
-
-  /* Ignore errors on close; these may happen if the remote
-     connection was already torn down.  */
-  remote_hostio_close (find_target_at (process_stratum), fd, &remote_errno);
-
-  /* Zero means success.  */
-  return 0;
-}
-
-static file_ptr
-remote_bfd_iovec_pread (struct bfd *abfd, void *stream, void *buf,
-                       file_ptr nbytes, file_ptr offset)
-{
-  int fd = *(int *)stream;
-  int remote_errno;
-  file_ptr pos, bytes;
-
-  pos = 0;
-  while (nbytes > pos)
-    {
-      bytes = remote_hostio_pread (find_target_at (process_stratum),
-                                  fd, (gdb_byte *) buf + pos, nbytes - pos,
-                                  offset + pos, &remote_errno);
-      if (bytes == 0)
-        /* Success, but no bytes, means end-of-file.  */
-        break;
-      if (bytes == -1)
-       {
-         errno = remote_fileio_errno_to_host (remote_errno);
-         bfd_set_error (bfd_error_system_call);
-         return -1;
-       }
-
-      pos += bytes;
-    }
-
-  return pos;
-}
-
-static int
-remote_bfd_iovec_stat (struct bfd *abfd, void *stream, struct stat *sb)
-{
-  int fd = *(int *) stream;
-  int remote_errno;
-  int result;
-
-  result = remote_hostio_fstat (find_target_at (process_stratum),
-                               fd, sb, &remote_errno);
-
-  if (result == -1)
-    {
-      errno = remote_fileio_errno_to_host (remote_errno);
-      bfd_set_error (bfd_error_system_call);
-    }
-
-  return result;
-}
-
-int
-remote_filename_p (const char *filename)
-{
-  return startswith (filename, REMOTE_SYSROOT_PREFIX);
-}
-
-bfd *
-remote_bfd_open (const char *remote_file, const char *target)
-{
-  bfd *abfd = gdb_bfd_openr_iovec (remote_file, target,
-                                  remote_bfd_iovec_open, NULL,
-                                  remote_bfd_iovec_pread,
-                                  remote_bfd_iovec_close,
-                                  remote_bfd_iovec_stat);
-
-  return abfd;
-}
-
 void
 remote_file_put (const char *local_file, const char *remote_file, int from_tty)
 {
index e6475377185b654f1f1a133cbd05fd72cb9b8aac..fb2a72b5950da143479e494aa0974da7761b4226 100644 (file)
@@ -49,17 +49,6 @@ void remote_file_get (const char *remote_file, const char *local_file,
                      int from_tty);
 void remote_file_delete (const char *remote_file, int from_tty);
 
-bfd *remote_bfd_open (const char *remote_file, const char *target);
-
-/* If a path starts with this sequence, GDB will retrieve the target
-   libraries from the remote system.  */
-
-#define REMOTE_SYSROOT_PREFIX "remote:"
-
-/* True if FILENAME starts with REMOTE_SYSROOT_PREFIX.  */
-
-int remote_filename_p (const char *filename);
-
 extern int remote_register_number_and_offset (struct gdbarch *gdbarch,
                                              int regnum, int *pnum,
                                              int *poffset);
index c8138ef7a89ddd3c0783bb3b0041d05930d4bdf0..2ec265a9aaf0ea9a7d29c58c45465e427e4210a1 100644 (file)
@@ -236,17 +236,17 @@ solib_find (char *in_pathname, int *fd)
         |-----------------+-----------+----------------|
         | /some/dir       | /         | c:/foo/bar.dll |
         | /some/dir       |           | /foo/bar.dll   |
-        | remote:         |           | c:/foo/bar.dll |
-        | remote:         |           | /foo/bar.dll   |
-        | remote:some/dir | /         | c:/foo/bar.dll |
-        | remote:some/dir |           | /foo/bar.dll   |
+        | target:         |           | c:/foo/bar.dll |
+        | target:         |           | /foo/bar.dll   |
+        | target:some/dir | /         | c:/foo/bar.dll |
+        | target:some/dir |           | /foo/bar.dll   |
 
        IOW, we don't need to add a separator if IN_PATHNAME already
-       has one, or when the the sysroot is exactly "remote:".
+       has one, or when the the sysroot is exactly "target:".
        There's no need to check for drive spec explicitly, as we only
        get here if IN_PATHNAME is considered an absolute path.  */
       need_dir_separator = !(IS_DIR_SEPARATOR (in_pathname[0])
-                            || strcmp (REMOTE_SYSROOT_PREFIX, sysroot) == 0);
+                            || strcmp (TARGET_SYSROOT_PREFIX, sysroot) == 0);
 
       /* Cat the prefixed pathname together.  */
       temp_pathname = concat (sysroot,
@@ -254,8 +254,8 @@ solib_find (char *in_pathname, int *fd)
                              in_pathname, (char *) NULL);
     }
 
-  /* Handle remote files.  */
-  if (remote_filename_p (temp_pathname))
+  /* Handle files to be accessed via the target.  */
+  if (is_target_filename (temp_pathname))
     {
       *fd = -1;
       do_cleanups (old_chain);
@@ -382,20 +382,10 @@ solib_find (char *in_pathname, int *fd)
 bfd *
 solib_bfd_fopen (char *pathname, int fd)
 {
-  bfd *abfd;
+  bfd *abfd = gdb_bfd_open (pathname, gnutarget, fd);
 
-  if (remote_filename_p (pathname))
-    {
-      gdb_assert (fd == -1);
-      abfd = remote_bfd_open (pathname, gnutarget);
-    }
-  else
-    {
-      abfd = gdb_bfd_open (pathname, gnutarget, fd);
-
-      if (abfd)
-       bfd_set_cacheable (abfd, 1);
-    }
+  if (abfd != NULL && !gdb_bfd_has_target_filename (abfd))
+    bfd_set_cacheable (abfd, 1);
 
   if (!abfd)
     {
@@ -1403,6 +1393,36 @@ reload_shared_libraries (char *ignored, int from_tty,
   ops->special_symbol_handling ();
 }
 
+/* Wrapper for reload_shared_libraries that replaces "remote:"
+   at the start of gdb_sysroot with "target:".  */
+
+static void
+gdb_sysroot_changed (char *ignored, int from_tty,
+                    struct cmd_list_element *e)
+{
+  const char *old_prefix = "remote:";
+  const char *new_prefix = TARGET_SYSROOT_PREFIX;
+
+  if (startswith (gdb_sysroot, old_prefix))
+    {
+      static int warning_issued = 0;
+
+      gdb_assert (strlen (old_prefix) == strlen (new_prefix));
+      memcpy (gdb_sysroot, new_prefix, strlen (new_prefix));
+
+      if (!warning_issued)
+       {
+         warning (_("\"%s\" is deprecated, use \"%s\" instead."),
+                  old_prefix, new_prefix);
+         warning (_("sysroot set to \"%s\"."), gdb_sysroot);
+
+         warning_issued = 1;
+       }
+    }
+
+  reload_shared_libraries (ignored, from_tty, e);
+}
+
 static void
 show_auto_solib_add (struct ui_file *file, int from_tty,
                     struct cmd_list_element *c, const char *value)
@@ -1597,7 +1617,7 @@ Show the current system root."), _("\
 The system root is used to load absolute shared library symbol files.\n\
 For other (relative) files, you can add directories using\n\
 `set solib-search-path'."),
-                                    reload_shared_libraries,
+                                    gdb_sysroot_changed,
                                     NULL,
                                     &setlist, &showlist);
 
index ba099d3a29bab5d2aa601aa6c003da363dd9dc95..0d8dae7c360e99f5ce9c1d37a85084c2cab61040 100644 (file)
@@ -1368,7 +1368,7 @@ separate_debug_file_exists (const char *name, unsigned long crc,
   if (filename_cmp (name, objfile_name (parent_objfile)) == 0)
     return 0;
 
-  abfd = gdb_bfd_open_maybe_remote (name);
+  abfd = gdb_bfd_open (name, gnutarget, -1);
 
   if (!abfd)
     return 0;
@@ -1712,23 +1712,6 @@ set_initial_language (void)
   expected_language = current_language; /* Don't warn the user.  */
 }
 
-/* If NAME is a remote name open the file using remote protocol, otherwise
-   open it normally.  Returns a new reference to the BFD.  On error,
-   returns NULL with the BFD error set.  */
-
-bfd *
-gdb_bfd_open_maybe_remote (const char *name)
-{
-  bfd *result;
-
-  if (remote_filename_p (name))
-    result = remote_bfd_open (name, gnutarget);
-  else
-    result = gdb_bfd_open (name, gnutarget, -1);
-
-  return result;
-}
-
 /* Open the file specified by NAME and hand it off to BFD for
    preliminary analysis.  Return a newly initialized bfd *, which
    includes a newly malloc'd` copy of NAME (tilde-expanded and made
@@ -1742,9 +1725,9 @@ symfile_bfd_open (const char *cname)
   char *name, *absolute_name;
   struct cleanup *back_to;
 
-  if (remote_filename_p (cname))
+  if (is_target_filename (cname))
     {
-      sym_bfd = remote_bfd_open (cname, gnutarget);
+      sym_bfd = gdb_bfd_open (cname, gnutarget, -1);
       if (!sym_bfd)
        error (_("`%s': can't open to read symbols: %s."), cname,
               bfd_errmsg (bfd_get_error ()));
@@ -2596,7 +2579,7 @@ reread_symbols (void)
            obfd_filename = bfd_get_filename (objfile->obfd);
            /* Open the new BFD before freeing the old one, so that
               the filename remains live.  */
-           objfile->obfd = gdb_bfd_open_maybe_remote (obfd_filename);
+           objfile->obfd = gdb_bfd_open (obfd_filename, gnutarget, -1);
            if (objfile->obfd == NULL)
              {
                /* We have to make a cleanup and error here, rather
index 7b66c62f8ff9fe445233dc7325a7ef64f0ab358f..9ef3f0baee6f1db30ba7d9bc7fde45128ceca92e 100644 (file)
@@ -514,8 +514,6 @@ extern void find_lowest_section (bfd *, asection *, void *);
 
 extern bfd *symfile_bfd_open (const char *);
 
-extern bfd *gdb_bfd_open_maybe_remote (const char *);
-
 extern int get_section_index (struct objfile *, char *);
 
 extern int print_symbol_loading_p (int from_tty, int mainline, int full);
index fbdddc99ec9ad283b05e121233e3c91fad6d5487..dc4e2e43c1c071153f6abe00cc8bfe89de3a54d5 100644 (file)
@@ -33,6 +33,7 @@
 #include "complaints.h"
 #include "solib.h"
 #include "solib-target.h"
+#include "gdbcore.h"
 
 struct cmd_list_element *info_w32_cmdlist;
 
@@ -401,7 +402,7 @@ windows_xfer_shared_library (const char* so_name, CORE_ADDR load_addr,
   obstack_grow_str (obstack, p);
   xfree (p);
   obstack_grow_str (obstack, "\"><segment address=\"");
-  dll = gdb_bfd_open_maybe_remote (so_name);
+  dll = gdb_bfd_open (so_name, gnutarget, -1);
   /* The following calls are OK even if dll is NULL.
      The default value 0x1000 is returned by pe_text_section_offset
      in that case.  */