From patchwork Wed Dec 23 21:27:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Packard X-Patchwork-Id: 11988939 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33C26C433DB for ; Wed, 23 Dec 2020 21:43:17 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AAFCF2246B for ; Wed, 23 Dec 2020 21:43:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AAFCF2246B Authentication-Results: mail.kernel.org; dmarc=pass (p=none dis=none) header.from=nongnu.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:41946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ksBud-0003Jc-SJ for qemu-devel@archiver.kernel.org; Wed, 23 Dec 2020 16:43:15 -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) 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 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) 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== Received: by keithp.com (Postfix, from userid 1000) id 9D83615821A4; Wed, 23 Dec 2020 13:28:14 -0800 (PST) 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 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_Mathieu-Daud=C3=A9?= , Keith Packard , =?utf-8?q?Alex_Benn=C3=A9e?= Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Reply-to: Keith Packard X-Patchwork-Original-From: Keith Packard via From: Keith Packard 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=auto */ /* On the first call check if gdb is connected and remember. */ if (gdb_syscall_mode == GDB_SYS_UNKNOWN) { - gdb_syscall_mode = gdbserver_state.init ? + gdb_syscall_mode = gdbserver_state.c_cpu != NULL ? GDB_SYS_ENABLED : GDB_SYS_DISABLED; } return gdb_syscall_mode == GDB_SYS_ENABLED;