From patchwork Thu Jul 13 14:24:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 107695 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp2301755qge; Thu, 13 Jul 2017 07:41:29 -0700 (PDT) X-Received: by 10.55.148.70 with SMTP id w67mr5082267qkd.160.1499956889843; Thu, 13 Jul 2017 07:41:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499956889; cv=none; d=google.com; s=arc-20160816; b=Ta5cKRdiDAtTBQy5IVYzpgfLP3UriIb8b70N2/F5wAbPGng6uam1mnbvnBmbUfy1gj n9lGWdUC/rJfCU1vrlkREM4CuJe+36BdEizJTrFIHnP4WWOdTAvbJX8EoMfTtDWDdrSG YtIDdQ4YJ0RDNNbLGe0FsI5xwfTCjXDISysr6tHi4FNSTHfjVhtxIVwkx8JiYAQXTfSe rtUF7PQE2A2OofAk61B4HabWtOKODanw9tqU7fTNgmksRmd0WCDX4nQvbaimWnyLFinV N93Niec6O+FFeLUdvnk0j8DHrspLeLnEvJKjDK8Q3rh/rzzbXF4sr49MmwdYdO8dnt5V PZ1w== 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=jEI1iyUNgqBDnBVxv41UCPc9Zo2uQoG7t4lksrVr4I0=; b=BLc0Cp9fYqIaFy5R9UULxbziDWQngFXe89qp9vChQi9MulTh1yBLOLJrH7Q7wfzs51 KTNvQXrAqSd5gND91b1eYPpKWwxIXhD/SK3ctSaDNafnDKWVZtW5lbu//AqABGeKKZhs +QoRvqgm/zVQ9hYsUeBoh1+bGttgxizHsbBAz8FM5dywx4UQ3CsxWX3qytdMMD6rIix3 Swb/TTud4liapL615nDLRoY6MUiKB2NVArZDChEvhNUR39t4X2maM1iomQnkMbhvYUty WWslweMLL5+uxtNF8MV2K62vtxN6JbMEyXsHyBRmkA0Ut+RPTgb7a9jLYf8ORr9du2JS re4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.b=bX0fRqQH; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [208.118.235.17]) by mx.google.com with ESMTPS id d51si5131070qtb.292.2017.07.13.07.41.29 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 13 Jul 2017 07:41:29 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.b=bX0fRqQH; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:60436 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVfIg-0007YW-3L for patch@linaro.org; Thu, 13 Jul 2017 10:41:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51805) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVf4R-0001tF-30 for qemu-devel@nongnu.org; Thu, 13 Jul 2017 10:26:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVf4N-0004KI-2L for qemu-devel@nongnu.org; Thu, 13 Jul 2017 10:26:23 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:35673) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dVf4M-0004K0-PM for qemu-devel@nongnu.org; Thu, 13 Jul 2017 10:26:18 -0400 Received: by mail-wr0-f195.google.com with SMTP id y28so4891663wrd.2 for ; Thu, 13 Jul 2017 07:26:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jEI1iyUNgqBDnBVxv41UCPc9Zo2uQoG7t4lksrVr4I0=; b=bX0fRqQHRbf4rkMZ7lNiT5rGYozByqSzVt1X9aNzf6JCIRiHjZqYRMO2qhBWdHYsj2 IF6U7ICHowD7RoWEMcOGtTJszFwYz64++AosAMtwYkL157zxXuSZK7yow0ujIvavPNYM mwy4kJkGAA5r2oITPl7eY0ET357Ldtpq0WkvG7aa+Ql0YAlJWv8oyEXAh4DIJEzpJMsX P77fW/F4PHGWm0y3E/4qq9i7YFyp0IMXfRjpo6aKdjarHEO1ewrAD8ZYdF1CRUAJLQQu 2anfT6OqRXzH4ta+HA3l0Uh5l7jfwRqolUxf/Na/HQGowMStmhpoixJhAbZxFXmFWpy5 SYUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=jEI1iyUNgqBDnBVxv41UCPc9Zo2uQoG7t4lksrVr4I0=; b=VzmwVvN4ssrF8tZd59zsranpxmcLCNNSa4YhI9foth7KEZjyHeLLLJtBYqnG0lMZJl yQH0C3N8IRp+egFZ3eK0uAhoByvPkDzyZBN2onIgN2K/XpffBSOC0lqJiwOHOpe9N1Xu xiIWIykTtmJuPqRmeJxpf91WFniQkGIZ+msWqltSo/PQ+EqdwnMkdBM+dIx3p81D5Gtq z3sccQQlWJpVBmFl+gzaN2fHuWjCBl78skN/Lfg0FemQPO6wABljE2SWykoTsPoxTVIY zdcHlasrbRDCNIlBjGLbSlZeSBAuhRgWMg5eR/vGBnRApxXXwRjBUEOAvudi+nfe3/HA P2lw== X-Gm-Message-State: AIVw113wB4TGkaK2V8J4EERLGzmoBpXMKTIkKKPR9f8JeibZyiULgcfJ bTec5+8AzRqbeya+/CI= X-Received: by 10.223.177.129 with SMTP id q1mr1873673wra.82.1499955917508; Thu, 13 Jul 2017 07:25:17 -0700 (PDT) Received: from 640k.lan (94-39-191-51.adsl-ull.clienti.tiscali.it. [94.39.191.51]) by smtp.gmail.com with ESMTPSA id k75sm6042448wmh.10.2017.07.13.07.25.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jul 2017 07:25:16 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 13 Jul 2017 16:24:17 +0200 Message-Id: <1499955874-10954-25-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1499955874-10954-1-git-send-email-pbonzini@redhat.com> References: <1499955874-10954-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.128.195 Subject: [Qemu-devel] [PULL 24/41] 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?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée 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 Message-Id: <20170712105216.747-2-alex.bennee@linaro.org> Signed-off-by: Paolo Bonzini --- gdbstub.c | 77 +++++++++++++++++++++++++++------------------------------------ 1 file changed, 33 insertions(+), 44 deletions(-) -- 1.8.3.1 diff --git a/gdbstub.c b/gdbstub.c index e561244..3965980 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -272,7 +272,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; @@ -548,9 +561,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)); } @@ -956,9 +967,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) { @@ -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 == '-') { -#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 != '$') @@ -1550,9 +1558,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: @@ -1568,9 +1574,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 */ @@ -1584,9 +1588,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 */ @@ -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 = 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 */ @@ -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 = 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 = RS_GETLINE; break; } s->line_csum |= fromhex(ch); if (s->line_csum != (s->line_sum & 0xff)) { + gdb_debug("got command packet with incorrect checksum\n"); /* send NAK reply */ reply = '-'; put_buffer(s, &reply, 1); -#ifdef DEBUG_GDB - printf("gdbstub got command packet with incorrect checksum\n"); -#endif s->state = RS_IDLE; } else { /* send ACK reply */ From patchwork Thu Jul 13 14:24:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 107694 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp2297846qge; Thu, 13 Jul 2017 07:38:12 -0700 (PDT) X-Received: by 10.55.118.66 with SMTP id r63mr4912130qkc.234.1499956692286; Thu, 13 Jul 2017 07:38:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499956692; cv=none; d=google.com; s=arc-20160816; b=efI7STIN0bkJoabegigs27L4Hc9R0p8nxC8qaCWtFYsfCmTOWGfIJmHWBqIWnjeO07 aCZVrFzPaV8rTYFNJ+RdiTjh6BXk6Zdf1WcBOonc6j50WNNl2j3YksTURMLp2KQve/vK h0rxxGpD/lJ3gT8WKK7kQ0k7bWCHiGWSkDYhlG/pEjRuYNpGgQPksTVOUBsBPAKMEP38 hhc2bldC8HrY+j8mH0UJ1uTNXwhHUB+VMTsix1rPNmPLYYsP52ldwmUEYrUH1EmynHW8 7a3yqCRNej8v6r4DeiAfXjxx/JJ0Wk1eAdYsE1lIpb/60OOCdmgbz5SwTplTlluriZhQ gonw== 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=5VxhkUvYqbtgQVQ0wVb8zX32heZrIbbUlUoJMa3P708=; b=hlbgOLQeCPNoeyxbNCEWaVoRy6crXrSv3dWl691Ya2Zd7Snw9Bd/pqe24H/js5gMUs ynxlJLUPbeu1fcsPICXfIzQLrU8w2vlN7sniAb46QhKbWHcASrnkCkS/ZvWYzdeYjgbq +jT1SB0IhEvAR19sjYwua/bTyYzszsnKz+fuaJwrlbjIAWs/ibkUtWL1WWxOunVEmDFi Rbdt+KCBWgcP1rjxbMY6kqGHZgEz9jDpGZFVKdVDUa6ZVrUVCaULA1KD2cw6TUn8dnpr e41qCt0VfgrKCDeaErt5gK8QWEd688AOT4Xru2ay/81ogfYrBxdvVDwH5QGzBzQT0mak cp4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.b=soCwjZLR; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [208.118.235.17]) by mx.google.com with ESMTPS id p65si5356537qkp.165.2017.07.13.07.38.11 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 13 Jul 2017 07:38:12 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.b=soCwjZLR; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:60421 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVfFp-0003Zd-JE for patch@linaro.org; Thu, 13 Jul 2017 10:38:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51240) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVf3R-00010d-AG for qemu-devel@nongnu.org; Thu, 13 Jul 2017 10:25:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVf3Q-0002UV-5e for qemu-devel@nongnu.org; Thu, 13 Jul 2017 10:25:21 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:34903) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dVf3P-0002U3-SQ for qemu-devel@nongnu.org; Thu, 13 Jul 2017 10:25:20 -0400 Received: by mail-wm0-x242.google.com with SMTP id u23so5457775wma.2 for ; Thu, 13 Jul 2017 07:25:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5VxhkUvYqbtgQVQ0wVb8zX32heZrIbbUlUoJMa3P708=; b=soCwjZLR3tm8lr5i94xapgJIFCtNt5yKWkvnThrTndSpJ9i+EPaltN6/IOD+eId88I U/PTA7UaXhIvG+WqvrSvb6jQ8SIdGmvFfeTv7Bubm2G9xoezEzbV5299kguEAOwH2Fcu R4lr4Z2s6d0OZCYHZgaqFyELU8wow4z8gjmAHyycgO3xz9Kk7414sKDfVfiHDlISdRXu KPoHFrq3LFjb7EI8if3hIs5Xxxa4IxXLbFdbzSWKE+HNGuAhqfRdSWFwfcDB1BgJ6HMv ArwQYhFUZ9Z4Ruj+z2uF/18goAgziR/pMhxlieRuP+tF9nLDIAhd9nldKRtUREPF/+lb wSuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=5VxhkUvYqbtgQVQ0wVb8zX32heZrIbbUlUoJMa3P708=; b=Jy99okRe7rpdn9gLa/V0dEjT10v6Mt23m+bW926GpzgfBjuwjMr99p99R5KYPJL/vx rWZcNH4jZGLuZ9Hlogl9iLIeSDCeOxwa95EjxJ5a2kaOJNMlWi+z0ARZjXCfQG49sMwC jP3ZEFj5VakTNsOMMuEKyvu2CiTYQrE467XbtXM3Ila2hp8sRYB2gq4qjXVDgJPSqTfB ibEc2srMcCKQOlwhFIiPz8AGO+VamkZ/H4FrMLg3vWAhHVq+yViLR3U0w5hl3uhwOSja m7J92503IS8f4Xa8TmRRwgwvbaugkVOK7lq+6nQJ+lIT0yqVNQrlCjAGm4cfDtYL+s6o MtLw== X-Gm-Message-State: AIVw110uZvwo/WRlKtST5qEyMsX3CmtZXxltqC8Tr19Y+9smsVbrfo+c E1I2hU3haJRM4JNAl50= X-Received: by 10.28.133.76 with SMTP id h73mr2279815wmd.92.1499955918630; Thu, 13 Jul 2017 07:25:18 -0700 (PDT) Received: from 640k.lan (94-39-191-51.adsl-ull.clienti.tiscali.it. [94.39.191.51]) by smtp.gmail.com with ESMTPSA id k75sm6042448wmh.10.2017.07.13.07.25.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jul 2017 07:25:17 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 13 Jul 2017 16:24:18 +0200 Message-Id: <1499955874-10954-26-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1499955874-10954-1-git-send-email-pbonzini@redhat.com> References: <1499955874-10954-1-git-send-email-pbonzini@redhat.com> 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::242 Subject: [Qemu-devel] [PULL 25/41] 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?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée 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é Message-Id: <20170712105216.747-3-alex.bennee@linaro.org> Signed-off-by: Paolo Bonzini --- gdbstub.c | 26 ++++++++++++++++++++------ include/exec/gdbstub.h | 9 --------- 2 files changed, 20 insertions(+), 15 deletions(-) -- 1.8.3.1 diff --git a/gdbstub.c b/gdbstub.c index 3965980..b1efe0b 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); } +/* 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, @@ -838,7 +852,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; } } @@ -926,7 +940,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); } /* @@ -976,7 +990,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 @@ -1244,7 +1258,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 @@ -1401,7 +1415,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; @@ -1435,7 +1449,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 f9708bb..9aa7756 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 Thu Jul 13 14:24:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 107697 Delivered-To: patch@linaro.org Received: by 10.182.45.195 with SMTP id p3csp2373929obm; Thu, 13 Jul 2017 07:57:09 -0700 (PDT) X-Received: by 10.237.40.103 with SMTP id r94mr5293272qtd.205.1499957829551; Thu, 13 Jul 2017 07:57:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499957829; cv=none; d=google.com; s=arc-20160816; b=pIT/AgH4rxPhY2ZllLlYowvj8WBLSI8F8jQ7KGqckHfnD8jXxOpRTTSiMWdHTHX87w 9w0U7XFyLdfyObvyS9xzJV1zrYTnj+sUI98GXkcw/XvRhCoTSgt2U92GLhFJ1aJYAiMj ceiSZQ0Fwwykbb5x7P+31GzmmFIWwWRFVMeK+cdmieB8wGc6lUeIh+C0A0Mm9Pit9dN8 5WZI9XczcbtQ44qiGeR2pNo26v+Z7Y3ClLF7hHNZQZxqJH9AN/tvR/wOdJlFGnuWZ/oc GgUQKPBmteS+POfV314AZaY4ax6CSiPAPyVyNSDHRekg6VlvqRN1DdBAKZ1OF7WqZbSI uPkw== 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=arbrowqiXXY1I5jnvtk2LC+cC4qs2l9RMhIv9E6O3oQ=; b=PHwjfltPJgbrz+VzHPPr3O4+qeULxXT6OIaOBUqFlry11vrrieKpKQsSmfFmRkqQU3 zJtckZGSubIf9pA8TRurzSMmvhz78o0i4KVXcy2Jstg8Tl29COe+3iIBA+CiP2LtB7xD 1rmeh67LUWtrES1EHZeM5WQ6xiRiAZr2tEU6nu0/Kpgfp+SlUVQhYIwZ3cSYIUPnki1D LTa6eT3E482dFiYObWexWnxGMNEIhLRMjUO5KGRGcDgoIFUaap11AYBkwADy+WFkcP23 Smtf0/+QUap2RZGSKTNywQtWT5gaZ252d3bGngrsoVE21dL4Eplgioy3W/T2HmSL3QVf VuVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.b=aUuNUqh3; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [208.118.235.17]) by mx.google.com with ESMTPS id r49si5307366qte.305.2017.07.13.07.57.09 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 13 Jul 2017 07:57:09 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.b=aUuNUqh3; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:60518 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVfYB-0005rx-1C for patch@linaro.org; Thu, 13 Jul 2017 10:57:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51813) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVf4T-0001vJ-A9 for qemu-devel@nongnu.org; Thu, 13 Jul 2017 10:26:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVf4P-0004L4-Dt for qemu-devel@nongnu.org; Thu, 13 Jul 2017 10:26:25 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:34671) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dVf4P-0004Kj-63 for qemu-devel@nongnu.org; Thu, 13 Jul 2017 10:26:21 -0400 Received: by mail-wm0-f68.google.com with SMTP id p204so5456275wmg.1 for ; Thu, 13 Jul 2017 07:26:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=arbrowqiXXY1I5jnvtk2LC+cC4qs2l9RMhIv9E6O3oQ=; b=aUuNUqh3DyKjJ9Qf6dPQeIJ7qBmlbMtAdMei5uIhE/tccL96VSv28a3yqTRCyJnKTT e4p6YxPfBcRCdXmohLuNvBMrh/D95U67DNtdZo+eOEL0HbGHZpTD3OmdTXxeM5Jbiw5j ZgA/YzLdldMSwCjAJ3S8wcifsGNmkXsCXiIIJb7GeLxdhEu5AC22QCVLM1PYJxE83/jH TQhjD40CSBJ6VIiEvaBYzdD+5nOh0Vmfaf1MwTP6ggqay5d3Hx49tLVOtTcwXD66GUTL Usf5QI50hcdz2luDQ8QLj4fEgLu/wwdZW9HBzWT9CpPXas4vFpxqQMqcvzibEGtTy9C/ 3s1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=arbrowqiXXY1I5jnvtk2LC+cC4qs2l9RMhIv9E6O3oQ=; b=LM+Hh1CP7Pi5AQjTBOWRuRl2F6VOETH7nGuszFjNwA6/fqz0qQgO6bzPpb3VJErqk2 SUrmipxsgSjsYfcd80DbwlJV1/XD6q/IdceR3VLtoYoQaWu8srLUCFf0ZsJrN0BN0Stl 3B+kiM+5inFRvoQZ4ndIQ1K/f/tL8oND2jRaO7Km1x/QXasIfT9N+1vlGgKsN3y9LiLV /pqX77vvJSKEyqfrwZ7hsGop9rslWXJZilOsCm4DSmia4Qomq2AnM2HzAzseXk4fXncy CEeIAzlSU9KnZJRPO8UB08asYdX8fUAmGB331vfz8fA+rsmI0h/VQ9/JnXy3ycs/ov5a LfiQ== X-Gm-Message-State: AIVw111YkbyFGqD2uiD0OjBTR2qhwf0leJQHsSw5eIxn+UkmzidaYOMI XYGiQG41ne/0SUJnXe4= X-Received: by 10.28.22.6 with SMTP id 6mr2458059wmw.124.1499955919716; Thu, 13 Jul 2017 07:25:19 -0700 (PDT) Received: from 640k.lan (94-39-191-51.adsl-ull.clienti.tiscali.it. [94.39.191.51]) by smtp.gmail.com with ESMTPSA id k75sm6042448wmh.10.2017.07.13.07.25.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jul 2017 07:25:19 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 13 Jul 2017 16:24:19 +0200 Message-Id: <1499955874-10954-27-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1499955874-10954-1-git-send-email-pbonzini@redhat.com> References: <1499955874-10954-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.68 Subject: [Qemu-devel] [PULL 26/41] 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: =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée 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ée Reviewed-by: Greg Kurz Reviewed-by: Claudio Imbrenda Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Laurent Vivier Message-Id: <20170712105216.747-4-alex.bennee@linaro.org> Signed-off-by: Paolo Bonzini --- 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(-) -- 1.8.3.1 diff --git a/bsd-user/qemu.h b/bsd-user/qemu.h index b550cee..19b2b8f 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 b1efe0b..378fdd8 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -64,7 +64,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 7bfd50c..d3c783b 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 925ae11..003943b 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 Thu Jul 13 14:24:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 107696 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp2303488qge; Thu, 13 Jul 2017 07:43:01 -0700 (PDT) X-Received: by 10.200.8.68 with SMTP id x4mr5781643qth.195.1499956981852; Thu, 13 Jul 2017 07:43:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499956981; cv=none; d=google.com; s=arc-20160816; b=CptDUAedeOfiW3ncAsI9Y+ojT650v7YTzhv/HqqKydFWsv8B2QzdQnm2FXi87W/bhR eeR/v9Xu546TjguqszshQEnzn1zFegzVNZntkhCoE947mDTXXgKif7YeYsCKWHU2EdQ2 zCcI0yYa02C3v9VtYRHVuCqORJIKL6wj4XsopEZhm4wFKSpNo1ldOJ4I/yRPniARVkHn 8cFRy9o8c6PiB0CZtnPv5LQphdHRvAp0h9i1YX77R3TN/hYxDmWBEMMj45g7I9thpzgY r5/pHioyAF4iGPVge0xyb+YqBGmFvkEayPVcQAP9dYghtzYymAPmuA4By01gThplW4nZ WKTg== 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=CMlD808lugJXGmG58AGJr1dxcm+wOz+OewK7oNnwtzA=; b=nd7bYPGD9hNUkKEMX2Lozb/x01EpXdPBhqktPlBTmqkAfyJx8YRzGvN6oM1eXZKg/u nUBMa+uMRz9amD0Tj6f42MhoL36zzS9I/6yTiBXfa38bEsm0Nf4nnhbvhSiWYsL5JizZ iDr3D+N52E3WrRbV25FrhwCF+JZS/d4538tnewBVF6RzSmcQqrTTjd5MQOjixqdOuCP1 vpqXngZqjm/nm9KeLudqvxIb7i0ygeWQUazwGeUZd7d5r9IwRXyaVDF75Nmv0P7vMWbr m9RXWtCvmu7K4B55JJcq1JA0asSxL38yB1GAJo5/zu794ps418oyflvhpw8qUiPEJPqf ikFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.b=N32PRGwG; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [208.118.235.17]) by mx.google.com with ESMTPS id o22si5199377qki.45.2017.07.13.07.43.01 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 13 Jul 2017 07:43:01 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.b=N32PRGwG; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:60442 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVfKV-0000jU-CM for patch@linaro.org; Thu, 13 Jul 2017 10:42:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51271) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVf3T-00012w-Ka for qemu-devel@nongnu.org; Thu, 13 Jul 2017 10:25:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVf3S-0002WC-JQ for qemu-devel@nongnu.org; Thu, 13 Jul 2017 10:25:23 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:34904) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dVf3S-0002Va-Ca for qemu-devel@nongnu.org; Thu, 13 Jul 2017 10:25:22 -0400 Received: by mail-wm0-x244.google.com with SMTP id u23so5457948wma.2 for ; Thu, 13 Jul 2017 07:25:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CMlD808lugJXGmG58AGJr1dxcm+wOz+OewK7oNnwtzA=; b=N32PRGwGYSBM2V3ezdy6x3rYu32xwpzbKYXxhaMwPm43vUEPXdc9JsygulGvjgDGtB BNGN2zabP0CKXV6BHw/myyoYdZedBUvybOtIchhEx74u8CK6ecAzvulVOzQjKRb9ApZC b8+HHXdAp60dLKKOah0pnqDSR+nnGWh4j84lz5928Tr4MYQiecg3OrOsHyOhOvUeLRlC QlPa7ltGxt6QDstVIcq8fWorck9mdPPx0yL3VL/pGXbE1XE3bpBTWfHaQHHum2Py5BR/ j+Fv+LwDZLJMGR67pFRAJ9CLbt5Vp/wnm3gisAmzfcBhufnPDzOlupiUTZ+P2ahgR5uF VPuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=CMlD808lugJXGmG58AGJr1dxcm+wOz+OewK7oNnwtzA=; b=SG20miiwdtTNLjKXT8bcPAV1VnU9fxFfQrcdsEooXoR2VyfFaKv0sY+7PVn9R/qbMr zgp1D6tcegdAH3qZSJhGbsD+EPMXEri3n0pAgUL7q2euT7JAvq6D8zlo2XIW+rjx7FiW wy8aP9GkhR+OFcndrlwAd64uKXPcL62Rm6sqN8c3RAkPMQIZ94jBWUbCXZuYj/4TJMck P8w0KYIWZ+n8mh/qdUy6t9BHosMNV+CiHkDAKDvDNH/604EEWXj0OLNXGbSVpNrcniOs Lpgx6pH75IBQykLP8FoqRXplCM+fXqZrlO+NJWP85/AB1KK19YIicsG4V6Lkm2BOC22F Gwwg== X-Gm-Message-State: AIVw111sv3RQvmKRTkCJZwOOV+UKp+Gp8fZD72aas/fJKm8pI3NyV3Lk MmRgJsiEZJsAygbmUxQ= X-Received: by 10.28.34.130 with SMTP id i124mr2294752wmi.116.1499955921125; Thu, 13 Jul 2017 07:25:21 -0700 (PDT) Received: from 640k.lan (94-39-191-51.adsl-ull.clienti.tiscali.it. [94.39.191.51]) by smtp.gmail.com with ESMTPSA id k75sm6042448wmh.10.2017.07.13.07.25.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jul 2017 07:25:20 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 13 Jul 2017 16:24:20 +0200 Message-Id: <1499955874-10954-28-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1499955874-10954-1-git-send-email-pbonzini@redhat.com> References: <1499955874-10954-1-git-send-email-pbonzini@redhat.com> 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::244 Subject: [Qemu-devel] [PULL 27/41] 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?= Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Alex Bennée 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 Reviewed-by: Philippe Mathieu-Daudé Message-Id: <20170712105216.747-5-alex.bennee@linaro.org> Signed-off-by: Paolo Bonzini --- gdbstub.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) -- 1.8.3.1 diff --git a/gdbstub.c b/gdbstub.c index 378fdd8..f936ddd 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 = 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;