aboutsummaryrefslogtreecommitdiff
path: root/gdb/python
diff options
context:
space:
mode:
authorGuinevere Larsen <guinevere@redhat.com>2024-03-14 16:14:27 +0100
committerGuinevere Larsen <guinevere@redhat.com>2025-01-17 11:49:16 -0300
commit1239e7cf37336d69931a656290c25a5d5455b9cc (patch)
treeb2b7d26d4df99d17acd7e8cff1649347392e6f6f /gdb/python
parentce36ef63aa74c30016334db0f6a4638d1ffe7256 (diff)
downloadgdb-1239e7cf37336d69931a656290c25a5d5455b9cc.zip
gdb-1239e7cf37336d69931a656290c25a5d5455b9cc.tar.gz
gdb-1239e7cf37336d69931a656290c25a5d5455b9cc.tar.bz2
gdb: Migrate frame unwinders to use C++ classes
Frame unwinders have historically been a structure populated with callback pointers, so that architectures (or other specific unwinders) could install their own way to handle the inferior. However, since moving to C++, we could use polymorphism to get the same functionality in a more readable way. Polymorphism also makes it simpler to add new functionality to all frame unwinders, since all that's required is adding it to the base class. As part of the changes to add support to disabling frame unwinders, this commit makes the first baby step in using polymorphism for the frame unwinders, by making frame_unwind a virtual class, and adds a couple of new classes. The main class added is frame_unwind_legacy, which works the same as the previous structs, using function pointers as callbacks. This class was added to allow the transition to happen piecemeal. New unwinders should instead follow the lead of the other classes implemented. 2 of the others, frame_unwind_python and frame_unwind_trampoline, were added because it seemed simpler at the moment to do that instead of reworking the dynamic allocation to work with the legacy class, and can be used as an example to future implementations. Finally, the cygwin unwinder was converted to a class since it was most of the way there already. Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org> Approved-By: Simon Marchi <simon.marchi@efficios.com> Approved-By: Andrew Burgess <aburgess@redhat.com>
Diffstat (limited to 'gdb/python')
-rw-r--r--gdb/python/py-unwind.c62
1 files changed, 39 insertions, 23 deletions
diff --git a/gdb/python/py-unwind.c b/gdb/python/py-unwind.c
index 9d9b048..af8ee98 100644
--- a/gdb/python/py-unwind.c
+++ b/gdb/python/py-unwind.c
@@ -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;
@@ -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);
@@ -948,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;
@@ -981,17 +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->unwinder_class = FRAME_UNWIND_EXTENSION;
- 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;
}