ChangeLog:
authorUlrich Weigand <uweigand@de.ibm.com>
Fri, 20 Jan 2012 09:47:32 +0000 (09:47 +0000)
committerUlrich Weigand <uweigand@de.ibm.com>
Fri, 20 Jan 2012 09:47:32 +0000 (09:47 +0000)
* configure.ac [AC_CHECK_FUNCS]: Check for readlink.
* config.in, configure: Regenerate.

* target.h (struct target_ops): Add to_fileio_readlink.
(target_fileio_readlink): Add prototype.
* target.c (target_fileio_readlink): New function.

* inf-child.c: Conditionally include <sys/param.h>.
(inf_child_fileio_readlink): New function.
(inf_child_target): Install it.

* remote.c (PACKET_vFile_readlink): New enum value.
(remote_hostio_readlink): New function.
(init_remote_ops): Install it.
(_initialize_remote): Handle vFile:readlink packet type.

doc/ChangeLog:

* gdb.texinfo (Remote Configuration): Document
"set remote hostio-readlink-packet" command.
(General Query Packets): Document vFile:readlink packet.

gdbserver/ChangeLog:

* hostio.c (handle_readlink): New function.
(handle_vFile): Call it to handle "vFile:readlink" packets.

12 files changed:
gdb/ChangeLog
gdb/config.in
gdb/configure
gdb/configure.ac
gdb/doc/ChangeLog
gdb/doc/gdb.texinfo
gdb/gdbserver/ChangeLog
gdb/gdbserver/hostio.c
gdb/inf-child.c
gdb/remote.c
gdb/target.c
gdb/target.h

index 65cfb170968d9550d3e2f8d45e4edea12bd7bd2f..db22bf33d78677e76ace0c031f34521504d44d6d 100644 (file)
@@ -1,3 +1,21 @@
+2012-01-20  Ulrich Weigand  <ulrich.weigand@linaro.org>
+
+       * configure.ac [AC_CHECK_FUNCS]: Check for readlink.
+       * config.in, configure: Regenerate.
+
+       * target.h (struct target_ops): Add to_fileio_readlink.
+       (target_fileio_readlink): Add prototype.
+       * target.c (target_fileio_readlink): New function.
+
+       * inf-child.c: Conditionally include <sys/param.h>.
+       (inf_child_fileio_readlink): New function.
+       (inf_child_target): Install it.
+
+       * remote.c (PACKET_vFile_readlink): New enum value.
+       (remote_hostio_readlink): New function.
+       (init_remote_ops): Install it.
+       (_initialize_remote): Handle vFile:readlink packet type.
+
 2012-01-20  Pedro Alves  <palves@redhat.com>
            Ulrich Weigand  <ulrich.weigand@linaro.org>
 
index 540234fbb2ae8a9389abd76727e21631558b020c..bae17635a3341df63032d8a9c1d1524d8d73332c 100644 (file)
 /* Define to 1 if wcwidth is declared even after undefining macros. */
 #undef HAVE_RAW_DECL_WCWIDTH
 
+/* Define to 1 if you have the `readlink' function. */
+#undef HAVE_READLINK
+
 /* Define to 1 if you have the `realpath' function. */
 #undef HAVE_REALPATH
 
index 5dd99fbc9fde3596b059808f7d31694b0f9e6517..920c7160eb837435963ee672f4b6635257f12a10 100755 (executable)
@@ -12932,7 +12932,7 @@ $as_echo "#define HAVE_WORKING_FORK 1" >>confdefs.h
 fi
 
 for ac_func in canonicalize_file_name realpath getrusage getuid getgid \
-               pipe poll pread pread64 pwrite resize_term \
+               pipe poll pread pread64 pwrite readlink resize_term \
                sbrk setpgid setpgrp setsid \
                sigaction sigprocmask sigsetmask socketpair syscall \
                ttrace wborder wresize setlocale iconvlist libiconvlist btowc \
