From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by sourceware.org (Postfix) with ESMTPS id 0DA083858C50 for ; Tue, 13 Feb 2024 15:01:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0DA083858C50 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0DA083858C50 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707836473; cv=none; b=JopZaRK2DcYTi2wF8T3ERUhOeOnYlwEAGK2VZq5tgxRrpVngNfy+CRNMcu1WeA+iNKsd/Z50sK26Qe/MltrAHtru5l4FTtzvpdTdOUt/lITNTXMVtn3DyVC86tslbT7ACG1c6H9nMfKwBiO+e+PraDoWjFs5GfHHH/zWz+OdXoY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707836473; c=relaxed/simple; bh=6oypEixcSe4kcccNwwDRdJli7a9+266y+mJPlX8jYOU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=MED1G7dsH2QvycnNEnw9g7uGErSzit676lynhW3MJ1Cv75/YT68mcMXYVvAGlrjFskEbF8WePfvMsqy0JlDBUDERoRGl2aAJSoMiG1eS+rl+ZgdA4DE2pDb1Etp4N2DbnkVKAf/JeWiUNcjdPEDF/nrgpsgksL7qaPBXjRf75Os= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-411d253098eso1645445e9.3 for ; Tue, 13 Feb 2024 07:01:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1707836468; x=1708441268; darn=sourceware.org; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YGwTEigngKuUXyIayw5VIBKNfOqqmR7Qna8Pc3MmDsc=; b=OGV0fuHbAeH/xQT4wBFngcbDn+40Q1z2sSh4vTTyVW7uRjrZUpoheBThDqWyLgY2DS cPIytS/YWC34N7ZVNsQ+PJYVDLgW7VaZ3s0FSBIWw9O4vHqFW9NGdhzZbWImKDzehKL1 xC/Vqu/70eQv/gP8MiTqSX+u7FPQTgJoBSOZWCkmw1Z3s5GlHEl/ujCuGqfd6/T08TbE 19W8b/lAljJD+5woNHDOCpWe2XjB9CMOluSPvbtxzQyNTtnO9R+xNc09v6i+/LqLUsN1 5Jf3QSMCocYl6NoMUVfHvL4GzHQyuVFJTKnetKN+Jcoj+MQ85YCCwIhXOC9LZ9x8k9JV jYgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707836468; x=1708441268; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=YGwTEigngKuUXyIayw5VIBKNfOqqmR7Qna8Pc3MmDsc=; b=eO9BeWQmOLZ+SC4RXoPZy4Fqv5aI/N60WNJK4oisdndDupGSBlDSh2Heu5JyOs8PE2 IAeAyPyA3AfgO1sIIKirXXbK1z/cj+inoRDHsZJWdH/tQu9F9I8RIg2RR4OVG2Farxjs Cnl74AX0yLscO2Y7yRo57Iz9qjKEYgljPNGjA2GpaiTy9qQrq4Cepbis1RdYFhNYB1lj pffCqSESzwVlUFlNcdAOSOYljkb+IPZfklhg82Sz2K5uoclT3oV9aUWxDaQ/KQMI7wsz MvODmotKAOHEYsetkyZfQwfricpFiWDPRL46HFe7i/vAI+Hi5FevTb59WsMq3L60X/yb rT7A== X-Gm-Message-State: AOJu0YyAosoWsZ4ee8xdcsXIc0Vkue4iQYk3HbM/N+yGQAIXCaZcRcaY sKIqcUol3ZAFQHyqih2tpOiSV1lFXVlUBWv5e5NCSWasxdkhYJOxzfSCO6HpRm9LH0sgiNGtxsb pWg== X-Google-Smtp-Source: AGHT+IEU2d+ucFlKcjSDiLBx1cUci2cPy8JRUZCH9+L3zwLisU6sThSCR4Ct5DmHioMBfKmsBzZZAQ== X-Received: by 2002:a05:600c:548f:b0:410:83a6:e042 with SMTP id iv15-20020a05600c548f00b0041083a6e042mr8468947wmb.5.1707836468293; Tue, 13 Feb 2024 07:01:08 -0800 (PST) Received: from legouguec-Precision-7550 ([2a01:e0a:253:fe0:78e6:864d:c0d3:c625]) by smtp.gmail.com with ESMTPSA id jn14-20020a05600c6b0e00b004104bc8d841sm11976567wmb.13.2024.02.13.07.01.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 07:01:07 -0800 (PST) From: =?utf-8?Q?K=C3=A9vin_Le_Gouguec?= To: Tom Tromey Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 2/2] Add return value to DAP scope In-Reply-To: <20240212-dap-finish-v1-2-8e30870e8b25@adacore.com> (Tom Tromey's message of "Mon, 12 Feb 2024 11:47:03 -0700") References: <20240212-dap-finish-v1-0-8e30870e8b25@adacore.com> <20240212-dap-finish-v1-2-8e30870e8b25@adacore.com> Date: Tue, 13 Feb 2024 16:01:07 +0100 Message-ID: <87o7cke7d8.fsf@adacore.com> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Tom Tromey writes: > diff --git a/gdb/python/lib/gdb/dap/scopes.py b/gdb/python/lib/gdb/dap/sc= opes.py > index ff553259ea9..f3bbe4fc614 100644 > --- a/gdb/python/lib/gdb/dap/scopes.py > +++ b/gdb/python/lib/gdb/dap/scopes.py > @@ -25,17 +25,32 @@ from .varref import BaseReference > frame_to_scope =3D {} >=20=20 >=20=20 > +# If the most recent stop was due to a 'finish', and the return value > +# could be computed, then this holds that value. Otherwise it holds > +# None. > +_last_return_value =3D None > + > + > # When the inferior is re-started, we erase all scope references. See > # the section "Lifetime of Objects References" in the spec. > @in_gdb_thread > def clear_scopes(event): > global frame_to_scope > frame_to_scope =3D {} > + global _last_return_value > + _last_return_value =3D None [=E2=80=A6 some lines elided =E2=80=A6] > + def fetch_one_child(self, idx): > + global _last_return_value > + if _last_return_value is not None: > + if idx =3D=3D 0: > + return ("(return)", _last_return_value) > + idx =3D idx - 1 > + return super().fetch_one_child(idx) If scopes are cleared whenever the inferior is resumed (my paraphrasing of =C2=A7 Lifetime of Objects References), can this method be called after _last_return_value has been reset to None? Wondering if the outer 'if' is necessary, since we only create a _FinishScopeReference when _last_return_value is not None: > @@ -120,10 +158,13 @@ def scopes(*, frameId: int, **extra): > args =3D tuple(frame.frame_args() or ()) > if args: > scopes.append(_ScopeReference("Arguments", "arguments", fram= e, args)) > + has_return_value =3D frameId =3D=3D 0 and _last_return_value is = not None > # Make sure to handle the None case as well as the empty > # iterator case. > locs =3D tuple(frame.frame_locals() or ()) > - if locs: > + if has_return_value: > + scopes.append(_FinishScopeReference("Locals", "locals", fram= e, locs)) > + elif locs: > scopes.append(_ScopeReference("Locals", "locals", frame, loc= s)) > scopes.append(_RegisterReference("Registers", frame)) > frame_to_scope[frameId] =3D scopes Tangentially, wondering if capturing _last_return_value as a _FinishScopeReference.__init__ parameter would make sense. It may well be that I don't completely understand the lifetime of the objects involved here. At any rate: Reviewed-By: K=C3=A9vin Le Gouguec