]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Warn when accessing binaries from remote targets
authorGary Benson <gbenson@redhat.com>
Fri, 21 Aug 2015 16:09:20 +0000 (17:09 +0100)
committerGary Benson <gbenson@redhat.com>
Fri, 21 Aug 2015 16:15:26 +0000 (17:15 +0100)
GDB provides no indicator of progress during file operations, and can
appear to have locked up during slow remote transfers.  This commit
updates GDB to print a warning each time a file is accessed over RSP.
An additional message detailing how to avoid remote transfers is
printed for the first transfer only.

gdb/ChangeLog:

* target.h (struct target_ops) <to_fileio_open>: New argument
warn_if_slow.  Update comment.  All implementations updated.
(target_fileio_open_warn_if_slow): New declaration.
* target.c (target_fileio_open): Renamed as...
(target_fileio_open_1): ...this.  New argument warn_if_slow.
Pass warn_if_slow to implementation.  Update debug printing.
(target_fileio_open): New function.
(target_fileio_open_warn_if_slow): Likewise.
* gdb_bfd.c (gdb_bfd_iovec_fileio_open): Use new function
target_fileio_open_warn_if_slow.

gdb/testsuite/ChangeLog:

* gdb.trace/pending.exp: Cope with remote transfer warnings.

gdb/ChangeLog
gdb/gdb_bfd.c
gdb/inf-child.c
gdb/linux-nat.c
gdb/remote.c
gdb/target.c
gdb/target.h
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.trace/pending.exp

index fe07c5c35e7dcb437ef97cc61b9d5579acf98d2f..60ad15014dd2e9d789214473b9b058cf63387e6d 100644 (file)
@@ -1,3 +1,16 @@
+2015-08-21  Gary Benson  <gbenson@redhat.com>
+
+       * target.h (struct target_ops) <to_fileio_open>: New argument
+       warn_if_slow.  Update comment.  All implementations updated.
+       (target_fileio_open_warn_if_slow): New declaration.
+       * target.c (target_fileio_open): Renamed as...
+       (target_fileio_open_1): ...this.  New argument warn_if_slow.
+       Pass warn_if_slow to implementation.  Update debug printing.
+       (target_fileio_open): New function.
+       (target_fileio_open_warn_if_slow): Likewise.
+       * gdb_bfd.c (gdb_bfd_iovec_fileio_open): Use new function
+       target_fileio_open_warn_if_slow.
+
 2015-08-21  Gary Benson  <gbenson@redhat.com>
 
        * nat/linux-namespaces.c (linux_mntns_access_fs):
index 1781d80853723713a0b544928ae8edd4828214ca..264b6116d2ef8f46f437904f32ba42ab940915f4 100644 (file)
@@ -222,10 +222,11 @@ gdb_bfd_iovec_fileio_open (struct bfd *abfd, void *inferior)
 
   gdb_assert (is_target_filename (filename));
 
