From patchwork Wed Jul 12 10:52:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 107476 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp648415qge; Wed, 12 Jul 2017 03:55:28 -0700 (PDT) X-Received: by 10.55.110.133 with SMTP id j127mr5628875qkc.92.1499856928499; Wed, 12 Jul 2017 03:55:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499856928; cv=none; d=google.com; s=arc-20160816; b=uI2oxYzVZCwxn32z38Kcz2I9XSn5zFHBsmflEXtwje1TsGcKsfZ+VOJcpvEV1gj7rA GSLXlFsZPf1n+bruk6gLxiEx1lf8N4rSQL40ZcA2pV+s8Hhvhml1GX2EMuCVe6kXsOS9 13hZbOWTb5u7UYfrw1jH2+zNFQhHs3lkDmJTSj40EcgOzRlqSDT6Z0A8kIT68uF7zp9g L6iA7YtUQ8kUyfVF5GApwweDTOxFcdEz4JI7lH1ki3ywUCb0YJlH5gxRcu1HdTnWTY3i ngJvQ6k2YCxsHFyjMgBPc83v7+nksOO8n5p6xj527r/J3EsMzqdq8OQ8wAqG28FTGr6S hkZg== 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=IMqTMgNti8BoQzaOjugYl05GbQiU0olK4bgHdDtryW4=; b=pw1382qRijxYkZSvMVcn+O0Ii76Nq1S+HQ7h3jfQr36YPa9SqbJXutBVF0At5rZTRL vwnIyy4iHwRZ5UwUlYEW6hTLaIazrUt996JkaB3vclVT9wA5gRHFKsLi/pzOGPF/yIy4 +lNMl3Fm4lutGUrC959dInpkOuUVXGREBYQvXkjjmHbZxHBhRnmFjCfZTWKAb2eREVN8 OS3yLe9/5T54xlDZIWuz4SOoHOk71e12Wr9qGjCEZ/YDrmmKZb6AsOA3QY4o/DGBVyq/ +8uAVQGSUJm4ljwmjRyKUINZHF/GHaO4vcFGtcFFcNP9BIDFNaZSQN48rDLBaJ+Cei6A 8L/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.b=Sue6pbIR; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [208.118.235.17]) by mx.google.com with ESMTPS id u5si1967548qtu.171.2017.07.12.03.55.27 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 12 Jul 2017 03:55:28 -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=@linaro.org header.b=Sue6pbIR; 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=linaro.org Received: from localhost ([::1]:51696 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVFIj-0006Hr-HF for patch@linaro.org; Wed, 12 Jul 2017 06:55:25 -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) 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) 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) From: =?utf-8?q?Alex_Benn=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 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_Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Convert the a gdb_debug helper which compiles away to nothing when not used but still ensures the format strings are checked. There is some minor code motion for the incorrect checksum message to report it before we attempt to send the reply. Signed-off-by: Alex Bennée Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Greg Kurz --- gdbstub.c | 77 +++++++++++++++++++++++++++------------------------------------ 1 file changed, 33 insertions(+), 44 deletions(-) -- 2.13.0 diff --git a/gdbstub.c b/gdbstub.c index ec4e4b25be..31db2309aa 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 Wed Jul 12 10:52:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 107475 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp647257qge; Wed, 12 Jul 2017 03:54:08 -0700 (PDT) X-Received: by 10.237.63.119 with SMTP id q52mr5627555qtf.49.1499856847367; Wed, 12 Jul 2017 03:54:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499856847; cv=none; d=google.com; s=arc-20160816; b=QLNDwTFXhmp1IwDBTM0jHKjSpI/AT0bxFAMCMvCjQPXrKKNW9CxAAD5UarDy3V+ITh TIJJCuvVmP357wN0Y+mAOpFm7Xwf3dUKB42gqOxbN6BXjAk9Z9BeCtEDce3zpP08Yuol Kf840pdiZH3U0yCdy4opHxrXCor7RUihrOafQSX3MapZSepujT3K7wstoDl/WzOpJB5f NiFXj0YylCj8oKaJkRm8h2/j+op9PrlrENfsG2jQXLilzQ+ks2MTlrY/Y1Hgeb38Nw8Q uh9wV5S228kBHSvLq75oi3ao3HScB/uOx+f7KfswcWILviSy8AEcMMrQysPEekuEv3gw ju7A== 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=Qyr74MK/WKlKl4i65M6gkzrmGAnBET1CwJnF1BUvyb0=; b=Y66G0ZWc7RCI2rE2h62lpgp3Db9WPwS+pb0zfht7lWU6wg0TKpeV3nmRRrnv83CNZ2 L8baeaAj6yq+b/dnhqo6YCvi7B3F3+RJ3Uky2vcJdvyvyHudILsFbTIOuCdsQTkWZJkf h39yDY6aflR59TvuFKbVQj5eaTyaWtR2M4MJ4nzBrO73aErEwFTNtOT4r4fmk5AcGMWj n75mTu22MXPiqqo/CRXePU56+lcd28sa6b2+fnNhoNPbNuNbmViBR7pBueVCBSY5BHa1 /KsNflbl8Xzf/mJzPLJXKb2DyiIVqNMTU9w8vCV70pw+qqam4xwUqBrYjR7a+VqSS0qG xW4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.b=Xl+ok4w8; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [208.118.235.17]) by mx.google.com with ESMTPS id h126si1987354qkf.114.2017.07.12.03.54.06 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 12 Jul 2017 03:54:07 -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=@linaro.org header.b=Xl+ok4w8; 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=linaro.org Received: from localhost ([::1]:51690 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVFHQ-00051g-Lh for patch@linaro.org; Wed, 12 Jul 2017 06:54:04 -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) 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) 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) From: =?utf-8?q?Alex_Benn=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 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_Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This is to make it clear the index is purely a gdbstub function and should not be confused with the value of cpu->cpu_index. At the same time we move the function from the header to gdbstub itself which will help with later changes. Signed-off-by: Alex Bennée Reviewed-by: Greg Kurz Reviewed-by: Claudio Imbrenda Reviewed-by: Philippe Mathieu-Daudé --- v3 - move cpu_gdb_index into gdbstub --- gdbstub.c | 26 ++++++++++++++++++++------ include/exec/gdbstub.h | 9 --------- 2 files changed, 20 insertions(+), 15 deletions(-) -- 2.13.0 diff --git a/gdbstub.c b/gdbstub.c index 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); } +/* 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 f9708bbcd6..9aa7756d92 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -58,15 +58,6 @@ void gdb_register_coprocessor(CPUState *cpu, gdb_reg_cb get_reg, gdb_reg_cb set_reg, int num_regs, const char *xml, int g_pos); -static inline int cpu_index(CPUState *cpu) -{ -#if defined(CONFIG_USER_ONLY) - return cpu->host_tid; -#else - return cpu->cpu_index + 1; -#endif -} - /* The GDB remote protocol transfers values in target byte order. This means * we can use the raw memory access routines to access the value buffer. * Conveniently, these also handle the case where the buffer is mis-aligned. From patchwork Wed Jul 12 10:52:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 107477 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp649243qge; Wed, 12 Jul 2017 03:56:20 -0700 (PDT) X-Received: by 10.200.55.208 with SMTP id e16mr5326426qtc.198.1499856980017; Wed, 12 Jul 2017 03:56:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499856980; cv=none; d=google.com; s=arc-20160816; b=cRxdc978U44iN7ivihECfpaFqT9Jdha5rzxrEwiTKjpw++cMPyHq/yaed0EliI/85i s0qOHrJVa6bfCZ9EuBFUDevjAL/jRxpGkuABIb2Q/jINNb9uQY+qJrd4SaMi0FUqHosm srv/GGKsJYPVaptpo6E07Tck2uMx5s/5KPntIVJLyblaa+d926N7HXwdkY4wTjtMAH3K utTZmQOdcnJ9O+lMcKwmQsEJsU0kelel7lgBUBWPkZIw1SoaBpIVInBXjGVU2a+jVp1a 0pQWrrfQWz8sTHbrcw4ykajaKJqnYRgesO/pqfFtZaZDuQrwW60RFVYWqMkV5n65TqTS 8i/A== 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=TS4LOcMtR8F8ENWKcSA6UF3p+XUn+M+VO0pxw9VOPco=; b=i91olOHJryCIcxCeCHy5OzBL3JGzB+qGaGAylqqsRMfQK8Ig+nYV1v1lBQrAgIyT91 RPUf3aw03PjYgds/n2kXp97BSDe+3LoV2xdwNC9VdiuS66RpbCzmJBPFap+axzlx9ceU CYc4AzR8Yy7b9yRy6X+mfNBL/rch81U/+ArIZEMlXhbYKcmnj2cyBdUeNjMJQZ5aU2zs /H6BWlrbE2E35V1Cv4uIrAXqannJNwWMU+T7FD11YEyvpdevriIh4HIYiKauLZ2+V2tM 5AREwEVAthQYWtzK/PXumEnzuTptRSTY6Fkn9h4xHn35znZzAYxxAc9z3NnuU1EJpZeF Ljkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.b=kgejAX7h; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [208.118.235.17]) by mx.google.com with ESMTPS id v75si1929319qkl.144.2017.07.12.03.56.19 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 12 Jul 2017 03:56:20 -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=@linaro.org header.b=kgejAX7h; 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=linaro.org Received: from localhost ([::1]:51703 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVFJZ-0006yK-Na for patch@linaro.org; Wed, 12 Jul 2017 06:56:17 -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) 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) 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) From: =?utf-8?q?Alex_Benn=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 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_Benn=C3=A9e?= , qemu-devel@nongnu.org, Laurent Vivier Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This was only used by the gdbstub and even then was only being set for subsequent threads. Rather the continue duplicating the number just make the gdbstub get the information from TaskState structure. Now the tid is correctly reported for all threads the bug I was seeing with "vCont;C04:0;c" packets is fixed as the correct tid is reported to gdb. I moved cpu_gdb_index into the gdbstub to facilitate easy access to the TaskState which is used elsewhere in gdbstub. 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 --- 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(-) -- 2.13.0 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, 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 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 = 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 Wed Jul 12 10:52:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 107478 Delivered-To: patch@linaro.org Received: by 10.140.101.44 with SMTP id t41csp651202qge; Wed, 12 Jul 2017 03:58:22 -0700 (PDT) X-Received: by 10.237.61.47 with SMTP id g44mr5816932qtf.60.1499857102539; Wed, 12 Jul 2017 03:58:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1499857102; cv=none; d=google.com; s=arc-20160816; b=DXtlS7g1l9wIJ+Zf4U01VxrJBGzhlIM7ELbEhqqdwB0CEm6SS2oOWwulxmAdJ9focr d3MqqS1+ZEBzl/32aFx4tUlfYQt8+TQAqeXwIct925ywFmxGNdFdavIFKvChrRZvcCih /qS51PzNKM4vN2tItfpheh5PJ5q2+hW3XACrDqh5P+wc6Q0azLbAjXHqO7RKR1OZQH0J 9Q/+2Xgg5vCjO53RxnpAcEsXFjjojb9cf1rkT+CZldAZBdqZ2C70PR4DS6FZ/CEISjHA Q2B05zj3KXLEH9/+vVVJD/pzDsGFIrSe51VSjhUrDHFuyHoblY+JakQoQA9m+SFDvafz ZlYA== 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=xO/Ec+K17JlCPGB7JDiTf1+3NzuWADj/2pGqep1gdO0=; b=r+QW/+ICWk/zaIDxRgHb8Mw6ZzRYD5dkmyI8Rhmf50K1mgIGUgPuaMAVtU6tP821je oC9lVIXVG3iCpCW7svvkkFZwTAKU6JhEvuWgnAEm4gR4bxTlkUdyJuKXzd5XCL7EbNIw 5WvtEAVeLVqFUs1nJIeetpyBzTs6PB2d5M5t8aPM3TQ+UNKDD7J+GYFUDT3oizeh93VI H8TUQCE1wnvJIYoFPsRcKMJrxfW+EniQcRN60oCwr5YEvF9elSeZIIztTItzJuFsSvtb oUaE4bLK4LTG+z9FYM2mqUxQAmS6sGz7zYRD7mYPWDCdr/i/DP3iWS5DFnjWq77/IV2q IGJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.b=CA2eJEBr; 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=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [208.118.235.17]) by mx.google.com with ESMTPS id h68si2009546qkd.34.2017.07.12.03.58.22 for (version=TLS1 cipher=AES128-SHA bits=128/128); Wed, 12 Jul 2017 03:58:22 -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=@linaro.org header.b=CA2eJEBr; 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=linaro.org Received: from localhost ([::1]:51720 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVFLX-0000MK-VU for patch@linaro.org; Wed, 12 Jul 2017 06:58:20 -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) 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) 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) From: =?utf-8?q?Alex_Benn=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 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_Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The thread-id of 0 means any CPU but we then ignore the fact we find the first_cpu in this case who can have an index of 0. Instead of bailing out just test if we have managed to match up thread-id to a CPU. Otherwise you get: gdb_handle_packet: command='vCont;C04:0;c' put_packet: reply='E22' The actual reason for gdb sending vCont;C04:0;c was fixed in a previous commit where we ensure the first_cpu's tid is correctly reported to gdb however we should still behave correctly next time it does send 0. Signed-off-by: Alex Bennée Reviewed-by: Greg Kurz Reviewed-by: Claudio Imbrenda Reviewed-by: Philippe Mathieu-Daudé --- 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(-) -- 2.13.0 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 = 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;