[v6,1/5] gdb: make gdbarch store a vector of frame unwinders

Message ID 20241010172220.3700189-2-guinevere@redhat.com
State New
Headers
Series Modernize frame unwinders and add disable feature |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Guinevere Larsen Oct. 10, 2024, 5:22 p.m. UTC
  From: Guinevere Larsen <blarsen@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 adds an std::vector to gdbarch
to store the unwinders in.

There should be no user-visible changes.

Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Approved-By: Simon Marchi <simon.marchi@efficios.com>
---
 gdb/arch-utils.c   |   8 ++++
 gdb/frame-unwind.c | 114 +++++++++++++++++----------------------------
 gdb/gdbarch-gen.c  |   6 +++
 gdb/gdbarch.h      |   5 ++
 gdb/gdbarch.py     |   6 +++
 5 files changed, 67 insertions(+), 72 deletions(-)
  

Comments

Gerlicher, Klaus Oct. 11, 2024, 7:07 a.m. UTC | #1
Hi Guinevere,

I had a quick look over this patch, inline.

Thanks
Klaus

> -----Original Message-----
> From: Guinevere Larsen <guinevere@redhat.com>
> Sent: Thursday, October 10, 2024 7:22 PM
> To: gdb-patches@sourceware.org
> Cc: Guinevere Larsen <blarsen@redhat.com>; Thiago Jung Bauermann
> <thiago.bauermann@linaro.org>; Simon Marchi
> <simon.marchi@efficios.com>
> Subject: [PATCH v6 1/5] gdb: make gdbarch store a vector of frame unwinders
> 
> From: Guinevere Larsen <blarsen@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 adds an std::vector to gdbarch
> to store the unwinders in.
> 
> There should be no user-visible changes.
> 
> Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
> Approved-By: Simon Marchi <simon.marchi@efficios.com>
> ---
>  gdb/arch-utils.c   |   8 ++++
>  gdb/frame-unwind.c | 114 +++++++++++++++++----------------------------
>  gdb/gdbarch-gen.c  |   6 +++
>  gdb/gdbarch.h      |   5 ++
>  gdb/gdbarch.py     |   6 +++
>  5 files changed, 67 insertions(+), 72 deletions(-)
> 
> diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
> index 6ffa4109765..5a4ed097321 100644
> --- a/gdb/arch-utils.c
> +++ b/gdb/arch-utils.c
> @@ -1225,6 +1225,14 @@ obstack *gdbarch_obstack (gdbarch *arch)
> 
>  /* See gdbarch.h.  */
> 
> +std::vector<const frame_unwind *> &
> +gdbarch_unwinder_list (struct gdbarch *arch)

Does this still need struct? It's not generated so I would assume not.

