From nobody Tue Nov 18 07:42:01 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1608759799; cv=none; d=zohomail.com; s=zohoarc; b=FlSzoCYjHRye119e7G3mKoaTRm7DJ+VvdMjoPwIFEOcPsyJnzxx4cJUCEviXeKu/1hGSvF8Qt9VwhBU4RBkgJnI4cjFH5IZZWM/q5fiGVHrtMQacAmpjpEC6bm6PQuIZbYE9jifdYpyoq8geZzXasPvlCGTOD9Z7jMaSn3l0lNw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608759799; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject:To; bh=X8CPegkAOfMEwOsRsECr2c65sFlWcoKZDwzw37DwwQU=; b=QO3t1Y6BZ6SF84DBqh6dPigexiHW1imhdzYwd5V4BeZWwnoLKwCC2uOwEnT6o0gUG5lzLG5jSZee21fRQubjXwyv2qM0z/1aER8dj2Z6sfE1ChKkXM3UZBIU5sqkVmvZJNGwQS8Bf54dAmX8C8NN2Lk1ox1xN2hD0l1dbiUINkY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1608759799233925.2205601425936; Wed, 23 Dec 2020 13:43:19 -0800 (PST) Received: from localhost ([::1]:41946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ksBug-0003Jc-3w for importer@patchew.org; Wed, 23 Dec 2020 16:43:18 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:45264) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ksBgG-00036h-Em for qemu-devel@nongnu.org; Wed, 23 Dec 2020 16:28:24 -0500 Received: from home.keithp.com ([63.227.221.253]:50312 helo=elaine.keithp.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ksBgD-0004bb-I1 for qemu-devel@nongnu.org; Wed, 23 Dec 2020 16:28:24 -0500 Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 1960E3F2E465; Wed, 23 Dec 2020 13:28:16 -0800 (PST) Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id lnBC8o8VI7SS; Wed, 23 Dec 2020 13:28:14 -0800 (PST) Received: from keithp.com (koto.keithp.com [10.0.0.2]) by elaine.keithp.com (Postfix) with ESMTPSA id C9E183F2E350; Wed, 23 Dec 2020 13:28:14 -0800 (PST) Received: by keithp.com (Postfix, from userid 1000) id 9D83615821A4; Wed, 23 Dec 2020 13:28:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1608758896; bh=3I5CQu0+8qCnbx7HvhLX7o+qoX16KwRm+Viq0hjsdOo=; h=From:To:Cc:Subject:Date:From; b=LHxqpehq1NpzBJAk522hdx3tnWhIkxBTpMXBY8ysQl+2LLVrYozp5N4HrFohQhnOq zofi1+iwdZCdS9pNwtPdM6Xf7AH0LeCTruJ8724F839zwKcNHxtqBpRBQ3bwun36bN meRaz+3fBy7qP53qK+VxV+2Tuct5kV9VRcBUUl9Hp3EtxWgTKvAHYZJKtLRA3vJfXL jeJt3qQP5+OlJOLBgkFJmCW4upU7r7240gpiSd/9oS6q68zgND3OxPfbEZ+p/r/nWb Y/Ql2DpODz04cMFwbpWxI4Cq4rBqm8i7r5CeD4OOMggR0WhpChuuQ/IlwYODahEake a+voN3gdb9q/A== X-Virus-Scanned: Debian amavisd-new at keithp.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=keithp.com; s=mail; t=1608758894; bh=3I5CQu0+8qCnbx7HvhLX7o+qoX16KwRm+Viq0hjsdOo=; h=From:To:Cc:Subject:Date:From; b=iOhGEWsuncQIAVMqCTxP+irG+nI87UrQpT78MPepaWd8CC2IT+EE/8MkZXz5E1biQ ZyXayJb4ihRmIwwm2Y2UX6fHOeWb3/fxrRvzSVqWHL2GB4/phKcFMzsob0tYUjyGX2 wT3SG8XCEC1zFn+m6adlHCZCfH8R/lXMkDwGrkGe0+ATuBVhHG1Ue5wpAaXkq4Yie4 eeNkD2mqCDcnYh96tDvwDuuHsv4qKI1prS/b9j9de4mTy5bmOxYNm6Wx0GdVP/VBq5 IFNP9tb4/e38i5a59DYg2Ssp3Z7ZZuet+8cVuszbmjx9VkOVurYyjzuRdgjlleMJ81 hNbq4H5+TSavg== To: qemu-devel@nongnu.org Subject: [PATCH] gdbstub.c uses incorrect check for active gdb in use_gdb_syscalls Date: Wed, 23 Dec 2020 13:27:52 -0800 Message-Id: <20201223212752.1145294-1-keithp@keithp.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.227.221.253; envelope-from=keithp@keithp.com; helo=elaine.keithp.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, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Keith Packard , =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Reply-to: Keith Packard From: Keith Packard via X-ZohoMail-DKIM: fail (found 2 invalid signatures) Content-Type: text/plain; charset="utf-8" When checking whether there is a live gdb connection, code shouldn't use 'gdbserver_state.init' as that value is set when the gdbserver_state structure is initialized in init_gdbserver_state, not when the gdb socket has a valid connection. The 'handle_detach' function appears to use 'gdbserver_state.c_cpu' as an indication of whether there is a connection, so I've used the same in use_gdb_syscalls. This avoids a segfault when qemu is run with the '-s' flag (create a gdb protocol socket), but without the '-S' flag (delay until 'c' command is received). I would like this patch to inform a discussion on whether the numerous other places using gdbserver_state.init are also incorrect (most of them appear to be using it in the same way use_gdb_syscalls does), and also whether use_gdb_syscalls should cache the result of this check or whether it should check each time it is called to see if a gdb connection is currently acive. For the second question, I don't have a clear idea; mixing gdb and native calls seems problematic for stateful operations like file open/close. Signed-off-by: Keith Packard --- gdbstub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdbstub.c b/gdbstub.c index d99bc0bf2e..4e709d16fd 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -460,7 +460,7 @@ int use_gdb_syscalls(void) /* -semihosting-config target=3Dauto */ /* On the first call check if gdb is connected and remember. */ if (gdb_syscall_mode =3D=3D GDB_SYS_UNKNOWN) { - gdb_syscall_mode =3D gdbserver_state.init ? + gdb_syscall_mode =3D gdbserver_state.c_cpu !=3D NULL ? GDB_SYS_ENABLED : GDB_SYS_DISABLED; } return gdb_syscall_mode =3D=3D GDB_SYS_ENABLED; --=20 2.29.2