This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] auxv support


> Seems reasonable.  Probably the packet will need to be conditionally
> supported (see packet_ok, remote_P_packet or so).  The mechanism for
> doing that at the moment involves a couple of copy/pastes, it needs
> cleaning up eventually.

Ok.

> Personally I would prefer a separate packet for each type of aux data. 

Alrighty.  I decided to keep the reply format simple and the request format
matching gdb's usage need (i.e. OFFSET+LEN), since anything more
informative would not be useful unless the way to_xfer_partial is used were
to change.

> Note that you'll need to use LinuxThreads (or no threads) if you want
> to test this with gdbserver; I have NPTL support almost done but it
> needs the remote.c patch I posted today.

I just tested single-threaded cases.  Threads are orthogonal to this support.

Following are three pairs of log entry and patch.  First, docs for info
auxv and the new qAuxVector remote protocol packet.  Second, remote.c
support for using qAuxVector.  Third, gdbserver support for the qAuxVector
packet using a new target hook, implemented in the Linux backend.  

I tested the remote support using gdbserver on Linux, though I have not
tested any of the error cases (just saw "info auxv" work right via gdbserver).


Thanks,
Roland



2004-02-01  Roland McGrath  <roland@redhat.com>

	* gdb.texinfo (Auxiliary Vector): New node (section).
	(Data): Add it to the menu.
	(General Query Packets): Document qAuxVector query packet.

--- doc/gdb.texinfo.~1.190.~	2004-01-28 16:21:23.000000000 -0800
+++ doc/gdb.texinfo	2004-02-01 15:43:20.000000000 -0800
@@ -4684,6 +4684,7 @@ Table}.
 * Registers::                   Registers
 * Floating Point Hardware::     Floating point hardware
 * Vector Unit::                 Vector Unit
+* Auxiliary Vector::            Auxiliary data provided by operating system
 * Memory Region Attributes::    Memory region attributes
 * Dump/Restore Files::          Copy between memory and a file
 * Character Sets::              Debugging programs that use a different
@@ -5864,6 +5865,32 @@ Display information about the vector uni
 layout vary depending on the hardware.
 @end table
 
+@node Auxiliary Vector
+@section Operating system auxiliary vector
+@cindex auxiliary vector
+@cindex vector, auxiliary
+
+Some operating systems supply an @dfn{auxiliary vector} to programs at
+startup.  This is akin to the arguments and environment that you
+specify for a program, but contains a system-dependent variety of
+binary values that tell system libraries important details about the
+hardware, operating system, and process.  Each value's purpose is
+identified by an integer tag; the meanings are well-known but system-specific.
+Depending on the configuration and operating system facilities,
+@value{GDBN} may be able to show you this information.
+
+@table @code
+@kindex info auxv
+@item info auxv
+Display the auxiliary vector of the inferior, which can be either a
+live process or a core dump file.  @{GDBN} prints each tag value
+numerically, and also shows names and text descriptions for recognized
+tags.  Some values in the vector are numbers, some bit masks, and some
+pointers to strings or other data.  @{GDBN} displays each value in the
+most appropriate form for a recognized tag, and in hexadecimal for
+an unrecognized tag.
+@end table
+
 @node Memory Region Attributes
 @section Memory region attributes 
 @cindex memory region attributes
@@ -20363,6 +20390,18 @@ encoded).  @value{GDBN} will continue to
 (if available), until the target ceases to request them.
 @end table
 
+@item @code{qAuxVector}:@var{offset},@var{length} --- auxiliary vector data
+
+Read from the target's @dfn{auxiliary vector}, treated as an
+uninterpreted block of bytes.  Request @var{length} starting at
+@var{offset} bytes into the data.
+
+Reply:
+@table @samp
+@item @code{A=}@var{data}
+@var{data} (hex encoded) contains the data bytes read.
+@end table
+
 @end table
 
 @node Register Packet Format



2004-02-01  Roland McGrath  <roland@redhat.com>

	* remote.c (remote_protocol_qAuxVector): New variable.
	(init_all_packet_configs): Initialize it.
	(set_remote_protocol_qAuxVector_packet_cmd): New function.
	(show_remote_protocol_qAuxVector_packet_cmd): New function.
	(show_remote_cmd): Call it.
	(_initialize_remote): Initialize commands.
	(remote_xfer_partial): If enabled, use qAuxVector query to service
	TARGET_OBJECT_AUXV requests.

