Implement qXfer:exec-file:read in gdbserver
authorGary Benson <gbenson@redhat.com>
Fri, 17 Apr 2015 08:47:30 +0000 (09:47 +0100)
committerGary Benson <gbenson@redhat.com>
Fri, 17 Apr 2015 08:47:30 +0000 (09:47 +0100)
This commit implements the "qXfer:exec-file:read" packet in gdbserver.

gdb/gdbserver/ChangeLog:

* target.h (struct target_ops) <pid_to_exec_file>: New field.
* linux-low.c (linux_target_ops): Initialize pid_to_exec_file.
* server.c (handle_qxfer_exec_file): New function.
(qxfer_packets): Add exec-file entry.
(handle_query): Report qXfer:exec-file:read as supported packet.

gdb/gdbserver/ChangeLog
gdb/gdbserver/linux-low.c
gdb/gdbserver/server.c
gdb/gdbserver/target.h

index 165c42ca99755968ba533faf49bfbe439f75c4b2..56da6dcd219b94b660e204a3f47d955ab9f4228c 100644 (file)
@@ -1,3 +1,11 @@
+2015-04-17  Gary Benson  <gbenson@redhat.com>
+
+       * target.h (struct target_ops) <pid_to_exec_file>: New field.
+       * linux-low.c (linux_target_ops): Initialize pid_to_exec_file.
+       * server.c (handle_qxfer_exec_file): New function.
+       (qxfer_packets): Add exec-file entry.
+       (handle_query): Report qXfer:exec-file:read as supported packet.
+
 2015-04-14  Romain Naour <romain.naour@openwide.fr>  (tiny change)
 
        * linux-low.c (linux_read_offsets): Remove get_thread_lwp.
index a7f8446f7365cf4e94745c3fea449ed8c019a303..1c4c2d73bd341ca5cd3e0b5537b9356647b0c945 100644 (file)
@@ -6433,6 +6433,7 @@ static struct target_ops linux_target_ops = {
   NULL,
 #endif
   linux_supports_range_stepping,
+  linux_proc_pid_to_exec_file,
 };
 
 static void
index 3408ef7a838dcc884ec04e83e7812a3234941486..d2e20d920140cc57a85da507f687563c4e15b297 100644 (file)
@@ -1137,6 +1137,42 @@ handle_qxfer_auxv (const char *annex,
   return (*the_target->read_auxv) (offset, readbuf, len);
 }
 
+/* Handle qXfer:exec-file:read.  */
+
+static int
+handle_qxfer_exec_file (const char *const_annex,
+                       gdb_byte *readbuf, const gdb_byte *writebuf,
+                       ULONGEST offset, LONGEST len)
+{
+  char *annex, *file;
+  ULONGEST pid;
+  int total_len;
+
+  if (the_target->pid_to_exec_file == NULL || writebuf != NULL)
+    return -2;
+
+  annex = alloca (strlen (const_annex) + 1);
+  strcpy (annex, const_annex);
+  annex = unpack_varlen_hex (annex, &pid);
+  if (annex[0] != '\0' || pid == 0)
+    return -1;
+
+  file = (*the_target->pid_to_exec_file) (pid);
+  if (file == NULL)
+    return -1;
+
+  total_len = strlen (file);
+
+  if (offset > total_len)
+    return -1;
+
+  if (offset + len > total_len)
+    len = total_len - offset;
+
+  memcpy (readbuf, file + offset, len);
+  return len;
+}
+
 /* Handle qXfer:features:read.  */
 
 static int
@@ -1638,6 +1674,7 @@ static const struct qxfer qxfer_packets[] =
     { "auxv", handle_qxfer_auxv },
     { "btrace", handle_qxfer_btrace },
     { "btrace-conf", handle_qxfer_btrace_conf },
+    { "exec-file", handle_qxfer_exec_file},
     { "fdpic", handle_qxfer_fdpic},
     { "features", handle_qxfer_features },
     { "libraries", handle_qxfer_libraries },
@@ -2082,6 +2119,9 @@ handle_query (char *own_buf, int packet_len, int *new_packet_len_p)
       if (target_supports_stopped_by_hw_breakpoint ())
        strcat (own_buf, ";hwbreak+");
 
+      if (the_target->pid_to_exec_file != NULL)
+       strcat (own_buf, ";qXfer:exec-file:read+");
+
       return;
     }
 
index 126c861a68169c9a6a38611c634448c17ee15e6d..6280c267377413f6ca9770f79206012ddbbd7443 100644 (file)
@@ -394,6 +394,14 @@ struct target_ops
 
   /* Return true if target supports range stepping.  */
   int (*supports_range_stepping) (void);
+
+  /* Return the full absolute name of the executable file that was
+     run to create the process PID.  If the executable file cannot
+     be determined, NULL is returned.  Otherwise, a pointer to a
+     character string containing the pathname is returned.  This
+     string should be copied into a buffer by the client if the string
+     will not be immediately used, or if it must persist.  */
+  char *(*pid_to_exec_file) (int pid);
 };
 
 extern struct target_ops *the_target;
This page took 0.036837 seconds and 4 git commands to generate.