> +{
> +  return arch->unwinders;
> +}
> +
> +/* See gdbarch.h.  */
> +
>  char *
>  gdbarch_obstack_strdup (struct gdbarch *arch, const char *string)
>  {
> diff --git a/gdb/frame-unwind.c b/gdb/frame-unwind.c
> index e5f108d3257..3df28985e2e 100644
> --- a/gdb/frame-unwind.c
> +++ b/gdb/frame-unwind.c
> @@ -31,49 +31,11 @@
>  #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.  */

Is there any mechanism that asserts it's always the first?

> +static constexpr auto standard_unwinders =
>  {
> -  const struct frame_unwind *unwinder;
> -  struct frame_unwind_table_entry *next;
> -};
> -
> -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;
> -};
> -
> -static const registry<gdbarch>::key<struct frame_unwind_table>
> -     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 *
> -get_frame_unwind_table (struct gdbarch *gdbarch)
> -{
> -  struct frame_unwind_table *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;
> -
> -  struct obstack *obstack = gdbarch_obstack (gdbarch);
> -  link = add_unwinder (obstack, &dummy_frame_unwind, link);
> +  &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
> @@ -81,12 +43,33 @@ get_frame_unwind_table (struct gdbarch *gdbarch)
>       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);
> +  &dwarf2_tailcall_frame_unwind,
> +  &inline_frame_unwind,
> +};
> +
> +/* 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 ();
> +
> +/* Start the table out with a few default sniffers.  OSABI code
> +   can't override this.  */
> +static void
> +initialize_frame_unwind_table (std::vector<const frame_unwind *>& table)
> +{
> +  gdb_assert (table.empty ());
> +
> +  table.insert (table.begin (), standard_unwinders.begin (),
> +		standard_unwinders.end ());
> +}
> 
> -  /* The insertion point for OSABI sniffers.  */
> -  table->osabi_head = link;
> -  frame_unwind_data.set (gdbarch, 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)
> +{
> +  std::vector<const frame_unwind *> &table = gdbarch_unwinder_list
> (gdbarch);
> +  if (table.empty ())
> +    initialize_frame_unwind_table (table);
> 
>    return table;
>  }
> @@ -95,27 +78,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 +160,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 +174,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 +318,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,11 +326,10 @@ 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);
> +      const char *name = unwinder->name;
> +      const char *type = frame_type_str (unwinder->type);
> 
>        ui_out_emit_list tuple_emitter (uiout, nullptr);
>        uiout->field_string ("name", name);
> diff --git a/gdb/gdbarch-gen.c b/gdb/gdbarch-gen.c
> index 0d00cd7c993..03894b19bd6 100644
> --- a/gdb/gdbarch-gen.c
> +++ b/gdb/gdbarch-gen.c
> @@ -27,6 +27,8 @@
> 
>  /* Maintain the struct gdbarch object.  */
> 
> +#include <vector>
> +
>  struct gdbarch
>  {
>    /* Has this architecture been fully initialized?  */
> @@ -34,9 +36,13 @@ struct gdbarch
> 
>    /* An obstack bound to the lifetime of the architecture.  */
>    auto_obstack obstack;
> +
>    /* Registry.  */
>    registry<gdbarch> registry_fields;
> 
> +  /* List of frame unwinders.  */
> +  std::vector<const frame_unwind *> unwinders;
> +
>    /* basic architectural information.  */
>    const struct bfd_arch_info * bfd_arch_info;
>    enum bfd_endian byte_order;
> diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
> index 60a0f60df39..d729b16f7cb 100644
> --- a/gdb/gdbarch.h
> +++ b/gdb/gdbarch.h
> @@ -30,6 +30,7 @@
>  #include "displaced-stepping.h"
>  #include "gdbsupport/gdb-checked-static-cast.h"
>  #include "registry.h"
> +#include "frame-unwind.h"

Instead of the full header, I think the established pattern in this file are the forward decls below, so "struct frame_unwind;" there
would be enough since it's just using a pointer.

> 
>  struct floatformat;
>  struct ui_file;
> @@ -310,6 +311,10 @@ extern obstack *gdbarch_obstack (gdbarch *arch);
> 
>  #define GDBARCH_OBSTACK_ZALLOC(GDBARCH, TYPE)
> obstack_zalloc<TYPE> (gdbarch_obstack ((GDBARCH)))
> 
> +/* Return the vector of unwinders stored in a gdbarch object.  */
> +
> +std::vector<const frame_unwind*> &gdbarch_unwinder_list (struct gdbarch
> *arch);
> +
>  /* Duplicate STRING, returning an equivalent string that's allocated on the
>     obstack associated with GDBARCH.  The string is freed when the
> corresponding
>     architecture is also freed.  */
> diff --git a/gdb/gdbarch.py b/gdb/gdbarch.py
> index dd1658d5274..274be3ab0d7 100755
> --- a/gdb/gdbarch.py
> +++ b/gdb/gdbarch.py
> @@ -125,6 +125,8 @@ with open("gdbarch-gen.c", "w") as f:
>      print(file=f)
>      print("/* Maintain the struct gdbarch object.  */", file=f)
>      print(file=f)
> +    print("#include <vector>", file=f)

Is this the intended location of the #include <vector>? I think it would fit better above the "Maintain..." comment.

> +    print(file=f)
>      #
>      # The struct definition body.
>      #
> @@ -135,9 +137,13 @@ with open("gdbarch-gen.c", "w") as f:
>      print(file=f)
>      print("  /* An obstack bound to the lifetime of the architecture.  */", file=f)
>      print("  auto_obstack obstack;", file=f)
> +    print(file=f)
>      print("  /* Registry.  */", file=f)
>      print("  registry<gdbarch> registry_fields;", file=f)
>      print(file=f)
> +    print("  /* List of frame unwinders.  */", file=f)
> +    print("  std::vector<const frame_unwind *> unwinders;", file=f)
> +    print(file=f)
>      print("  /* basic architectural information.  */", file=f)
>      for c in filter(info, components):
>          print(f"  {c.type} {c.name};", file=f)
> --
> 2.46.2
> 

Intel Deutschland GmbH
Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Sean Fennelly, Jeffrey Schneiderman, Tiffany Doon Silva
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
  
Guinevere Larsen Oct. 11, 2024, 12:42 p.m. UTC | #2
On 10/11/24 4:07 AM, Gerlicher, Klaus wrote:
> Hi Guinevere,
>
> I had a quick look over this patch, inline.
>
> Thanks
> Klaus
>
>> -----Original Message-----
>> From: Guinevere Larsen <guinevere@redhat.com>
>> Sent: Thursday, October 10, 2024 7:22 PM
>> To: gdb-patches@sourceware.org
>> Cc: Guinevere Larsen <blarsen@redhat.com>; Thiago Jung Bauermann
>> <thiago.bauermann@linaro.org>; Simon Marchi
>> <simon.marchi@efficios.com>
>> Subject: [PATCH v6 1/5] gdb: make gdbarch store a vector of frame unwinders
>>
>> From: Guinevere Larsen <blarsen@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 adds an std::vector to gdbarch
>> to store the unwinders in.
>>
>> There should be no user-visible changes.
>>
>> Reviewed-by: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
>> Approved-By: Simon Marchi <simon.marchi@efficios.com>
>> ---
>>   gdb/arch-utils.c   |   8 ++++
>>   gdb/frame-unwind.c | 114 +++++++++++++++++----------------------------
>>   gdb/gdbarch-gen.c  |   6 +++
>>   gdb/gdbarch.h      |   5 ++
>>   gdb/gdbarch.py     |   6 +++
>>   5 files changed, 67 insertions(+), 72 deletions(-)
>>
>> diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
>> index 6ffa4109765..5a4ed097321 100644
>> --- a/gdb/arch-utils.c
>> +++ b/gdb/arch-utils.c
>> @@ -1225,6 +1225,14 @@ obstack *gdbarch_obstack (gdbarch *arch)
>>
>>   /* See gdbarch.h.  */
>>
>> +std::vector<const frame_unwind *> &
>> +gdbarch_unwinder_list (struct gdbarch *arch)
> Does this still need struct? It's not generated so I would assume not.

You mean the keyword "struct" in the parameter?

it isn't necessary, but everything else in the file uses the keyword, so 
I think this makes the function fit better in the file.

>
>> +{
>> +  return arch->unwinders;
>> +}
>> +
>> +/* See gdbarch.h.  */
>> +
>>   char *
>>   gdbarch_obstack_strdup (struct gdbarch *arch, const char *string)
>>   {
>> diff --git a/gdb/frame-unwind.c b/gdb/frame-unwind.c
>> index e5f108d3257..3df28985e2e 100644
>> --- a/gdb/frame-unwind.c
>> +++ b/gdb/frame-unwind.c
>> @@ -31,49 +31,11 @@
>>   #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.  */
> Is there any mechanism that asserts it's always the first?
There isn't any assertion anywhere, but if the code follows he current 
usage, which is to always use get_frame_unwind_table, and using the 
functions in frame-unwind to append or prepend unwinders, this is 
maintained.
>
>> +static constexpr auto standard_unwinders =
>>   {
>> -  const struct frame_unwind *unwinder;
>> -  struct frame_unwind_table_entry *next;
>> -};
>> -
>> -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;
>> -};
>> -
>> -static const registry<gdbarch>::key<struct frame_unwind_table>
>> -     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 *
>> -get_frame_unwind_table (struct gdbarch *gdbarch)
>> -{
>> -  struct frame_unwind_table *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;
>> -
>> -  struct obstack *obstack = gdbarch_obstack (gdbarch);
>> -  link = add_unwinder (obstack, &dummy_frame_unwind, link);
>> +  &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
>> @@ -81,12 +43,33 @@ get_frame_unwind_table (struct gdbarch *gdbarch)
>>        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);
>> +  &dwarf2_tailcall_frame_unwind,
>> +  &inline_frame_unwind,
>> +};
>> +
>> +/* 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 ();
>> +
>> +/* Start the table out with a few default sniffers.  OSABI code
>> +   can't override this.  */
>> +static void
>> +initialize_frame_unwind_table (std::vector<const frame_unwind *>& table)
>> +{
>> +  gdb_assert (table.empty ());
>> +
>> +  table.insert (table.begin (), standard_unwinders.begin (),
>> +		standard_unwinders.end ());
>> +}
>>
>> -  /* The insertion point for OSABI sniffers.  */
>> -  table->osabi_head = link;
>> -  frame_unwind_data.set (gdbarch, 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)
>> +{
>> +  std::vector<const frame_unwind *> &table = gdbarch_unwinder_list
>> (gdbarch);
>> +  if (table.empty ())
>> +    initialize_frame_unwind_table (table);
>>
>>     return table;
>>   }
>> @@ -95,27 +78,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 +160,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 +174,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 +318,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,11 +326,10 @@ 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);
>> +      const char *name = unwinder->name;
>> +      const char *type = frame_type_str (unwinder->type);
>>
>>         ui_out_emit_list tuple_emitter (uiout, nullptr);
>>         uiout->field_string ("name", name);
>> diff --git a/gdb/gdbarch-gen.c b/gdb/gdbarch-gen.c
>> index 0d00cd7c993..03894b19bd6 100644
>> --- a/gdb/gdbarch-gen.c
>> +++ b/gdb/gdbarch-gen.c
>> @@ -27,6 +27,8 @@
>>
>>   /* Maintain the struct gdbarch object.  */
>>
>> +#include <vector>
>> +
>>   struct gdbarch
>>   {
>>     /* Has this architecture been fully initialized?  */
>> @@ -34,9 +36,13 @@ struct gdbarch
>>
>>     /* An obstack bound to the lifetime of the architecture.  */
>>     auto_obstack obstack;
>> +
>>     /* Registry.  */
>>     registry<gdbarch> registry_fields;
>>
>> +  /* List of frame unwinders.  */
>> +  std::vector<const frame_unwind *> unwinders;
>> +
>>     /* basic architectural information.  */
>>     const struct bfd_arch_info * bfd_arch_info;
>>     enum bfd_endian byte_order;
>> diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
>> index 60a0f60df39..d729b16f7cb 100644
>> --- a/gdb/gdbarch.h
>> +++ b/gdb/gdbarch.h
>> @@ -30,6 +30,7 @@
>>   #include "displaced-stepping.h"
>>   #include "gdbsupport/gdb-checked-static-cast.h"
>>   #include "registry.h"
>> +#include "frame-unwind.h"
> Instead of the full header, I think the established pattern in this file are the forward decls below, so "struct frame_unwind;" there
> would be enough since it's just using a pointer.
Makes sense, fixed.
>
>>   struct floatformat;
>>   struct ui_file;
>> @@ -310,6 +311,10 @@ extern obstack *gdbarch_obstack (gdbarch *arch);
>>
>>   #define GDBARCH_OBSTACK_ZALLOC(GDBARCH, TYPE)
>> obstack_zalloc<TYPE> (gdbarch_obstack ((GDBARCH)))
>>
>> +/* Return the vector of unwinders stored in a gdbarch object.  */
>> +
>> +std::vector<const frame_unwind*> &gdbarch_unwinder_list (struct gdbarch
>> *arch);
>> +
>>   /* Duplicate STRING, returning an equivalent string that's allocated on the
>>      obstack associated with GDBARCH.  The string is freed when the
>> corresponding
>>      architecture is also freed.  */
>> diff --git a/gdb/gdbarch.py b/gdb/gdbarch.py
>> index dd1658d5274..274be3ab0d7 100755
>> --- a/gdb/gdbarch.py
>> +++ b/gdb/gdbarch.py
>> @@ -125,6 +125,8 @@ with open("gdbarch-gen.c", "w") as f:
>>       print(file=f)
>>       print("/* Maintain the struct gdbarch object.  */", file=f)
>>       print(file=f)
>> +    print("#include <vector>", file=f)
> Is this the intended location of the #include <vector>? I think it would fit better above the "Maintain..." comment.
Makes sense. fixed.
>
>> +    print(file=f)
>>       #
>>       # The struct definition body.
>>       #
>> @@ -135,9 +137,13 @@ with open("gdbarch-gen.c", "w") as f:
>>       print(file=f)
>>       print("  /* An obstack bound to the lifetime of the architecture.  */", file=f)
>>       print("  auto_obstack obstack;", file=f)
>> +    print(file=f)
>>       print("  /* Registry.  */", file=f)
>>       print("  registry<gdbarch> registry_fields;", file=f)
>>       print(file=f)
>> +    print("  /* List of frame unwinders.  */", file=f)
>> +    print("  std::vector<const frame_unwind *> unwinders;", file=f)
>> +    print(file=f)
>>       print("  /* basic architectural information.  */", file=f)
>>       for c in filter(info, components):
>>           print(f"  {c.type} {c.name};", file=f)
>> --
>> 2.46.2
>>
> Intel Deutschland GmbH
> Registered Address: Am Campeon 10, 85579 Neubiberg, Germany
> Tel: +49 89 99 8853-0, www.intel.de
> Managing Directors: Sean Fennelly, Jeffrey Schneiderman, Tiffany Doon Silva
> Chairperson of the Supervisory Board: Nicole Lau
> Registered Office: Munich
> Commercial Register: Amtsgericht Muenchen HRB 186928
>
  

Patch

diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index 6ffa4109765..5a4ed097321 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -1225,6 +1225,14 @@  obstack *gdbarch_obstack (gdbarch *arch)
 
 /* See gdbarch.h.  */
 
+std::vector<const frame_unwind *> &
+gdbarch_unwinder_list (struct gdbarch *arch)
+{
+  return arch->unwinders;
+}
+
+/* See gdbarch.h.  */
+
 char *
 gdbarch_obstack_strdup (struct gdbarch *arch, const char *string)
 {
diff --git a/gdb/frame-unwind.c b/gdb/frame-unwind.c
index e5f108d3257..3df28985e2e 100644
--- a/gdb/frame-unwind.c
+++ b/gdb/frame-unwind.c
@@ -31,49 +31,11 @@ 
 #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;
-};
-
-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;
-};
-
-static const registry<gdbarch>::key<struct frame_unwind_table>
-     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 *
-get_frame_unwind_table (struct gdbarch *gdbarch)
-{
-  struct frame_unwind_table *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;
-
-  struct obstack *obstack = gdbarch_obstack (gdbarch);
-  link = add_unwinder (obstack, &dummy_frame_unwind, link);
+  &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
@@ -81,12 +43,33 @@  get_frame_unwind_table (struct gdbarch *gdbarch)
      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);
