public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 6/8] Select frame when fetching a frame variable in DAP
Date: Tue, 22 Aug 2023 09:25:12 -0600	[thread overview]
Message-ID: <20230822-array-and-string-like-v1-6-2dcea29b0567@adacore.com> (raw)
In-Reply-To: <20230822-array-and-string-like-v1-0-2dcea29b0567@adacore.com>

Right now, if a program uses multiple languages, DAP value formatting
will always use the language of the innermost frame.  However, it is
better to use the variable's defining frame instead.  This patch does
this by selecting the frame first.

This also fixes a possibly latent bug in the "stepOut" command --
"finish" is sensitive to the selected frame, but the DAP code may
already select other frames when convenient.  The DAP stepOut request
only works on the newest frame, so be sure to select it before
invoking "finish".
---
 gdb/python/lib/gdb/dap/next.py   | 11 ++++++++---
 gdb/python/lib/gdb/dap/scopes.py |  4 ++++
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/gdb/python/lib/gdb/dap/next.py b/gdb/python/lib/gdb/dap/next.py
index 8b112770a0c..5046963cb81 100644
--- a/gdb/python/lib/gdb/dap/next.py
+++ b/gdb/python/lib/gdb/dap/next.py
@@ -23,9 +23,10 @@ from .state import set_thread
 
 # Helper function to set the current thread and the scheduler-locking
 # mode.  Returns True if scheduler-locking was successfully set to
-# 'on', False in all other cases, including error.
+# 'on', False in all other cases, including error.  When SELECT is
+# True, also select that thread's newest frame.
 @in_gdb_thread
-def _handle_thread_step(thread_id, single_thread):
+def _handle_thread_step(thread_id, single_thread, select=False):
     # Ensure we're going to step the correct thread.
     set_thread(thread_id)
     if single_thread:
@@ -41,6 +42,10 @@ def _handle_thread_step(thread_id, single_thread):
         gdb.execute("set scheduler-locking " + arg, from_tty=True, to_string=True)
     except gdb.error:
         result = False
+    # Other DAP code may select a frame, and the "finish" command uses
+    # the selected frame.
+    if select:
+        gdb.newest_frame().select()
     return result
 
 
@@ -70,7 +75,7 @@ def step_in(
 
 @request("stepOut")
 def step_out(*, threadId: int, singleThread: bool = False):
-    send_gdb(lambda: _handle_thread_step(threadId, singleThread))
+    send_gdb(lambda: _handle_thread_step(threadId, singleThread, True))
     send_gdb(ExecutionInvoker("finish", StopKinds.STEP))
 
 
diff --git a/gdb/python/lib/gdb/dap/scopes.py b/gdb/python/lib/gdb/dap/scopes.py
index 1687094c4ce..4874d001216 100644
--- a/gdb/python/lib/gdb/dap/scopes.py
+++ b/gdb/python/lib/gdb/dap/scopes.py
@@ -49,6 +49,10 @@ class _ScopeReference(BaseReference):
 
     @in_gdb_thread
     def fetch_one_child(self, idx):
+        # Make sure to select the frame first.  Ideally this would not
+        # be needed, but this is a way to set the current language
+        # properly so that language-dependent APIs will work.
+        self.inf_frame.select()
         # Here SYM will conform to the SymValueWrapper interface.
         sym = self.var_list[idx]
         name = str(sym.symbol())

-- 
2.40.1


  parent reply	other threads:[~2023-08-22 15:25 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-22 15:25 [PATCH 0/8] Handle array- and string-like types " Tom Tromey
2023-08-22 15:25 ` [PATCH 1/8] Move rust_language::lookup_symbol_nonlocal Tom Tromey
2023-08-22 15:25 ` [PATCH 2/8] Refactor Rust code for slice-to-array operation Tom Tromey
2023-08-22 15:25 ` [PATCH 3/8] Introduce TYPE_SPECIFIC_RUST_STUFF Tom Tromey
2023-08-22 15:25 ` [PATCH 4/8] Use ada_value_subscript in valpy_getitem Tom Tromey
2023-08-22 15:25 ` [PATCH 5/8] Introduce type::is_array_like and value_to_array Tom Tromey
2023-08-22 15:25 ` Tom Tromey [this message]
2023-08-22 15:25 ` [PATCH 7/8] Add new Python APIs to support DAP value display Tom Tromey
2023-08-22 15:46   ` Eli Zaretskii
2023-08-22 15:25 ` [PATCH 8/8] Handle array- and string-like values in no-op pretty printers Tom Tromey
2023-09-05 17:22 ` [PATCH 0/8] Handle array- and string-like types in DAP Tom Tromey

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=20230822-array-and-string-like-v1-6-2dcea29b0567@adacore.com \
    --to=tromey@adacore.com \
    --cc=gdb-patches@sourceware.org \
    /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).