public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: "Kévin Le Gouguec" <legouguec@adacore.com>
To: Tom Tromey <tromey@adacore.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH 2/2] Add return value to DAP scope
Date: Tue, 13 Feb 2024 16:01:07 +0100	[thread overview]
Message-ID: <87o7cke7d8.fsf@adacore.com> (raw)
In-Reply-To: <20240212-dap-finish-v1-2-8e30870e8b25@adacore.com> (Tom Tromey's message of "Mon, 12 Feb 2024 11:47:03 -0700")

Tom Tromey <tromey@adacore.com> writes:

> diff --git a/gdb/python/lib/gdb/dap/scopes.py b/gdb/python/lib/gdb/dap/scopes.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 = {}
>  
>  
> +# 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 = 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 = {}
> +    global _last_return_value
> +    _last_return_value = None

[… some lines elided …]
> +    def fetch_one_child(self, idx):
> +        global _last_return_value
> +        if _last_return_value is not None:
> +            if idx == 0:
> +                return ("(return)", _last_return_value)
> +            idx = idx - 1
> +        return super().fetch_one_child(idx)

If scopes are cleared whenever the inferior is resumed (my paraphrasing
of § 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 = tuple(frame.frame_args() or ())
>          if args:
>              scopes.append(_ScopeReference("Arguments", "arguments", frame, args))
> +        has_return_value = frameId == 0 and _last_return_value is not None
>          # Make sure to handle the None case as well as the empty
>          # iterator case.
>          locs = tuple(frame.frame_locals() or ())
> -        if locs:
> +        if has_return_value:
> +            scopes.append(_FinishScopeReference("Locals", "locals", frame, locs))
> +        elif locs:
>              scopes.append(_ScopeReference("Locals", "locals", frame, locs))
>          scopes.append(_RegisterReference("Registers", frame))
>          frame_to_scope[frameId] = 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évin Le Gouguec <legouguec@adacore.com>

  reply	other threads:[~2024-02-13 15:01 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-12 18:47 [PATCH 0/2] Add "finish" return value to DAP Tom Tromey
2024-02-12 18:47 ` [PATCH 1/2] Export "finish" return value to Python Tom Tromey
2024-02-12 19:24   ` Eli Zaretskii
2024-02-12 18:47 ` [PATCH 2/2] Add return value to DAP scope Tom Tromey
2024-02-13 15:01   ` Kévin Le Gouguec [this message]
2024-02-13 16:51     ` Tom Tromey
2024-02-13 22:16       ` Kévin Le Gouguec

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87o7cke7d8.fsf@adacore.com \
    --to=legouguec@adacore.com \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@adacore.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).