From patchwork Thu Oct 1 11:54:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Tmd1eeG7hW4gVGjDoWkgTmfhu41jIER1eQ==?= X-Patchwork-Id: 8900 Received: (qmail 15673 invoked by alias); 1 Oct 2015 11:54:39 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 15579 invoked by uid 89); 1 Oct 2015 11:54:39 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-pa0-f49.google.com Received: from mail-pa0-f49.google.com (HELO mail-pa0-f49.google.com) (209.85.220.49) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Thu, 01 Oct 2015 11:54:36 +0000 Received: by pacfv12 with SMTP id fv12so74364086pac.2 for ; Thu, 01 Oct 2015 04:54:35 -0700 (PDT) X-Received: by 10.66.218.66 with SMTP id pe2mr11884254pac.13.1443700474914; Thu, 01 Oct 2015 04:54:34 -0700 (PDT) Received: from lanh ([171.232.94.118]) by smtp.gmail.com with ESMTPSA id i9sm6252759pbq.84.2015.10.01.04.54.32 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Oct 2015 04:54:34 -0700 (PDT) Received: by lanh (sSMTP sendmail emulation); Thu, 01 Oct 2015 18:55:12 +0700 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= To: gdb-patches@sourceware.org Cc: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Subject: [PATCH 2/3] gdb/remote.c: support getting thread names with qThreadName Date: Thu, 1 Oct 2015 18:54:55 +0700 Message-Id: <1443700496-2936-3-git-send-email-pclouds@gmail.com> In-Reply-To: <1443700496-2936-1-git-send-email-pclouds@gmail.com> References: <1443700496-2936-1-git-send-email-pclouds@gmail.com> MIME-Version: 1.0 X-IsSubscribed: yes Signed-off-by: Nguyễn Thái Ngọc Duy --- gdb/remote.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/gdb/remote.c b/gdb/remote.c index f40f791..89c2baf 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -1478,6 +1478,9 @@ enum { /* Support for query supported vCont actions. */ PACKET_vContSupported, + /* Support for query thread name. */ + PACKET_qThreadName, + PACKET_MAX }; @@ -4392,7 +4395,8 @@ static const struct protocol_feature remote_protocol_features[] = { PACKET_exec_event_feature }, { "Qbtrace-conf:pt:size", PACKET_DISABLE, remote_supported_packet, PACKET_Qbtrace_conf_pt_size }, - { "vContSupported", PACKET_DISABLE, remote_supported_packet, PACKET_vContSupported } + { "vContSupported", PACKET_DISABLE, remote_supported_packet, PACKET_vContSupported }, + { "qThreadName", PACKET_DISABLE, remote_supported_packet, PACKET_qThreadName } }; static char *remote_support_xml; @@ -4488,6 +4492,9 @@ remote_query_supported (void) if (packet_set_cmd_state (PACKET_vContSupported) != AUTO_BOOLEAN_FALSE) q = remote_query_supported_append (q, "vContSupported+"); + if (packet_set_cmd_state (PACKET_qThreadName) != AUTO_BOOLEAN_FALSE) + q = remote_query_supported_append (q, "qThreadName+"); + q = reconcat (q, "qSupported:", q, (char *) NULL); putpkt (q); @@ -10243,6 +10250,52 @@ remote_pid_to_str (struct target_ops *ops, ptid_t ptid) } } +/* Convert a thread ID to a string. Returns the string in a static + buffer. */ + +static char * +remote_thread_name (struct target_ops *ops, struct thread_info *thr) +{ + if (packet_support (PACKET_qThreadName) != PACKET_DISABLE) + { + struct remote_state *rs = get_remote_state (); + char *p = rs->buf; + char *endp = rs->buf + get_remote_packet_size (); + enum packet_result result; + + strcpy (p, "qThreadName:"); + p += strlen (p); + p = write_ptid (p, endp, thr->ptid); + *p++ = '\0'; + + putpkt (rs->buf); + getpkt (&rs->buf, &rs->buf_size, 0); + result = packet_ok (rs->buf, + &remote_protocol_packets[PACKET_qThreadName]); + if (result == PACKET_OK) + { +#define COMM_LEN 16 /* from linux-nat.c */ + static char name[COMM_LEN + 1]; + ULONGEST ignored; + + p = unpack_varlen_hex (rs->buf, &ignored); + if (*p != ';') + error (_("invalid qThreadName packet: %s"), rs->buf); + strncpy(name, p + 1, COMM_LEN); + name[COMM_LEN] = '\0'; + return name; + } + else if (result == PACKET_UNKNOWN) + throw_error (TLS_GENERIC_ERROR, + _("Remote target doesn't support qThreadName packet")); + else + throw_error (TLS_GENERIC_ERROR, + _("Remote target failed to process qThreadName request")); + } + + return NULL; +} + /* Get the address of the thread local variable in OBJFILE which is stored at OFFSET within the thread local storage for thread PTID. */ @@ -12744,6 +12797,7 @@ Specify the serial device it is connected to\n\ remote_ops.to_thread_alive = remote_thread_alive; remote_ops.to_update_thread_list = remote_update_thread_list; remote_ops.to_pid_to_str = remote_pid_to_str; + remote_ops.to_thread_name = remote_thread_name; remote_ops.to_extra_thread_info = remote_threads_extra_info; remote_ops.to_get_ada_task_ptid = remote_get_ada_task_ptid; remote_ops.to_stop = remote_stop; @@ -13485,6 +13539,9 @@ Show the maximum size of the address (in bits) in a memory packet."), NULL, add_packet_config_cmd (&remote_protocol_packets[PACKET_exec_event_feature], "exec-event-feature", "exec-event-feature", 0); + add_packet_config_cmd (&remote_protocol_packets[PACKET_qThreadName], + "qThreadName", "thread-name", 0); + /* Assert that we've registered "set remote foo-packet" commands for all packet configs. */ {