+  &dwarf2_tailcall_frame_unwind,
+  &inline_frame_unwind,
+};
+
+/* 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 ();
+
+/* Start the table out with a few default sniffers.  OSABI code
+   can't override this.  */
+static void
+initialize_frame_unwind_table (std::vector<const frame_unwind *>& table)
+{
+  gdb_assert (table.empty ());
+
+  table.insert (table.begin (), standard_unwinders.begin (),
+		standard_unwinders.end ());
+}
 
-  /* The insertion point for OSABI sniffers.  */
-  table->osabi_head = link;
-  frame_unwind_data.set (gdbarch, 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)
+{
+  std::vector<const frame_unwind *> &table = gdbarch_unwinder_list (gdbarch);
+  if (table.empty ())
+    initialize_frame_unwind_table (table);
 
   return table;
 }
@@ -95,27 +78,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 +160,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 +174,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 +318,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,11 +326,10 @@  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);
+      const char *name = unwinder->name;
+      const char *type = frame_type_str (unwinder->type);
 
       ui_out_emit_list tuple_emitter (uiout, nullptr);
       uiout->field_string ("name", name);
diff --git a/gdb/gdbarch-gen.c b/gdb/gdbarch-gen.c
index 0d00cd7c993..03894b19bd6 100644
--- a/gdb/gdbarch-gen.c
+++ b/gdb/gdbarch-gen.c
@@ -27,6 +27,8 @@ 
 
 /* Maintain the struct gdbarch object.  */
 
+#include <vector>
+
 struct gdbarch
 {
   /* Has this architecture been fully initialized?  */
@@ -34,9 +36,13 @@  struct gdbarch
 
   /* An obstack bound to the lifetime of the architecture.  */
   auto_obstack obstack;
+
   /* Registry.  */
   registry<gdbarch> registry_fields;
 
+  /* List of frame unwinders.  */
+  std::vector<const frame_unwind *> unwinders;
+
   /* basic architectural information.  */
   const struct bfd_arch_info * bfd_arch_info;
   enum bfd_endian byte_order;
diff --git a/gdb/gdbarch.h b/gdb/gdbarch.h
index 60a0f60df39..d729b16f7cb 100644
--- a/gdb/gdbarch.h
+++ b/gdb/gdbarch.h
@@ -30,6 +30,7 @@ 
 #include "displaced-stepping.h"
 #include "gdbsupport/gdb-checked-static-cast.h"
 #include "registry.h"
+#include "frame-unwind.h"
 
 struct floatformat;
 struct ui_file;
@@ -310,6 +311,10 @@  extern obstack *gdbarch_obstack (gdbarch *arch);
 
 #define GDBARCH_OBSTACK_ZALLOC(GDBARCH, TYPE)   obstack_zalloc<TYPE> (gdbarch_obstack ((GDBARCH)))
 
+/* Return the vector of unwinders stored in a gdbarch object.  */
+
+std::vector<const frame_unwind*> &gdbarch_unwinder_list (struct gdbarch *arch);
+
 /* Duplicate STRING, returning an equivalent string that's allocated on the
    obstack associated with GDBARCH.  The string is freed when the corresponding
    architecture is also freed.  */
diff --git a/gdb/gdbarch.py b/gdb/gdbarch.py
index dd1658d5274..274be3ab0d7 100755
--- a/gdb/gdbarch.py
+++ b/gdb/gdbarch.py
@@ -125,6 +125,8 @@  with open("gdbarch-gen.c", "w") as f:
     print(file=f)
     print("/* Maintain the struct gdbarch object.  */", file=f)
     print(file=f)
+    print("#include <vector>", file=f)
+    print(file=f)
     #
     # The struct definition body.
     #
@@ -135,9 +137,13 @@  with open("gdbarch-gen.c", "w") as f:
     print(file=f)
     print("  /* An obstack bound to the lifetime of the architecture.  */", file=f)
     print("  auto_obstack obstack;", file=f)
+    print(file=f)
     print("  /* Registry.  */", file=f)
     print("  registry<gdbarch> registry_fields;", file=f)
     print(file=f)
+    print("  /* List of frame unwinders.  */", file=f)
+    print("  std::vector<const frame_unwind *> unwinders;", file=f)
+    print(file=f)
     print("  /* basic architectural information.  */", file=f)
     for c in filter(info, components):
         print(f"  {c.type} {c.name};", file=f)