From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12796 invoked by alias); 25 Feb 2004 19:42:02 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 12786 invoked from network); 25 Feb 2004 19:42:00 -0000 Received: from unknown (HELO gateway.sf.frob.com) (64.81.54.130) by sources.redhat.com with SMTP; 25 Feb 2004 19:42:00 -0000 Received: from magilla.sf.frob.com (magilla.sf.frob.com [198.49.250.228]) by gateway.sf.frob.com (Postfix) with ESMTP id D02AB357B; Wed, 25 Feb 2004 11:41:59 -0800 (PST) Received: from magilla.sf.frob.com (localhost.localdomain [127.0.0.1]) by magilla.sf.frob.com (8.12.9/8.12.9) with ESMTP id i1PJfxOi004867; Wed, 25 Feb 2004 11:41:59 -0800 Received: (from roland@localhost) by magilla.sf.frob.com (8.12.9/8.12.9/Submit) id i1PJfx4p004863; Wed, 25 Feb 2004 11:41:59 -0800 Date: Wed, 25 Feb 2004 19:42:00 -0000 Message-Id: <200402251941.i1PJfx4p004863@magilla.sf.frob.com> From: Roland McGrath To: gdb-patches@sources.redhat.com Subject: [PATCH] remote protocol support for TARGET_OBJECT_AUXV Emacs: because Hell was full. X-SW-Source: 2004-02/txt/msg00735.txt.bz2 This patch implements the remote support for auxv access. The new protocol bits were just committed to gdb.texinfo, which see. Here is the patch for the gdb side, followed by the patch implementing the stub side for gdbserver on GNU/Linux. Thanks, Roland 2004-02-25 Roland McGrath * remote.c (remote_protocol_qPart_auxv): New variable. (init_all_packet_configs): Initialize it. (set_remote_protocol_qPart_auxv_packet_cmd): New function. (show_remote_protocol_qPart_auxv_packet_cmd): New function. (show_remote_cmd): Call it. (_initialize_remote): Initialize commands. (remote_xfer_partial): If enabled, use qPart:auxv:read:... query to service TARGET_OBJECT_AUXV requests. Index: remote.c =================================================================== RCS file: /cvs/src/src/gdb/remote.c,v retrieving revision 1.129 diff -b -p -u -r1.129 remote.c --- remote.c 15 Feb 2004 15:22:06 -0000 1.129 +++ remote.c 25 Feb 2004 19:38:03 -0000 @@ -981,6 +981,23 @@ show_remote_protocol_binary_download_cmd show_packet_config_cmd (&remote_protocol_binary_download); } +/* Should we try the 'qPart:auxv' (target auxiliary vector read) request? */ +static struct packet_config remote_protocol_qPart_auxv; + +static void +set_remote_protocol_qPart_auxv_packet_cmd (char *args, int from_tty, + struct cmd_list_element *c) +{ + update_packet_config (&remote_protocol_qPart_auxv); +} + +static void +show_remote_protocol_qPart_auxv_packet_cmd (char *args, int from_tty, + struct cmd_list_element *c) +{ + show_packet_config_cmd (&remote_protocol_qPart_auxv); +} + /* 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_qPart_auxv); } /* Symbol look-up. */ @@ -4872,6 +4890,41 @@ remote_xfer_partial (struct target_ops * case TARGET_OBJECT_AVR: query_type = 'R'; break; + + case TARGET_OBJECT_AUXV: + if (remote_protocol_qPart_auxv.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, + "qPart:auxv:read::%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_qPart_auxv) != PACKET_OK) + return total > 0 ? total : -1; + if (buf2[0] == 'O' && buf2[1] == 'K' && buf2[2] == '\0') + break; /* Got EOF indicator. */ + /* Got some data. */ + i = hex2bin (buf2, readbuf, len); + if (i > 0) + { + readbuf = (void *) ((char *) readbuf + i); + offset += i; + len -= i; + total += i; + } + } + return total; + } + return -1; + default: return -1; } @@ -5369,6 +5422,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_qPart_auxv_packet_cmd (args, from_tty, NULL); } static void @@ -5609,6 +5663,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_qPart_auxv, + "qPart_auxv", "read-aux-vector", + set_remote_protocol_qPart_auxv_packet_cmd, + show_remote_protocol_qPart_auxv_packet_cmd, &remote_set_cmdlist, &remote_show_cmdlist, 0); 2004-02-25 Roland McGrath * target.h (struct target_ops): New member `read_auxv'. * server.c (handle_query): Handle qPart:auxv:read: query using that. * 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 25 Feb 2004 19:38:03 -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 25 Feb 2004 19:38:03 -0000 @@ -120,6 +120,26 @@ handle_query (char *own_buf) } } + if (the_target->read_auxv != NULL + && strncmp ("qPart:auxv:read::", own_buf, 17) == 0) + { + char data[(PBUFSIZ - 1) / 2]; + CORE_ADDR ofs; + unsigned int len; + int n; + decode_m_packet (&own_buf[17], &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, "OK"); + else if (n < 0) + write_enn (own_buf); + else + convert_int_to_ascii (data, own_buf, 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 25 Feb 2004 19:38:03 -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;