From nobody Tue Apr 30 01:05:21 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.zohomail.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 1499856916993807.9136133443607; Wed, 12 Jul 2017 03:55:16 -0700 (PDT) Received: from localhost ([::1]:51696 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVFIY-0006Hr-E6 for importer@patchew.org; Wed, 12 Jul 2017 06:55:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32896) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVFGm-0004h1-5e for qemu-devel@nongnu.org; Wed, 12 Jul 2017 06:53:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVFGj-0001zC-3m for qemu-devel@nongnu.org; Wed, 12 Jul 2017 06:53:24 -0400 Received: from mail-wr0-f170.google.com ([209.85.128.170]:32807) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dVFGi-0001ym-Ql for qemu-devel@nongnu.org; Wed, 12 Jul 2017 06:53:21 -0400 Received: by mail-wr0-f170.google.com with SMTP id r103so28274364wrb.0 for ; Wed, 12 Jul 2017 03:53:20 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id e17sm1958582wma.19.2017.07.12.03.52.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Jul 2017 03:52:17 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 0C9CD3E07A0; Wed, 12 Jul 2017 11:52:17 +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=IMqTMgNti8BoQzaOjugYl05GbQiU0olK4bgHdDtryW4=; b=Sue6pbIRs9peyf5UiyWe7GGYMnf3Z0jkP3b6JKbXAyCrfXCEnlBfmylSi6+FhsiZIF Bh/Jalvy4yV5/gBQONGE/8DDbmLjfxjxE58G8oBYM+L1ZpD0X+fe4iPc5oFps8uo7k98 CEQLDpQ6iXs56lduZ2DzQmzljrJbfIVMOHN7s= 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=IMqTMgNti8BoQzaOjugYl05GbQiU0olK4bgHdDtryW4=; b=ciSDT2718n4pggtKXuY52dS9rFIa+D6yQz/tuNrXZBpSqikBy1jEUuTj/Uxc/dvU0v OBaoY7TnRQMlsVbJf+UJVQgNObu32cpwlz4MApDEJlyP1yBBQbw6WYwqwrj2tBa5JRHm 58OyiU+4vL6vECeJSHift/rHkYcTPatX3DizNEv6S0aiN69SiQb3mUUuym3T+BZVfAwn whkZLcGVgpsEg4TPn8j1B1tQdCGGrQJuhPa374mj5HModZ2G9O6o2Y9rWZxutiFxkWeN jF7XHh2dMaBQn5Nph6bJezga6lH3dNvZLEAUIOpMM5MTEpQbS1r5zALYikLeY9saL+nP F5Zg== X-Gm-Message-State: AIVw113EOMCSnZO1PezxA39xn6lz71sjecjTTK4AhAYc3mDof3+LME4M 73njBSrzOXyXVAnS X-Received: by 10.28.23.1 with SMTP id 1mr2215984wmx.106.1499856739582; Wed, 12 Jul 2017 03:52:19 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: pbonzini@redhat.com Date: Wed, 12 Jul 2017 11:52:13 +0100 Message-Id: <20170712105216.747-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170712105216.747-1-alex.bennee@linaro.org> References: <20170712105216.747-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: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.128.170 Subject: [Qemu-devel] [PATCH v4 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 ec4e4b25be..31db2309aa 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -272,7 +272,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; @@ -548,9 +561,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)); } @@ -956,9 +967,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) { @@ -1519,17 +1530,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 '$') @@ -1550,9 +1558,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: @@ -1568,9 +1574,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 */ @@ -1584,9 +1588,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 */ @@ -1598,25 +1600,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 */ @@ -1631,9 +1626,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; } @@ -1644,21 +1637,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 Tue Apr 30 01:05:21 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.zohomail.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 1499856838577188.04891756413667; Wed, 12 Jul 2017 03:53:58 -0700 (PDT) Received: from localhost ([::1]:51690 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVFHI-00051g-5k for importer@patchew.org; Wed, 12 Jul 2017 06:53:56 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60805) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVFFq-0003uF-FN for qemu-devel@nongnu.org; Wed, 12 Jul 2017 06:52:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVFFm-0001YC-E0 for qemu-devel@nongnu.org; Wed, 12 Jul 2017 06:52:26 -0400 Received: from mail-wr0-x233.google.com ([2a00:1450:400c:c0c::233]:36679) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dVFFm-0001XU-3z for qemu-devel@nongnu.org; Wed, 12 Jul 2017 06:52:22 -0400 Received: by mail-wr0-x233.google.com with SMTP id c11so28151532wrc.3 for ; Wed, 12 Jul 2017 03:52:21 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id j31sm1134618wre.67.2017.07.12.03.52.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Jul 2017 03:52:18 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 1E4003E07A1; Wed, 12 Jul 2017 11:52:17 +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=Qyr74MK/WKlKl4i65M6gkzrmGAnBET1CwJnF1BUvyb0=; b=Xl+ok4w8d3F76HIOW9XcSyIG62MQcxoJoSqr1COiEXHAT4m9MAf0IdMTalWEAB6j4i ydba1jXbltsMjf5TqHHXSMoJ/zw5p8l0wPbSewDm/oQPkVLTRGdAqARBpp55W867eAfn gbrH54+IEloS6xpx5Vj8jCTJllt6fr79YR+Bo= 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=Qyr74MK/WKlKl4i65M6gkzrmGAnBET1CwJnF1BUvyb0=; b=R0D9yjbNeRpDJic3YJUCnIQsrxmFZxbsQhyX0FRygMpkP6jHBDOVan3AktquAnQwJX J7NFR5MBtJ0c83bs5VyNCXidFOf2WYeM768ZrzjTsl6aXH/HwRAkMZU0tCURka3zbcdz vDdtkWd5AWrF0jm+yjrRO4+wlXXqboVX06qq3xjWfpJAPP2PV1eNsCs5R3F0OLyrfdIr NC1iYXMFoK/QOS0zHtnuBDJqZu2KN2JJQUDFJiBRnFmRLvOC4BsOioMyflfMTMAeq5I0 fImt25iYEp/b2HL5z+ZMKYLydNaRRSApfgDqEmlBGkiqkSJC48NfAQa9pVGKwLMh0OW/ Mkqw== X-Gm-Message-State: AIVw110kc/krRGpHg2LBpOzNBggODkiQMtKNetf1rm5TT2aZo9g2hSmd BHQSy0T0NtznmDPk X-Received: by 10.223.151.216 with SMTP id t24mr2660593wrb.40.1499856740903; Wed, 12 Jul 2017 03:52:20 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: pbonzini@redhat.com Date: Wed, 12 Jul 2017 11:52:14 +0100 Message-Id: <20170712105216.747-3-alex.bennee@linaro.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170712105216.747-1-alex.bennee@linaro.org> References: <20170712105216.747-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:c0c::233 Subject: [Qemu-devel] [PATCH v4 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. 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=C3=A9e Reviewed-by: Greg Kurz Reviewed-by: Claudio Imbrenda Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- v3 - move cpu_gdb_index into gdbstub --- gdbstub.c | 26 ++++++++++++++++++++------ include/exec/gdbstub.h | 9 --------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/gdbstub.c b/gdbstub.c index 31db2309aa..6b56f55eba 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -56,6 +56,20 @@ 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) + return cpu->host_tid; +#else + return cpu->cpu_index + 1; +#endif +} + enum { GDB_SIGNAL_0 =3D 0, GDB_SIGNAL_INT =3D 2, @@ -838,7 +852,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; } } @@ -926,7 +940,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 /* @@ -976,7 +990,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 @@ -1244,7 +1258,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 @@ -1401,7 +1415,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; @@ -1435,7 +1449,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..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); =20 -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 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. --=20 2.13.0 From nobody Tue Apr 30 01:05:21 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.zohomail.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 1499856968351147.9359772534317; Wed, 12 Jul 2017 03:56:08 -0700 (PDT) Received: from localhost ([::1]:51703 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVFJP-0006yK-3p for importer@patchew.org; Wed, 12 Jul 2017 06:56:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32922) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVFGo-0004jK-QV for qemu-devel@nongnu.org; Wed, 12 Jul 2017 06:53:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVFGl-00020F-NZ for qemu-devel@nongnu.org; Wed, 12 Jul 2017 06:53:26 -0400 Received: from mail-wr0-f176.google.com ([209.85.128.176]:34058) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dVFGl-0001zh-HS for qemu-devel@nongnu.org; Wed, 12 Jul 2017 06:53:23 -0400 Received: by mail-wr0-f176.google.com with SMTP id 77so28342456wrb.1 for ; Wed, 12 Jul 2017 03:53:23 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id 143sm2469838wmg.9.2017.07.12.03.52.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Jul 2017 03:52:19 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 335823E08FA; Wed, 12 Jul 2017 11:52:17 +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=TS4LOcMtR8F8ENWKcSA6UF3p+XUn+M+VO0pxw9VOPco=; b=kgejAX7hYxl+sUoeD4tT9QLmWCTmcyq+F3gpawCXrMH60LXOjKRlhqljUWka+Sr5eW LEauwKWk58O02Gub3gwxXi8UT1rv5RlCjDkC2LiaVS9Ogt+8ARBSgJ9uX1SK11KuLXeC kfOC2p/B4Tjcww9afy5mYlwlwQ7IcjMLsk9Rw= 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=TS4LOcMtR8F8ENWKcSA6UF3p+XUn+M+VO0pxw9VOPco=; b=i7rSl2zGq+WtR1N7wuOyE5pv7832So1Qvc5RYnSv7Aao1euPXBFeFuJrKUyXYC6No3 KP/waGEt6n6yhJYN/GgzI4by+QHHs8EebT2d9OrF96WuHgNHf/SgiBgRJmbrHUkHo3Uv rSnIfFjWGcjuQf6YOfmfEXZIncDXgTvY+VSXyjGy6548x8MFloNdHnnCgqDzB3cDQ86P i0kapn1P31yYgWZZCQ4M1i2a3E7UsWf6p7Aqeyx5LfGCCuQfKy32rF1NmfMdNJc6ZnNR Pp1aTf/7joGJQth2nNJA866WEP4Td/Q14OYQgqjvEZgyPbvx+6/FbyhiI4fbEOugIkYt NO7A== X-Gm-Message-State: AIVw110wkswMbEXQyZv2GW57y5/XaVoUMndphNj882astmNjmjcprHbT 3y51IwGhVIyg5Pb68KnVCQ== X-Received: by 10.28.221.85 with SMTP id u82mr1880367wmg.40.1499856742175; Wed, 12 Jul 2017 03:52:22 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: pbonzini@redhat.com Date: Wed, 12 Jul 2017 11:52:15 +0100 Message-Id: <20170712105216.747-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170712105216.747-1-alex.bennee@linaro.org> References: <20170712105216.747-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: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.128.176 Subject: [Qemu-devel] [PATCH v4 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. To prevent BSD failing to build I've included ts_tid into its TaskStruct but not populated it - which was the same state as the old cpu->host_tid. I'll leave it up to the BSD maintainers to actually populate this properly if they want a working gdbstub with user-threads. Signed-off-by: Alex Benn=C3=A9e Reviewed-by: Greg Kurz Reviewed-by: Claudio Imbrenda Reviewed-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Laurent Vivier --- v4 - add host_tid field for BSD (but don't populate it) v3 - fix merge, did move of function in previous commit --- bsd-user/qemu.h | 2 ++ gdbstub.c | 3 ++- include/qom/cpu.h | 2 -- linux-user/syscall.c | 1 - 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index b550cee0cb..19b2b8fecb 100644 --- a/bsd-user/qemu.h +++ b/bsd-user/qemu.h @@ -85,6 +85,8 @@ struct emulated_sigtable { /* NOTE: we force a big alignment so that the stack stored after is aligned too */ typedef struct TaskState { + pid_t ts_tid; /* tid (or pid) of this task */ + struct TaskState *next; int used; /* non zero if used */ struct image_info *info; diff --git a/gdbstub.c b/gdbstub.c index 6b56f55eba..484e96dbd9 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -64,7 +64,8 @@ static inline int target_memory_rw_debug(CPUState *cpu, t= arget_ulong addr, static inline int cpu_gdb_index(CPUState *cpu) { #if defined(CONFIG_USER_ONLY) - return cpu->host_tid; + TaskState *ts =3D (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 7bfd50cc32..d3c783b4b5 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -265,7 +265,6 @@ struct qemu_work_item; * @cpu_index: CPU index (informative). * @nr_cores: Number of cores within this CPU package. * @nr_threads: Number of threads within this CPU. - * @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. @@ -319,7 +318,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 =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 Tue Apr 30 01:05:21 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.zohomail.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 1499857092327773.4698924423882; Wed, 12 Jul 2017 03:58:12 -0700 (PDT) Received: from localhost ([::1]:51720 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVFLP-0000MK-58 for importer@patchew.org; Wed, 12 Jul 2017 06:58:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32935) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVFGq-0004kR-0b for qemu-devel@nongnu.org; Wed, 12 Jul 2017 06:53:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVFGm-000212-UO for qemu-devel@nongnu.org; Wed, 12 Jul 2017 06:53:28 -0400 Received: from mail-wr0-f169.google.com ([209.85.128.169]:35461) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dVFGm-00020X-No for qemu-devel@nongnu.org; Wed, 12 Jul 2017 06:53:24 -0400 Received: by mail-wr0-f169.google.com with SMTP id k67so28124806wrc.2 for ; Wed, 12 Jul 2017 03:53:24 -0700 (PDT) Received: from zen.linaro.local ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id j190sm2533310wmd.22.2017.07.12.03.52.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 12 Jul 2017 03:52:19 -0700 (PDT) Received: from zen.linaroharston (localhost [127.0.0.1]) by zen.linaro.local (Postfix) with ESMTP id 443B53E0B27; Wed, 12 Jul 2017 11:52:17 +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=xO/Ec+K17JlCPGB7JDiTf1+3NzuWADj/2pGqep1gdO0=; b=CA2eJEBrDkT+U3teA2mTrFEXB3miCBLQM098JYElTkU7P2vMjrkftgWEZXfj1yQ9MJ tiHMzydsPw78zqNCDvVbkjJbQj/dpKwS2m01xolce8w2ljRuG4/J4xUNKecxmAum7uuy WOXQBY4HTm8lc6Q79+UeqchcTfCBojFIv4G9Q= 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=xO/Ec+K17JlCPGB7JDiTf1+3NzuWADj/2pGqep1gdO0=; b=tgYeAhzAIHvmXKmIIkm2rbYC1W4MaEM9rpejfe4leHzoj+yJSOeu8c/D2dp4xgRCGG CbbCf07eW5Np9InAD4tc67jzzkoSNhcQpl9OOAUzAaj7+h72B6Ued+tzsNUYRcsj8NoU /cnw22Dn2olxcLgnh1plvFOPNYZHZdfB8B0/QBtcjWKWSwoV8UZEeEdY01UHA6erQDyU ORGmFsOMd7TBq+Pepqq8LlXcKAL9lp1RpUTL5zkymSaq1l7kDWET4LBWddoLGa1J22lH l7x6KsNR5wEn+BfmFxJpg1h5n5U9frDgliQy4WNcrltTU2ENyL6PxWfXaSIcJAcEUKHi 68nw== X-Gm-Message-State: AIVw111y8OitUZ/acCBZ7Cf86RQ/DmUsmmxhxGN5m/pyxeGg8OMuBBmN 0/0YOjjmLwKXWI7p X-Received: by 10.28.31.203 with SMTP id f194mr2111526wmf.44.1499856743403; Wed, 12 Jul 2017 03:52:23 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: pbonzini@redhat.com Date: Wed, 12 Jul 2017 11:52:16 +0100 Message-Id: <20170712105216.747-5-alex.bennee@linaro.org> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170712105216.747-1-alex.bennee@linaro.org> References: <20170712105216.747-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: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.128.169 Subject: [Qemu-devel] [PATCH v4 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 --- v4 - one more r-b 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 484e96dbd9..a576585638 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -938,23 +938,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