public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Handle DAP "stepOut" request in outermost frame
@ 2024-04-25 17:20 Johan Sternerup
  2024-04-25 17:52 ` Tom Tromey
  0 siblings, 1 reply; 6+ messages in thread
From: Johan Sternerup @ 2024-04-25 17:20 UTC (permalink / raw)
  To: gdb-patches; +Cc: Johan Sternerup

Previously a "stepOut" request when in the outermost frame would result
in a sucessful response even though gdb internally would reject the
associated "finish" request, which means no stoppedEvent would ever be
sent back to the client. Thus the client would believe the inferior was
still running and as a consequence reject subsequent "next" and "stepIn"
requests from the user.

The solution here is to make the same check that is made in
'infcmd.c/finish_command()' to make sure we're not in the outermost
frame, but now we do it _before_ actually running the "finish" command
so that we can send an error response immediately.
---
 gdb/python/lib/gdb/dap/next.py     | 10 ++++++----
 gdb/testsuite/gdb.dap/step-out.exp | 11 +++++++++++
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/gdb/python/lib/gdb/dap/next.py b/gdb/python/lib/gdb/dap/next.py
index 1dc1d6dd74d..05a9946b752 100644
--- a/gdb/python/lib/gdb/dap/next.py
+++ b/gdb/python/lib/gdb/dap/next.py
@@ -17,7 +17,7 @@ import gdb
 
 from .events import exec_and_expect_stop
 from .server import capability, request, send_gdb, send_gdb_with_response
-from .startup import in_gdb_thread
+from .startup import DAPException, in_gdb_thread
 from .state import set_thread
 
 
@@ -73,10 +73,12 @@ def step_in(
     exec_and_expect_stop(cmd)
 
 
-@request("stepOut", response=False)
+@request("stepOut", on_dap_thread=True)
 def step_out(*, threadId: int, singleThread: bool = False, **args):
-    _handle_thread_step(threadId, singleThread, True)
-    exec_and_expect_stop("finish")
+    if not gdb.selected_frame().older():
+        raise DAPException("\"finish\" not meaningful in the outermost frame.")
+    send_gdb_with_response(lambda: _handle_thread_step(threadId, singleThread))
+    send_gdb(lambda: exec_and_expect_stop("finish"))
 
 
 # This is a server-side request because it is funny: it wants to
diff --git a/gdb/testsuite/gdb.dap/step-out.exp b/gdb/testsuite/gdb.dap/step-out.exp
index 757f4ebdaca..207eb73e191 100644
--- a/gdb/testsuite/gdb.dap/step-out.exp
+++ b/gdb/testsuite/gdb.dap/step-out.exp
@@ -79,4 +79,15 @@ gdb_assert {[dict get $varlist variablesReference] > 0} \
 gdb_assert {[dict get $varlist name] == "(return)"} \
     "variable is return value"
 
+set response_and_events [dap_request_and_response stepOut {o threadId [i 1]}]
+set response [lindex $response_and_events 0]
+if {[dict get $response success] == "true"} {
+	fail "stepOut from outermost frame should not succeed"
+} else {
+    pass "stepOut from outermost frame failed like it should"
+}
+
+dap_check_request_and_response "still stopped and may request backtrace" \
+	stackTrace {o threadId [i 1]}
+
 dap_shutdown
-- 
2.34.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-04-27  8:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-25 17:20 [PATCH] Handle DAP "stepOut" request in outermost frame Johan Sternerup
2024-04-25 17:52 ` Tom Tromey
2024-04-25 18:05   ` Tom Tromey
2024-04-26 18:32     ` Johan Sternerup
2024-04-26 20:28       ` Tom Tromey
2024-04-27  8:24         ` Johan Sternerup

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).