From nobody Sun May 5 10:33:40 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 1496328785656496.56800058097156; Thu, 1 Jun 2017 07:53:05 -0700 (PDT) Received: from localhost ([::1]:45065 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGRTE-0007Kp-4x for importer@patchew.org; Thu, 01 Jun 2017 10:53:04 -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) 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) 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) From: =?UTF-8?q?Alex=20Benn=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 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::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=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: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Greg Kurz --- 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 Sun May 5 10:33:40 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 149632877429334.723355340963394; Thu, 1 Jun 2017 07:52:54 -0700 (PDT) Received: from localhost ([::1]:45064 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGRT2-00076R-7V for importer@patchew.org; Thu, 01 Jun 2017 10:52:52 -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) 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) 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) From: =?UTF-8?q?Alex=20Benn=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 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::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=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 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=C3=A9e Reviewed-by: Claudio Imbrenda Reviewed-by: Greg Kurz Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- gdbstub.c | 12 ++++++------ include/exec/gdbstub.h | 7 ++++++- 2 files changed, 12 insertions(+), 7 deletions(-) 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; =20 CPU_FOREACH(cpu) { - if (cpu_index(cpu) =3D=3D thread_id) { + if (cpu_gdb_index(cpu) =3D=3D thread_id) { return cpu; } } @@ -925,7 +925,7 @@ static int gdb_handle_vcont(GDBState *s, const char *p) idx =3D tmp; /* 0 means any thread, so we pick the first valid CPU */ if (!idx) { - idx =3D cpu_index(first_cpu); + idx =3D cpu_gdb_index(first_cpu); } =20 /* @@ -975,7 +975,7 @@ static int gdb_handle_packet(GDBState *s, const char *l= ine_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") =3D=3D 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_c= pu)); put_packet(s, buf); s->query_cpu =3D CPU_NEXT(s->query_cpu); } else @@ -1400,7 +1400,7 @@ static void gdb_vm_state_change(void *opaque, int run= ning, 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 =3D NULL; goto send_packet; @@ -1434,7 +1434,7 @@ static void gdb_vm_state_change(void *opaque, int run= ning, 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= )); =20 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); =20 -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; --=20 2.13.0 From nobody Sun May 5 10:33:40 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 149632869679935.825071603876495; Thu, 1 Jun 2017 07:51:36 -0700 (PDT) Received: from localhost ([::1]:45060 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGRRm-000678-CQ for importer@patchew.org; Thu, 01 Jun 2017 10:51:34 -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) 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) 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) From: =?UTF-8?q?Alex=20Benn=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 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 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=20Benn=C3=A9e?= , qemu-devel@nongnu.org, Laurent Vivier 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 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=C3=A9e Reviewed-by: Claudio Imbrenda Reviewed-by: Greg Kurz Reviewed-by: Laurent Vivier Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- 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(-) 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); } =20 +/* 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 =3D (TaskState *) cpu->opaque; + return ts->ts_tid; +#else + return cpu->cpu_index + 1; +#endif +} + enum { GDB_SIGNAL_0 =3D 0, GDB_SIGNAL_INT =3D 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); =20 -/* 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 me= ans * we can use the raw memory access routines to access the value buffer. * Conveniently, these also handle the case where the buffer is mis-aligne= d. 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 =3D cpu; ts =3D (TaskState *)cpu->opaque; info->tid =3D gettid(); - cpu->host_tid =3D info->tid; task_settid(ts); if (info->child_tidptr) put_user_u32(info->tid, info->child_tidptr); --=20 2.13.0 From nobody Sun May 5 10:33:40 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 149632865764711.265692127660714; Thu, 1 Jun 2017 07:50:57 -0700 (PDT) Received: from localhost ([::1]:45059 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dGRRA-0005eE-77 for importer@patchew.org; Thu, 01 Jun 2017 10:50:56 -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) 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) 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) From: =?UTF-8?q?Alex=20Benn=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 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::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=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' 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=C3=A9e Reviewed-by: Greg Kurz Reviewed-by: Claudio Imbrenda Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- v2 - used Greg's less convoluted suggestion - expand commit message --- gdbstub.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) 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 =3D tmp; + /* 0 means any thread, so we pick the first valid CPU */ - if (!idx) { - idx =3D cpu_gdb_index(first_cpu); - } + cpu =3D tmp ? find_cpu(tmp) : first_cpu; =20 - /* - * 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 =3D find_cpu(idx); /* invalid CPU/thread specified */ - if (!idx || !cpu) { + if (!cpu) { res =3D -EINVAL; goto out; } + /* only use if no previous match occourred */ if (newstates[cpu->cpu_index] =3D=3D 1) { newstates[cpu->cpu_index] =3D cur_action; --=20 2.13.0