diff options
author | Tom Tromey <tromey@adacore.com> | 2024-02-12 08:12:02 -0700 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2024-03-08 10:50:12 -0700 |
commit | 99761c5ab53e11105b6067bc4314e74bb066006c (patch) | |
tree | de1272d440cd7d8c6680ccf36f5fa9f016706161 /gdb/python/py-stopevent.c | |
parent | 03fa0c63d3a5944afcf031ecf0b433b2985e6eeb (diff) | |
download | binutils-99761c5ab53e11105b6067bc4314e74bb066006c.zip binutils-99761c5ab53e11105b6067bc4314e74bb066006c.tar.gz binutils-99761c5ab53e11105b6067bc4314e74bb066006c.tar.bz2 |
Export "finish" return value to Python
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.
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Diffstat (limited to 'gdb/python/py-stopevent.c')
-rw-r--r-- | gdb/python/py-stopevent.c | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/gdb/python/py-stopevent.c b/gdb/python/py-stopevent.c index 61d9372..fcaebe2 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 |