From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id AlaoKaA+nWCGfAAAWB0awg (envelope-from ) for ; Thu, 13 May 2021 10:58:40 -0400 Received: by simark.ca (Postfix, from userid 112) id 990A21F11C; Thu, 13 May 2021 10:58:40 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 9C2771E783 for ; Thu, 13 May 2021 10:58:39 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2C116385700D; Thu, 13 May 2021 14:58:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2C116385700D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1620917919; bh=jSOvePo5kiPk9BKq3Cm5nUsCGG3P6ECQLs8PMWrdd9A=; h=Subject:To:References:Date:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=Y52fpw4qrHY7XFqD1UcHChksBlhQfNW9WfSE7OVwWWXu+GIWQ+d13SdGtj0WY2z0u UwHG0BS46G/mfX/zWriY97/ex9gyM6ukhK0TJUbHQpUHFZZX8auX3DUCudQEZt9NTJ Q0m0VHNYNBQ3fHDEtwV84II1GEV8aUWQSFwo25Rc= Received: from smtp.polymtl.ca (smtp.polymtl.ca [132.207.4.11]) by sourceware.org (Postfix) with ESMTPS id C4E2C385700D for ; Thu, 13 May 2021 14:58:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C4E2C385700D 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 14DEwUHU032031 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 May 2021 10:58:35 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 14DEwUHU032031 Received: from [10.0.0.11] (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 80BA41E783; Thu, 13 May 2021 10:58:30 -0400 (EDT) Subject: Re: [PATCH 2/4] gdb: make struct output_source_filename_data more C++ like To: Andrew Burgess , gdb-patches@sourceware.org References: Message-ID: Date: Thu, 13 May 2021 10:58:30 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Poly-FromMTA: (simark.ca [158.69.221.121]) at Thu, 13 May 2021 14:58:30 +0000 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" 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 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 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