Fetch the ELF auxiliary vector from live processes on FreeBSD.
authorJohn Baldwin <jhb@FreeBSD.org>
Sat, 11 Jun 2016 22:07:38 +0000 (15:07 -0700)
committerJohn Baldwin <jhb@FreeBSD.org>
Fri, 24 Jun 2016 17:33:04 +0000 (10:33 -0700)
Use the kern.proc.auxv.<pid> sysctl to fetch the ELF auxiliary vector for
a live process.

gdb/ChangeLog:

* fbsd-nat.c [KERN_PROC_AUXV] New variable super_xfer_partial.
(fbsd_xfer_partial): New function.
(fbsd_nat_add_target) [KERN_PROC_AUXV] Set "to_xfer_partial" to
"fbsd_xfer_partial".

gdb/ChangeLog
gdb/fbsd-nat.c

index 630dbc917f25abef9e3b7adcdfb36fca784891b2..18c7a9997b702cbd93ecdbbb50c13c483abb936b 100644 (file)
@@ -1,3 +1,10 @@
+2016-06-24  John Baldwin  <jhb@FreeBSD.org>
+
+       * fbsd-nat.c [KERN_PROC_AUXV] New variable super_xfer_partial.
+       (fbsd_xfer_partial): New function.
+       (fbsd_nat_add_target) [KERN_PROC_AUXV] Set "to_xfer_partial" to
+       "fbsd_xfer_partial".
+
 2016-06-23  Tom Tromey  <tom@tromey.com>
 
        * symtab.c (symbol_find_demangled_name): Loop over languages and
index b582abe72df320934b8d48e2f7c24392414565ab..dc65e2972a4f415820cf66cb103ecab82c86f60b 100644 (file)
@@ -206,6 +206,78 @@ fbsd_find_memory_regions (struct target_ops *self,
 }
 #endif
 
+#ifdef KERN_PROC_AUXV
+static enum target_xfer_status (*super_xfer_partial) (struct target_ops *ops,
+                                                     enum target_object object,
+                                                     const char *annex,
+                                                     gdb_byte *readbuf,
+                                                     const gdb_byte *writebuf,
+                                                     ULONGEST offset,
+                                                     ULONGEST len,
+                                                     ULONGEST *xfered_len);
+
+/* Implement the "to_xfer_partial target_ops" method.  */
+
+static enum target_xfer_status
+fbsd_xfer_partial (struct target_ops *ops, enum target_object object,
+                  const char *annex, gdb_byte *readbuf,
+                  const gdb_byte *writebuf,
+                  ULONGEST offset, ULONGEST len, ULONGEST *xfered_len)
+{
+  pid_t pid = ptid_get_pid (inferior_ptid);
+
+  switch (object)
+    {
+    case TARGET_OBJECT_AUXV:
+      {
+       struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
+       unsigned char *buf;
+       size_t buflen;
+       int mib[4];
+
+       if (writebuf != NULL)
+         return TARGET_XFER_E_IO;
+       mib[0] = CTL_KERN;
+       mib[1] = KERN_PROC;
+       mib[2] = KERN_PROC_AUXV;
+       mib[3] = pid;
+       if (offset == 0)
+         {
+           buf = readbuf;
+           buflen = len;
+         }
+       else
+         {
+           buflen = offset + len;
+           buf = XCNEWVEC (unsigned char, buflen);
+           cleanup = make_cleanup (xfree, buf);
+         }
+       if (sysctl (mib, 4, buf, &buflen, NULL, 0) == 0)
+         {
+           if (offset != 0)
+             {
+               if (buflen > offset)
+                 {
+                   buflen -= offset;
+                   memcpy (readbuf, buf + offset, buflen);
+                 }
+               else
+                 buflen = 0;
+             }
+           do_cleanups (cleanup);
+           *xfered_len = buflen;
+           return (buflen == 0) ? TARGET_XFER_EOF : TARGET_XFER_OK;
+         }
+       do_cleanups (cleanup);
+       return TARGET_XFER_E_IO;
+      }
+    default:
+      return super_xfer_partial (ops, object, annex, readbuf, writebuf, offset,
+                                len, xfered_len);
+    }
+}
+#endif
+
 #ifdef PT_LWPINFO
 static int debug_fbsd_lwp;
 
@@ -824,6 +896,10 @@ fbsd_nat_add_target (struct target_ops *t)
 {
   t->to_pid_to_exec_file = fbsd_pid_to_exec_file;
   t->to_find_memory_regions = fbsd_find_memory_regions;
+#ifdef KERN_PROC_AUXV
+  super_xfer_partial = t->to_xfer_partial;
+  t->to_xfer_partial = fbsd_xfer_partial;
+#endif
 #ifdef PT_LWPINFO
   t->to_thread_alive = fbsd_thread_alive;
   t->to_pid_to_str = fbsd_pid_to_str;