From mboxrd@z Thu Jan 1 00:00:00 1970 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=-13.6 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 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 292DDC433DB for ; Fri, 8 Jan 2021 12:55:55 +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 7BD1B23770 for ; Fri, 8 Jan 2021 12:55:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7BD1B23770 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:45662 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kxrJ3-0000W8-7l for qemu-devel@archiver.kernel.org; Fri, 08 Jan 2021 07:55:53 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:33920) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxrIC-0008PE-8r for qemu-devel@nongnu.org; Fri, 08 Jan 2021 07:55:00 -0500 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]:36434) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kxrIA-0007pJ-CZ for qemu-devel@nongnu.org; Fri, 08 Jan 2021 07:54:59 -0500 Received: by mail-wr1-x436.google.com with SMTP id t16so8931023wra.3 for ; Fri, 08 Jan 2021 04:54:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=references:user-agent:from:to:cc:subject:date:in-reply-to :message-id:mime-version:content-transfer-encoding; bh=JHfKgbFBE78ffVGPMtC/OXIpuVrprZXYeZSPYUDjHQ0=; b=VUCZSi4AekbdNtO3y81F8cHC9C1TvrKWBe5SbC3EyjBybu9+7KavOJmkBhCyhb4Ubt R2j2n7Ye5BUJWE4AyV+r/hlKUlAFcjYMUbNra6dJjKhoGeihKUy+mRRPHiyHFZE2FTrG +/ZYYtVMs1GlM/dmVLEin0Nd8sGVwdZiujG7g47Tvf8x0rro6m4IhIrwZsML1e4TtO82 wiFdczdUsTEKaQSmrclgiAx4y84hXdpiwETLj+hYHV91Jo92HSaRExGPHm9zWTjGCLC8 dEZt11uD+VOTeXw8PNFz3dTHi3Uyu/BhHedJwBozL3Dq7neq9IjLKX5kBuryDg8VaFk+ FC9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:references:user-agent:from:to:cc:subject:date :in-reply-to:message-id:mime-version:content-transfer-encoding; bh=JHfKgbFBE78ffVGPMtC/OXIpuVrprZXYeZSPYUDjHQ0=; b=CPGjM9iMx2smN6BMe8555WnmtTuaYTuNQff3Qwe91dmTAZk67wr4oNzGpNx5GNEBEW W5ksWI4a4xv9iEWiPeq5ZxYta+n5XWAGTw4a4iccgsqUI8HmfvJ835oUK5f/ftJq0CGg hMbbmOik0DY5ve/sDpID3+3FKy0k3YzryO/oQDh1STxTf2WeSXwDM7T+X3uaZwwn5Lqq ab1AEq1Ov5s24dgl0g3h8INQ4Cqnk2JL3pOopFJ24Rt5Vqrb7pM1hB61rJnBbNxuq6ji 5/xrdRqlmA6EW7TmzLy9gY+M6ZSEbSfgzr3fBk5EwczhRuQ0u1XThjR3ECptKGn/dv+C 2w6A== X-Gm-Message-State: AOAM531lLR/CTsPdrdEHMTe4XerAq+VqEujSqN0CQ/E5ajjb1seWVIqE R+TeaXBkru9+tSzm2Y5DWk5RXA== X-Google-Smtp-Source: ABdhPJxw9UcxguO1V2RwVLHQa0MsAfX0p1ZiCCW2rRale6BHe8ASvyCEBR7EX5vRbjzR4Oe8lHKPGA== X-Received: by 2002:a5d:5913:: with SMTP id v19mr3564547wrd.207.1610110496783; Fri, 08 Jan 2021 04:54:56 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id z6sm11487207wmi.15.2021.01.08.04.54.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Jan 2021 04:54:54 -0800 (PST) Received: from zen (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id B2B611FF7E; Fri, 8 Jan 2021 12:54:53 +0000 (GMT) References: <20201223212752.1145294-1-keithp@keithp.com> User-agent: mu4e 1.5.7; emacs 28.0.50 From: Alex =?utf-8?Q?Benn=C3=A9e?= To: Keith Packard Subject: Re: [PATCH] gdbstub.c uses incorrect check for active gdb in use_gdb_syscalls Date: Fri, 08 Jan 2021 12:36:06 +0000 In-reply-to: <20201223212752.1145294-1-keithp@keithp.com> Message-ID: <875z471tcy.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Received-SPF: pass client-ip=2a00:1450:4864:20::436; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x436.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 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: Philippe =?utf-8?Q?Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" Keith Packard writes: > 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. I guess it could be anything that is set by gdb_accept_init(). I'm a little wary of c_cpu given it has a specific meaning of current cpu and does move around depending on actions of the debugger. It would be better to wrap the test in a function (static bool is_connected()?) so the semantic meaning is clear in the code and we can fix things in one place if needed. > 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). How exactly did you create the segfault? Just starting with -s and attaching to a running tasks works fine for me although I Can see semihosting stuff would never get to gdb after connection. > 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. Hmm I don't see anything obviously wrong - although I note a bunch of tests also check for ->fd which is probably a clearer indication of an active connection. I'm sure this could be improved with a semantically clearer code though. > 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. Yes it's a bit of a hack. I can imagine starting with a remote GDB connection and then loosing it after opening a file descriptor would result in Bad Things (tm). I'm not sure what the cleanest approach is to handling the resulting mess. > > 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 Alex Benn=C3=A9e