From nobody Mon Apr 29 09:22:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496243539013345.5044275626133; Wed, 31 May 2017 08:12:19 -0700 (PDT) Received: from localhost ([::1]:60102 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG5IG-0001Df-8G for importer@patchew.org; Wed, 31 May 2017 11:12:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45193) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG5FS-0007sz-BF for qemu-devel@nongnu.org; Wed, 31 May 2017 11:09:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dG5FP-0005Yk-RL for qemu-devel@nongnu.org; Wed, 31 May 2017 11:09:22 -0400 Received: from mail-wm0-x22f.google.com ([2a00:1450:400c:c09::22f]:35324) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dG5FP-0005WS-G3 for qemu-devel@nongnu.org; Wed, 31 May 2017 11:09:19 -0400 Received: by mail-wm0-x22f.google.com with SMTP id b84so122842756wmh.0 for ; Wed, 31 May 2017 08:09:19 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id m11sm24080607wmg.34.2017.05.31.08.09.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 May 2017 08:09:16 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id A67463E01C6; Wed, 31 May 2017 16:09:33 +0100 (BST) 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=7KFhDR0nMsc+M7xnsT5SMXY6H1oyT2gD10ARpOoMEW0=; b=FKGxcMZhkkE0676ShronwvDOGTROtmTx4Et0xfIE0zmcP/e7RAzNzu+2wz9Vw4nTw3 UlfDT484bUsBIb43Ndg7CygAJmdIPBdTP0vQhRRqTgp6sqEFXOhoDV6lBaPJc2QNFbBX OqmtVfFNhukcCjuqp8ZjC615J5CUZwRv3JK3M= 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=7KFhDR0nMsc+M7xnsT5SMXY6H1oyT2gD10ARpOoMEW0=; b=g7xeI+4Y/kO8vPHukL+kFdVV0u3Vv2q9Hn61ybrf1/1q2i9+P4vnK+i4dQCxZyioEc upyMTsi6iadazdfxAZBG7iIuK7nsuMEylGZNH0phZvgUJQvTmD3hAK3eNUEVlpEh3Lbl +EB/6hjZg23azU5CCKo57QtO12gtu2MxfH/w08NKGLLOyUSB/p/CNMTw5Nv1B6GPgcjx uH8m3kSGKjxED/e781XseHvukzwzOMfZmuiRLE8Eedxq4BNdmsgfV01+Mj4Wau2AiRdH mpDD6QpFgI3FAIG4YWt+1HhNXm9u++Mjr6X9f3lvjZk6eSMNdsRpLPu28CgH3UxH143I VLzQ== X-Gm-Message-State: AODbwcAl1Si9aWSZXC0uRDRHuI9csGRdPcH7zLqYu1Jt+/bj/tMH6IAw mDk45EhMXKk50dA/ X-Received: by 10.28.136.83 with SMTP id k80mr5402034wmd.38.1496243358399; Wed, 31 May 2017 08:09:18 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: pbonzini@redhat.com, doug16k@gmail.com, imbrenda@linux.vnet.ibm.com Date: Wed, 31 May 2017 16:09:32 +0100 Message-Id: <20170531150933.10156-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170531150933.10156-1-alex.bennee@linaro.org> References: <20170531150933.10156-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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 v1 1/2] 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=20Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 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=C3=A9e Reviewed-by: Greg Kurz Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- gdbstub.c | 77 +++++++++++++++++++++++++++--------------------------------= ---- 1 file changed, 33 insertions(+), 44 deletions(-) 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; } =20 -//#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) + =20 typedef struct GDBRegisterState { int base_reg; @@ -547,9 +560,7 @@ static int put_packet_binary(GDBState *s, const char *b= uf, int len) /* return -1 if error, 0 if OK */ static int put_packet(GDBState *s, const char *buf) { -#ifdef DEBUG_GDB - printf("reply=3D'%s'\n", buf); -#endif + gdb_debug("reply=3D'%s'\n", buf); =20 return put_packet_binary(s, buf, strlen(buf)); } @@ -955,9 +966,9 @@ static int gdb_handle_packet(GDBState *s, const char *l= ine_buf) uint8_t *registers; target_ulong addr, len; =20 -#ifdef DEBUG_GDB - printf("command=3D'%s'\n", line_buf); -#endif + + gdb_debug("command=3D'%s'\n", line_buf); + p =3D line_buf; ch =3D *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 =3D=3D '-') { -#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 =3D=3D '+') { + gdb_debug("Got ACK\n"); + } else { + gdb_debug("Got '%c' when expecting ACK/NACK\n", ch); } -#ifdef DEBUG_GDB - else if (ch =3D=3D '+') - printf("Got ACK\n"); - else - printf("Got '%c' when expecting ACK/NACK\n", ch); -#endif + if (ch =3D=3D '+' || ch =3D=3D '$') s->last_packet_len =3D 0; if (ch !=3D '$') @@ -1549,9 +1557,7 @@ static void gdb_read_byte(GDBState *s, int ch) s->line_sum =3D 0; s->state =3D 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 =3D RS_CHKSUM1; } else if (s->line_buf_index >=3D 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 =3D RS_IDLE; } else { /* unescaped command character */ @@ -1583,9 +1587,7 @@ static void gdb_read_byte(GDBState *s, int ch) s->state =3D RS_CHKSUM1; } else if (s->line_buf_index >=3D 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 =3D 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 =3D RS_GETLINE; } else { /* decode repeat length */ int repeat =3D (unsigned char)ch - ' ' + 3; if (s->line_buf_index + repeat >=3D 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 =3D 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 =3D 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 =3D 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 =3D RS_GETLINE; break; } s->line_csum |=3D fromhex(ch); =20 if (s->line_csum !=3D (s->line_sum & 0xff)) { + gdb_debug("got command packet with incorrect checksum\n"); /* send NAK reply */ reply =3D '-'; put_buffer(s, &reply, 1); -#ifdef DEBUG_GDB - printf("gdbstub got command packet with incorrect checksum= \n"); -#endif s->state =3D RS_IDLE; } else { /* send ACK reply */ --=20 2.13.0 From nobody Mon Apr 29 09:22:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1496243443124270.10911966167134; Wed, 31 May 2017 08:10:43 -0700 (PDT) Received: from localhost ([::1]:60098 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG5Gf-0000As-5S for importer@patchew.org; Wed, 31 May 2017 11:10:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45192) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dG5FS-0007sy-A8 for qemu-devel@nongnu.org; Wed, 31 May 2017 11:09:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dG5FR-0005aM-Da for qemu-devel@nongnu.org; Wed, 31 May 2017 11:09:22 -0400 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]:36739) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dG5FR-0005ZN-6w for qemu-devel@nongnu.org; Wed, 31 May 2017 11:09:21 -0400 Received: by mail-wm0-x22b.google.com with SMTP id 7so122366400wmo.1 for ; Wed, 31 May 2017 08:09:21 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id j126sm17303823wmd.29.2017.05.31.08.09.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 May 2017 08:09:18 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id B78C33E01CB; Wed, 31 May 2017 16:09:33 +0100 (BST) 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=6lt72P3aLwFXOUi+wPId6VktQXhcG3oK7BqMKsED0EE=; b=eWjUKzXiK9Erm0vxFTlZkRCR8gRNQSgo+CN5tYOfTuJ8vpWxJMuWWwAs0X74ciCoqH jI+kZIG02TkPKiQdHrIHYMPGTnUfkEnuf7NajjaWH0T44diYVIQhRJfN+u7NW4WeMjUh Dyiimag+VCSqzOG/YyyOCh5MpgJo9kICj5afE= 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=6lt72P3aLwFXOUi+wPId6VktQXhcG3oK7BqMKsED0EE=; b=s7sYZ3Uw3CR4SkASEMlzvK46DzGBIRBPdJAFuyAkHLHWISf/EyxhTlh3mrTXDzt10P UWsRqJCefqqYiB8MtW5Q9nVvJBqrup0BJLHUZhNkNCnUS8zYEEbSIx2eyCMjQlSxsBcZ bbGwN2f3CHpuv7kxOkcGMV53r9EjZd4rF22clTw0Mi9UAARqsOkY0MKETpCygi/DTQhq fCjvJnvBchzxMsSTMr30kd86fyYWS3254nw6G9KjKdG1z9DU0o8yMdm++7AIlf5WBa4l WtRDPCZ4oG0RMUf9DK93BQpTB2cP8O4xqdHWa/XBLUdTpT5MGoJwIooT4NWfDYY0k8iP yZ/g== X-Gm-Message-State: AODbwcBT4ktQlzfli4p/N7dBKTI6Knj66rjfcd9bPJVpF2vDUMrA6uWt ktSQ8520U0nGNgdK X-Received: by 10.28.145.73 with SMTP id t70mr5416065wmd.88.1496243360124; Wed, 31 May 2017 08:09:20 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: pbonzini@redhat.com, doug16k@gmail.com, imbrenda@linux.vnet.ibm.com Date: Wed, 31 May 2017 16:09:33 +0100 Message-Id: <20170531150933.10156-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170531150933.10156-1-alex.bennee@linaro.org> References: <20170531150933.10156-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::22b Subject: [Qemu-devel] [PATCH v1 2/2] 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=20Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 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=3D'vCont;C04:0;c' put_packet: reply=3D'E22' Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Greg Kurz --- gdbstub.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index a249846954..29c9ed3002 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -934,8 +934,8 @@ static int gdb_handle_vcont(GDBState *s, const char *p) * CPU first, and only then we can use its index. */ cpu =3D find_cpu(idx); - /* invalid CPU/thread specified */ - if (!idx || !cpu) { + /* invalid thread specified, cpu not found. */ + if (!cpu) { res =3D -EINVAL; goto out; } --=20 2.13.0