index aca96b8ce3448458d05f99c4219d6eba9da7d149..6f9a42cfd1bef151470cf61c520e6873d45c356e 100644 (file)
@@ -1064,7 +1064,7 @@ AC_FUNC_ALLOCA
 AC_FUNC_MMAP
 AC_FUNC_VFORK
 AC_CHECK_FUNCS([canonicalize_file_name realpath getrusage getuid getgid \
-               pipe poll pread pread64 pwrite resize_term \
+               pipe poll pread pread64 pwrite readlink resize_term \
                sbrk setpgid setpgrp setsid \
                sigaction sigprocmask sigsetmask socketpair syscall \
                ttrace wborder wresize setlocale iconvlist libiconvlist btowc \
index e5a0dacee7747a6968ff1fe92dec0cb3e2cdafff..99bc8817c7b5d341def5f2412073f46927e1c9ff 100644 (file)
@@ -1,3 +1,9 @@
+2012-01-20  Ulrich Weigand  <ulrich.weigand@linaro.org>
+
+       * gdb.texinfo (Remote Configuration): Document
+       "set remote hostio-readlink-packet" command.
+       (General Query Packets): Document vFile:readlink packet.
+
 2012-01-16  Tom Tromey  <tromey@redhat.com>
 
        * gdb.texinfo (Specify Location): Document relative file name
index 49db18933bda3c7c14c6f521e0214e0a2eb9f648..20b0b67c20ac0a53487c507660ec218d41dff985 100644 (file)
@@ -17455,6 +17455,10 @@ are:
 @tab @code{vFile:unlink}
 @tab @code{remote delete}
 
+@item @code{hostio-readlink-packet}
+@tab @code{vFile:readlink}
+@tab Host I/O
+
 @item @code{noack-packet}
 @tab @code{QStartNoAckMode}
 @tab Packet acknowledgment
@@ -36205,6 +36209,16 @@ error occurred.
 Delete the file at @var{pathname} on the target.  Return 0,
 or -1 if an error occurs.  @var{pathname} is a string.
 
+@item vFile:readlink: @var{filename}
+Read value of symbolic link @var{filename} on the target.  Return
+the number of bytes read, or -1 if an error occurs.
+
+The data read should be returned as a binary attachment on success.
+If zero bytes were read, the response should include an empty binary
+attachment (i.e.@: a trailing semicolon).  The return value is the
+number of target bytes read; the binary attachment may be longer if
+some characters were escaped.
+
 @end table
 
 @node Interrupts
index 72f02861bd7cde8d82eb544fcb0a31defab521ba..0cb67da17b47ac9ccf8fb3bf31302d7e830c31ec 100644 (file)
@@ -1,3 +1,8 @@
+2012-01-20  Ulrich Weigand  <ulrich.weigand@linaro.org>
+
+       * hostio.c (handle_readlink): New function.
+       (handle_vFile): Call it to handle "vFile:readlink" packets.
+
 2012-01-20  Pedro Alves  <palves@redhat.com>
            Ulrich Weigand  <ulrich.weigand@linaro.org>
 
index b1508ec3babb41bc00954722efb7629790d36ac1..34e4fa8e09ebf4441cce45e3c66690c19ec36904 100644 (file)
@@ -456,6 +456,37 @@ handle_unlink (char *own_buf)
   hostio_reply (own_buf, ret);
 }
 
+static void
+handle_readlink (char *own_buf, int *new_packet_len)
+{
+  char filename[PATH_MAX], linkname[PATH_MAX];
+  char *p;
+  int ret, bytes_sent;
+
+  p = own_buf + strlen ("vFile:readlink:");
+
+  if (require_filename (&p, filename)
+      || require_end (p))
+    {
+      hostio_packet_error (own_buf);
+      return;
+    }
+
+  ret = readlink (filename, linkname, sizeof linkname);
+  if (ret == -1)
+    {
+      hostio_error (own_buf);
+      return;
+    }
+
+  bytes_sent = hostio_reply_with_data (own_buf, linkname, ret, new_packet_len);
+
+  /* If the response does not fit into a single packet, do not attempt
+     to return a partial response, but simply fail.  */
+  if (bytes_sent < ret)
+    sprintf (own_buf, "F-1,%x", FILEIO_ENAMETOOLONG);
+}
+
 /* Handle all the 'F' file transfer packets.  */
 
 int
@@ -471,6 +502,8 @@ handle_vFile (char *own_buf, int packet_len, int *new_packet_len)
     handle_close (own_buf);
   else if (strncmp (own_buf, "vFile:unlink:", 13) == 0)
     handle_unlink (own_buf);
+  else if (strncmp (own_buf, "vFile:readlink:", 15) == 0)
+    handle_readlink (own_buf, new_packet_len);
   else
     return 0;
 
index 0dda33151876d82e2d9e426cdf34b11171cd0c51..22718248b136499d19c825c1786c6516399edeba 100644 (file)
@@ -29,6 +29,9 @@
 #include "inf-child.h"
 #include "gdb/fileio.h"
 
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>         /* for MAXPATHLEN */
+#endif
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
@@ -299,6 +302,36 @@ inf_child_fileio_unlink (const char *filename, int *target_errno)
   return ret;
 }
 
