Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: simon.marchi@polymtl.ca, gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: Re: [PATCH v2 03/11] gdb: factor out regexp compilation from global_symbol_searcher::search
Date: Thu, 01 Oct 2026 14:19:31 +0100	[thread overview]
Message-ID: <877bk1zhgc.fsf@redhat.com> (raw)
In-Reply-To: <20261001020952.698419-4-simon.marchi@polymtl.ca>

simon.marchi@polymtl.ca writes:

> From: Simon Marchi <simon.marchi@efficios.com>
>
> Factor out the scopes that compile the regexps, in order to make
> global_symbol_searcher::search itself simpler to read.  Factor out a helper
> to compile a symbol search regex as well.

Three super minor nits, two of which are pre-existing, see inline...

> diff --git a/gdb/symtab.c b/gdb/symtab.c
> index aae82218b5cf..49e8719f4ec0 100644
> --- a/gdb/symtab.c
> +++ b/gdb/symtab.c
> @@ -4938,66 +4938,86 @@ global_symbol_searcher::add_matching_msymbols
>    return true;
>  }
>  
> -/* See symtab.h.  */
> +/* Compile REGEXP, a symbol name or symbol type regexp.
>  
> -std::vector<symbol_search>
> -global_symbol_searcher::search () const
> +   If REGEXP is nullptr, return an empty optional.  */
> +
> +static std::optional<compiled_regex>
> +compile_symbol_search_regex (const char *regexp)
>  {
> -  std::optional<compiled_regex> name_regex;
> -  std::optional<compiled_regex> type_regex;
> +  if (regexp == nullptr)
> +    return {};
>  
> -  if (m_symbol_name_regexp != NULL)
> -    {
> -      const char *symbol_name_regexp = m_symbol_name_regexp;
> -      std::string symbol_name_regexp_holder;
> +  int cflags
> +    = REG_NOSUB | (case_sensitivity == case_sensitive_off ? REG_ICASE : 0);
>  
> -      /* Make sure spacing is right for C++ operators.
> -	 This is just a courtesy to make the matching less sensitive
> -	 to how many spaces the user leaves between 'operator'
> -	 and <TYPENAME> or <OPERATOR>.  */
> -      const char *op_end;
> -      const char *opname = operator_chars (symbol_name_regexp, &op_end);
> +  return std::make_optional<compiled_regex> (regexp, cflags,
> +					    _("Invalid regexp"));

I think the indentation of the "Invalid regexp" line is off.

> +}
>  
> -      if (*opname)
> -	{
> -	  int fix = -1;		/* -1 means ok; otherwise number of
> -				    spaces needed.  */
> +/* See symtab.h.  */
>  
> -	  if (c_isalpha (*opname) || *opname == '_' || *opname == '$')
> -	    {
> -	      /* There should 1 space between 'operator' and 'TYPENAME'.  */
> -	      if (opname[-1] != ' ' || opname[-2] == ' ')
> -		fix = 1;
> -	    }
> -	  else
> -	    {
> -	      /* There should 0 spaces between 'operator' and 'OPERATOR'.  */
> -	      if (opname[-1] == ' ')
> -		fix = 0;
> -	    }
> -	  /* If wrong number of spaces, fix it.  */
> -	  if (fix >= 0)
> -	    {
> -	      symbol_name_regexp_holder
> -		= string_printf ("operator%.*s%s", fix, " ", opname);
> -	      symbol_name_regexp = symbol_name_regexp_holder.c_str ();
> -	    }
> -	}
> +std::optional<compiled_regex>
> +global_symbol_searcher::compile_name_regex () const
> +{
> +  if (m_symbol_name_regexp == nullptr)
> +    return {};
>  
> -      int cflags = REG_NOSUB | (case_sensitivity == case_sensitive_off
> -				? REG_ICASE : 0);
> -      name_regex.emplace (symbol_name_regexp, cflags,
> -			  _("Invalid regexp"));
> -    }
> +  const char *symbol_name_regexp = m_symbol_name_regexp;
> +  std::string symbol_name_regexp_holder;
> +
> +  /* Make sure spacing is right for C++ operators.
> +     This is just a courtesy to make the matching less sensitive
> +     to how many spaces the user leaves between 'operator'
> +     and <TYPENAME> or <OPERATOR>.  */
> +  const char *op_end;
> +  const char *opname = operator_chars (symbol_name_regexp, &op_end);
>  
> -  if (m_symbol_type_regexp != NULL)
> +  if (*opname)
>      {
> -      int cflags = REG_NOSUB | (case_sensitivity == case_sensitive_off
> -				? REG_ICASE : 0);
> -      type_regex.emplace (m_symbol_type_regexp, cflags,
> -			  _("Invalid regexp"));
> +      /* -1 means ok; otherwise number of spaces needed.  */
> +      int fix = -1;
> +
> +      if (c_isalpha (*opname) || *opname == '_' || *opname == '$')
> +	{
> +	  /* There should 1 space between 'operator' and 'TYPENAME'.  */

This comment has a (pre-existing) missing 'be':

  /* There should BE 1 space between .... */

> +	  if (opname[-1] != ' ' || opname[-2] == ' ')
> +	    fix = 1;
> +	}
> +      else
> +	{
> +	  /* There should 0 spaces between 'operator' and 'OPERATOR'.  */

Same missing 'BE' here.

With those all fixed:

Approved-By: Andrew Burgess <aburgess@redhat.com>

Thanks,
Andrew


  reply	other threads:[~2026-10-01 13:20 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
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 [this message]
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=877bk1zhgc.fsf@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@efficios.com \
    --cc=simon.marchi@polymtl.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