From: Guinevere Larsen <guinevere@redhat.com>
To: Simon Marchi <simark@simark.ca>, gdb-patches@sourceware.org
Cc: Eli Zaretskii <eliz@gnu.org>
Subject: Re: [PATCH v5 2/5] gdb: add "unwinder class" to frame unwinders
Date: Tue, 8 Oct 2024 15:22:04 -0300 [thread overview]
Message-ID: <b3f4c39e-02da-464a-90a3-5e3db4d33f0c@redhat.com> (raw)
In-Reply-To: <b647f34d-661b-4691-978b-969e4f058c6f@simark.ca>
On 10/3/24 3:46 PM, Simon Marchi wrote:
> On 10/1/24 2:42 PM, Guinevere Larsen wrote:
>> From: Guinevere Larsen <blarsen@redhat.com>
>>
>> A future patch will add a way to disable certain unwinders based on
>> different characteristics. This patch aims to make it more convenient
>> to disable related unwinders in bulk, such as architecture specific
>> ones, by indentifying all unwinders by which part of the code adds it.
> indentifying -> identifying
>
>> diff --git a/gdb/frame-unwind.c b/gdb/frame-unwind.c
>> index b69ae8596a2..afc1258c6a9 100644
>> --- a/gdb/frame-unwind.c
>> +++ b/gdb/frame-unwind.c
>> @@ -30,6 +30,17 @@
>> #include "dwarf2/frame-tailcall.h"
>> #include "cli/cli-cmds.h"
>> #include "inferior.h"
>> +#include <map>
>> +
>> +/* Conversion list between the enum for frame_unwind_class and
>> + string. */
>> +static std::map<enum frame_unwind_class, const char *> unwind_class_conversion =
>> +{
>> + {FRAME_UNWIND_GDB, "GDB"},
>> + {FRAME_UNWIND_ARCH, "ARCH"},
>> + {FRAME_UNWIND_EXTENSION, "EXTENSION"},
>> + {FRAME_UNWIND_DEBUGINFO, "DEBUGINFO"},
>> +};
> It's not reaaally a big deal, but using an std::map for this is kind of
> heavyweight. It could probably be a simple array, still indexed by the
> enum value. Personally, I used functions with switches to handle cases
> this (see target_waitkind_str), because compilers can warn you if you
> forget to handle an enumerator (which can easily happen when a new one
> is added).
Since I have 2 functions, one to convert from enum to string, and
another from string to enum, I'll go with a simple array that makes it
easy to do both.
This is my proposed change:
diff --git a/gdb/frame-unwind.c b/gdb/frame-unwind.c
index ef05b658f94..10d9f2e9f88 100644
--- a/gdb/frame-unwind.c
+++ b/gdb/frame-unwind.c
@@ -34,12 +34,12 @@
/* Conversion list between the enum for frame_unwind_class and
string. */
-static std::map<enum frame_unwind_class, const char *>
unwind_class_conversion =
+static const char * unwind_class_conversion[] =
{
- {FRAME_UNWIND_GDB, "GDB"},
- {FRAME_UNWIND_ARCH, "ARCH"},
- {FRAME_UNWIND_EXTENSION, "EXTENSION"},
- {FRAME_UNWIND_DEBUGINFO, "DEBUGINFO"},
+ "GDB",
+ "ARCH",
+ "EXTENSION",
+ "DEBUGINFO",
};
/* Default sniffers, that must always be the first in the unwinder list,
@@ -88,9 +88,8 @@ get_frame_unwind_table (struct gdbarch *gdbarch)
static const char *
frame_unwinder_class_str (frame_unwind_class uclass)
{
- auto location = unwind_class_conversion.find (uclass);
- gdb_assert (location != unwind_class_conversion.end ());
- return location->second;
+ gdb_assert (uclass < UNWIND_CLASS_NUMBER);
+ return unwind_class_conversion[uclass];
}
/* Case insensitive search for a frame_unwind_class based on the given
@@ -102,10 +101,10 @@ str_to_frame_unwind_class (const char *class_str)
/* Skip the prefix if present. */
if (strncasecmp (class_str, prefix, strlen(prefix)) == 0)
class_str += strlen (prefix);
- for (const auto &it : unwind_class_conversion)
+ for (int i = 0; i < UNWIND_CLASS_NUMBER; i++)
{
- if (strcasecmp (it.second, class_str) == 0)
- return it.first;
+ if (strcasecmp (unwind_class_conversion[i], class_str) == 0)
+ return (frame_unwind_class) i;
}
error (_("Unknown frame unwind class: %s"), class_str);
}
diff --git a/gdb/frame-unwind.h b/gdb/frame-unwind.h
index f5ea8d9f690..555a5d98d5b 100644
--- a/gdb/frame-unwind.h
+++ b/gdb/frame-unwind.h
@@ -167,6 +167,8 @@ enum frame_unwind_class
FRAME_UNWIND_DEBUGINFO,
/* The unwinder was created and handles target dependent things. */
FRAME_UNWIND_ARCH,
+ /* Meta enum value, to ensure we're always sent a valid unwinder
class. */
+ UNWIND_CLASS_NUMBER,
};
>
> Otherwise, a more medium-term but clean solution would be to integrate
> one of these libs in GDB:
>
> https://github.com/Neargye/magic_enum
> https://github.com/quicknir/wise_enum
>
> I use the latter in another project, and it works nicely.
>
> Otherwise, LGTM:
>
> Approved-By: Simon Marchi <simon.marchi@efficios.com>
Can I add the tag with that change? (just making sure you're ok with my
solution (: )
--
Cheers,
Guinevere Larsen
She/Her/Hers
>
> Simon
>
next prev parent reply other threads:[~2024-10-08 18:22 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
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 [this message]
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=b3f4c39e-02da-464a-90a3-5e3db4d33f0c@redhat.com \
--to=guinevere@redhat.com \
--cc=eliz@gnu.org \
--cc=gdb-patches@sourceware.org \
--cc=simark@simark.ca \
/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