+/* Read value of symbolic link FILENAME on the target.  Return a
+   null-terminated string allocated via xmalloc, or NULL if an error
+   occurs (and set *TARGET_ERRNO).  */
+static char *
+inf_child_fileio_readlink (const char *filename, int *target_errno)
+{
+  /* We support readlink only on systems that also provide a compile-time
+     maximum path length (MAXPATHLEN), at least for now.  */
+#if defined (HAVE_READLINK) && defined (MAXPATHLEN)
+  char buf[MAXPATHLEN];
+  int len;
+  char *ret;
+
+  len = readlink (filename, buf, sizeof buf);
+  if (len < 0)
+    {
+      *target_errno = inf_child_errno_to_fileio_error (errno);
+      return NULL;
+    }
+
+  ret = xmalloc (len + 1);
+  memcpy (ret, buf, len);
+  ret[len] = '\0';
+  return ret;
+#else
+  *target_errno = FILEIO_ENOSYS;
+  return NULL;
+#endif
+}
+
 
 struct target_ops *
 inf_child_target (void)
@@ -336,6 +369,7 @@ inf_child_target (void)
   t->to_fileio_pread = inf_child_fileio_pread;
   t->to_fileio_close = inf_child_fileio_close;
   t->to_fileio_unlink = inf_child_fileio_unlink;
+  t->to_fileio_readlink = inf_child_fileio_readlink;
   t->to_magic = OPS_MAGIC;
   return t;
 }
index 89d491ee3be9f5b6f99d3ceea6c068d15d93440c..f348536179757023c4bde38a09a9ec99287b6bb2 100644 (file)
@@ -1238,6 +1238,7 @@ enum {
   PACKET_vFile_pwrite,
   PACKET_vFile_close,
   PACKET_vFile_unlink,
+  PACKET_vFile_readlink,
   PACKET_qXfer_auxv,
   PACKET_qXfer_features,
   PACKET_qXfer_libraries,
@@ -9358,6 +9359,44 @@ remote_hostio_unlink (const char *filename, int *remote_errno)
                                     remote_errno, NULL, NULL);
 }
 
