From: Guinevere Larsen <guinevere@redhat.com>
To: gdb-patches@sourceware.org
Cc: Guinevere Larsen <guinevere@redhat.com>,
Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Subject: [PATCH v8 1/5] gdb: make gdbarch store a vector of frame unwinders
Date: Tue, 10 Dec 2024 16:51:11 -0300 [thread overview]
Message-ID: <20241210195115.3046370-2-guinevere@redhat.com> (raw)
In-Reply-To: <20241210195115.3046370-1-guinevere@redhat.com>
Before this commit, all frame unwinders would be stored in the obstack
of a gdbarch and accessed by using the registry system. This made for
unwieldy code, and unnecessarily complex logic in the frame_unwinder
implementation, along with making frame_unwind structs be unable to have
non-trivial destructors.
Seeing as a future patch of this series wants to refactor the
frame_unwind struct to use inheritance, and we'd like to not restrict
the future derived classes on what destructors are allowed. In
preparation for that change, this commit changes the registry in gdbarch
to instead store an std::vector, which doesn't require using an obstack
and doesn't rely on a linked list.
There should be no user-visible changes.
Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
---
gdb/frame-unwind.c | 107 +++++++++++++++------------------------------
1 file changed, 36 insertions(+), 71 deletions(-)
diff --git a/gdb/frame-unwind.c b/gdb/frame-unwind.c
index 352779fcdcc..e61f6244913 100644
--- a/gdb/frame-unwind.c
+++ b/gdb/frame-unwind.c
@@ -31,61 +31,42 @@
#include "cli/cli-cmds.h"
#include "inferior.h"
-struct frame_unwind_table_entry
+/* Default sniffers, that must always be the first in the unwinder list,
+ no matter the architecture. */
+static constexpr auto standard_unwinders =
{
- const struct frame_unwind *unwinder;
- struct frame_unwind_table_entry *next;
+ &dummy_frame_unwind,
+ /* The DWARF tailcall sniffer must come before the inline sniffer.
+ Otherwise, we can end up in a situation where a DWARF frame finds
+ tailcall information, but then the inline sniffer claims a frame
+ before the tailcall sniffer, resulting in confusion. This is
+ safe to do always because the tailcall sniffer can only ever be
+ activated if the newer frame was created using the DWARF
+ unwinder, and it also found tailcall information. */
+ &dwarf2_tailcall_frame_unwind,
+ &inline_frame_unwind,
};
-struct frame_unwind_table
-{
- struct frame_unwind_table_entry *list = nullptr;
- /* The head of the OSABI part of the search list. */
- struct frame_unwind_table_entry **osabi_head = nullptr;
-};
+/* If an unwinder should be prepended to the list, this is the
+ index in which it should be inserted. */
+static constexpr int prepend_unwinder_index = standard_unwinders.size ();
-static const registry<gdbarch>::key<struct frame_unwind_table>
+static const registry<gdbarch>::key<std::vector<const frame_unwind *>>
frame_unwind_data;
-/* A helper function to add an unwinder to a list. LINK says where to
- install the new unwinder. The new link is returned. */
-
-static struct frame_unwind_table_entry **
-add_unwinder (struct obstack *obstack, const struct frame_unwind *unwinder,
- struct frame_unwind_table_entry **link)
-{
- *link = OBSTACK_ZALLOC (obstack, struct frame_unwind_table_entry);
- (*link)->unwinder = unwinder;
- return &(*link)->next;
-}
-
-static struct frame_unwind_table *
+/* Retrieve the list of frame unwinders available in GDBARCH.
+ If this list is empty, it is initialized before being returned. */
+static std::vector<const frame_unwind *> *
get_frame_unwind_table (struct gdbarch *gdbarch)
{
- struct frame_unwind_table *table = frame_unwind_data.get (gdbarch);
+ std::vector<const frame_unwind *> *table = frame_unwind_data.get (gdbarch);
if (table != nullptr)
return table;
- table = new frame_unwind_table;
-
- /* Start the table out with a few default sniffers. OSABI code
- can't override this. */
- struct frame_unwind_table_entry **link = &table->list;
+ table = new std::vector<const frame_unwind *>;
+ table->insert (table->begin (), standard_unwinders.begin (),
+ standard_unwinders.end ());
- struct obstack *obstack = gdbarch_obstack (gdbarch);
- link = add_unwinder (obstack, &dummy_frame_unwind, link);
- /* The DWARF tailcall sniffer must come before the inline sniffer.
- Otherwise, we can end up in a situation where a DWARF frame finds
- tailcall information, but then the inline sniffer claims a frame
- before the tailcall sniffer, resulting in confusion. This is
- safe to do always because the tailcall sniffer can only ever be
- activated if the newer frame was created using the DWARF
- unwinder, and it also found tailcall information. */
- link = add_unwinder (obstack, &dwarf2_tailcall_frame_unwind, link);
- link = add_unwinder (obstack, &inline_frame_unwind, link);
-
- /* The insertion point for OSABI sniffers. */
- table->osabi_head = link;
frame_unwind_data.set (gdbarch, table);
return table;
@@ -95,27 +76,16 @@ void
frame_unwind_prepend_unwinder (struct gdbarch *gdbarch,
const struct frame_unwind *unwinder)
{
- struct frame_unwind_table *table = get_frame_unwind_table (gdbarch);
- struct frame_unwind_table_entry *entry;
-
- /* Insert the new entry at the start of the list. */
- entry = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct frame_unwind_table_entry);
- entry->unwinder = unwinder;
- entry->next = (*table->osabi_head);
- (*table->osabi_head) = entry;
+ std::vector<const frame_unwind *> *table = get_frame_unwind_table (gdbarch);
+
+ table->insert (table->begin () + prepend_unwinder_index, unwinder);
}
void
frame_unwind_append_unwinder (struct gdbarch *gdbarch,
const struct frame_unwind *unwinder)
{
- struct frame_unwind_table *table = get_frame_unwind_table (gdbarch);
- struct frame_unwind_table_entry **ip;
-
- /* Find the end of the list and insert the new entry there. */
- for (ip = table->osabi_head; (*ip) != NULL; ip = &(*ip)->next);
- (*ip) = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct frame_unwind_table_entry);
- (*ip)->unwinder = unwinder;
+ get_frame_unwind_table (gdbarch)->push_back (unwinder);
}
/* Call SNIFFER from UNWINDER. If it succeeded set UNWINDER for
@@ -188,9 +158,6 @@ frame_unwind_find_by_frame (const frame_info_ptr &this_frame, void **this_cache)
FRAME_SCOPED_DEBUG_ENTER_EXIT;
frame_debug_printf ("this_frame=%d", frame_relative_level (this_frame));
- struct gdbarch *gdbarch = get_frame_arch (this_frame);
- struct frame_unwind_table *table = get_frame_unwind_table (gdbarch);
- struct frame_unwind_table_entry *entry;
const struct frame_unwind *unwinder_from_target;
unwinder_from_target = target_get_unwinder ();
@@ -205,8 +172,10 @@ frame_unwind_find_by_frame (const frame_info_ptr &this_frame, void **this_cache)
unwinder_from_target))
return;
- for (entry = table->list; entry != NULL; entry = entry->next)
- if (frame_unwind_try_unwinder (this_frame, this_cache, entry->unwinder))
+ struct gdbarch *gdbarch = get_frame_arch (this_frame);
+ std::vector<const frame_unwind *> *table = get_frame_unwind_table (gdbarch);
+ for (auto unwinder : *table)
+ if (frame_unwind_try_unwinder (this_frame, this_cache, unwinder))
return;
internal_error (_("frame_unwind_find_by_frame failed"));
@@ -347,7 +316,7 @@ static void
maintenance_info_frame_unwinders (const char *args, int from_tty)
{
gdbarch *gdbarch = current_inferior ()->arch ();
- struct frame_unwind_table *table = get_frame_unwind_table (gdbarch);
+ std::vector<const frame_unwind *> *table = get_frame_unwind_table (gdbarch);
ui_out *uiout = current_uiout;
ui_out_emit_table table_emitter (uiout, 2, -1, "FrameUnwinders");
@@ -355,15 +324,11 @@ maintenance_info_frame_unwinders (const char *args, int from_tty)
uiout->table_header (25, ui_left, "type", "Type");
uiout->table_body ();
- for (struct frame_unwind_table_entry *entry = table->list; entry != NULL;
- entry = entry->next)
+ for (auto unwinder : *table)
{
- const char *name = entry->unwinder->name;
- const char *type = frame_type_str (entry->unwinder->type);
-
ui_out_emit_list tuple_emitter (uiout, nullptr);
- uiout->field_string ("name", name);
- uiout->field_string ("type", type);
+ uiout->field_string ("name", unwinder->name);
+ uiout->field_string ("type", frame_type_str (unwinder->type));
uiout->text ("\n");
}
}
--
2.47.0
next prev parent reply other threads:[~2024-12-10 19:55 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-10 19:51 [PATCH v8 0/5] Modernize frame unwinders and add disable feature Guinevere Larsen
2024-12-10 19:51 ` Guinevere Larsen [this message]
2025-01-14 14:28 ` [PATCH v8 1/5] gdb: make gdbarch store a vector of frame unwinders Andrew Burgess
2025-01-14 20:34 ` Guinevere Larsen
2024-12-10 19:51 ` [PATCH v8 2/5] gdb: add "unwinder class" to " Guinevere Larsen
2025-01-14 15:28 ` Andrew Burgess
2024-12-10 19:51 ` [PATCH v8 3/5] gdb: Migrate frame unwinders to use C++ classes Guinevere Larsen
2025-01-14 17:13 ` Andrew Burgess
2024-12-10 19:51 ` [PATCH v8 4/5] gdb: introduce ability to disable frame unwinders Guinevere Larsen
2025-01-16 12:06 ` Andrew Burgess
2025-01-17 12:40 ` Guinevere Larsen
2025-01-17 13:55 ` Andrew Burgess
2025-01-17 14:47 ` Guinevere Larsen
2025-01-16 16:22 ` Andrew Burgess
2024-12-10 19:51 ` [PATCH v8 5/5] gdb/testsuite: Test for a backtrace through object without debuginfo Guinevere Larsen
2025-01-16 14:37 ` Andrew Burgess
2025-01-16 18:42 ` Guinevere Larsen
2025-01-17 13:58 ` Andrew Burgess
2025-01-18 8:07 ` Tom de Vries
2025-01-20 12:26 ` [PATCH] gdb/testsuite: Fix file location for gdb.base/backtrace-through-cu-nodebug Guinevere Larsen
2025-01-20 12:46 ` Tom de Vries
2025-01-20 12:48 ` Guinevere Larsen
2025-01-07 12:11 ` [PING][PATCH v8 0/5] Modernize frame unwinders and add disable feature Guinevere Larsen
2025-01-17 14:49 ` [PATCH " Guinevere Larsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241210195115.3046370-2-guinevere@redhat.com \
--to=guinevere@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=thiago.bauermann@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox