Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Guinevere Larsen <guinevere@redhat.com>, gdb-patches@sourceware.org
Cc: Guinevere Larsen <blarsen@redhat.com>
Subject: Re: [PATCH v5 1/5] gdb: make gdbarch store a vector of frame unwinders
Date: Thu, 3 Oct 2024 14:33:34 -0400	[thread overview]
Message-ID: <1ca86959-4d08-43cf-812e-487e29a25f4b@simark.ca> (raw)
In-Reply-To: <20241001184235.3710608-2-guinevere@redhat.com>

On 10/1/24 2:42 PM, Guinevere Larsen wrote:
> 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.

Just some nits, but with those addressed:

Approved-By: Simon Marchi <simon.marchi@efficios.com>

> ---
>  gdb/arch-utils.c   |   8 ++++
>  gdb/frame-unwind.c | 113 +++++++++++++++++----------------------------
>  gdb/gdbarch-gen.c  |   6 +++
>  gdb/gdbarch.h      |   5 ++
>  gdb/gdbarch.py     |   6 +++
>  5 files changed, 67 insertions(+), 71 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)
> +{
> +  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..b69ae8596a2 100644
> --- a/gdb/frame-unwind.c
> +++ b/gdb/frame-unwind.c
> @@ -31,62 +31,46 @@
>  #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;
>  };
>  
> -static const registry<gdbarch>::key<struct frame_unwind_table>
> -     frame_unwind_data;
> +/* 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 ();
>  
> -/* 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)
> +/* 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)
>  {
> -  *link = OBSTACK_ZALLOC (obstack, struct frame_unwind_table_entry);
> -  (*link)->unwinder = unwinder;
> -  return &(*link)->next;
> +  gdb_assert (table.empty ());
> +
> +  table.insert(table.begin (), standard_unwinders.begin (), standard_unwinders.end ());

Line a bit too long and missing space.

>  }
>  
> -static struct frame_unwind_table *
> +/* This function call retrieves the list of frame unwinders available in
> +   GDBARCH.  If this list is empty, it is initialized before being
> +   returned.  */

For brevity, I think you should remove "This function call", just start
with "Retrieve" or "Retrieves", depending of which school you are.

> +static std::vector<const frame_unwind *> &
>  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);
> -  /* 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);
> +  std::vector<const frame_unwind *> &table = gdbarch_unwinder_list (gdbarch);
> +  if (table.size () == 0)

table.empty ()

Simon

  parent reply	other threads:[~2024-10-03 18:34 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-01 18:42 [PATCH v5 0/5] Modernize frame unwinders and add disable feature Guinevere Larsen
2024-10-01 18:42 ` [PATCH v5 1/5] gdb: make gdbarch store a vector of frame unwinders Guinevere Larsen
2024-10-02 21:49   ` Thiago Jung Bauermann
2024-10-08 17:01     ` Guinevere Larsen
2024-10-03 18:33   ` Simon Marchi [this message]
2024-10-04 18:37   ` Tom Tromey
2024-10-12  1:34     ` Thiago Jung Bauermann
2024-10-14 18:18       ` Guinevere Larsen
2024-10-17 22:53         ` Tom Tromey
2024-10-18 17:40           ` Guinevere Larsen
2024-10-17 23:41       ` Tom Tromey
2024-10-01 18:42 ` [PATCH v5 2/5] gdb: add "unwinder class" to " Guinevere Larsen
2024-10-02 22:08   ` Thiago Jung Bauermann
2024-10-03 18:46   ` Simon Marchi
2024-10-08 18:22     ` Guinevere Larsen
2024-10-08 18:37       ` Simon Marchi
2024-10-01 18:42 ` [PATCH v5 3/5] gdb: Migrate frame unwinders to use C++ classes Guinevere Larsen
2024-10-03  0:23   ` Thiago Jung Bauermann
2024-10-09 18:16     ` Guinevere Larsen
2024-10-03 20:06   ` Simon Marchi
2024-10-04  5:21     ` Simon Marchi
2024-10-10 14:10       ` Guinevere Larsen
2024-10-10 16:28         ` Simon Marchi
2024-10-09 20:00     ` Guinevere Larsen
2024-10-01 18:42 ` [PATCH v5 4/5] gdb: introduce ability to disable frame unwinders Guinevere Larsen
2024-10-02  6:10   ` Eli Zaretskii
2024-10-04 17:57     ` Guinevere Larsen
2024-10-03  2:45   ` Thiago Jung Bauermann
2024-10-08 19:23     ` Guinevere Larsen
2024-10-06  2:51   ` Simon Marchi
2024-10-09 13:32     ` Guinevere Larsen
2024-10-09 15:38       ` Simon Marchi
2024-10-01 18:42 ` [PATCH v5 5/5] gdb/testsuite: Test for a backtrace through object without debuginfo Guinevere Larsen
2024-10-03  2:47   ` Thiago Jung Bauermann
2024-10-03  6:58   ` Gerlicher, Klaus
2024-10-09 14:56     ` 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=1ca86959-4d08-43cf-812e-487e29a25f4b@simark.ca \
    --to=simark@simark.ca \
    --cc=blarsen@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=guinevere@redhat.com \
    /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