This is the mail archive of the
gdb@sources.redhat.com
mailing list for the GDB project.
remote protocol support for TARGET_OBJECT_AUXV
- From: Roland McGrath <roland at redhat dot com>
- To: gdb at sources dot redhat dot com
- Date: Wed, 4 Feb 2004 15:58:46 -0800
- Subject: remote protocol support for TARGET_OBJECT_AUXV
I am proposing a new query packet `qAuxVector' to support reading
TARGET_OBJECT_AUXV data. Here's the proposed docs addition describing it.
After that, I've appended (short) patches implementing it in gdb and
gdbserver so you can see concretely what I mean.
Thanks,
Roland
Index: gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.192
diff -u -b -p -r1.192 gdb.texinfo
--- gdb.texinfo 4 Feb 2004 23:24:43 -0000 1.192
+++ gdb.texinfo 4 Feb 2004 23:56:55 -0000
@@ -20420,6 +20420,23 @@ The target does not need to look up any
The target requests the value of a new symbol @var{sym_name} (hex
encoded). @value{GDBN} will continue to supply the values of symbols
(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. (@xref{Auxiliary Vector}.)
+Request @var{length} bytes starting at @var{offset} bytes into the data.
+
+Reply:
+@table @samp
+@item @code{=}@var{data}
+@var{data} (hex encoded) contains the data bytes read.
+There is no more auxiliary data after what was requested.
+
+@item @code{+}@var{data}
+@var{data} (hex encoded) contains the data bytes read.
+There may be additional data that can be read with another request.
@end table
@end table
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 4 Feb 2004 23:56:37 -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,50 @@ 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;
+ switch (buf2[0])
+ {
+ case '=': /* Final data. */
+ return total + hex2bin (&buf2[1], readbuf, len);
+
+ case '+': /* Some data here, but there is more. */
+ i = hex2bin (&buf2[2], readbuf, len);
+ if (i > 0)
+ {
+ readbuf = (void *) ((char *) readbuf + i);
+ offset += i;
+ len -= i;
+ total += i;
+ break;
+ }
+
+ default:
+ warning ("Malformed response to qAuxVector: %s", buf2);
+ return total > 0 ? total : i;
+ }
+ }
+ return total;
+ }
+ return -1;
+
default:
return -1;
}
@@ -5369,6 +5431,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 +5673,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 4 Feb 2004 23:55:48 -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 4 Feb 2004 23:55:48 -0000
@@ -120,6 +120,31 @@ 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 - 2) / 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] = n < len ? '=' : '+';
+ convert_int_to_ascii (data, &own_buf[1], 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 4 Feb 2004 23:55:48 -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;