public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@polymtl.ca>
To: Andrew Burgess <andrew.burgess@embecosm.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 2/4] gdb: make struct output_source_filename_data more C++ like
Date: Thu, 13 May 2021 10:58:30 -0400	[thread overview]
Message-ID: <caa1c0e9-f2ef-c156-6bd6-5d1929ce320f@polymtl.ca> (raw)
In-Reply-To: <b301ce462403c3cac6d00488fa8eef00192f03b2.1619456691.git.andrew.burgess@embecosm.com>

LGTM, I just noted a few nits / potential future cleanups.

> @@ -4211,35 +4212,83 @@ struct filename_partial_match_opts
>    bool basename = false;
>  };
>  
> -/* Data structure to maintain printing state for output_source_filename.  */
> +/* Data structure to maintain the state used for printing the results of
> +   the 'info sources' command.  */
>  
>  struct output_source_filename_data
>  {
> -  /* Output only filenames matching REGEXP.  */
> -  std::string regexp;
> -  gdb::optional<compiled_regex> c_regexp;
> -  /* Possibly only match a part of the filename.  */
> -  filename_partial_match_opts partial_match;
> +  output_source_filename_data (const char *regexp,
> +			       bool match_on_dirname,
> +			       bool match_on_basename)
> +  {
> +    m_partial_match.dirname = match_on_dirname;
> +    m_partial_match.basename = match_on_basename;

You could initialize in in the initializer list:

  : m_partial_match {match_on_dirname, match_on_basename}

>  
> +private:
> +
> +  /* Set the current regular expression, used for matching against files,
> +     to REGEXP.  */
> +  void set_regexp (const std::string regexp)

I'm a bit surprised that this is "const", but gets moved.  I'm
surprised this even compiles at all!

> +  {
> +    m_regexp = std::move (regexp);
> +    if (!m_regexp.empty ())
> +      {
> +	int cflags = REG_NOSUB;
> +#ifdef HAVE_CASE_INSENSITIVE_FILE_SYSTEM
> +	cflags |= REG_ICASE;
> +#endif
> +	m_c_regexp.emplace (m_regexp.c_str (), cflags,
> +			  _("Invalid regexp"));

This last line is missing a bit of indentation.

> +      }
> +  }
> +
> +  /* Output only filenames matching REGEXP.  */
> +  std::string m_regexp;
> +  gdb::optional<compiled_regex> m_c_regexp;
> +
> +  /* Flag of whether we're printing the first one.  */
> +  bool m_first = true;
> +
> +  /* Cache of what we've seen so far.  */
> +  filename_seen_cache m_filename_seen_cache;
> +
> +  /* Possibly only match a part of the filename.  */
> +  filename_partial_match_opts m_partial_match;
>  };
>  
> +/* See comment is class declaration above.  */

is -> in

I'm all for adding comments to functions, but I feel that these comments
(the /* See foo.h.  */ typically) are a bit useless.  If our standard is
to document external functions in headers and class declarations, do we
really need a comment to tell us to go look there for us to go look
there? >/morning rant>

> @@ -4354,49 +4399,33 @@ info_sources_command_completer (cmd_list_element *ignore,
>      return;
>  }
>  
> +/* Implement the 'info sources' command.  */
> +
>  static void
>  info_sources_command (const char *args, int from_tty)
>  {
> -  struct output_source_filename_data data;
> -
>    if (!have_full_symbols () && !have_partial_symbols ())
> -    {
> -      error (_("No symbol table is loaded.  Use the \"file\" command."));
> -    }
> -
> -  filename_seen_cache filenames_seen;
> -
> -  auto group = make_info_sources_options_def_group (&data.partial_match);
> +    error (_("No symbol table is loaded.  Use the \"file\" command."));
>  
> +  struct filename_partial_match_opts match_opts;
> +  auto group = make_info_sources_options_def_group (&match_opts);
>    gdb::option::process_options
>      (&args, gdb::option::PROCESS_OPTIONS_UNKNOWN_IS_ERROR, group);
>  
> -  if (args != NULL && *args != '\000')
> -    data.regexp = args;
> +  if (match_opts.dirname && match_opts.basename)
> +    error (_("You cannot give both -basename and -dirname to 'info sources'."));

That's orthogonal to your change, but given that match_on_dirname and
match_on_basename are mutually exclusive, I think that
output_source_filename_data / filename_partial_match_opts should take an
enum instead, like

  enum class match_what
  {
    all,
    dirname,
    basename,
  };

It would be clearer that it's one or the other.  And it would by design
make it impossible for it to have an invalid state (both booleans to
true).

Simon

  reply	other threads:[~2021-05-13 14:58 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-26 17:06 [PATCH 0/4] New option for 'info sources', also better MI support Andrew Burgess
2021-04-26 17:07 ` [PATCH 1/4] gdb: add new function quick_symbol_functions::has_unexpanded_symbols Andrew Burgess
2021-05-13 14:38   ` Simon Marchi
2021-05-13 17:29     ` Tom Tromey
2021-05-13 14:46   ` Simon Marchi
2021-04-26 17:07 ` [PATCH 2/4] gdb: make struct output_source_filename_data more C++ like Andrew Burgess
2021-05-13 14:58   ` Simon Marchi [this message]
2021-04-26 17:07 ` [PATCH 3/4] gdb: add new -group-by-binary flag to info sources command Andrew Burgess
2021-04-26 17:34   ` Eli Zaretskii
2021-05-13 15:05   ` Simon Marchi
2021-05-15  8:45     ` Andrew Burgess
2021-05-15 13:19       ` Simon Marchi
2021-04-26 17:07 ` [PATCH 4/4] gdb/mi: extend -file-list-exec-source-files command Andrew Burgess
2021-04-26 17:39   ` Eli Zaretskii
2021-05-13 15:47   ` Simon Marchi
2021-05-13 10:34 ` [PATCH 0/4] New option for 'info sources', also better MI support Andrew Burgess
2021-05-19 11:12 ` [PATCHv2 0/5] "info sources" - group by objfile Andrew Burgess
2021-05-19 11:12   ` [PATCHv2 1/5] gdb: add new function quick_symbol_functions::has_unexpanded_symbols Andrew Burgess
2021-05-19 11:12   ` [PATCHv2 2/5] gdb: make struct output_source_filename_data more C++ like Andrew Burgess
2021-05-19 11:12   ` [PATCHv2 3/5] gdb/mi: add regexp filtering to -file-list-exec-source-files Andrew Burgess
2021-05-19 11:51     ` Eli Zaretskii
2021-05-19 11:12   ` [PATCHv2 4/5] gdb/mi: add new --group-by-objfile flag for -file-list-exec-source-files Andrew Burgess
2021-05-19 11:44     ` Eli Zaretskii
2021-05-19 11:12   ` [PATCHv2 5/5] gdb: change info sources to group results by objfile Andrew Burgess
2021-05-19 11:53     ` Eli Zaretskii
2021-06-03 13:08     ` Simon Marchi
2021-06-03  9:27   ` [PATCHv2 0/5] "info sources" - group " Andrew Burgess
2021-06-03 13:15     ` Simon Marchi
2021-06-07 18:32   ` [PATCHv3 " Andrew Burgess
2021-06-07 18:32     ` [PATCHv3 1/5] gdb: add new function quick_symbol_functions::has_unexpanded_symbols Andrew Burgess
2021-06-07 18:32     ` [PATCHv3 2/5] gdb: make struct output_source_filename_data more C++ like Andrew Burgess
2021-07-05 12:31       ` Tom de Vries
2021-07-26 13:21         ` Andrew Burgess
2021-06-07 18:32     ` [PATCHv3 3/5] gdb/mi: add regexp filtering to -file-list-exec-source-files Andrew Burgess
2021-06-07 18:32     ` [PATCHv3 4/5] gdb/mi: add new --group-by-objfile flag for -file-list-exec-source-files Andrew Burgess
2021-06-07 18:32     ` [PATCHv3 5/5] gdb: change info sources to group results by objfile Andrew Burgess
2021-06-21 12:02     ` PING! Re: [PATCHv3 0/5] "info sources" - group " Andrew Burgess
2021-06-25 20:08       ` Andrew Burgess

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=caa1c0e9-f2ef-c156-6bd6-5d1929ce320f@polymtl.ca \
    --to=simon.marchi@polymtl.ca \
    --cc=andrew.burgess@embecosm.com \
    --cc=gdb-patches@sourceware.org \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).