diff options
author | Guinevere Larsen <guinevere@redhat.com> | 2024-03-14 16:14:27 +0100 |
---|---|---|
committer | Guinevere Larsen <guinevere@redhat.com> | 2025-01-17 11:49:16 -0300 |
commit | 1239e7cf37336d69931a656290c25a5d5455b9cc (patch) | |
tree | b2b7d26d4df99d17acd7e8cff1649347392e6f6f /gdb/frame.c | |
parent | ce36ef63aa74c30016334db0f6a4638d1ffe7256 (diff) | |
download | binutils-1239e7cf37336d69931a656290c25a5d5455b9cc.zip binutils-1239e7cf37336d69931a656290c25a5d5455b9cc.tar.gz binutils-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/frame.c')
-rw-r--r-- | gdb/frame.c | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/gdb/frame.c b/gdb/frame.c index 10a32dc..a524678 100644 --- a/gdb/frame.c +++ b/gdb/frame.c @@ -269,12 +269,10 @@ frame_addr_hash_eq (const void *a, const void *b) static void frame_info_del (frame_info *frame) { - if (frame->prologue_cache != nullptr - && frame->unwind->dealloc_cache != nullptr) + if (frame->prologue_cache != nullptr) frame->unwind->dealloc_cache (frame, frame->prologue_cache); - if (frame->base_cache != nullptr - && frame->base->unwind->dealloc_cache != nullptr) + if (frame->base_cache != nullptr) frame->base->unwind->dealloc_cache (frame, frame->base_cache); } @@ -487,12 +485,12 @@ frame_info::to_string () const res += string_printf ("{level=%d,", fi->level); if (fi->unwind != NULL) - res += string_printf ("type=%s,", frame_type_str (fi->unwind->type)); + res += string_printf ("type=%s,", frame_type_str (fi->unwind->type ())); else res += "type=<unknown>,"; if (fi->unwind != NULL) - res += string_printf ("unwinder=\"%s\",", fi->unwind->name); + res += string_printf ("unwinder=\"%s\",", fi->unwind->name ()); else res += "unwinder=<unknown>,"; @@ -2366,7 +2364,7 @@ get_prev_frame_always_1 (const frame_info_ptr &this_frame) This check is valid only if this frame and the next frame are NORMAL. See the comment at frame_id_inner for details. */ if (get_frame_type (this_frame) == NORMAL_FRAME - && this_frame->next->unwind->type == NORMAL_FRAME + && this_frame->next->unwind->type () == NORMAL_FRAME && frame_id_inner (get_frame_arch (frame_info_ptr (this_frame->next)), get_frame_id (this_frame), get_frame_id (frame_info_ptr (this_frame->next)))) @@ -2994,7 +2992,7 @@ get_frame_type (const frame_info_ptr &frame) /* Initialize the frame's unwinder because that's what provides the frame's type. */ frame_unwind_find_by_frame (frame, &frame->prologue_cache); - return frame->unwind->type; + return frame->unwind->type (); } struct program_space * @@ -3075,11 +3073,8 @@ frame_unwind_arch (const frame_info_ptr &next_frame) if (next_frame->unwind == NULL) frame_unwind_find_by_frame (next_frame, &next_frame->prologue_cache); - if (next_frame->unwind->prev_arch != NULL) - arch = next_frame->unwind->prev_arch (next_frame, - &next_frame->prologue_cache); - else - arch = get_frame_arch (next_frame); + arch = next_frame->unwind->prev_arch (next_frame, + &next_frame->prologue_cache); next_frame->prev_arch.arch = arch; next_frame->prev_arch.p = true; |