From patchwork Thu Jun 1 14:49:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 100938 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp843369qge; Thu, 1 Jun 2017 07:53:16 -0700 (PDT) X-Received: by 10.55.17.11 with SMTP id b11mr2319271qkh.5.1496328796012; Thu, 01 Jun 2017 07:53:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496328796; cv=none; d=google.com; s=arc-20160816; b=Ps1UMAeIjPA4IpG7Nlpl6SvmC/+xrIJYXgbk0xhx2VErWcLjak0vLofT/TLI3w8Spd x5KJctLW1ibqgSTn08ZUVjrk399X/9vGpFABLy+Cfi3oWLMYE4QwXHLJ59VaIpVHm1FK O0aEwz4cN3znquxiKilpTh/2z+C4Hp4HVbsBGMytys26fO1iDcBLItprZEUWwWAvvAYE sOXtJDswSKH7VCBdMdEvm/oUE5hnyITKd8XhSdv+H1RsU+pUGnsEJRwyYAV5qKGdXPlA 633ZIpP3c65+G++CLZKH7K02JG0AP0TVc7cLVX5Na5A3Py2kWbqtw3M93n19GtyBte0Q +vVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=NOnco/Cvx2mg6+/Y/0FweVdPOcj5yDorUWvINKyGrJA=; b=eXTbAzMKwFFv4BMruXjCuiifd7dR9wCCPNVb0CaEjCPnDsgV5KmlL83MwMRCbAGBYR p8d2LcYLp9Eg0FedZiAvQPlt+KDBy5i5zJzt6jsgm4BZKQMq9RBf10091VVwDIintGnF xFJkvXZIhloL0TgqIP08RvZ4e3LLC/HD+ACoE17ImXV6XK611fB9t1wmSmUQu6zpJoNE NjxxGcvLb0+fB1JtyMb2CrSbVptzyUGv/CFoadLSR9Uh5yxVQIco+JPYl4TM7ddUhmYV YMvhUz5tgFoOlDoxLNEjE2D4k9SIZfbFLWr96DxGQBBAEhcy6sGDV3JgJ4/ln1e8Cjzv pvLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id a85si8568483qka.152.2017.06.01.07.53.15 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 01 Jun 2017 07:53:16 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:45065 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGRTN-0007Kp-EC for patch@linaro.org; Thu, 01 Jun 2017 10:53:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43967) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGRPM-0004Y9-JT for qemu-devel@nongnu.org; Thu, 01 Jun 2017 10:49:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGRPK-0002Vc-Ny for qemu-devel@nongnu.org; Thu, 01 Jun 2017 10:49:04 -0400 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]:35591) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGRPK-0002VC-EE for qemu-devel@nongnu.org; Thu, 01 Jun 2017 10:49:02 -0400 Received: by mail-wm0-x234.google.com with SMTP id b84so161718946wmh.0 for ; Thu, 01 Jun 2017 07:49:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NOnco/Cvx2mg6+/Y/0FweVdPOcj5yDorUWvINKyGrJA=; b=Y+m2I4E8TmjvkKUcVAjO7hSriNPLrH213SjTL5BLE2Kf5L9HsUhKRBHFJkdZtrXpeM WgVrBYUtZyX12SH0tkncVNzGHGX5xgy3vIrSUkUcwA2pXG3GB9dVP9Kw48N9wMs9lu+J tM0mE8hswicnophvQgKMB+u3Dw17Ybn2bTva8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NOnco/Cvx2mg6+/Y/0FweVdPOcj5yDorUWvINKyGrJA=; b=ceXnY6xkQivgqlYC6QwPdRUAk6XHDs/kZTNGohmPU/jc1wi3x2etj2NekbOGptv4Ub kC7htxdcrI7EA1z/4oZTNLUqTd87v4N6d69upOCGfKG/dXSGTXKL7+xgiRYc53F7S4F4 cFYHXQm8Zn6pHQtw4kTmSCxpl9TOgpVzh0dxLPuvWG+B6q3ZNQroWYYVw+V2+H1CfFqO CE1gxgcqotUr7aIB4p54m21Romh7/i7MZvZfMG/e+0vc2zAuaCOlwlyz4A9Ouy6A6WZ5 txjNfKgLAh1OXsQqOfZ5DBQR77qAjy8TeYq8PgQMVTrtceqViBXLbHLTswiOc1JCjxph z+fg== X-Gm-Message-State: AODbwcDDS7AUarSflOyJ/18oohbL65yblm2wah6q82mgjem+2PxNlPgw fk316cIP1ZEm7j+b X-Received: by 10.28.133.210 with SMTP id h201mr2149655wmd.3.1496328541135; Thu, 01 Jun 2017 07:49:01 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id j65sm25162535wmg.0.2017.06.01.07.48.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 07:48:57 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 5EDCC3E0422; Thu, 1 Jun 2017 15:49:15 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: pbonzini@redhat.com, doug16k@gmail.com, imbrenda@linux.vnet.ibm.com Date: Thu, 1 Jun 2017 15:49:12 +0100 Message-Id: <20170601144915.20778-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170601144915.20778-1-alex.bennee@linaro.org> References: <20170601144915.20778-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::234 Subject: [Qemu-devel] [PATCH v2 1/4] gdbstub: modernise DEBUG_GDB X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Convert the a gdb_debug helper which compiles away to nothing when not used but still ensures the format strings are checked. There is some minor code motion for the incorrect checksum message to report it before we attempt to send the reply. Signed-off-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Greg Kurz --- gdbstub.c | 77 +++++++++++++++++++++++++++------------------------------------ 1 file changed, 33 insertions(+), 44 deletions(-) -- 2.13.0 diff --git a/gdbstub.c b/gdbstub.c index 86eed4f97c..a249846954 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -271,7 +271,20 @@ static int gdb_signal_to_target (int sig) return -1; } -//#define DEBUG_GDB +/* #define DEBUG_GDB */ + +#ifdef DEBUG_GDB +# define DEBUG_GDB_GATE 1 +#else +# define DEBUG_GDB_GATE 0 +#endif + +#define gdb_debug(fmt, ...) do { \ + if (DEBUG_GDB_GATE) { \ + fprintf(stderr, "%s: " fmt, __func__, ## __VA_ARGS__); \ + } \ +} while (0) + typedef struct GDBRegisterState { int base_reg; @@ -547,9 +560,7 @@ static int put_packet_binary(GDBState *s, const char *buf, int len) /* return -1 if error, 0 if OK */ static int put_packet(GDBState *s, const char *buf) { -#ifdef DEBUG_GDB - printf("reply='%s'\n", buf); -#endif + gdb_debug("reply='%s'\n", buf); return put_packet_binary(s, buf, strlen(buf)); } @@ -955,9 +966,9 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) uint8_t *registers; target_ulong addr, len; -#ifdef DEBUG_GDB - printf("command='%s'\n", line_buf); -#endif + + gdb_debug("command='%s'\n", line_buf); + p = line_buf; ch = *p++; switch(ch) { @@ -1518,17 +1529,14 @@ static void gdb_read_byte(GDBState *s, int ch) /* Waiting for a response to the last packet. If we see the start of a new command then abandon the previous response. */ if (ch == '-') { -#ifdef DEBUG_GDB - printf("Got NACK, retransmitting\n"); -#endif + gdb_debug("Got NACK, retransmitting\n"); put_buffer(s, (uint8_t *)s->last_packet, s->last_packet_len); + } else if (ch == '+') { + gdb_debug("Got ACK\n"); + } else { + gdb_debug("Got '%c' when expecting ACK/NACK\n", ch); } -#ifdef DEBUG_GDB - else if (ch == '+') - printf("Got ACK\n"); - else - printf("Got '%c' when expecting ACK/NACK\n", ch); -#endif + if (ch == '+' || ch == '$') s->last_packet_len = 0; if (ch != '$') @@ -1549,9 +1557,7 @@ static void gdb_read_byte(GDBState *s, int ch) s->line_sum = 0; s->state = RS_GETLINE; } else { -#ifdef DEBUG_GDB - printf("gdbstub received garbage between packets: 0x%x\n", ch); -#endif + gdb_debug("received garbage between packets: 0x%x\n", ch); } break; case RS_GETLINE: @@ -1567,9 +1573,7 @@ static void gdb_read_byte(GDBState *s, int ch) /* end of command, start of checksum*/ s->state = RS_CHKSUM1; } else if (s->line_buf_index >= sizeof(s->line_buf) - 1) { -#ifdef DEBUG_GDB - printf("gdbstub command buffer overrun, dropping command\n"); -#endif + gdb_debug("command buffer overrun, dropping command\n"); s->state = RS_IDLE; } else { /* unescaped command character */ @@ -1583,9 +1587,7 @@ static void gdb_read_byte(GDBState *s, int ch) s->state = RS_CHKSUM1; } else if (s->line_buf_index >= sizeof(s->line_buf) - 1) { /* command buffer overrun */ -#ifdef DEBUG_GDB - printf("gdbstub command buffer overrun, dropping command\n"); -#endif + gdb_debug("command buffer overrun, dropping command\n"); s->state = RS_IDLE; } else { /* parse escaped character and leave escape state */ @@ -1597,25 +1599,18 @@ static void gdb_read_byte(GDBState *s, int ch) case RS_GETLINE_RLE: if (ch < ' ') { /* invalid RLE count encoding */ -#ifdef DEBUG_GDB - printf("gdbstub got invalid RLE count: 0x%x\n", ch); -#endif + gdb_debug("got invalid RLE count: 0x%x\n", ch); s->state = RS_GETLINE; } else { /* decode repeat length */ int repeat = (unsigned char)ch - ' ' + 3; if (s->line_buf_index + repeat >= sizeof(s->line_buf) - 1) { /* that many repeats would overrun the command buffer */ -#ifdef DEBUG_GDB - printf("gdbstub command buffer overrun," - " dropping command\n"); -#endif + gdb_debug("command buffer overrun, dropping command\n"); s->state = RS_IDLE; } else if (s->line_buf_index < 1) { /* got a repeat but we have nothing to repeat */ -#ifdef DEBUG_GDB - printf("gdbstub got invalid RLE sequence\n"); -#endif + gdb_debug("got invalid RLE sequence\n"); s->state = RS_GETLINE; } else { /* repeat the last character */ @@ -1630,9 +1625,7 @@ static void gdb_read_byte(GDBState *s, int ch) case RS_CHKSUM1: /* get high hex digit of checksum */ if (!isxdigit(ch)) { -#ifdef DEBUG_GDB - printf("gdbstub got invalid command checksum digit\n"); -#endif + gdb_debug("got invalid command checksum digit\n"); s->state = RS_GETLINE; break; } @@ -1643,21 +1636,17 @@ static void gdb_read_byte(GDBState *s, int ch) case RS_CHKSUM2: /* get low hex digit of checksum */ if (!isxdigit(ch)) { -#ifdef DEBUG_GDB - printf("gdbstub got invalid command checksum digit\n"); -#endif + gdb_debug("got invalid command checksum digit\n"); s->state = RS_GETLINE; break; } s->line_csum |= fromhex(ch); if (s->line_csum != (s->line_sum & 0xff)) { + gdb_debug("got command packet with incorrect checksum\n"); /* send NAK reply */ reply = '-'; put_buffer(s, &reply, 1); -#ifdef DEBUG_GDB - printf("gdbstub got command packet with incorrect checksum\n"); -#endif s->state = RS_IDLE; } else { /* send ACK reply */ From patchwork Thu Jun 1 14:49:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 100937 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp843280qge; Thu, 1 Jun 2017 07:53:03 -0700 (PDT) X-Received: by 10.55.25.41 with SMTP id k41mr2142994qkh.163.1496328783546; Thu, 01 Jun 2017 07:53:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496328783; cv=none; d=google.com; s=arc-20160816; b=lNuCxpJp41TONZvOAviSpaq0cix9Fr4pV4lhhbgvVS/u7UDqn7H4DKESD8QNxqZFdH Kf3HUIRnXi6Vg7Jrg0GTerkBRi3KnRqtHe5+JKm5OoltVoFwatWawF2KsapufAIitIoG 2P88l3o0XN+2SXaiw8VRzosdCmDFwyr89gfPwBh0Opl06zvTkwlVhoo+x+mxkxVvwx12 HKeLrZz/nKlROCrTKxA/XJwBwT4S7m9U1xedK3PHC7iEaSspAWRHJHfrboZQvy5ShAD0 akg7K1E+cNmzs1mbLjoyA7AUiKWFlrtDlhap3U/POdbYwU+b9Sjkjfl4+29XVgVB+Rj5 JC7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=nFQz955pVf6XYmLR/H9E6SlZOO9vXhykp50f21v7cj8=; b=nncPPK2dt8d0rse5lE9DwduCqCg9tUf/WGOOgt9HfWUSrDn4w7uPlmyPGRmq5BjoD3 Qlu6SicMPKf4CkV2ekqv6BavCvFhgdhdhPkBBR5LRnJKAZumTfIxOhJ/K7S1hP4rwgow mLwtRPnaukEHDSn86zSCNV+CndfwmdNSUsvFOB8qIFbLgTB6sEwVazaHGy6PBkUceVTo HN5samaiUzlk3g1UqtEcpIoQktvdvRTTMwOz2VOJUwq/SfUb92g0JxGEosH/tKqs/D/1 9/c1gGE/nOmQg4fvq+N4L6Mwhoz/corH/2lHDtfuAlr4B3f/eXIO2WiKjrpwcSrBXLCT iQtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id u128si19366173qkf.227.2017.06.01.07.53.03 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 01 Jun 2017 07:53:03 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:45064 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGRTB-00076R-1P for patch@linaro.org; Thu, 01 Jun 2017 10:53:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43995) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGRPP-0004ZP-GE for qemu-devel@nongnu.org; Thu, 01 Jun 2017 10:49:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGRPJ-0002Uz-GC for qemu-devel@nongnu.org; Thu, 01 Jun 2017 10:49:07 -0400 Received: from mail-wm0-x229.google.com ([2a00:1450:400c:c09::229]:38393) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGRPJ-0002UK-96 for qemu-devel@nongnu.org; Thu, 01 Jun 2017 10:49:01 -0400 Received: by mail-wm0-x229.google.com with SMTP id n195so35525007wmg.1 for ; Thu, 01 Jun 2017 07:49:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nFQz955pVf6XYmLR/H9E6SlZOO9vXhykp50f21v7cj8=; b=LOIbfVuNRJYlctX+i1nU9VDFP+8fYZkBNjbVpolncPyO3ug0M8beflPrucg9c0xttB 1TBJzc8C2aJjBZiCSN3s44v3FJagMt4u0juEfASPNYNjAzqYstWS0M9eRRZLmbPXkV6x eH6U3OsUBG6a23cDKUCkCy0ag0iRLYm8//qC8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nFQz955pVf6XYmLR/H9E6SlZOO9vXhykp50f21v7cj8=; b=YHTbXHFn+Z6Yh9rbuD/S+LcvpKzfrE8d6J7rLhERKPaDc5XrrV6YLynF+WA4qitnbe 4IgpwbrnBuHXeXiAOeE8/a8H+50N3jnEONxnMKurMo9rsz00tvJ9hL++kMkCoi8V566G vLa8njSSfe0yZjeKnH8XDxjZEOmnKSkQZRCzYKEf2lObXPVJRzEZM8XWbM6CKVhF7X+E PWQAQoTG7wxgE3zQu8KjMsb9wr3ioLwAi1nwh4HDLjJUezjE2hLi0XFr712mIuMZgWpp CA3XrHX63pzTGEijbiyA7vRwEienQxCTvBSnXtwFRckH9QKe7LXLllyQC7xZ3wjcZKiI bb/w== X-Gm-Message-State: AODbwcC5zfEz+s5zSpVoK+cVG3SALvoMPKXHCQ2P5QFQP5JCMRIiCQxF 8a4p+Ptf1bU5NluB X-Received: by 10.28.30.139 with SMTP id e133mr2141101wme.71.1496328540091; Thu, 01 Jun 2017 07:49:00 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id o49sm17880823wrb.47.2017.06.01.07.48.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 07:48:57 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 70F9B3E0488; Thu, 1 Jun 2017 15:49:15 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: pbonzini@redhat.com, doug16k@gmail.com, imbrenda@linux.vnet.ibm.com Date: Thu, 1 Jun 2017 15:49:13 +0100 Message-Id: <20170601144915.20778-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170601144915.20778-1-alex.bennee@linaro.org> References: <20170601144915.20778-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::229 Subject: [Qemu-devel] [PATCH v2 2/4] gdbstub: rename cpu_index -> cpu_gdb_index X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This is to make it clear the index is purely a gdbstub function and should not be confused with the value of cpu->cpu_index. Signed-off-by: Alex Bennée --- gdbstub.c | 12 ++++++------ include/exec/gdbstub.h | 7 ++++++- 2 files changed, 12 insertions(+), 7 deletions(-) -- 2.13.0 Reviewed-by: Greg Kurz Reviewed-by: Claudio Imbrenda Reviewed-by: Philippe Mathieu-Daudé diff --git a/gdbstub.c b/gdbstub.c index a249846954..026d1fe6bb 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -837,7 +837,7 @@ static CPUState *find_cpu(uint32_t thread_id) CPUState *cpu; CPU_FOREACH(cpu) { - if (cpu_index(cpu) == thread_id) { + if (cpu_gdb_index(cpu) == thread_id) { return cpu; } } @@ -925,7 +925,7 @@ static int gdb_handle_vcont(GDBState *s, const char *p) idx = tmp; /* 0 means any thread, so we pick the first valid CPU */ if (!idx) { - idx = cpu_index(first_cpu); + idx = cpu_gdb_index(first_cpu); } /* @@ -975,7 +975,7 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) case '?': /* TODO: Make this return the correct value for user-mode. */ snprintf(buf, sizeof(buf), "T%02xthread:%02x;", GDB_SIGNAL_TRAP, - cpu_index(s->c_cpu)); + cpu_gdb_index(s->c_cpu)); put_packet(s, buf); /* Remove all the breakpoints when this query is issued, * because gdb is doing and initial connect and the state @@ -1243,7 +1243,7 @@ static int gdb_handle_packet(GDBState *s, const char *line_buf) } else if (strcmp(p,"sThreadInfo") == 0) { report_cpuinfo: if (s->query_cpu) { - snprintf(buf, sizeof(buf), "m%x", cpu_index(s->query_cpu)); + snprintf(buf, sizeof(buf), "m%x", cpu_gdb_index(s->query_cpu)); put_packet(s, buf); s->query_cpu = CPU_NEXT(s->query_cpu); } else @@ -1400,7 +1400,7 @@ static void gdb_vm_state_change(void *opaque, int running, RunState state) } snprintf(buf, sizeof(buf), "T%02xthread:%02x;%swatch:" TARGET_FMT_lx ";", - GDB_SIGNAL_TRAP, cpu_index(cpu), type, + GDB_SIGNAL_TRAP, cpu_gdb_index(cpu), type, (target_ulong)cpu->watchpoint_hit->vaddr); cpu->watchpoint_hit = NULL; goto send_packet; @@ -1434,7 +1434,7 @@ static void gdb_vm_state_change(void *opaque, int running, RunState state) break; } gdb_set_stop_cpu(cpu); - snprintf(buf, sizeof(buf), "T%02xthread:%02x;", ret, cpu_index(cpu)); + snprintf(buf, sizeof(buf), "T%02xthread:%02x;", ret, cpu_gdb_index(cpu)); send_packet: put_packet(s, buf); diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index f9708bbcd6..c4fe567600 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -58,7 +58,12 @@ void gdb_register_coprocessor(CPUState *cpu, gdb_reg_cb get_reg, gdb_reg_cb set_reg, int num_regs, const char *xml, int g_pos); -static inline int cpu_index(CPUState *cpu) +/* Return the GDB index for a given vCPU state. + * + * For user mode this is simply the thread id. In system mode GDB + * numbers CPUs from 1 as 0 is reserved as an "any cpu" index. + */ +static inline int cpu_gdb_index(CPUState *cpu) { #if defined(CONFIG_USER_ONLY) return cpu->host_tid; From patchwork Thu Jun 1 14:49:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 100934 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp842145qge; Thu, 1 Jun 2017 07:50:23 -0700 (PDT) X-Received: by 10.237.59.20 with SMTP id p20mr2401008qte.95.1496328623373; Thu, 01 Jun 2017 07:50:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496328623; cv=none; d=google.com; s=arc-20160816; b=dINt4Taow2sZu6zUPcQGMlw0oQvB5/lR0dD1RsA857d7i4Ig0u/csfJvM2+eXODBQH gfc66y5wXBuguMNfc41jSeqe9LPTrXPGG4DyULGy02Y+bqYNdqQPAW0G362xzK7l4oP+ jxsGUYH2hc9R+j3ao1LgcCeEucpIHSXFQ4/mN4hD/Xa8ONHi3Xct/Z1TP5vWgdxhrsnh d0l5wZASNiNmJipiV4kh88gw+kVLxxtxqgr0KjlMLOlFJiyAoZ9td5aS/K+tC4f8Gok9 +P2akMIJALXEGPIr/E6THHIKPestiw6BBbidYvj2AMlSNnfsYMtwNwaiKf1w/tPtASYK r7/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=HhZLgiZIYSbWdRfyBX/zeaHilTG24DkAtqRdhfxEMJg=; b=uXoJmndGw62GZAHwP6Jn1Axbpu9X7iSWDpI/pHvnMZ96gWqI6ARjSaEp5bSMUWC4V7 4/JSiVpF+3XUqMFuFqfZJRsUcOPhws32iMQNHSHe7Omz8GfKOEYP6UYWbp33ell0ke6c 4JXSxh8GPe/jRohWiRfcEhM2g15cZx7BttXJGxOKEAE4F1WhWbxesJjDP8dF2GOWxVuh B2A/dtpWI8ZlGez/mRQo10xuAO0eAtDborFP+mwKGH5T12JoJA4YWudEHpLGTaAzATTc xwVHDEuY6pMIq51f3ECrDVuJkK/dThin3V9SJcEbCPYemaPWjcfJDmHw+KWQwoYPX3OX 6ySQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id k36si1569210qtd.264.2017.06.01.07.50.22 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 01 Jun 2017 07:50:23 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:45052 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGRQZ-0005CW-Of for patch@linaro.org; Thu, 01 Jun 2017 10:50:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43954) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGRPM-0004Xp-4i for qemu-devel@nongnu.org; Thu, 01 Jun 2017 10:49:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGRPK-0002VR-B4 for qemu-devel@nongnu.org; Thu, 01 Jun 2017 10:49:04 -0400 Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]:37314) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGRPK-0002U3-4Y for qemu-devel@nongnu.org; Thu, 01 Jun 2017 10:49:02 -0400 Received: by mail-wm0-x22f.google.com with SMTP id d127so63402976wmf.0 for ; Thu, 01 Jun 2017 07:49:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HhZLgiZIYSbWdRfyBX/zeaHilTG24DkAtqRdhfxEMJg=; b=SGT7Q2ILJxL5l2Z6H3WzIqwRNQgRX9TcTYLK7Qu4zzv02sx/0TLdpV0uhQDZYXFjZa kV5OjGGUBfTZ6r3+f7JoB0RaKcB+nZYMXB52E4CfFUgogh6Nj0h9sNH2DAiZthesL6HP nht1D0/DudnW2pkIl/2EBwie7dc4gf5erh9s4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HhZLgiZIYSbWdRfyBX/zeaHilTG24DkAtqRdhfxEMJg=; b=nUAi/iX7CHaaP0nC9Y59KSlTO6//5ICC2zvtn7JGKauoApzPj9jF68Jw5nEyGVGWUl AYQ+GSxB72wnc6W0UkEJ0sGkVq2KRsyPlWzPUrFoeMfpRWHP1eDtkY8ZwMQGJrIS1Jr+ dnuzLVGpieJltCN4/i894MSaiAaz7r7cIUdUu40aqEjp6OR0grJPt0Y0x+xqXO3cyHyk xhR4Kv/v9AOABpzK/3QfdqFsHQ3CAY3ookGVJ9y5vkIcV7ysv8TVpK1asQ3hv1dWHeC8 /3hK9SuMzyWi7zRS/EChU6EMqXzT/oE7bflNXLQp0gBFHLkVQR2zkK1PijmeRvIsxtzD mVbQ== X-Gm-Message-State: AODbwcAv9fEgao6vc9OHtcdC/S9coy7jHwSi5zTtcOO0SZf4gPemUL5b F8QgDeNfYywwuEYr X-Received: by 10.28.7.16 with SMTP id 16mr9605106wmh.16.1496328539014; Thu, 01 Jun 2017 07:48:59 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id l30sm13817208wre.25.2017.06.01.07.48.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 07:48:57 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 84D7C3E0496; Thu, 1 Jun 2017 15:49:15 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: pbonzini@redhat.com, doug16k@gmail.com, imbrenda@linux.vnet.ibm.com Date: Thu, 1 Jun 2017 15:49:14 +0100 Message-Id: <20170601144915.20778-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170601144915.20778-1-alex.bennee@linaro.org> References: <20170601144915.20778-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::22f Subject: [Qemu-devel] [PATCH v2 3/4] qom/cpu: remove host_tid field X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Riku Voipio , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org, Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This was only used by the gdbstub and even then was only being set for subsequent threads. Rather the continue duplicating the number just make the gdbstub get the information from TaskState structure. Now the tid is correctly reported for all threads the bug I was seeing with "vCont;C04:0;c" packets is fixed as the correct tid is reported to gdb. I moved cpu_gdb_index into the gdbstub to facilitate easy access to the TaskState which is used elsewhere in gdbstub. Signed-off-by: Alex Bennée --- gdbstub.c | 15 +++++++++++++++ include/exec/gdbstub.h | 14 -------------- include/qom/cpu.h | 2 -- linux-user/syscall.c | 1 - 4 files changed, 15 insertions(+), 17 deletions(-) -- 2.13.0 Reviewed-by: Greg Kurz Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Claudio Imbrenda Reviewed-by: Laurent Vivier diff --git a/gdbstub.c b/gdbstub.c index 026d1fe6bb..45a3a0b16b 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -55,6 +55,21 @@ static inline int target_memory_rw_debug(CPUState *cpu, target_ulong addr, return cpu_memory_rw_debug(cpu, addr, buf, len, is_write); } +/* Return the GDB index for a given vCPU state. + * + * For user mode this is simply the thread id. In system mode GDB + * numbers CPUs from 1 as 0 is reserved as an "any cpu" index. + */ +static inline int cpu_gdb_index(CPUState *cpu) +{ +#if defined(CONFIG_USER_ONLY) + TaskState *ts = (TaskState *) cpu->opaque; + return ts->ts_tid; +#else + return cpu->cpu_index + 1; +#endif +} + enum { GDB_SIGNAL_0 = 0, GDB_SIGNAL_INT = 2, diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index c4fe567600..9aa7756d92 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -58,20 +58,6 @@ void gdb_register_coprocessor(CPUState *cpu, gdb_reg_cb get_reg, gdb_reg_cb set_reg, int num_regs, const char *xml, int g_pos); -/* Return the GDB index for a given vCPU state. - * - * For user mode this is simply the thread id. In system mode GDB - * numbers CPUs from 1 as 0 is reserved as an "any cpu" index. - */ -static inline int cpu_gdb_index(CPUState *cpu) -{ -#if defined(CONFIG_USER_ONLY) - return cpu->host_tid; -#else - return cpu->cpu_index + 1; -#endif -} - /* The GDB remote protocol transfers values in target byte order. This means * we can use the raw memory access routines to access the value buffer. * Conveniently, these also handle the case where the buffer is mis-aligned. diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 55214ce131..909e7ae994 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -266,7 +266,6 @@ struct qemu_work_item; * @nr_cores: Number of cores within this CPU package. * @nr_threads: Number of threads within this CPU. * @numa_node: NUMA node this CPU is belonging to. - * @host_tid: Host thread ID. * @running: #true if CPU is currently running (lockless). * @has_waiter: #true if a CPU is currently waiting for the cpu_exec_end; * valid under cpu_list_lock. @@ -321,7 +320,6 @@ struct CPUState { HANDLE hThread; #endif int thread_id; - uint32_t host_tid; bool running, has_waiter; struct QemuCond *halt_cond; bool thread_kicked; diff --git a/linux-user/syscall.c b/linux-user/syscall.c index cec8428589..cada188e58 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6216,7 +6216,6 @@ static void *clone_func(void *arg) thread_cpu = cpu; ts = (TaskState *)cpu->opaque; info->tid = gettid(); - cpu->host_tid = info->tid; task_settid(ts); if (info->child_tidptr) put_user_u32(info->tid, info->child_tidptr); From patchwork Thu Jun 1 14:49:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 100936 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp842444qge; Thu, 1 Jun 2017 07:51:07 -0700 (PDT) X-Received: by 10.237.34.119 with SMTP id o52mr2445199qtc.217.1496328667618; Thu, 01 Jun 2017 07:51:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496328667; cv=none; d=google.com; s=arc-20160816; b=o8ph4Kwr10VwZ3sk6GQQMJZhsMNNme8w9VjbcpUlaBhXB4pNvODxKckb3uOhlH5gej 38RH4B2bofMuolf4PKi4HOvpzTdx/vXYycYXYK+3SVIsI3fbgLNsQbesnMcxgD4PKtV4 LTRmP+b/VeJsAVTEKehLKoOmiNGbzea3//HqdvqGIgE1WOq/f5CCWg8LMNySqzNnq9dx DDOur8jRxUbtSlBJdhE6ixM59afnNJe1m1Dofal4qjJjREnw8cWntzKc0HKZcZWKzy6z dPm51EKRlD9Ut/A5YZ7sZub8dDinxqH/AS3Dk9Ca5JuFJ7uALDhvJnBO419ZT/EBDqRs yXhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature:arc-authentication-results; bh=5OogvM61zaVGLQSzQRGX5MoPluxmn9smhK+bGD4tX3M=; b=lrh3xlOPHklqkAEpFAJvibKKoNUvci+lABKX0XCw458A9ST820ZEyCMpBaUjpEVOxS XbAN7lY3oSnJFUttBW4MjEMKK0ciyIT8nOvMQmv7IkQ29u5mhA9kA/o3CM7KiYVJoLgS lgd1DGoQ+Vnx2Js837agULR8Hx+jJSUx1m4qyf/wMdpRrqJmFE6TySkt1fQYm+M7wr/4 vdkllNiv+g7UPJD/gqqElf5AjPjMdDNtH4SZDPVOxxCPZyXEaNz6Oe2JHd15sDZ7NPIQ NFcpEMy5iZQLbxYbupr+kE/EAoMRaxUeYjaUzPVGgclAX3W8xQxDudCWH5a//4uGSJ1A yVEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id q76si19282505qki.199.2017.06.01.07.51.07 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 01 Jun 2017 07:51:07 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:45059 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGRRJ-0005eE-97 for patch@linaro.org; Thu, 01 Jun 2017 10:51:05 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43972) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGRPM-0004YM-S4 for qemu-devel@nongnu.org; Thu, 01 Jun 2017 10:49:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGRPL-0002WA-T4 for qemu-devel@nongnu.org; Thu, 01 Jun 2017 10:49:04 -0400 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]:37353) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGRPL-0002Vo-N1 for qemu-devel@nongnu.org; Thu, 01 Jun 2017 10:49:03 -0400 Received: by mail-wm0-x22d.google.com with SMTP id d127so63405140wmf.0 for ; Thu, 01 Jun 2017 07:49:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5OogvM61zaVGLQSzQRGX5MoPluxmn9smhK+bGD4tX3M=; b=FyG6GHLEH3VKMXCJYLdQSgvBTLUWkSmi6DUT3/vfMvUM1gF66rg0Y8JBsoC1pUMnCE /5UGuc0zjpMOXXsXkwugNKeaJAH4EHId/AlU7opQVoupwpxNT+qYAsQhr36rMyyDc0J8 azMMfXdRowdMETvvyXlRImR/9typk1c33X8M0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5OogvM61zaVGLQSzQRGX5MoPluxmn9smhK+bGD4tX3M=; b=Zc2mfUM3Z/Oso+YydwUa0IZIH0WsC9TgT22/lGtwX9rIABSHUf+obvMcP69T06IZsa 8Vv3fh/Lh1MEjTbDir617WKhGvCEGFPhqdLtksHbeFDV6FmmZW7l0vg5P7ODkLCyyzqC 20QkCOX1rjYnlAW6S0S9lPScquMFThV5+MhA6TG1eql8fxv1lWNiFUu59GT+i/lLPqE7 cI2icQ8BPSshzkPKyWkt2g730gzGU5ILxlWxRm3tNkaroCq0Bs+z8fMHLRpwnfGtB/dj 676xc0GcnrESOE+RAR4UrK4zHv0xbCwOR8uvmSFjyZY9zMQ70bjR9YXx5m3IwlW4TYNH WPMg== X-Gm-Message-State: AODbwcCtepsli9TQaQ6id3NJg9YvGRIoyPObT+2spRmpF7QHWwb6AlBu 53VL7hxEkwpUHtv2 X-Received: by 10.223.150.39 with SMTP id b36mr1830921wra.149.1496328542195; Thu, 01 Jun 2017 07:49:02 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id o65sm17626580wmo.19.2017.06.01.07.48.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Jun 2017 07:48:59 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 955CA3E04BC; Thu, 1 Jun 2017 15:49:15 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: pbonzini@redhat.com, doug16k@gmail.com, imbrenda@linux.vnet.ibm.com Date: Thu, 1 Jun 2017 15:49:15 +0100 Message-Id: <20170601144915.20778-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170601144915.20778-1-alex.bennee@linaro.org> References: <20170601144915.20778-1-alex.bennee@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::22d Subject: [Qemu-devel] [PATCH v2 4/4] gdbstub: don't fail on vCont; C04:0; c packets X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The thread-id of 0 means any CPU but we then ignore the fact we find the first_cpu in this case who can have an index of 0. Instead of bailing out just test if we have managed to match up thread-id to a CPU. Otherwise you get: gdb_handle_packet: command='vCont;C04:0;c' put_packet: reply='E22' The actual reason for gdb sending vCont;C04:0;c was fixed in a previous commit where we ensure the first_cpu's tid is correctly reported to gdb however we should still behave correctly next time it does send 0. Signed-off-by: Alex Bennée Reviewed-by: Greg Kurz --- v2 - used Greg's less convoluted suggestion - expand commit message --- gdbstub.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) -- 2.13.0 Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Claudio Imbrenda diff --git a/gdbstub.c b/gdbstub.c index 45a3a0b16b..6b1e72e9f7 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -937,23 +937,16 @@ static int gdb_handle_vcont(GDBState *s, const char *p) if (res) { goto out; } - idx = tmp; + /* 0 means any thread, so we pick the first valid CPU */ - if (!idx) { - idx = cpu_gdb_index(first_cpu); - } + cpu = tmp ? find_cpu(tmp) : first_cpu; - /* - * If we are in user mode, the thread specified is actually a - * thread id, and not an index. We need to find the actual - * CPU first, and only then we can use its index. - */ - cpu = find_cpu(idx); /* invalid CPU/thread specified */ - if (!idx || !cpu) { + if (!cpu) { res = -EINVAL; goto out; } + /* only use if no previous match occourred */ if (newstates[cpu->cpu_index] == 1) { newstates[cpu->cpu_index] = cur_action;