Index: remote.c
===================================================================
RCS file: /cvs/src/src/gdb/remote.c,v
retrieving revision 1.128
diff -u -b -p -r1.128 remote.c
--- remote.c	26 Jan 2004 23:07:00 -0000	1.128
+++ remote.c	2 Feb 2004 00:00:39 -0000
@@ -981,6 +981,23 @@ show_remote_protocol_binary_download_cmd
   show_packet_config_cmd (&remote_protocol_binary_download);
 }
 
+/* Should we try the 'qAuxVector' (target auxiliary vector read) request? */
+static struct packet_config remote_protocol_qAuxVector;
+
+static void
+set_remote_protocol_qAuxVector_packet_cmd (char *args, int from_tty,
+					   struct cmd_list_element *c)
+{
+  update_packet_config (&remote_protocol_qAuxVector);
+}
+
+static void
+show_remote_protocol_qAuxVector_packet_cmd (char *args, int from_tty,
+					    struct cmd_list_element *c)
+{
+  show_packet_config_cmd (&remote_protocol_qAuxVector);
+}
+
 
 /* Tokens for use by the asynchronous signal handlers for SIGINT */
 static void *sigint_remote_twice_token;
@@ -2070,6 +2087,7 @@ init_all_packet_configs (void)
   /* Force remote_write_bytes to check whether target supports binary
      downloading. */
   update_packet_config (&remote_protocol_binary_download);
+  update_packet_config (&remote_protocol_qAuxVector);
 }
 
 /* Symbol look-up. */
@@ -4872,6 +4890,42 @@ remote_xfer_partial (struct target_ops *
     case TARGET_OBJECT_AVR:
       query_type = 'R';
       break;
+
+    case TARGET_OBJECT_AUXV:
+      if (remote_protocol_qAuxVector.support != PACKET_DISABLE)
+	{
+	  unsigned int total = 0;
+	  while (len > 0)
+	    {
+	      LONGEST n = min ((rs->remote_packet_size - 2) / 2, len);
+	      snprintf (buf2, rs->remote_packet_size,
+			"qAuxVector:%s,%s",
+			phex_nz (offset, sizeof offset),
+			phex_nz (n, sizeof n));
+	      i = putpkt (buf2);
+	      if (i < 0)
+		return total > 0 ? total : i;
+	      buf2[0] = '\0';
+	      getpkt (buf2, rs->remote_packet_size, 0);
+	      if (packet_ok (buf2, &remote_protocol_qAuxVector) != PACKET_OK)
+		return total > 0 ? total : -1;
+	      if (buf2[0] != 'A' || buf2[1] != '=')
+		{
+		  warning ("Malformed response to qAuxVector: %s", buf2);
+		  return total > 0 ? total : i;
+		}
+	      i = hex2bin (&buf2[2], readbuf, len);
+	      if (i == 0)
+		break;
+	      readbuf = (void *) ((char *) readbuf + i);
+	      offset += i;
+	      len -= i;
+	      total += i;
+	    }
+	  return total;
+	}
+      return -1;
+
     default:
       return -1;
     }
@@ -5369,6 +5423,7 @@ show_remote_cmd (char *args, int from_tt
   show_remote_protocol_qSymbol_packet_cmd (args, from_tty, NULL);
   show_remote_protocol_vcont_packet_cmd (args, from_tty, NULL);
   show_remote_protocol_binary_download_cmd (args, from_tty, NULL);
+  show_remote_protocol_qAuxVector_packet_cmd (args, from_tty, NULL);
 }
 
 static void
@@ -5610,6 +5665,13 @@ in a memory packet.\n",
 			 "Z4", "access-watchpoint",
 			 set_remote_protocol_Z_access_wp_packet_cmd,
 			 show_remote_protocol_Z_access_wp_packet_cmd,