+/* Read value of symbolic link FILENAME on the remote target.  Return
+   a null-terminated string allocated via xmalloc, or NULL if an error
+   occurs (and set *REMOTE_ERRNO).  */
+
+static char *
+remote_hostio_readlink (const char *filename, int *remote_errno)
+{
+  struct remote_state *rs = get_remote_state ();
+  char *p = rs->buf;
+  char *attachment;
+  int left = get_remote_packet_size ();
+  int len, attachment_len;
+  int read_len;
+  char *ret;
+
+  remote_buffer_add_string (&p, &left, "vFile:readlink:");
+
+  remote_buffer_add_bytes (&p, &left, (const gdb_byte *) filename,
+                          strlen (filename));
+
+  len = remote_hostio_send_command (p - rs->buf, PACKET_vFile_readlink,
+                                   remote_errno, &attachment,
+                                   &attachment_len);
+
+  if (len < 0)
+    return NULL;
+
+  ret = xmalloc (len + 1);
+
+  read_len = remote_unescape_input (attachment, attachment_len,
+                                   ret, len);
+  if (read_len != len)
+    error (_("Readlink returned %d, but %d bytes."), len, read_len);
+
+  ret[len] = '\0';
+  return ret;
+}
+
 static int
 remote_fileio_errno_to_host (int errnum)
 {
@@ -10679,6 +10718,7 @@ Specify the serial device it is connected to\n\
   remote_ops.to_fileio_pread = remote_hostio_pread;
   remote_ops.to_fileio_close = remote_hostio_close;
   remote_ops.to_fileio_unlink = remote_hostio_unlink;
+  remote_ops.to_fileio_readlink = remote_hostio_readlink;
   remote_ops.to_supports_enable_disable_tracepoint = remote_supports_enable_disable_tracepoint;
   remote_ops.to_supports_string_tracing = remote_supports_string_tracing;
   remote_ops.to_trace_init = remote_trace_init;
@@ -11177,6 +11217,9 @@ Show the maximum size of the address (in bits) in a memory packet."), NULL,
   add_packet_config_cmd (&remote_protocol_packets[PACKET_vFile_unlink],
                         "vFile:unlink", "hostio-unlink", 0);
 
+  add_packet_config_cmd (&remote_protocol_packets[PACKET_vFile_readlink],
+                        "vFile:readlink", "hostio-readlink", 0);
+
   add_packet_config_cmd (&remote_protocol_packets[PACKET_vAttach],
                         "vAttach", "attach", 0);
 
index 595c2ced6c3a9fbf2bf9599803a956680db93e0f..32260e10df235eef210b196ab4a9f985d99cb15d 100644 (file)
@@ -3318,6 +3318,33 @@ target_fileio_unlink (const char *filename, int *target_errno)
   return -1;
 }
 
+/* Read value of symbolic link FILENAME on the target.  Return a
+   null-terminated string allocated via xmalloc, or NULL if an error
+   occurs (and set *TARGET_ERRNO).  */
+char *
+target_fileio_readlink (const char *filename, int *target_errno)
+{
+  struct target_ops *t;
+
+  for (t = default_fileio_target (); t != NULL; t = t->beneath)
+    {
+      if (t->to_fileio_readlink != NULL)
+       {
+         char *ret = t->to_fileio_readlink (filename, target_errno);
+
+         if (targetdebug)
+           fprintf_unfiltered (gdb_stdlog,
+                               "target_fileio_readlink (%s) = %s (%d)\n",
+                               filename, ret? ret : "(nil)",
+                               ret? 0 : *target_errno);
+         return ret;
+       }
+    }
+
+  *target_errno = FILEIO_ENOSYS;
+  return NULL;
+}
+
 static void
 target_fileio_close_cleanup (void *opaque)
 {
index 4bbf4de88d19e8eb3af71e65797478a316b04a53..e1deb5ef33e23b842326b23d8f74db575724fab5 100644 (file)
@@ -709,6 +709,11 @@ struct target_ops
        occurs (and set *TARGET_ERRNO).  */
     int (*to_fileio_unlink) (const char *filename, int *target_errno);
 
+    /* Read value of symbolic link FILENAME on the target.  Return a
+       null-terminated string allocated via xmalloc, or NULL if an error
+       occurs (and set *TARGET_ERRNO).  */
+    char *(*to_fileio_readlink) (const char *filename, int *target_errno);
+
 
     /* Tracepoint-related operations.  */
 
@@ -1546,6 +1551,11 @@ extern int target_fileio_close (int fd, int *target_errno);
    occurs (and set *TARGET_ERRNO).  */
 extern int target_fileio_unlink (const char *filename, int *target_errno);
 
+/* Read value of symbolic link FILENAME on the target.  Return a
+   null-terminated string allocated via xmalloc, or NULL if an error
+   occurs (and set *TARGET_ERRNO).  */
+extern char *target_fileio_readlink (const char *filename, int *target_errno);
+
 /* Read target file FILENAME.  The return value will be -1 if the transfer
    fails or is not supported; 0 if the object is empty; or the length
    of the object otherwise.  If a positive value is returned, a
This page took 0.063279 seconds and 4 git commands to generate.