From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/2] Export "finish" return value to Python
Date: Mon, 12 Feb 2024 11:47:02 -0700 [thread overview]
Message-ID: <20240212-dap-finish-v1-1-8e30870e8b25@adacore.com> (raw)
In-Reply-To: <20240212-dap-finish-v1-0-8e30870e8b25@adacore.com>
This patch changes the Python "stop" event emission code to also add
the function return value, if it is known. This happens when the stop
comes from a "finish" command and when the value can be fetched.
The test is in the next patch.
---
gdb/doc/python.texi | 6 ++++++
gdb/infcmd.c | 17 -----------------
gdb/python/py-stopevent.c | 23 ++++++++++++++++++++++-
gdb/thread-fsm.h | 19 +++++++++++++++++++
4 files changed, 47 insertions(+), 18 deletions(-)
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index ece9038844c..21a84fabb34 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -3813,6 +3813,12 @@ corresponding MI output (@pxref{GDB/MI Async Records}).
A dictionary was used for this (rather than adding attributes directly
to the event object) so that the MI keys could be used unchanged.
+
+When a @code{StopEvent} results from a @code{finish} command, it will
+also hold the return value from the function, if that is available.
+This will be an entry named @samp{return-value} in the @code{details}
+dictionary. The value of this entry will be a @code{gdb.Value}
+object.
@end defvar
Emits @code{gdb.SignalEvent}, which extends @code{gdb.StopEvent}.
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 4e17a6b0629..68f64f0d2b3 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -1484,23 +1484,6 @@ get_return_value (struct symbol *func_symbol, struct value *function)
return value;
}
-/* The captured function return value/type and its position in the
- value history. */
-
-struct return_value_info
-{
- /* The captured return value. May be NULL if we weren't able to
- retrieve it. See get_return_value. */
- struct value *value;
-
- /* The return type. In some cases, we'll not be able extract the
- return value, but we always know the type. */
- struct type *type;
-
- /* If we captured a value, this is the value history index. */
- int value_history_index;
-};
-
/* Helper for print_return_value. */
static void
diff --git a/gdb/python/py-stopevent.c b/gdb/python/py-stopevent.c
index 61d93727b31..fcaebe26f13 100644
--- a/gdb/python/py-stopevent.c
+++ b/gdb/python/py-stopevent.c
@@ -20,6 +20,7 @@
#include "defs.h"
#include "py-stopevent.h"
#include "py-uiout.h"
+#include "thread-fsm.h"
gdbpy_ref<>
create_stop_event_object (PyTypeObject *py_type, const gdbpy_ref<> &dict)
@@ -45,6 +46,7 @@ static gdbpy_ref<>
py_print_bpstat (bpstat *bs, enum gdb_signal stop_signal)
{
py_ui_out uiout;
+ struct value *return_value = nullptr;
try
{
@@ -55,6 +57,10 @@ py_print_bpstat (bpstat *bs, enum gdb_signal stop_signal)
{
async_reply_reason reason = tp->thread_fsm ()->async_reply_reason ();
uiout.field_string ("reason", async_reason_lookup (reason));
+
+ return_value_info *rvinfo = tp->thread_fsm ()->return_value ();
+ if (rvinfo != nullptr && rvinfo->value != nullptr)
+ return_value = rvinfo->value;
}
if (stop_signal != GDB_SIGNAL_0 && stop_signal != GDB_SIGNAL_TRAP)
@@ -73,7 +79,22 @@ py_print_bpstat (bpstat *bs, enum gdb_signal stop_signal)
return nullptr;
}
- return uiout.result ();
+ gdbpy_ref<> dict = uiout.result ();
+ if (dict == nullptr)
+ return nullptr;
+
+ /* This has to be done separately to avoid error issues, and because
+ there's no API to add generic Python objects to a py_ui_out. */
+ if (return_value != nullptr)
+ {
+ gdbpy_ref<> val (value_to_value_object (return_value));
+ if (val == nullptr)
+ return nullptr;
+ if (PyDict_SetItemString (dict.get (), "finish-value", val.get ()) < 0)
+ return nullptr;
+ }
+
+ return dict;
}
/* Callback observers when a stop event occurs. This function will create a
diff --git a/gdb/thread-fsm.h b/gdb/thread-fsm.h
index 90abb5c27f6..ed117719c0d 100644
--- a/gdb/thread-fsm.h
+++ b/gdb/thread-fsm.h
@@ -23,6 +23,25 @@
struct return_value_info;
struct thread_fsm_ops;
+struct type;
+struct value;
+
+/* The captured function return value/type and its position in the
+ value history. */
+
+struct return_value_info
+{
+ /* The captured return value. May be NULL if we weren't able to
+ retrieve it. See get_return_value. */
+ struct value *value;
+
+ /* The return type. In some cases, we'll not be able extract the
+ return value, but we always know the type. */
+ struct type *type;
+
+ /* If we captured a value, this is the value history index. */
+ int value_history_index;
+};
/* A thread finite-state machine structure contains the necessary info
and callbacks to manage the state machine protocol of a thread's
--
2.43.0
next prev parent reply other threads:[~2024-02-12 18:47 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 ` Tom Tromey [this message]
2024-02-12 19:24 ` [PATCH 1/2] Export "finish" return value to Python 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
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=20240212-dap-finish-v1-1-8e30870e8b25@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).