Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: John Baldwin <jhb@FreeBSD.org>
To: gdb-patches@sourceware.org,	binutils@sourceware.org
Subject: [PATCH 3/6] Fetch the ELF auxiliary vector from live processes on FreeBSD.
Date: Thu, 16 Jun 2016 06:02:00 -0000	[thread overview]
Message-ID: <20160616060202.63470-4-jhb@FreeBSD.org> (raw)
In-Reply-To: <20160616060202.63470-1-jhb@FreeBSD.org>

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  |  7 ++++++
 gdb/fbsd-nat.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 9e57431..b11174c 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2016-06-15  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-14  John Baldwin  <jhb@FreeBSD.org>
 
 	* v850-tdep.c (v850_use_struct_convention): Trim type length checks.
diff --git a/gdb/fbsd-nat.c b/gdb/fbsd-nat.c
index b582abe..f9cfee6 100644
--- a/gdb/fbsd-nat.c
+++ b/gdb/fbsd-nat.c
@@ -206,6 +206,76 @@ 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);
+
+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)
+	  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 +894,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;
-- 
2.8.4


  parent reply	other threads:[~2016-06-16  6:02 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-16  6:02 [PATCH 0/6] Add ELF auxiliary vector handling for FreeBSD John Baldwin
2016-06-16  6:02 ` [PATCH 2/6] Add elfcore_grok_freebsd_note to parse FreeBSD ELF core notes John Baldwin
2016-06-17  8:28   ` Nick Clifton
2016-06-16  6:02 ` [PATCH 6/6] Add a gdbarch 'print_auxv' method for FreeBSD ABIs John Baldwin
2016-06-20 23:43   ` Pedro Alves
2016-06-16  6:02 ` [PATCH 1/6] Add constants for FreeBSD-specific auxiliary vector entry types John Baldwin
2016-06-17  8:27   ` Nick Clifton
2016-06-16  6:02 ` John Baldwin [this message]
2016-06-20 23:01   ` [PATCH 3/6] Fetch the ELF auxiliary vector from live processes on FreeBSD Pedro Alves
2016-06-16  6:11 ` [PATCH 5/6] Add a new gdbarch method to print a single AUXV entry John Baldwin
2016-06-20 23:40   ` Pedro Alves
2016-06-23 20:19     ` John Baldwin
2016-06-16  6:11 ` [PATCH 4/6] Create a psuedo section for the ELF AUXV core dump note on FreeBSD John Baldwin
2016-06-17  8:28   ` Nick Clifton
2016-06-20 23:45   ` Pedro Alves
2016-06-20 17:10 ` [PATCH 0/6] Add ELF auxiliary vector handling for FreeBSD John Baldwin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160616060202.63470-4-jhb@FreeBSD.org \
    --to=jhb@freebsd.org \
    --cc=binutils@sourceware.org \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox