From patchwork Fri Jun 2 13:05: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: 101246 Delivered-To: patch@linaro.org Received: by 10.182.202.35 with SMTP id kf3csp183964obc; Fri, 2 Jun 2017 06:05:32 -0700 (PDT) X-Received: by 10.200.49.81 with SMTP id h17mr2899198qtb.13.1496408732427; Fri, 02 Jun 2017 06:05:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496408732; cv=none; d=google.com; s=arc-20160816; b=q71BjzByS1itTzsCb89+XIV2pjMp1SjJGxpfR+pGuQ1w3uTGIk+ciGqNruizvGqtHd I0a+9VMWQ8AETwpzD5GiuEj42EE0u8vXcVtgLNkx+OhdAugyxWsRdh8QFC2YQpJJ7kfD gv+NwMrFO41dta3sz8KG07QMUEnNJ9VR57iRWotUVdv0jJtXKlySVlGR1Zd3jKvv9qY8 1rBIEQSBCNjoGAnm0zGCV2KoA/FU8mCl859osvykVH9QyNMgmh0IijsR/SBFgwps7d9h NyAjwk6GOSDg3pf4grXLoGbqxP7iyj5Zpgr6X3UPVhYo8mSMMwtDc0RaX2tfKg26GIFF nSRg== 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=zNhqsXs04UE8WSrEfjYYn9ABWEMnP7OXUGR7L0wc4IHk0gMxK94avdG/JNGvjEjq2+ IvI1T64sVFXS5RLLkT6garZKe+b/B7zzT92VHqXKX68L5sl2h1/kohBnApmHfV88dkAe QfnRZR35QF3BHcJ+eSCfMEyQZkuypdDxRlVMP7qo17MHr0MmxDcRrzfUA5H+3BgSkImV JHim16t6Lf9EQw76G3CL8/kUicwWcUq0RpTCMZeZsL/bIJMJ7mWNKxIyfcDgOaFrPpyG gqzJtWPBr55c9XgUTQG0hs3VO1y6m45SOFrK8wiSykhMEh53w5SQ/GKGpDB1tMnMADkE EV8Q== 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 y74si200558qky.95.2017.06.02.06.05.31 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 02 Jun 2017 06:05:32 -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]:49701 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGmGf-0006IP-Sx for patch@linaro.org; Fri, 02 Jun 2017 09:05:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33947) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGmGI-0006G3-9u for qemu-devel@nongnu.org; Fri, 02 Jun 2017 09:05:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGmGD-0002ex-Vm for qemu-devel@nongnu.org; Fri, 02 Jun 2017 09:05:06 -0400 Received: from mail-wm0-x230.google.com ([2a00:1450:400c:c09::230]:37063) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGmGD-0002dL-N1 for qemu-devel@nongnu.org; Fri, 02 Jun 2017 09:05:01 -0400 Received: by mail-wm0-x230.google.com with SMTP id d127so26440280wmf.0 for ; Fri, 02 Jun 2017 06:05: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=NOnco/Cvx2mg6+/Y/0FweVdPOcj5yDorUWvINKyGrJA=; b=de7JHAFbSJ0mwTLXXL9Ve8A5+pfObP0N6nRnchhLhbbqAMDXUZO/Aey9ZGk5y398dk LwLK3XnMNpvrpkPonnN9Hslb287aYEX3SGjKBAcr9dj5yxfQ7YH1jp5N5wmv9D8iyj2i Fkl7r5UkrOcVZW91NRGlTNVhGoU9uPl/P73Y0= 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=DgzyxkZq+s96E274WoXyjFbtMvG9RdhlupsBo+vlgAQv2N0XAZZTBtOgRvT5UtOA2i tylmOH0i0+obMnJ4zS0NRu8WEtl7a7plEf0gQaW02UfhzKIfZypiQGLbYSisw1ikhbaA TZhCX9SOJawhZrqG15flgIIRvcBlQMSJETp6jtc2hLgKs31jcPZf7VIUsEDnJg6/juZ4 flNK3FoD1+EXZ/jhoy0516B+wEvClAHlh8jPSrEVd689APcSjoC52C4YYwIH36MpeSJZ OiEN81OnNwJduKRxCsUbeTx4ljH/MqWNI4FEbo/cQfoo9XOysII02k2SbZCctFPht31N tHyw== X-Gm-Message-State: AODbwcBWyiwVJTiOQXIBFj7+4mv/a7BqSrif4k9E+IXaBQSYS9cxsC4t MBv0M/p+n7LfEWO1 X-Received: by 10.28.87.207 with SMTP id l198mr3207150wmb.114.1496408700505; Fri, 02 Jun 2017 06:05:00 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id x133sm2817136wme.0.2017.06.02.06.04.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Jun 2017 06:04:59 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id F006D3E01BB; Fri, 2 Jun 2017 14:05:18 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org, pbonzini@redhat.com, doug16k@gmail.com, imbrenda@linux.vnet.ibm.com Date: Fri, 2 Jun 2017 14:05:15 +0100 Message-Id: <20170602130518.22943-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170602130518.22943-1-alex.bennee@linaro.org> References: <20170602130518.22943-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::230 Subject: [Qemu-devel] [PATCH v3 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 Fri Jun 2 13:05:16 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: 101248 Delivered-To: patch@linaro.org Received: by 10.182.202.35 with SMTP id kf3csp185419obc; Fri, 2 Jun 2017 06:08:42 -0700 (PDT) X-Received: by 10.200.37.106 with SMTP id 39mr8782670qtn.92.1496408922606; Fri, 02 Jun 2017 06:08:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496408922; cv=none; d=google.com; s=arc-20160816; b=letp302jBf++o8K2BQnC2H1LE0LI5OHKRSlzMbJpjaySUorCHXSrLLVd/A9tQl9pb9 fDuHIIaI2cU7m3snUePVEbkoTO675xlAB+6T3HhIb9jBub7MepDF+awDKgv7Acw879Fs NlhYvN+iyknytB9drVjF2R9lXmsjLvll1ui51FZSEox22ItfbhCbD02D1yJysvrZzlLT CycfZ28MS5xwLvZDqJ8OZPXF61VkssgBwtFvTDMeiJh98ictVvVxSgnQv/snWs35Kuax 8bOk9FKioOQj/QC9LGK32BcDt4K1EwZNdkhcksKJmC7aZh3LkHfLhN8NAP6ljEo9Ya3q pKew== 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=6sg3kie9Ld0x8HhFkP/i5HCiFXfPvNuO9JNLs6kYBaE=; b=KhQwEqpZMmoapZ+JKMj2K+erQw63CiyRkX4ggcHhUVKPcDfBWaeSAplWGzmhtzKoUl HVFbZ/804EqFF1CyGiOVJ904ceYzY3UHiqwDq7rKteI3nKH+YCS2rS5BlDAnW7zOEK8Z +3rDdQTmkZRMfTMJAydAtysbtPV5m19s/0iz/Up4JrXiyyzDFBb8ye08k1qKAR1eHsV4 etQdCDXDl0G8/CHoJWUncm49SrSs+ZsUlM+5e8p+iMxBJm6jv3ldVZwrmvw7gZm6leGU /DqRjPkyjaCF+xrxwgWzW0+PTb6F8JvMdHH8tUziiu9Ht391pfY2Iln64boJdnY09vRH vlWw== 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 t10si15474195qki.329.2017.06.02.06.08.42 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 02 Jun 2017 06:08:42 -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]:49711 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGmJj-0000Y5-Uh for patch@linaro.org; Fri, 02 Jun 2017 09:08:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34040) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGmGS-0006Ru-9h for qemu-devel@nongnu.org; Fri, 02 Jun 2017 09:05:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGmGN-0002lj-UL for qemu-devel@nongnu.org; Fri, 02 Jun 2017 09:05:16 -0400 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]:35840) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGmGN-0002lJ-Kx for qemu-devel@nongnu.org; Fri, 02 Jun 2017 09:05:11 -0400 Received: by mail-wm0-x236.google.com with SMTP id 7so25271487wmo.1 for ; Fri, 02 Jun 2017 06:05:11 -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=6sg3kie9Ld0x8HhFkP/i5HCiFXfPvNuO9JNLs6kYBaE=; b=bBu0XkNlqIsHBsaK5BessrjHYmFRxR3HFiWeid7O2Q5UNtcKtT4krdF3hH8coWfzMt PdEF5ZsfuibeQWHJLyBZc4hP1P98zJuMGXNmraJ8XBavDR3sXFjBOjCVKGraZA9tgibH GnbF1/E2MiY/jaiuKLH1wnzi7WHjuHGa/k2Wc= 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=6sg3kie9Ld0x8HhFkP/i5HCiFXfPvNuO9JNLs6kYBaE=; b=HjYOElc5+N1y4hMPOACpnUMBe9J6RxkO/SBWOWmmUYXKMgDBWsm8Pz3AtW5oGFjP07 +SrU6/RTq1vlKAmSVvOuUoDmBjUTzaOwtQLgJk7eqP7eEwdQRGOwqHdsBjgzbqWqkOvh xi0YOHt8eFb9RhvwMzrudcecfxMNikoGjWMu2WFIBmp/GRhEhSyNZ9+1RDDcFp+Am8Sz XrFTGd7C27yoF3diOnVDmB02f4wwZRgFY+Gv4huqxYKCSN6t2H/oq4JENIJi1ysSiF6O 2btLeZr9MrGWjHjdkJ6dl1M+v8PAb3lA1fhGHoJDVNViD8HiLJ3SeIYq0fngKLGUatyd cdoQ== X-Gm-Message-State: AODbwcAP5VPtZCa+YhFv+jopwSv7dSOLJA2GwBT59Mu0XhpzcrsERuzD drlsoE+/ExIl8Tmn X-Received: by 10.28.175.84 with SMTP id y81mr3213524wme.25.1496408710476; Fri, 02 Jun 2017 06:05:10 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id t8sm12537944wrc.28.2017.06.02.06.05.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Jun 2017 06:05:09 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 0D7AF3E028C; Fri, 2 Jun 2017 14:05:19 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org, pbonzini@redhat.com, doug16k@gmail.com, imbrenda@linux.vnet.ibm.com Date: Fri, 2 Jun 2017 14:05:16 +0100 Message-Id: <20170602130518.22943-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170602130518.22943-1-alex.bennee@linaro.org> References: <20170602130518.22943-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::236 Subject: [Qemu-devel] [PATCH v3 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. At the same time we move the function from the header to gdbstub itself which will help with later changes. Signed-off-by: Alex Bennée Reviewed-by: Greg Kurz Reviewed-by: Claudio Imbrenda Reviewed-by: Philippe Mathieu-Daudé --- v3 - move cpu_gdb_index into gdbstub --- gdbstub.c | 26 ++++++++++++++++++++------ include/exec/gdbstub.h | 9 --------- 2 files changed, 20 insertions(+), 15 deletions(-) -- 2.13.0 diff --git a/gdbstub.c b/gdbstub.c index a249846954..57befe16e2 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -55,6 +55,20 @@ 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) + return cpu->host_tid; +#else + return cpu->cpu_index + 1; +#endif +} + enum { GDB_SIGNAL_0 = 0, GDB_SIGNAL_INT = 2, @@ -837,7 +851,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 +939,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 +989,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 +1257,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 +1414,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 +1448,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..9aa7756d92 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -58,15 +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); -static inline int cpu_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. From patchwork Fri Jun 2 13:05:17 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: 101247 Delivered-To: patch@linaro.org Received: by 10.182.202.35 with SMTP id kf3csp184574obc; Fri, 2 Jun 2017 06:06:53 -0700 (PDT) X-Received: by 10.200.11.193 with SMTP id p1mr7828328qti.221.1496408812946; Fri, 02 Jun 2017 06:06:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496408812; cv=none; d=google.com; s=arc-20160816; b=HDjKHPcX/cZ61tGSWPsIuTbtiyID/qBOUQa7lJzaxq3I/OZVIgSBXJzqLqPd9Zr2yh vJyxNJQx6IhZU3lVIGrG8GZ0l3UhFulIoiGY7738DTHDp9Mb3C5w8n7yo1DteoRQves4 g+ChvHcw06EbRWL5b/9a46VwbsjnyUE7chCKiwKZ3d4TDwWUk2R6335lAxQy3sNtNSXm uoCdd8St7i4fvqsVHp42OhWnnqRSnFXSMJNFT3d8NboiEZKJCTOm8ct2f5WaJT4NjN2a kvLKbO345FCRIrP9sWos32N/FbS+/WLTbkqe4YVPkGH1wu2EB3zOSXw51rLDtnQGimaG f6+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=/vgkPSMEl2YnnOoLebzx/r20nDGLFE6ysMUjmT0ACR4=; b=jtZAjvX7T4CBDCZEi5oGKmF6nccBUP5W8pZ1zaOyaQIgYUZ6iZG79mHrEED4dB7nJV PyQtPn34Z3mVs+xy81KWBotuvIMS5OsfX2xo6Rm6UoGm1p1GGpONpDTbxxtNMHR7nwPg AHp+xJkbz1qSGYk8RfxlPjC+SOhmuAacLrYc+X6pWQzd9SfT5WBSZ0mqeSzccVKWJ0yT VI6rk0tW8KXF7XlWtQpsxbNFTjXZ+yxloM8X0hU87fuY0hFF++v6TVkwtfq+f232jsTt 7ELyNlz1ybj7v0sskyeiZUhA9L3qlFhDI4BZmbuVCMP63OkIXNjSDyALt1snUguXl+3m 2tzg== 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 g65si21770059qke.238.2017.06.02.06.06.52 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 02 Jun 2017 06:06:52 -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]:49703 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGmHy-00079A-9e for patch@linaro.org; Fri, 02 Jun 2017 09:06:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33949) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGmGI-0006G6-SX for qemu-devel@nongnu.org; Fri, 02 Jun 2017 09:05:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGmGF-0002fd-I6 for qemu-devel@nongnu.org; Fri, 02 Jun 2017 09:05:06 -0400 Received: from mail-wr0-x234.google.com ([2a00:1450:400c:c0c::234]:34664) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGmGF-0002fB-BE for qemu-devel@nongnu.org; Fri, 02 Jun 2017 09:05:03 -0400 Received: by mail-wr0-x234.google.com with SMTP id g76so6683896wrd.1 for ; Fri, 02 Jun 2017 06:05: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=/vgkPSMEl2YnnOoLebzx/r20nDGLFE6ysMUjmT0ACR4=; b=JUsJuddJ4y5i0rGIQhRz8lAvFG6EOIb+cgCvVFZYfch5/FxZ47KY1ATTfJOihtgOQm 0ZryqBgW74tBZSU0Mt7/PFG49By8XKjG+EmvmWhMkMRY4Rw+GWQ3XHQ33l6TgtyVzm41 AXcMdDxRFumKMgX+uaJe2RsqWdWCCcLdSeIxU= 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=/vgkPSMEl2YnnOoLebzx/r20nDGLFE6ysMUjmT0ACR4=; b=uRFdvT4vmrUFWdthBbpv29oNZKBjaOTyuXReLcc+A+E0hy37nqBoY2tvYFmLFRzHvI HS2j2SxtupPhHHnasC8a5SL6Y+6l2tOyTLIAdJ/JVZ7KpeB/ifphQzTYcHDR37YSpk4q ceXyjz+zuaIBMk2QFD4g/ZXjqTIgkY8jF7bznysgdNwk5/bBPV/LLgcoa6tw48zqkfl/ J/45YnL5CYzwSItjUc+a7KxKBv18IdkZGpzDTwBjEXkEAJsVN/JkH0oNzJE2nsV0z6VZ PlSbNu4k7DmCKzNJ4wlMOEeuvduQsVcTts/28+MZ6KyQo4UQNDrdKDIDY/RpovJ9cGdq 831w== X-Gm-Message-State: AODbwcDRrl3b56jocAkud8ykDNWpTlAgBMqjbctKxzq0Jth3MAlfJECC oa9hdbiSETV8Y+/w X-Received: by 10.223.154.195 with SMTP id a61mr4890392wrc.47.1496408702200; Fri, 02 Jun 2017 06:05:02 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id x126sm2491100wme.12.2017.06.02.06.04.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Jun 2017 06:04:59 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 206B03E031F; Fri, 2 Jun 2017 14:05:19 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org, pbonzini@redhat.com, doug16k@gmail.com, imbrenda@linux.vnet.ibm.com Date: Fri, 2 Jun 2017 14:05:17 +0100 Message-Id: <20170602130518.22943-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170602130518.22943-1-alex.bennee@linaro.org> References: <20170602130518.22943-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:c0c::234 Subject: [Qemu-devel] [PATCH v3 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 Reviewed-by: Greg Kurz Reviewed-by: Claudio Imbrenda Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Laurent Vivier --- v3 - fix merge, did move of function in previous commit --- gdbstub.c | 3 ++- include/qom/cpu.h | 2 -- linux-user/syscall.c | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) -- 2.13.0 diff --git a/gdbstub.c b/gdbstub.c index 57befe16e2..45a3a0b16b 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -63,7 +63,8 @@ static inline int target_memory_rw_debug(CPUState *cpu, target_ulong addr, static inline int cpu_gdb_index(CPUState *cpu) { #if defined(CONFIG_USER_ONLY) - return cpu->host_tid; + TaskState *ts = (TaskState *) cpu->opaque; + return ts->ts_tid; #else return cpu->cpu_index + 1; #endif 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 925ae11ea6..003943b736 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -6219,7 +6219,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 Fri Jun 2 13:05:18 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: 101249 Delivered-To: patch@linaro.org Received: by 10.182.202.35 with SMTP id kf3csp185474obc; Fri, 2 Jun 2017 06:08:50 -0700 (PDT) X-Received: by 10.55.207.92 with SMTP id e89mr7634124qkj.200.1496408930284; Fri, 02 Jun 2017 06:08:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496408930; cv=none; d=google.com; s=arc-20160816; b=tA/cOD/kjbSe84vM2F7e5tSjil37Y1tL5LBpxqhdbbWj9bUJgXJkIbxGMyjPf4Ww+n qofQmSiDpjLp83cr9H2AWlrDWucsp08vn6zXZVHkQb9/u78F04IhsEYcVYnpB//vVWB5 Nnl8m/jYQoHrSXOH16GD2+Tko/rWjLMP4tmohOX+xTvm+AMLlNS3ZHYvFGlp6NugUOD8 L6Pk3odGYtLvGB0TdH4XAVRdNNfAeqcbnggreLLLXtmiyhYRbFVghBSw3b0msRudgi2h WpoPVBe+tQGTlqInEKjbd89ph3g+WdCz5q5XuShjnuqYJPh6dfonbPBQWgBukxL9wl08 C7/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=373B82/lO7Ee29Th9u3Ny6pJqw3QChtQzNQzvI0GHDw=; b=YO1gouaY61jf+xWzAcNKW9v5DVIEEM4MNYk27auoY6f0q0J9InfyxXC0lzaGthrk4I G/hMpNI4SqD2QoDweXpZSYVitjwyRd6Aa+KLJr/riQadmsMMK9nhk2c7JYyoBbRV1lpQ vn01x9+yP6+t9GnC3QcYfWFKK6BpLuy7hNjfQgL1P/bLkMeHHKwFfbVlOQ3RT8unJKse +XLLoo5YYZCNzpDyn+CdZeb+OsOa9u5tsg6TLq73vWgAJJhe22GsTb6eWGIU6LwGiCUW pAb2AXEpeca9RCTeNUxp4/4qEL+3GgSDlQNmBeU7hUNhQzoYzi8Xnc5BmkXkbQDnAGDv tZzw== 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 q16si21499000qkh.113.2017.06.02.06.08.49 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 02 Jun 2017 06:08:50 -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]:49712 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGmJr-0000e3-JI for patch@linaro.org; Fri, 02 Jun 2017 09:08:47 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33962) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGmGJ-0006H1-HK for qemu-devel@nongnu.org; Fri, 02 Jun 2017 09:05:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dGmGE-0002fI-PQ for qemu-devel@nongnu.org; Fri, 02 Jun 2017 09:05:07 -0400 Received: from mail-wr0-x22c.google.com ([2a00:1450:400c:c0c::22c]:34662) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dGmGE-0002es-Id for qemu-devel@nongnu.org; Fri, 02 Jun 2017 09:05:02 -0400 Received: by mail-wr0-x22c.google.com with SMTP id g76so6683697wrd.1 for ; Fri, 02 Jun 2017 06:05: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=373B82/lO7Ee29Th9u3Ny6pJqw3QChtQzNQzvI0GHDw=; b=GoYoqJoP9c8T3+U28WbFHCm+xSs1RJE8rOodVtZSsCns69FSgVrXsKutXS/I9Un6xo 67PvQ9IXBbXToDDqAmfilz8uO2MxTBAYvnQciSG8jdqbMzXzVKFRe85S+JYQfJ40KnZb 2ZibYshNGFjZCBabCJmCVjUv65cC+prIsN3kA= 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=373B82/lO7Ee29Th9u3Ny6pJqw3QChtQzNQzvI0GHDw=; b=IF3Q88R9fb/usDZci54PPOTDwaM/f9Zi/s27/+40KZPnqB1i+bWMRj/p93qVnZliY6 tkKmVYU14KrnloQ9O4ygJPtmfnt28rTHEasHUcqyhQQwbOlvPJ4Iy/o1t0Gg7hLHIPUZ rflgnE9SZrAVhWF3nPNqOZsCTpT4Cy5UINlDrbAO4t2wmc1/drpP5eHjJXS+iHpl0syB qbk0SfWGeMgCSyiEUnBs/OxA6v7MZKANzHcZyMEG/eC/KHROzZBXi4F60dhn3HfGdaaC Ru4ujAN6f2Q4oQXfhbAJh6qJB8WCzdtjKysm/y8xftdbzx8Awwrr5O6w1BBAjK+/7kT8 C+Aw== X-Gm-Message-State: AODbwcCRTlXHk76SIWgHZ1n1ELzVVeoycQmL8cHbkcMwaz+fMp9IROSq SXZeXYXySeCt7DeQ X-Received: by 10.223.164.7 with SMTP id d7mr4685641wra.183.1496408701394; Fri, 02 Jun 2017 06:05:01 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id x37sm39747831wrb.42.2017.06.02.06.04.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 02 Jun 2017 06:04:59 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 308D13E0334; Fri, 2 Jun 2017 14:05:19 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org, pbonzini@redhat.com, doug16k@gmail.com, imbrenda@linux.vnet.ibm.com Date: Fri, 2 Jun 2017 14:05:18 +0100 Message-Id: <20170602130518.22943-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170602130518.22943-1-alex.bennee@linaro.org> References: <20170602130518.22943-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:c0c::22c Subject: [Qemu-devel] [PATCH v3 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 Reviewed-by: Claudio Imbrenda --- 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é 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;