From patchwork Mon Jul 31 14:15:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 708413 Delivered-To: patch@linaro.org Received: by 2002:a5d:6787:0:b0:317:2194:b2bc with SMTP id v7csp2330437wru; Mon, 31 Jul 2023 07:16:49 -0700 (PDT) X-Google-Smtp-Source: APBJJlHF6xL9bjDF/83ncuZ6AlLlLUTSe603uY5vn7RUm1dJYxvHfcPsin45iBg+mKitx7OhhZ1m X-Received: by 2002:a05:6214:4014:b0:63c:fa7d:74ee with SMTP id kd20-20020a056214401400b0063cfa7d74eemr13198344qvb.50.1690813009566; Mon, 31 Jul 2023 07:16:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690813009; cv=none; d=google.com; s=arc-20160816; b=OGKnRqZxE4Y0y1YApvGn2Quu06koyehMhRdm7rPeTmvUQ0NKA8CMtz/AGVw0AoY2kj L9oQZWbLRlSgjyFx8oaQod4PWGYJU7EB2DpnQqe0bocKzR4XJMf/iJCZ5RwPztlqt9J+ aje9saqq8dOFsvQHaWUKEFJa62NbV5e9hbfgCCUNWusgUSlA0PObsIamAQzofzkzYQjU GdGIRehMifVYnsA12B6YYTQvYx1tyP6PLZL2z+N/7HeirUl18tonvEGSEGhfdyE61yql laeuj8FuVH3+djcQC6yg2Nx+Jk2bK52B0fUVMhiByiOQhEhnqcGBQ8ThbzgroQvO9dX0 11lQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=umPuKK0TP/i1glV8Qojb6FP6t/DJTY4yK7JJ/sINZ5E=; fh=bFDrUYhlTVi/QyetgXx/byg2+yO/22Hp9SjwoefyKLk=; b=eHDsyGF8V9skB6APCaxvkCiOckA75UxG/t5pgSch9UlLV0822s5FvjM+ry0zzNXcVU QeQaI8PxZ+Jdhg8Xw6M+TrbzyOMmkrHypMHTIemgIlJLO/cpMYHSNuVzBnzTpK0VlKIH +hc71PF+2SygvlzieL7m/xNIYtafdYkXJ9zR93AwYlCtrge1MwPwLMO23qqopxtBCMbQ UCuV+CMcr3cnRP7nuUMxBuyCJXcy4S0syA2p2aMoujzaVwCLip0Tp90TTAfM6NsARqZV lssVX34IkTTymvIU2EadG6LQRgdH+ETQ/kK78h4U/wckkH60EDIE8MJAH1DWhHvzQ43h W8qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MFrKBW+i; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id k13-20020a0cf58d000000b0063d26039f64si5655398qvm.555.2023.07.31.07.16.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 31 Jul 2023 07:16:49 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MFrKBW+i; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qQTgb-0005al-2s; Mon, 31 Jul 2023 10:15:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qQTgT-0005Xy-Tm for qemu-devel@nongnu.org; Mon, 31 Jul 2023 10:15:41 -0400 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qQTgR-0007ex-QP for qemu-devel@nongnu.org; Mon, 31 Jul 2023 10:15:41 -0400 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-3fe2048c910so9789235e9.1 for ; Mon, 31 Jul 2023 07:15:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1690812938; x=1691417738; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=umPuKK0TP/i1glV8Qojb6FP6t/DJTY4yK7JJ/sINZ5E=; b=MFrKBW+iLqvFD3CUTIt8nain8KfYljuJkzxSmKOVH2WaY2eHKUQ/bZBX9g2NqO4BtS vfqZJnerM9oyDYR0uGaMweOhuHoRE9KETpezJxS9yOEDgz6XlJUHGpDS/SNxID04pXfp +R5+CMe1nnV1IHHjeQnuPMjV2NALGZB0wmSdgMpkgu1mBszVXXOE4Yjr2A7dj4qNHQht vPpyzBquqZUn9l86j8j4ugjY/K3ng3KMy6wh6nfKp4O1Hj+TZHuccFzpHG5IxPnIyKU+ TBT6wVsP3q5PrlpS1J8RXPk8VuWJ5ElB6JQCKcSNi/tYKKjGMvww5e0BTNKnoEyffzg7 KUdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690812938; x=1691417738; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=umPuKK0TP/i1glV8Qojb6FP6t/DJTY4yK7JJ/sINZ5E=; b=KARH+nFz7diFro5g8565NrS4N2fpo+vUpxxaUZ/P7ZSRSgjtVfrrZxveNGxTjGnxZf HIjn3N7Y5qrpPtSPz+yadldoGRViITg9Hwfxm7iEDLxtE8GNnl/TeMPy+rIPfJypafUF an5Bm9rnjZ9O64ClqIe0MWemM63lNztugqKNV+kv55DrFF2toeVbINX+uZ4OOM1u6Q2n BgbXBo12nGMiW/rdgyCjc8al9ches66/RXmnxCSClqTdYMGFCGPHhK9dWwRFs3tV6NpA Y51ajH46eiUCSJBeOmgS64Kp0fej9H0N1ENRPB6oarTjDc4RGL68LY2UfaC4DL883BC8 NgSQ== X-Gm-Message-State: ABy/qLY+vSr3QraxG9TKC+IneB4cMd/7ucMA9w+Yrj7Qi6zYpLeptcDs ZSFBU3SaKR7j52K7wpEBta8TMWcyedg7ZpWsCwE= X-Received: by 2002:a05:600c:215:b0:3fe:25b3:951d with SMTP id 21-20020a05600c021500b003fe25b3951dmr77568wmi.5.1690812938053; Mon, 31 Jul 2023 07:15:38 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id z15-20020a05600c114f00b003fbb5506e54sm11450675wmz.29.2023.07.31.07.15.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 31 Jul 2023 07:15:37 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 6/6] gdbstub: Fix client Ctrl-C handling Date: Mon, 31 Jul 2023 15:15:33 +0100 Message-Id: <20230731141533.3303894-7-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230731141533.3303894-1-peter.maydell@linaro.org> References: <20230731141533.3303894-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x333.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org From: Nicholas Piggin The gdb remote protocol has a special interrupt character (0x03) that is transmitted outside the regular packet processing, and represents a Ctrl-C pressed in the client. Despite not being a regular packet, it does expect a regular stop response if the stub successfully stops the running program. See: https://sourceware.org/gdb/onlinedocs/gdb/Interrupts.html Inhibiting the stop reply packet can lead to gdb client hang. So permit a stop response when receiving a character from gdb that stops the vm. Additionally, add a warning if that was not a 0x03 character, because the gdb session is likely to end up getting confused if this happens. Cc: qemu-stable@nongnu.org Fixes: 758370052fb ("gdbstub: only send stop-reply packets when allowed to") Reported-by: Frederic Barrat Signed-off-by: Nicholas Piggin Tested-by: Joel Stanley Message-id: 20230711085903.304496-1-npiggin@gmail.com Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- gdbstub/gdbstub.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c index 6911b73c079..ce8b42eb159 100644 --- a/gdbstub/gdbstub.c +++ b/gdbstub/gdbstub.c @@ -2051,8 +2051,17 @@ void gdb_read_byte(uint8_t ch) return; } if (runstate_is_running()) { - /* when the CPU is running, we cannot do anything except stop - it when receiving a char */ + /* + * When the CPU is running, we cannot do anything except stop + * it when receiving a char. This is expected on a Ctrl-C in the + * gdb client. Because we are in all-stop mode, gdb sends a + * 0x03 byte which is not a usual packet, so we handle it specially + * here, but it does expect a stop reply. + */ + if (ch != 0x03) { + warn_report("gdbstub: client sent packet while target running\n"); + } + gdbserver_state.allow_stop_reply = true; vm_stop(RUN_STATE_PAUSED); } else #endif