From: Johan Sternerup <johan.sternerup@gmail.com>
To: gdb-patches@sourceware.org
Cc: Johan Sternerup <johan.sternerup@gmail.com>
Subject: [PATCH] Handle DAP "stepOut" request in outermost frame
Date: Thu, 25 Apr 2024 19:20:19 +0200 [thread overview]
Message-ID: <20240425172019.863412-1-johan.sternerup@gmail.com> (raw)
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
next reply other threads:[~2024-04-25 17:20 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-25 17:20 Johan Sternerup [this message]
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
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=20240425172019.863412-1-johan.sternerup@gmail.com \
--to=johan.sternerup@gmail.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).