+			 &remote_set_cmdlist, &remote_show_cmdlist,
+			 0);
+
+  add_packet_config_cmd (&remote_protocol_qAuxVector,
+			 "qAuxVector", "read-aux-vector",
+			 set_remote_protocol_qAuxVector_packet_cmd,
+			 show_remote_protocol_qAuxVector_packet_cmd,
 			 &remote_set_cmdlist, &remote_show_cmdlist,
 			 0);



2004-02-01  Roland McGrath  <roland@redhat.com>

	* target.h (struct target_ops): New member `read_auxv'.
	* server.c (handle_query): Handle qAuxVector query using that hook.
	* linux-low.c (linux_read_auxv): New function.
	(linux_target_ops): Initialize `read_auxv' member to that.

Index: gdbserver/linux-low.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/linux-low.c,v
retrieving revision 1.27
diff -b -p -u -r1.27 linux-low.c
--- gdbserver/linux-low.c	31 Jan 2004 22:19:31 -0000	1.27
+++ gdbserver/linux-low.c	2 Feb 2004 00:00:02 -0000
@@ -1381,6 +1381,32 @@ linux_send_signal (int signum)
     kill (signal_pid, signum);
 }
 
+/* Copy LEN bytes from inferior's auxiliary vector starting at OFFSET
+   to debugger memory starting at MYADDR.  */
+
+static int
+linux_read_auxv (CORE_ADDR offset, char *myaddr, unsigned int len)
+{
+  char filename[PATH_MAX];
+  int fd, n;
+
+  snprintf (filename, sizeof filename, "/proc/%d/auxv", inferior_pid);
+
+  fd = open (filename, O_RDONLY);
+  if (fd < 0)
+    return -1;
+
+  if (offset != (CORE_ADDR) 0
+      && lseek (fd, (off_t) offset, SEEK_SET) != (off_t) offset)
+    n = -1;
+  else
+    n = read (fd, myaddr, len);
+
+  close (fd);
+
+  return n;
+}
+
 
 static struct target_ops linux_target_ops = {
   linux_create_inferior,
@@ -1396,6 +1422,7 @@ static struct target_ops linux_target_op
   linux_write_memory,
   linux_look_up_symbols,
   linux_send_signal,
+  linux_read_auxv,
 };
 
 static void
Index: gdbserver/server.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/server.c,v
retrieving revision 1.16
diff -b -p -u -r1.16 server.c
--- gdbserver/server.c	13 Oct 2003 16:17:21 -0000	1.16
+++ gdbserver/server.c	2 Feb 2004 00:00:02 -0000
@@ -120,6 +120,32 @@ handle_query (char *own_buf)
 	}
     }
       
+  if (strncmp ("qAuxVector:", own_buf, 11) == 0)
+    {
+      if (the_target->read_auxv == NULL)
+	strcpy (own_buf, "E00");
+      else
+	{
+	  char data[(PBUFSIZ - 3) / 2];
+	  CORE_ADDR ofs;
+	  unsigned int len;
+	  int n;
+	  decode_m_packet (&own_buf[11], &ofs, &len); /* "OFS,LEN" */
+	  if (len > sizeof data)
+	    len = sizeof data;
+	  n = (*the_target->read_auxv) (ofs, data, len);
+	  if (n < 0)
+	    strcpy (own_buf, "E00");
+	  else
+	    {
+	      own_buf[0] = 'A';
+	      own_buf[1] = '=';
+	      convert_int_to_ascii (data, &own_buf[2], n);
+	    }
+	}
+      return;
+    }
+
   /* Otherwise we didn't know what packet it was.  Say we didn't
      understand it.  */
   own_buf[0] = 0;
Index: gdbserver/target.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/target.h,v
retrieving revision 1.8
diff -b -p -u -r1.8 target.h
--- gdbserver/target.h	13 Oct 2003 16:17:21 -0000	1.8
+++ gdbserver/target.h	2 Feb 2004 00:00:02 -0000
@@ -125,6 +125,12 @@ struct target_ops
 
   /* Send a signal to the inferior process, however is appropriate.  */
   void (*send_signal) (int);
+
+  /* Read auxiliary vector data from the inferior process.
+
+     Read LEN bytes at OFFSET into a buffer at MYADDR.  */
+
+  int (*read_auxv) (CORE_ADDR offset, char *myaddr, unsigned int len);
 };
 
 extern struct target_ops *the_target;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]