aboutsummaryrefslogtreecommitdiff
path: root/gdb/python/py-unwind.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/python/py-unwind.c')
-rw-r--r--gdb/python/py-unwind.c114
1 files changed, 63 insertions, 51 deletions
diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c
index e36768e..dc078ec 100644
--- a/gdb/python/py-unwind.c
+++ b/gdb/python/py-unwind.c
@@ -1,6 +1,6 @@
/* Python frame unwinder interface.
- Copyright (C) 2015-2024 Free Software Foundation, Inc.
+ Copyright (C) 2015-2025 Free Software Foundation, Inc.
This file is part of GDB.
@@ -228,7 +228,7 @@ unwind_infopy_str (PyObject *self)
}
catch (const gdb_exception &except)
{
- GDB_PY_HANDLE_EXCEPTION (except);
+ return gdbpy_handle_gdb_exception (nullptr, except);
}
}
else
@@ -378,7 +378,7 @@ unwind_infopy_add_saved_register (PyObject *self, PyObject *args, PyObject *kw)
}
catch (const gdb_exception &except)
{
- GDB_PY_HANDLE_EXCEPTION (except);
+ return gdbpy_handle_gdb_exception (nullptr, except);
}
gdbpy_ref<> new_value = gdbpy_ref<>::new_reference (pyo_reg_value);
@@ -429,7 +429,7 @@ pending_framepy_str (PyObject *self)
}
catch (const gdb_exception &except)
{
- GDB_PY_HANDLE_EXCEPTION (except);
+ return gdbpy_handle_gdb_exception (nullptr, except);
}
return PyUnicode_FromFormat ("SP=%s,PC=%s", sp_str, pc_str);
@@ -456,7 +456,7 @@ pending_framepy_repr (PyObject *self)
}
catch (const gdb_exception &except)
{
- GDB_PY_HANDLE_EXCEPTION (except);
+ return gdbpy_handle_gdb_exception (nullptr, except);
}
return PyUnicode_FromFormat ("<%s level=%d, sp=%s, pc=%s>",
@@ -505,7 +505,7 @@ pending_framepy_read_register (PyObject *self, PyObject *args, PyObject *kw)
}
catch (const gdb_exception &except)
{
- GDB_PY_HANDLE_EXCEPTION (except);
+ return gdbpy_handle_gdb_exception (nullptr, except);
}
return result;
@@ -546,7 +546,7 @@ pending_framepy_name (PyObject *self, PyObject *args)
}
catch (const gdb_exception &except)
{
- GDB_PY_HANDLE_EXCEPTION (except);
+ return gdbpy_handle_gdb_exception (nullptr, except);
}
if (name != nullptr)
@@ -574,7 +574,7 @@ pending_framepy_pc (PyObject *self, PyObject *args)
}
catch (const gdb_exception &except)
{
- GDB_PY_HANDLE_EXCEPTION (except);
+ return gdbpy_handle_gdb_exception (nullptr, except);
}
return gdb_py_object_from_ulongest (pc).release ();
@@ -601,7 +601,7 @@ pending_framepy_language (PyObject *self, PyObject *args)
}
catch (const gdb_exception &except)
{
- GDB_PY_HANDLE_EXCEPTION (except);
+ return gdbpy_handle_gdb_exception (nullptr, except);
}
Py_RETURN_NONE;
@@ -628,7 +628,7 @@ pending_framepy_find_sal (PyObject *self, PyObject *args)
}
catch (const gdb_exception &except)
{
- GDB_PY_HANDLE_EXCEPTION (except);
+ return gdbpy_handle_gdb_exception (nullptr, except);
}
return sal_obj;
@@ -653,7 +653,7 @@ pending_framepy_block (PyObject *self, PyObject *args)
}
catch (const gdb_exception &except)
{
- GDB_PY_HANDLE_EXCEPTION (except);
+ return gdbpy_handle_gdb_exception (nullptr, except);
}
for (fn_block = block;
@@ -696,7 +696,7 @@ pending_framepy_function (PyObject *self, PyObject *args)
}
catch (const gdb_exception &except)
{
- GDB_PY_HANDLE_EXCEPTION (except);
+ return gdbpy_handle_gdb_exception (nullptr, except);
}
if (sym != nullptr)
@@ -785,11 +785,35 @@ pending_framepy_level (PyObject *self, PyObject *args)
return gdb_py_object_from_longest (level).release ();
}
+/* Class for frame unwinders registered by the Python architecture callback. */
+class frame_unwind_python : public frame_unwind
+{
+public:
+ frame_unwind_python (const struct frame_data *newarch)
+ : frame_unwind ("python", NORMAL_FRAME, FRAME_UNWIND_EXTENSION, newarch)
+ { }
+
+ /* No need to override stop_reason, we want the default. */
+
+ int sniff (const frame_info_ptr &this_frame,
+ void **this_prologue_cache) const override;
+
+ void this_id (const frame_info_ptr &this_frame, void **this_prologue_cache,
+ struct frame_id *id) const override;
+
+ struct value *prev_register (const frame_info_ptr &this_frame,
+ void **this_prologue_cache,
+ int regnum) const override;
+
+ void dealloc_cache (frame_info *self, void *this_cache) const override;
+};
+
/* frame_unwind.this_id method. */
-static void
-pyuw_this_id (const frame_info_ptr &this_frame, void **cache_ptr,
- struct frame_id *this_id)
+void
+frame_unwind_python::this_id (const frame_info_ptr &this_frame,
+ void **cache_ptr,
+ struct frame_id *this_id) const
{
*this_id = ((cached_frame_info *) *cache_ptr)->frame_id;
pyuw_debug_printf ("frame_id: %s", this_id->to_string ().c_str ());
@@ -797,9 +821,9 @@ pyuw_this_id (const frame_info_ptr &this_frame, void **cache_ptr,
/* frame_unwind.prev_register. */
-static struct value *
-pyuw_prev_register (const frame_info_ptr &this_frame, void **cache_ptr,
- int regnum)
+struct value *
+frame_unwind_python::prev_register (const frame_info_ptr &this_frame,
+ void **cache_ptr, int regnum) const
{
PYUW_SCOPED_DEBUG_ENTER_EXIT;
@@ -812,7 +836,7 @@ pyuw_prev_register (const frame_info_ptr &this_frame, void **cache_ptr,
for (; reg_info < reg_info_end; ++reg_info)
{
if (regnum == reg_info->num)
- return frame_unwind_got_bytes (this_frame, regnum, reg_info->data.get ());
+ return frame_unwind_got_bytes (this_frame, regnum, reg_info->data);
}
return frame_unwind_got_optimized (this_frame, regnum);
@@ -820,13 +844,13 @@ pyuw_prev_register (const frame_info_ptr &this_frame, void **cache_ptr,
/* Frame sniffer dispatch. */
-static int
-pyuw_sniffer (const struct frame_unwind *self, const frame_info_ptr &this_frame,
- void **cache_ptr)
+int
+frame_unwind_python::sniff (const frame_info_ptr &this_frame,
+ void **cache_ptr) const
{
PYUW_SCOPED_DEBUG_ENTER_EXIT;
- struct gdbarch *gdbarch = (struct gdbarch *) (self->unwind_data);
+ struct gdbarch *gdbarch = (struct gdbarch *) (this->unwind_data ());
cached_frame_info *cached_frame;
gdbpy_enter enter_py (gdbarch);
@@ -905,9 +929,9 @@ pyuw_sniffer (const struct frame_unwind *self, const frame_info_ptr &this_frame,
/* Received UnwindInfo, cache data. */
PyObject *pyo_unwind_info = PyTuple_GET_ITEM (pyo_execute_ret.get (), 0);
- if (PyObject_IsInstance (pyo_unwind_info,
- (PyObject *) &unwind_info_object_type) <= 0)
- error (_("A Unwinder should return gdb.UnwindInfo instance."));
+ if (!PyObject_TypeCheck (pyo_unwind_info, &unwind_info_object_type))
+ error (_("an Unwinder should return gdb.UnwindInfo, not %s."),
+ Py_TYPE (pyo_unwind_info)->tp_name);
{
unwind_info_object *unwind_info =
@@ -936,8 +960,9 @@ pyuw_sniffer (const struct frame_unwind *self, const frame_info_ptr &this_frame,
cached_reg_t *cached = new (&cached_frame->reg[i]) cached_reg_t ();
cached->num = reg->number;
- cached->data.reset ((gdb_byte *) xmalloc (data_size));
- memcpy (cached->data.get (), value->contents ().data (), data_size);
+ cached->data.resize (data_size);
+ gdb::array_view<const gdb_byte> contents = value->contents ();
+ cached->data.assign (contents.begin (), contents.end ());
}
}
@@ -947,8 +972,8 @@ pyuw_sniffer (const struct frame_unwind *self, const frame_info_ptr &this_frame,
/* Frame cache release shim. */
-static void
-pyuw_dealloc_cache (frame_info *this_frame, void *cache)
+void
+frame_unwind_python::dealloc_cache (frame_info *this_frame, void *cache) const
{
PYUW_SCOPED_DEBUG_ENTER_EXIT;
cached_frame_info *cached_frame = (cached_frame_info *) cache;
@@ -980,16 +1005,9 @@ pyuw_on_new_gdbarch (gdbarch *newarch)
if (!data->unwinder_registered)
{
struct frame_unwind *unwinder
- = GDBARCH_OBSTACK_ZALLOC (newarch, struct frame_unwind);
-
- unwinder->name = "python";
- unwinder->type = NORMAL_FRAME;
- unwinder->stop_reason = default_frame_unwind_stop_reason;
- unwinder->this_id = pyuw_this_id;
- unwinder->prev_register = pyuw_prev_register;
- unwinder->unwind_data = (const struct frame_data *) newarch;
- unwinder->sniffer = pyuw_sniffer;
- unwinder->dealloc_cache = pyuw_dealloc_cache;
+ = obstack_new<frame_unwind_python>
+ (gdbarch_obstack (newarch), (const struct frame_data *) newarch);
+
frame_unwind_prepend_unwinder (newarch, unwinder);
data->unwinder_registered = 1;
}
@@ -1002,22 +1020,16 @@ gdbpy_initialize_unwind (void)
{
gdb::observers::new_architecture.attach (pyuw_on_new_gdbarch, "py-unwind");
- if (PyType_Ready (&pending_frame_object_type) < 0)
+ if (gdbpy_type_ready (&pending_frame_object_type) < 0)
return -1;
- int rc = gdb_pymodule_addobject (gdb_module, "PendingFrame",
- (PyObject *) &pending_frame_object_type);
- if (rc != 0)
- return rc;
- if (PyType_Ready (&unwind_info_object_type) < 0)
+ if (gdbpy_type_ready (&unwind_info_object_type) < 0)
return -1;
- return gdb_pymodule_addobject (gdb_module, "UnwindInfo",
- (PyObject *) &unwind_info_object_type);
+
+ return 0;
}
-void _initialize_py_unwind ();
-void
-_initialize_py_unwind ()
+INIT_GDB_FILE (py_unwind)
{
add_setshow_boolean_cmd
("py-unwind", class_maintenance, &pyuw_debug,