From: Simon Marchi <simon.marchi@polymtl.ca>
To: Andrew Burgess <aburgess@redhat.com>, gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: Re: [PATCH v2 01/11] gdb: add symbol_search_kind enum for global_symbol_searcher
Date: Thu, 1 Oct 2026 09:22:11 -0400 [thread overview]
Message-ID: <15465f38-b454-4e6e-9c32-625f6262d6df@polymtl.ca> (raw)
In-Reply-To: <87cxttzp9p.fsf@redhat.com>
On 10/1/26 6:30 AM, Andrew Burgess wrote:
>
> I think this is looking good. Just one minor comment inline below:
>
> simon.marchi@polymtl.ca writes:
>
>> @@ -5166,20 +5179,18 @@ symtab_symbol_info (bool quiet, bool exclude_minsyms,
>> const char *classname;
>> switch (kind)
>> {
>> - case VAR_DOMAIN:
>> + case symbol_search_kind::VARIABLE:
>> classname = "variable";
>> break;
>> - case FUNCTION_DOMAIN:
>> + case symbol_search_kind::FUNCTION:
>> classname = "function";
>> break;
>> - case TYPE_DOMAIN:
>> + case symbol_search_kind::TYPE:
>> classname = "type";
>> break;
>> - case MODULE_DOMAIN:
>> + case symbol_search_kind::MODULE:
>> classname = "module";
>> break;
>> - default:
>> - gdb_assert_not_reached ("invalid domain enum");
>> }
>
> I initially wrote: please don't drop the default case, but then I
> checked the V1 review and saw this change was made specifically to
> address the feedback there.
>
> What I don't understand is you said:
>
>>> I think we could drop the "default" case as part of this refactoring. All
>>> cases are handled; we lose compile time warnings for unhandled cases with
>>> the "default" case.
>>
>> Agreed that we can drop the default. Note that we don't build with
>> -Wswitch, but we specifically enable it locally here and there.
>
> If the warning is mostly off, including here, then deleting the default
> seems like the wrong choice.
>
> I'm not too fussed, I think there's a middle group, that would keep my
> happy:
>
> 1. initialise classname to nullptr, and
>
> 2. follow this switch statement with:
> gdb_assert (classname != nullptr);
You're right, I applied the suggestion without thinking too much about
it. We definitely want an assert to fire instead of printing from an
uninitialized pointer. If that same code was in a function of its own,
I would have done it like this:
static const char *
ssk_to_string (symbol_search_kind kind)
{
switch (kind)
{
case symbol_search_kind::VARIABLE:
return "variable";
case symbol_search_kind::FUNCTION:
return "function";
case symbol_search_kind::TYPE:
return "type";
case symbol_search_kind::MODULE:
return "module";
}
gdb_assert_not_reached ("invalid symbol_search_kind value");
}
There is even an example of that in the same patch (the to_search_flags
function).
I'll initialize the variable with nullptr and add a nullptr check after
the switch. I prefer this over the default, because if we ever enable
-Wswitch (which will probably never happen, I tried it before and it was
painful), then we'll get a compile-time error if we are missing a case.
I don't think that this code is duplicated anywhere, so I don't think
it's worth moving it to a separate function.
>
> Even with the warning on it doesn't protect us from random garbage being
> cast to type symbol_search_kind and then passed to this function, which
> the 'default:' case does protect against. But the trailing assert is
> probably better anyway as it ensures each switch case is doing what
> needs to be done.
>
> With that:
>
> Approved-By: Andrew Burgess <aburgess@redhat.com>
Thanks,
Simon
next prev parent reply other threads:[~2026-10-01 13:22 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-29 19:39 [PATCH 0/9] Cleanups in global_symbol_searcher Simon Marchi
2026-09-29 19:39 ` [PATCH 1/9] gdb: add symbol_search_kind enum for global_symbol_searcher Simon Marchi
2026-09-30 9:31 ` Rohr, Stephan
2026-09-30 14:50 ` Simon Marchi
2026-09-29 19:39 ` [PATCH 2/9] gdb: factor out regexp compilation from global_symbol_searcher::search Simon Marchi
2026-09-30 12:10 ` Rohr, Stephan
2026-09-30 16:21 ` Simon Marchi
2026-09-29 19:39 ` [PATCH 3/9] gdb: simplify insertion in global_symbol_searcher::add_matching_symbols Simon Marchi
2026-09-30 8:20 ` Rohr, Stephan
2026-09-30 16:36 ` Simon Marchi
2026-09-29 19:39 ` [PATCH 4/9] gdb: use a switch on m_kind in add_matching_symbols Simon Marchi
[not found] ` <DS7PR11MB624725508FC878F3C263C2B3938B2@DS7PR11MB6247.namprd11.prod.outlook.com>
2026-09-30 19:41 ` Simon Marchi
2026-09-29 19:39 ` [PATCH 5/9] gdb: make global_symbol_searcher::is_suitable_msymbol non-static Simon Marchi
2026-09-30 12:39 ` Rohr, Stephan
2026-09-29 19:39 ` [PATCH 6/9] gdb: update comment of global_symbol_searcher::expand_symtabs Simon Marchi
2026-09-30 13:08 ` Rohr, Stephan
2026-09-30 20:01 ` Simon Marchi
2026-09-29 19:39 ` [PATCH 7/9] gdb: add matching helpers to global_symbol_searcher Simon Marchi
2026-09-30 13:51 ` Rohr, Stephan
2026-09-30 20:27 ` Simon Marchi
2026-09-29 19:39 ` [PATCH 8/9] gdb: pass result containers by reference in global_symbol_searcher Simon Marchi
2026-09-30 13:58 ` Rohr, Stephan
2026-10-01 1:33 ` Simon Marchi
2026-09-29 19:39 ` [PATCH 9/9] gdb: fix some comments " Simon Marchi
2026-09-30 14:01 ` Rohr, Stephan
2026-10-01 1:38 ` Simon Marchi
2026-10-01 2:09 ` [PATCH v2 00/11] Cleanups " simon.marchi
2026-10-01 2:09 ` [PATCH v2 01/11] gdb: add symbol_search_kind enum for global_symbol_searcher simon.marchi
2026-10-01 10:30 ` Andrew Burgess
2026-10-01 13:22 ` Simon Marchi [this message]
2026-10-01 15:35 ` Tom Tromey
2026-10-01 2:09 ` [PATCH v2 02/11] gdb: rename some preg/treg variables simon.marchi
2026-10-01 12:59 ` Andrew Burgess
2026-10-01 13:52 ` Simon Marchi
2026-10-01 2:09 ` [PATCH v2 03/11] gdb: factor out regexp compilation from global_symbol_searcher::search simon.marchi
2026-10-01 13:19 ` Andrew Burgess
2026-10-01 13:54 ` Simon Marchi
2026-10-01 2:09 ` [PATCH v2 04/11] gdb: use compile_symbol_search_regex in stack.c simon.marchi
2026-10-01 13:43 ` Andrew Burgess
2026-10-01 15:36 ` Tom Tromey
2026-10-01 15:52 ` Simon Marchi
2026-10-01 2:09 ` [PATCH v2 05/11] gdb: simplify insertion in global_symbol_searcher::add_matching_symbols simon.marchi
2026-10-01 13:46 ` Andrew Burgess
2026-10-01 2:09 ` [PATCH v2 06/11] gdb: use a switch on m_kind in add_matching_symbols simon.marchi
2026-10-01 15:01 ` Andrew Burgess
2026-10-01 15:07 ` Simon Marchi
2026-10-01 2:09 ` [PATCH v2 07/11] gdb: make global_symbol_searcher::is_suitable_msymbol non-static simon.marchi
2026-10-01 15:09 ` Andrew Burgess
2026-10-01 2:09 ` [PATCH v2 08/11] gdb: update comments of global_symbol_searcher::expand_symtabs simon.marchi
2026-10-01 15:13 ` Andrew Burgess
2026-10-01 2:09 ` [PATCH v2 09/11] gdb: add matching helpers to global_symbol_searcher simon.marchi
2026-10-01 15:39 ` Andrew Burgess
2026-10-01 15:48 ` Simon Marchi
2026-10-01 2:09 ` [PATCH v2 10/11] gdb: change some pointers to references in global_symbol_searcher simon.marchi
2026-10-01 15:53 ` Andrew Burgess
2026-10-01 15:55 ` Simon Marchi
2026-10-01 2:09 ` [PATCH v2 11/11] gdb: fix some comments " simon.marchi
2026-10-01 15:56 ` Andrew Burgess
2026-10-01 17:47 ` Simon Marchi
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=15465f38-b454-4e6e-9c32-625f6262d6df@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=aburgess@redhat.com \
--cc=gdb-patches@sourceware.org \
--cc=simon.marchi@efficios.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