forked from Imagelibrary/binutils-gdb
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>
This commit is contained in:
@@ -122,8 +122,8 @@ frame_unwind_try_unwinder (const frame_info_ptr &this_frame, void **this_cache,
|
||||
|
||||
try
|
||||
{
|
||||
frame_debug_printf ("trying unwinder \"%s\"", unwinder->name);
|
||||
res = unwinder->sniffer (unwinder, this_frame, this_cache);
|
||||
frame_debug_printf ("trying unwinder \"%s\"", unwinder->name ());
|
||||
res = unwinder->sniff (this_frame, this_cache);
|
||||
}
|
||||
catch (const gdb_exception &ex)
|
||||
{
|
||||
@@ -340,6 +340,64 @@ frame_unwind_got_address (const frame_info_ptr &frame, int regnum,
|
||||
return reg_val;
|
||||
}
|
||||
|
||||
/* See frame-unwind.h. */
|
||||
|
||||
enum unwind_stop_reason
|
||||
frame_unwind_legacy::stop_reason (const frame_info_ptr &this_frame,
|
||||
void **this_prologue_cache) const
|
||||
{
|
||||
return m_stop_reason (this_frame, this_prologue_cache);
|
||||
}
|
||||
|
||||
/* See frame-unwind.h. */
|
||||
|
||||
void
|
||||
frame_unwind_legacy::this_id (const frame_info_ptr &this_frame,
|
||||
void **this_prologue_cache,
|
||||
struct frame_id *id) const
|
||||
{
|
||||
return m_this_id (this_frame, this_prologue_cache, id);
|
||||
}
|
||||
|
||||
/* See frame-unwind.h. */
|
||||
|
||||
struct value *
|
||||
frame_unwind_legacy::prev_register (const frame_info_ptr &this_frame,
|
||||
void **this_prologue_cache,
|
||||
int regnum) const
|
||||
{
|
||||
return m_prev_register (this_frame, this_prologue_cache, regnum);
|
||||
}
|
||||
|
||||
/* See frame-unwind.h. */
|
||||
|
||||
int
|
||||
frame_unwind_legacy::sniff (const frame_info_ptr &this_frame,
|
||||
void **this_prologue_cache) const
|
||||
{
|
||||
return m_sniffer (this, this_frame, this_prologue_cache);
|
||||
}
|
||||
|
||||
/* See frame-unwind.h. */
|
||||
|
||||
void
|
||||
frame_unwind_legacy::dealloc_cache (frame_info *self, void *this_cache) const
|
||||
{
|
||||
if (m_dealloc_cache != nullptr)
|
||||
m_dealloc_cache (self, this_cache);
|
||||
}
|
||||
|
||||
/* See frame-unwind.h. */
|
||||
|
||||
struct gdbarch *
|
||||
frame_unwind_legacy::prev_arch (const frame_info_ptr &this_frame,
|
||||
void **this_prologue_cache) const
|
||||
{
|
||||
if (m_prev_arch == nullptr)
|
||||
return frame_unwind::prev_arch (this_frame, this_prologue_cache);
|
||||
return m_prev_arch (this_frame, this_prologue_cache);
|
||||
}
|
||||
|
||||
/* Implement "maintenance info frame-unwinders" command. */
|
||||
|
||||
static void
|
||||
@@ -358,10 +416,10 @@ maintenance_info_frame_unwinders (const char *args, int from_tty)
|
||||
for (const auto &unwinder : table)
|
||||
{
|
||||
ui_out_emit_list tuple_emitter (uiout, nullptr);
|
||||
uiout->field_string ("name", unwinder->name);
|
||||
uiout->field_string ("type", frame_type_str (unwinder->type));
|
||||
uiout->field_string ("name", unwinder->name ());
|
||||
uiout->field_string ("type", frame_type_str (unwinder->type ()));
|
||||
uiout->field_string ("class", frame_unwinder_class_str (
|
||||
unwinder->unwinder_class));
|
||||
unwinder->unwinder_class ()));
|
||||
uiout->text ("\n");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user