From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21402 invoked by alias); 31 Mar 2005 23:20:28 -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 21362 invoked from network); 31 Mar 2005 23:20:24 -0000 Received: from unknown (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org with SMTP; 31 Mar 2005 23:20:24 -0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.12.11/8.12.11) with ESMTP id j2VNKObx018025 for ; Thu, 31 Mar 2005 18:20:24 -0500 Received: from pobox.corp.redhat.com (pobox.corp.redhat.com [172.16.52.156]) by int-mx1.corp.redhat.com (8.11.6/8.11.6) with ESMTP id j2VNKOO03348 for ; Thu, 31 Mar 2005 18:20:24 -0500 Received: from localhost.localdomain (vpn50-40.rdu.redhat.com [172.16.50.40]) by pobox.corp.redhat.com (8.12.8/8.12.8) with ESMTP id j2VNKNwV028820 for ; Thu, 31 Mar 2005 18:20:24 -0500 Received: from ironwood.lan (ironwood.lan [192.168.64.8]) by localhost.localdomain (8.12.11/8.12.10) with ESMTP id j2VNKIEE032451 for ; Thu, 31 Mar 2005 16:20:18 -0700 Date: Thu, 31 Mar 2005 23:20:00 -0000 From: Kevin Buettner To: gdb-patches@sources.redhat.com Subject: [RFC] remote.c: Add remote TLS support Message-ID: <20050331162017.0e47552c@ironwood.lan> Organization: Red Hat Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-SW-Source: 2005-03/txt/msg00399.txt.bz2 The patch below adds remote TLS support. It is a rework of the remote.c portion of a patch posted late last year: http://sources.redhat.com/ml/gdb-patches/2004-12/msg00169.html In looking this over myself, the only thing that I find objectionable is that the new function show_remote_protocol_qGetTLSAddr_packet_cmd() calls the deprecated function deprecated_show_value_hack(). However, it doesn't make much sense to me to implement the set/show commands for the qGetTLSAddr packet differently from the support for the other protocol packets in remote.c. So, as I see it the alternatives are: 1) Allow this patch in even though it calls a deprecated function. 2) Convert the other functions that currently call deprecated_show_value_hack() to use some other mechanism. Then, resubmit this patch so that the new show_... function introduced in this patch uses the new machinery. Opinions? If (2) is the preferred route, could someone outline how the conversion to not use deprecated_show_value_hack() ought to be done? Kevin * remote.c (remote_protocol_qGetTLSAddr): New static global variable. (set_remote_protocol_qGetTLSAddr_packet_cmd) (show_remote_protocol_qGetTLSAddr_packet_cmd) (remote_get_thread_local_address): New functions. (init_all_packet_configs): Initialize remote_protocol_qGetTLSAddr variable. (init_remote_ops): Initialize ``to_get_thread_local_address'' in target vector. (show_remote_cmd): Call show_remote_protocol_qGetTLS_Addr_packet_cmd(). (_initialize_remote): Add support for the "set remote get-thread-local-storage-address-packet' and "show remote get-thread-local-address-packet" commands. Index: remote.c =================================================================== RCS file: /cvs/src/src/gdb/remote.c,v retrieving revision 1.179 diff -u -p -r1.179 remote.c --- remote.c 25 Mar 2005 20:39:45 -0000 1.179 +++ remote.c 31 Mar 2005 21:50:35 -0000 @@ -982,6 +982,25 @@ show_remote_protocol_qPart_auxv_packet_c show_packet_config_cmd (&remote_protocol_qPart_auxv); } +/* Should we try the 'qGetTLSAddr' (Get Thread Local Storage Address) request? */ +static struct packet_config remote_protocol_qGetTLSAddr; + +static void +set_remote_protocol_qGetTLSAddr_packet_cmd (char *args, int from_tty, + struct cmd_list_element *c) +{ + update_packet_config (&remote_protocol_qGetTLSAddr); +} + +static void +show_remote_protocol_qGetTLSAddr_packet_cmd (struct ui_file *file, int from_tty, + struct cmd_list_element *c, + const char *value) +{ + deprecated_show_value_hack (file, from_tty, c, value); + show_packet_config_cmd (&remote_protocol_qGetTLSAddr); +} + static struct packet_config remote_protocol_p; static void @@ -2111,6 +2130,7 @@ init_all_packet_configs (void) downloading. */ update_packet_config (&remote_protocol_binary_download); update_packet_config (&remote_protocol_qPart_auxv); + update_packet_config (&remote_protocol_qGetTLSAddr); } /* Symbol look-up. */ @@ -5330,6 +5350,58 @@ remote_pid_to_str (ptid_t ptid) return buf; } +/* Get the address of the thread local variable in OBJFILE which is + stored at OFFSET within the thread local storage for thread PTID. */ + +static CORE_ADDR +remote_get_thread_local_address (ptid_t ptid, CORE_ADDR lm, CORE_ADDR offset) +{ + if (remote_protocol_qGetTLSAddr.support != PACKET_DISABLE) + { + struct remote_state *rs = get_remote_state (); + char *buf = alloca (rs->remote_packet_size); + char *p = buf; + int status, argcnt; + ULONGEST *extra_args; + + strcpy (p, "qGetTLSAddr:"); + p += strlen (p); + p += hexnumstr (p, PIDGET (ptid)); + *p++ = ','; + p += hexnumstr (p, offset); + *p++ = ','; + p += hexnumstr (p, lm); + *p++ = '\0'; + + putpkt (buf); + getpkt (buf, rs->remote_packet_size, 0); + if (packet_ok (buf, &remote_protocol_qGetTLSAddr) == PACKET_OK) + { + ULONGEST result; + + unpack_varlen_hex (buf, &result); + return result; + } + else + { + struct exception e + = { RETURN_ERROR, TLS_GENERIC_ERROR, + "Remote target failed to process qGetTLSAddr request" }; + throw_exception (e); + + } + } + else + { + struct exception e + = { RETURN_ERROR, TLS_GENERIC_ERROR, + "TLS not supported or disabled on this target" }; + throw_exception (e); + } + /* Not reached. */ + return 0; +} + static void init_remote_ops (void) { @@ -5369,6 +5441,7 @@ Specify the serial device it is connecte remote_ops.to_stop = remote_stop; remote_ops.to_xfer_partial = remote_xfer_partial; remote_ops.to_rcmd = remote_rcmd; + remote_ops.to_get_thread_local_address = remote_get_thread_local_address; remote_ops.to_stratum = process_stratum; remote_ops.to_has_all_memory = 1; remote_ops.to_has_memory = 1; @@ -5544,6 +5617,7 @@ show_remote_cmd (char *args, int from_tt show_remote_protocol_vcont_packet_cmd (gdb_stdout, from_tty, NULL, NULL); show_remote_protocol_binary_download_cmd (gdb_stdout, from_tty, NULL, NULL); show_remote_protocol_qPart_auxv_packet_cmd (gdb_stdout, from_tty, NULL, NULL); + show_remote_protocol_qGetTLSAddr_packet_cmd (gdb_stdout, from_tty, NULL, NULL); } static void @@ -5774,6 +5848,13 @@ Show the maximum size of the address (in &remote_set_cmdlist, &remote_show_cmdlist, 0); + add_packet_config_cmd (&remote_protocol_qGetTLSAddr, + "qGetTLSAddr", "get-thread-local-storage-address", + set_remote_protocol_qGetTLSAddr_packet_cmd, + show_remote_protocol_qGetTLSAddr_packet_cmd, + &remote_set_cmdlist, &remote_show_cmdlist, + 0); + /* Keep the old ``set remote Z-packet ...'' working. */ add_setshow_auto_boolean_cmd ("Z-packet", class_obscure, &remote_Z_packet_detect, _("\