-  fd = target_fileio_open ((struct inferior *) inferior,
-                          filename + strlen (TARGET_SYSROOT_PREFIX),
-                          FILEIO_O_RDONLY, 0,
-                          &target_errno);
+  fd = target_fileio_open_warn_if_slow ((struct inferior *) inferior,
+                                       filename
+                                       + strlen (TARGET_SYSROOT_PREFIX),
+                                       FILEIO_O_RDONLY, 0,
+                                       &target_errno);
   if (fd == -1)
     {
       errno = fileio_errno_to_host (target_errno);
index 0326a93ae326f86a547e762f93419ed62d0ead43..ada570d96f6e41d5ca93c0acf521c548039b1906 100644 (file)
@@ -209,7 +209,8 @@ inf_child_pid_to_exec_file (struct target_ops *self, int pid)
 static int
 inf_child_fileio_open (struct target_ops *self,
                       struct inferior *inf, const char *filename,
-                      int flags, int mode, int *target_errno)
+                      int flags, int mode, int warn_if_slow,
+                      int *target_errno)
 {
   int nat_flags;
   mode_t nat_mode;
index 74d5997145be113a0088ab53545b57f247b695a1..727c8dac0c8d7edbfaed92ce61ebbb37e27bd531 100644 (file)
@@ -4904,7 +4904,8 @@ linux_nat_fileio_pid_of (struct inferior *inf)
 static int
 linux_nat_fileio_open (struct target_ops *self,
                       struct inferior *inf, const char *filename,
-                      int flags, int mode, int *target_errno)
+                      int flags, int mode, int warn_if_slow,
+                      int *target_errno)
 {
   int nat_flags;
   mode_t nat_mode;
index c5ec2c724539729376adc7e6798b65e4a13ef691..8fc90027a18a612e20cd29ae52b3d04cf966a829 100644 (file)
@@ -10371,12 +10371,29 @@ remote_hostio_set_filesystem (struct inferior *inf, int *remote_errno)
 static int
 remote_hostio_open (struct target_ops *self,
                    struct inferior *inf, const char *filename,
-                   int flags, int mode, int *remote_errno)
+                   int flags, int mode, int warn_if_slow,
+                   int *remote_errno)
 {
   struct remote_state *rs = get_remote_state ();
   char *p = rs->buf;
   int left = get_remote_packet_size () - 1;
 
+  if (warn_if_slow)
+    {
+      static int warning_issued = 0;
+
+      printf_unfiltered (_("Reading %s from remote target...\n"),
+                        filename);
+
+      if (!warning_issued)
+       {
+         warning (_("File transfers from remote targets can be slow."
+                    " Use \"set sysroot\" to access files locally"
+                    " instead."));
+         warning_issued = 1;
+       }
+    }
+
   if (remote_hostio_set_filesystem (inf, remote_errno) != 0)
     return -1;
 
@@ -10700,7 +10717,7 @@ remote_filesystem_is_local (struct target_ops *self)
             filename is irrelevant, we only care about whether
             the stub recognizes the packet or not.  */
          fd = remote_hostio_open (self, NULL, "just probing",
-                                  FILEIO_O_RDONLY, 0700,
+                                  FILEIO_O_RDONLY, 0700, 0,
                                   &remote_errno);
 
          if (fd >= 0)
@@ -10822,7 +10839,7 @@ remote_file_put (const char *local_file, const char *remote_file, int from_tty)
   fd = remote_hostio_open (find_target_at (process_stratum), NULL,
                           remote_file, (FILEIO_O_WRONLY | FILEIO_O_CREAT
                                         | FILEIO_O_TRUNC),
-                          0700, &remote_errno);
+                          0700, 0, &remote_errno);
   if (fd == -1)
     remote_hostio_error (remote_errno);
 
@@ -10906,7 +10923,8 @@ remote_file_get (const char *remote_file, const char *local_file, int from_tty)
     error (_("command can only be used with remote target"));
 
   fd = remote_hostio_open (find_target_at (process_stratum), NULL,
-                          remote_file, FILEIO_O_RDONLY, 0, &remote_errno);
+                          remote_file, FILEIO_O_RDONLY, 0, 0,
+                          &remote_errno);
   if (fd == -1)
     remote_hostio_error (remote_errno);
 
index 01bac7e186112e9c41cd7f3b76781705c28e7126..65fe7f81a9bb31ac72d79a99e278fecd538f942a 100644 (file)
@@ -2779,11 +2779,13 @@ release_fileio_fd (int fd, fileio_fh_t *fh)
 #define fileio_fd_to_fh(fd) \
   VEC_index (fileio_fh_t, fileio_fhandles, (fd))
 
-/* See target.h.  */
+/* Helper for target_fileio_open and
+   target_fileio_open_warn_if_slow.  */
 
-int
-target_fileio_open (struct inferior *inf, const char *filename,
-                   int flags, int mode, int *target_errno)
+static int
+target_fileio_open_1 (struct inferior *inf, const char *filename,
+                     int flags, int mode, int warn_if_slow,
+                     int *target_errno)
 {
   struct target_ops *t;
 
@@ -2792,7 +2794,7 @@ target_fileio_open (struct inferior *inf, const char *filename,
       if (t->to_fileio_open != NULL)
        {
          int fd = t->to_fileio_open (t, inf, filename, flags, mode,
-                                     target_errno);
+                                     warn_if_slow, target_errno);
 
          if (fd < 0)
            fd = -1;
@@ -2801,11 +2803,12 @@ target_fileio_open (struct inferior *inf, const char *filename,
 
          if (targetdebug)
            fprintf_unfiltered (gdb_stdlog,
-                               "target_fileio_open (%d,%s,0x%x,0%o)"
+                               "target_fileio_open (%d,%s,0x%x,0%o,%d)"
                                " = %d (%d)\n",
                                inf == NULL ? 0 : inf->num,
                                filename, flags, mode,
-                               fd, fd != -1 ? 0 : *target_errno);
+                               warn_if_slow, fd,
+                               fd != -1 ? 0 : *target_errno);
          return fd;
        }
     }
