| Message ID | 20261001020952.698419-7-simon.marchi@polymtl.ca |
|---|---|
| State | New |
| Headers |
Return-Path: <gdb-patches-bounces~patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 39BD34BB3BAE for <patchwork@sourceware.org>; Thu, 1 Oct 2026 02:17:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 39BD34BB3BAE Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=bLz6YgPU X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id B4AE64B9DB66 for <gdb-patches@sourceware.org>; Thu, 1 Oct 2026 02:17:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B4AE64B9DB66 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=polymtl.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=polymtl.ca ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B4AE64B9DB66 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=132.207.4.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790821027; cv=none; b=w2wLDPWzoEnU+Ee05NVyT7c3Vy7ztvt3SfTHvYSQKspvrSCZKOw87Kobv4M1x/usWr3IYMukN0nAEOzjej3pclUKctSEQepS9vqPFWKeIOukV53L+wXwSg6PTYIoZrcfuL1YVeWZLeU3Zum3UN/fQ9misOR3rG5kMar6A4vjI5Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790821027; c=relaxed/simple; bh=R7eD6+RGzsd/VPTSGQbv9pGOq3xihmeOudEBo47N0g4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=QKgiLbUzvsf3YuNR7ZkwogpojoxLRKMux9Ca0XW+1bTkRSblfDT/MHh+CrO0LveBxZeE1R7aWQGVImD9ubmL8PtjmEaf7RiuEQsg4aZQB3ebZrmhbbr9SXchljY0dpAcVN1QZ+MNLZ6xgRcKw7p0KWFxpSBezTNgAym2FkFQlA8= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=polymtl.ca header.i=@polymtl.ca header.a=rsa-sha256 header.s=oct2025 header.b=bLz6YgPU DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B4AE64B9DB66 Received: from simark.ca (simark.ca [158.69.221.121]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 6912H1gx169618 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Sep 2026 22:17:06 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 6912H1gx169618 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=oct2025; t=1790821026; bh=RsYTlmyuUDXN01Arc15AABCmHZek/vJHygfd80RuRR8=; h=From:To:Cc:Subject:Date:In-Reply-To:From; b=bLz6YgPUirrmJowM2pfXPfhgfccb6r+8mbgKWC5PvcaePp/m9vAU6UYRGpCt6Y8JP 2hPqYL8d2bPCI4Iu6E+uq/hE7ng6Ssoz0SrT0ckxziq2g9+BCCH1Mo03ZQk93HCAjW mOH3mwU4ykexnpmlC5FEErRclK1c+fgcmb8TFfnsamRCAuxIk/MLIPhFwQVSgitkpM w+CmfTm0PLQTBYnLmoLz4QpSPvFi5Fx58jtQiuoSlf/GGnlTHXmUUEEkx4NQycIKAw LHfXZFFsDSTHVmvzjVqh6fO3MzWp98+akV9BJyl5b/ZULuLBSEa/jwJFAZ5gBFZTRZ l5Zvsg+bkcASg== Received: by simark.ca (Postfix) id B2F4E1E0BC; Wed, 30 Sep 2026 22:09:56 -0400 (EDT) From: simon.marchi@polymtl.ca To: gdb-patches@sourceware.org Cc: Simon Marchi <simon.marchi@efficios.com> Subject: [PATCH v2 06/11] gdb: use a switch on m_kind in add_matching_symbols Date: Wed, 30 Sep 2026 22:09:23 -0400 Message-ID: <20261001020952.698419-7-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260929194119.155169-1-simon.marchi@efficios.com> References: <20260929194119.155169-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Thu, 1 Oct 2026 02:17:01 +0000 X-Spam-Status: No, score=-3034.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list <gdb-patches.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=subscribe> Errors-To: gdb-patches-bounces~patchwork=sourceware.org@sourceware.org |
| Series |
None
|
|
Commit Message
Simon Marchi
Oct. 1, 2026, 2:09 a.m. UTC
From: Simon Marchi <simon.marchi@efficios.com>
add_matching_symbols applies some filters that only make sense for some
kinds of searches: the type regexp for variables and functions, the
LOC_UNRESOLVED / enum constant filter for variables, and the line number
filter for modules. Some of these check m_kind, others check the
symbol's domain. Since the earlier sym->matches check only lets through
symbols whose domain corresponds to m_kind, the two are equivalent.
Group these filters in a single switch on m_kind. Add a comment for
the module filter, which skips module declarations, because it wasn't
obvious to me at first sight.
Change-Id: Idf1b366b4cfd16187848b64075a0067190c111fc
---
gdb/symtab.c | 33 +++++++++++++++++++--------------
1 file changed, 19 insertions(+), 14 deletions(-)
Comments
simon.marchi@polymtl.ca writes: > From: Simon Marchi <simon.marchi@efficios.com> > > add_matching_symbols applies some filters that only make sense for some > kinds of searches: the type regexp for variables and functions, the > LOC_UNRESOLVED / enum constant filter for variables, and the line number > filter for modules. Some of these check m_kind, others check the > symbol's domain. Since the earlier sym->matches check only lets through > symbols whose domain corresponds to m_kind, the two are equivalent. > > Group these filters in a single switch on m_kind. Add a comment for > the module filter, which skips module declarations, because it wasn't > obvious to me at first sight. > > Change-Id: Idf1b366b4cfd16187848b64075a0067190c111fc > --- > gdb/symtab.c | 33 +++++++++++++++++++-------------- > 1 file changed, 19 insertions(+), 14 deletions(-) > > diff --git a/gdb/symtab.c b/gdb/symtab.c > index 35dd2981a53a..6cc85a7eacc5 100644 > --- a/gdb/symtab.c > +++ b/gdb/symtab.c > @@ -4858,25 +4858,30 @@ global_symbol_searcher::add_matching_symbols > nullptr, 0) != 0) > continue; > > - if (((sym->domain () == VAR_DOMAIN > - || sym->domain () == FUNCTION_DOMAIN) > - && type_regex.has_value () > - && !regex_matches_sym_type_name (*type_regex, sym))) > - continue; > - > - if (m_kind == symbol_search_kind::VARIABLE) > + switch (m_kind) > { > + case symbol_search_kind::VARIABLE: > + /* LOC_CONST can be used for more than just enums, e.g., > + C++ static const members. We only want to skip enums > + here. */ > if (sym->loc_class () == LOC_UNRESOLVED > - /* LOC_CONST can be used for more than > - just enums, e.g., c++ static const > - members. We only want to skip enums > - here. */ > || (sym->loc_class () == LOC_CONST > - && (sym->type ()->code () == TYPE_CODE_ENUM))) > + && sym->type ()->code () == TYPE_CODE_ENUM)) > continue; > + [[fallthrough]]; > + > + case symbol_search_kind::FUNCTION: > + if (type_regex.has_value () > + && !regex_matches_sym_type_name (*type_regex, sym)) > + continue; > + break; > + > + case symbol_search_kind::MODULE: > + /* Skip module declarations, keep only definitions. */ > + if (sym->line () == 0) > + continue; > + break; I agree with Stephan's suggestion that you should add: case symbol_search_kind::TYPE: break; I would not focus on GDB's use or non-use of -Wswitch. Instead, my argument is that by specifically mentioning the extra case we make it clear that nothing needs to be done rather than leaving it for a future reader of the code to try and figure out if TYPE is missing on purpose, or by accident. I don't find the reasoning that there are lots of other missing case labels compelling, I think the argument for or against should stand on its own technical merits -- unless you're suggesting that the GDB style is to trim the case list as much as possible? That said, I only care enough to send one email on the topic :) If you're still not convinced then go ahead: Approved-By: Andrew Burgess <aburgess@redhat.com> Thanks, Andrew > } > - if (sym->domain () == MODULE_DOMAIN && sym->line () == 0) > - continue; > > /* Match, insert if not already in the results. */ > if (result_set->size () < m_max_search_results) > -- > 2.55.0
On 10/1/26 11:01 AM, Andrew Burgess wrote: > simon.marchi@polymtl.ca writes: > >> From: Simon Marchi <simon.marchi@efficios.com> >> >> add_matching_symbols applies some filters that only make sense for some >> kinds of searches: the type regexp for variables and functions, the >> LOC_UNRESOLVED / enum constant filter for variables, and the line number >> filter for modules. Some of these check m_kind, others check the >> symbol's domain. Since the earlier sym->matches check only lets through >> symbols whose domain corresponds to m_kind, the two are equivalent. >> >> Group these filters in a single switch on m_kind. Add a comment for >> the module filter, which skips module declarations, because it wasn't >> obvious to me at first sight. >> >> Change-Id: Idf1b366b4cfd16187848b64075a0067190c111fc >> --- >> gdb/symtab.c | 33 +++++++++++++++++++-------------- >> 1 file changed, 19 insertions(+), 14 deletions(-) >> >> diff --git a/gdb/symtab.c b/gdb/symtab.c >> index 35dd2981a53a..6cc85a7eacc5 100644 >> --- a/gdb/symtab.c >> +++ b/gdb/symtab.c >> @@ -4858,25 +4858,30 @@ global_symbol_searcher::add_matching_symbols >> nullptr, 0) != 0) >> continue; >> >> - if (((sym->domain () == VAR_DOMAIN >> - || sym->domain () == FUNCTION_DOMAIN) >> - && type_regex.has_value () >> - && !regex_matches_sym_type_name (*type_regex, sym))) >> - continue; >> - >> - if (m_kind == symbol_search_kind::VARIABLE) >> + switch (m_kind) >> { >> + case symbol_search_kind::VARIABLE: >> + /* LOC_CONST can be used for more than just enums, e.g., >> + C++ static const members. We only want to skip enums >> + here. */ >> if (sym->loc_class () == LOC_UNRESOLVED >> - /* LOC_CONST can be used for more than >> - just enums, e.g., c++ static const >> - members. We only want to skip enums >> - here. */ >> || (sym->loc_class () == LOC_CONST >> - && (sym->type ()->code () == TYPE_CODE_ENUM))) >> + && sym->type ()->code () == TYPE_CODE_ENUM)) >> continue; >> + [[fallthrough]]; >> + >> + case symbol_search_kind::FUNCTION: >> + if (type_regex.has_value () >> + && !regex_matches_sym_type_name (*type_regex, sym)) >> + continue; >> + break; >> + >> + case symbol_search_kind::MODULE: >> + /* Skip module declarations, keep only definitions. */ >> + if (sym->line () == 0) >> + continue; >> + break; > > I agree with Stephan's suggestion that you should add: > > case symbol_search_kind::TYPE: > break; > > I would not focus on GDB's use or non-use of -Wswitch. Instead, my > argument is that by specifically mentioning the extra case we make it > clear that nothing needs to be done rather than leaving it for a future > reader of the code to try and figure out if TYPE is missing on purpose, > or by accident. > > I don't find the reasoning that there are lots of other missing case > labels compelling, I think the argument for or against should stand on > its own technical merits -- unless you're suggesting that the GDB style > is to trim the case list as much as possible? When seeing an empty case, my intuition would be to remove it, but I really don't have strong feelings about that. Since you both mentioned it, I'll add it. > > That said, I only care enough to send one email on the topic :) If > you're still not convinced then go ahead: > > Approved-By: Andrew Burgess <aburgess@redhat.com> Thanks, Simon
diff --git a/gdb/symtab.c b/gdb/symtab.c index 35dd2981a53a..6cc85a7eacc5 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -4858,25 +4858,30 @@ global_symbol_searcher::add_matching_symbols nullptr, 0) != 0) continue; - if (((sym->domain () == VAR_DOMAIN - || sym->domain () == FUNCTION_DOMAIN) - && type_regex.has_value () - && !regex_matches_sym_type_name (*type_regex, sym))) - continue; - - if (m_kind == symbol_search_kind::VARIABLE) + switch (m_kind) { + case symbol_search_kind::VARIABLE: + /* LOC_CONST can be used for more than just enums, e.g., + C++ static const members. We only want to skip enums + here. */ if (sym->loc_class () == LOC_UNRESOLVED - /* LOC_CONST can be used for more than - just enums, e.g., c++ static const - members. We only want to skip enums - here. */ || (sym->loc_class () == LOC_CONST - && (sym->type ()->code () == TYPE_CODE_ENUM))) + && sym->type ()->code () == TYPE_CODE_ENUM)) continue; + [[fallthrough]]; + + case symbol_search_kind::FUNCTION: + if (type_regex.has_value () + && !regex_matches_sym_type_name (*type_regex, sym)) + continue; + break; + + case symbol_search_kind::MODULE: + /* Skip module declarations, keep only definitions. */ + if (sym->line () == 0) + continue; + break; } - if (sym->domain () == MODULE_DOMAIN && sym->line () == 0) - continue; /* Match, insert if not already in the results. */ if (result_set->size () < m_max_search_results)