@@ -2816,6 +2819,27 @@ target_fileio_open (struct inferior *inf, const char *filename,
 
 /* See target.h.  */
 
+int
+target_fileio_open (struct inferior *inf, const char *filename,
+                   int flags, int mode, int *target_errno)
+{
+  return target_fileio_open_1 (inf, filename, flags, mode, 0,
+                              target_errno);
+}
+
+/* See target.h.  */
+
+int
+target_fileio_open_warn_if_slow (struct inferior *inf,
+                                const char *filename,
+                                int flags, int mode, int *target_errno)
+{
+  return target_fileio_open_1 (inf, filename, flags, mode, 1,
+                              target_errno);
+}
+
+/* See target.h.  */
+
 int
 target_fileio_pwrite (int fd, const gdb_byte *write_buf, int len,
                      ULONGEST offset, int *target_errno)
index cad5c52cc25be6c150bbc6e73560ff0fdb36a8dd..b9dca55c6156d7d86b394acad2ae2180bca85f18 100644 (file)
@@ -863,11 +863,14 @@ struct target_ops
     /* Open FILENAME on the target, in the filesystem as seen by INF,
        using FLAGS and MODE.  If INF is NULL, use the filesystem seen
        by the debugger (GDB or, for remote targets, the remote stub).
-       Return a target file descriptor, or -1 if an error occurs (and
-       set *TARGET_ERRNO).  */
+       If WARN_IF_SLOW is nonzero, print a warning message if the file
+       is being accessed over a link that may be slow.  Return a
+       target file descriptor, or -1 if an error occurs (and set
+       *TARGET_ERRNO).  */
     int (*to_fileio_open) (struct target_ops *,
                           struct inferior *inf, const char *filename,
-                          int flags, int mode, int *target_errno);
+                          int flags, int mode, int warn_if_slow,
+                          int *target_errno);
 
     /* Write up to LEN bytes from WRITE_BUF to FD on the target.
        Return the number of bytes written, or -1 if an error occurs
@@ -1983,6 +1986,14 @@ extern int target_fileio_open (struct inferior *inf,
                               const char *filename, int flags,
                               int mode, int *target_errno);
 
+/* Like target_fileio_open, but print a warning message if the
+   file is being accessed over a link that may be slow.  */
+extern int target_fileio_open_warn_if_slow (struct inferior *inf,
+                                           const char *filename,
+                                           int flags,
+                                           int mode,
+                                           int *target_errno);
+
 /* Write up to LEN bytes from WRITE_BUF to FD on the target.
    Return the number of bytes written, or -1 if an error occurs
    (and set *TARGET_ERRNO).  */
index 37586da1a2698b3905049d3b88ec37305dd5e694..12754fc795d144ca93e70da7caa8fecb4d0ae9dd 100644 (file)
@@ -1,3 +1,7 @@
+2015-08-21  Gary Benson <gbenson@redhat.com>
+
+       * gdb.trace/pending.exp: Cope with remote transfer warnings.
+
 2015-08-13  Joel Brobecker  <brobecker@adacore.com>
 
        * gdb.base/dso2dso.exp: Improve the testcase's documentation.
index 0399807b8107e5860de23dc85f071620d0242a09..9938c5ae841237b4997836b0a1a1940d05c02b5a 100644 (file)
@@ -221,7 +221,7 @@ proc pending_tracepoint_resolved_during_trace { trace_type } \
                fail $test
            }
        }
-       -re "Continuing.\r\n\r\nBreakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
+       -re "Continuing.\r\n(Reading .* from remote target...\r\n)?\r\nBreakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
            pass $test
        }
     }
@@ -294,7 +294,7 @@ proc pending_tracepoint_installed_during_trace { trace_type } \
                fail $test
            }
        }
-       -re "Continuing.\r\n\r\nBreakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
+       -re "Continuing.\r\n(Reading .* from remote target...\r\n)?\r\nBreakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
            pass $test
        }
     }
@@ -391,7 +391,7 @@ proc pending_tracepoint_disconnect_after_resolved { trace_type } \
 
     gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*pending.c.*" \
        "continue to marker 1"
-    gdb_test "continue" "Continuing.\r\n\r\nBreakpoint.*marker.*at.*pending.c.*" \
+    gdb_test "continue" "Continuing.\r\n(Reading .* from remote target...\r\n)?\r\nBreakpoint.*marker.*at.*pending.c.*" \
        "continue to marker 2"
 
     # There should be no pending tracepoint, so no warning should be emitted.
@@ -473,7 +473,7 @@ proc pending_tracepoint_with_action_resolved { trace_type } \
                fail $test
             }
        }
-       -re "Continuing.\r\n\r\nBreakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
+       -re "Continuing.\r\n(Reading .* from remote target...\r\n)?\r\nBreakpoint.*marker.*at.*$srcfile.*$gdb_prompt $" {
            pass "continue to marker 2"
        }