From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id 301B23858000 for ; Mon, 1 Nov 2021 15:50:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 301B23858000 X-ASG-Debug-ID: 1635781811-0c856e03878b84e0001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id KITf8vm2mBePHBFg (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 01 Nov 2021 11:50:11 -0400 (EDT) X-Barracuda-Envelope-From: simon.marchi@efficios.com X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from smarchi-efficios.internal.efficios.com (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) by smtp.ebox.ca (Postfix) with ESMTP id 28405441D67; Mon, 1 Nov 2021 11:50:11 -0400 (EDT) From: Simon Marchi X-Barracuda-RBL-IP: 192.222.180.24 X-Barracuda-Effective-Source-IP: 192-222-180-24.qc.cable.ebox.net[192.222.180.24] X-Barracuda-Apparent-Source-IP: 192.222.180.24 To: gdb-patches@sourceware.org Subject: [PATCH 4/5] gdb: add "info index-cache stats", deprecate "show index-cache stats" Date: Mon, 1 Nov 2021 11:50:08 -0400 X-ASG-Orig-Subj: [PATCH 4/5] gdb: add "info index-cache stats", deprecate "show index-cache stats" Message-Id: <20211101155009.457224-5-simon.marchi@efficios.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211101155009.457224-1-simon.marchi@efficios.com> References: <20211101155009.457224-1-simon.marchi@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1635781811 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-BRTS-Status: 1 X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 10070 X-Barracuda-Spam-Score: 0.50 X-Barracuda-Spam-Status: No, SCORE=0.50 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests=BSF_RULE7568M X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.93667 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- 0.50 BSF_RULE7568M Custom Rule 7568M X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org 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: , X-List-Received-Date: Mon, 01 Nov 2021 15:50:21 -0000 From: Simon Marchi The "show index-cache stats" command is used to show some statistics about the index-cache usage. I believe this is not a good use of a show command, as it is not a setting. For example, it is listed by "info set", in a way that doesn't make sense: ... host-charset: The host character set is "auto; currently UTF-8". index-cache directory: The directory of the index cache is "/home/simark/.cache/gdb". index-cache stats: Cache hits (this session): 0 Cache misses (this session): 0 inferior-tty: Terminal for future runs of program being debugged is "". ... When using the -gdb-show MI command, the result isn't useful either: (gdb) interpreter-exec mi "-gdb-show index-cache stats" ~" Cache hits (this session): 0\n" ~"Cache misses (this session): 0\n" ^done I think it makes more sense to have an info command for this kind of thing, and that set/show commands should be kept for actual settings. Introduce "info index-cache stats", and make "show index-cache stats" a deprecated alias of that. Just with that change, the output of the "info index-cache" prefix included the deprecated "show index-cache stats" alias: (gdb) info index-cache List of info index-cache subcommands: info index-cache stats, show index-cache stats -- Print some statistics about the index cache. When listing sub-commands, I don't think we should show the deprecated aliases. They are kept for backwards compatibility, but we don't really want to advertise them. Change fput_command_names_styled to exclude aliases marked as deprecated. Update tests using "show index-cache stats" to use the new command, and update the doc. Change-Id: I13be3c6f98dec9bb4159013b2f7a5df234f6af32 --- gdb/cli/cli-decode.c | 36 ++++++++++++++--- gdb/doc/gdb.texinfo | 2 +- gdb/dwarf2/index-cache.c | 53 +++++++++++++------------- gdb/testsuite/gdb.base/index-cache.exp | 7 ++-- gdb/testsuite/gdb.base/maint.exp | 2 +- 5 files changed, 62 insertions(+), 38 deletions(-) diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index de90198dfa71..ab06954de5da 100644 --- a/gdb/cli/cli-decode.c +++ b/gdb/cli/cli-decode.c @@ -1359,9 +1359,11 @@ fput_aliases_definition_styled (struct cmd_list_element *cmd, } -/* If C has one or more aliases, style print the name of C and - the name of its aliases, separated by commas. +/* If C has one or more non-deprecated aliases, style print the name of C and + the name of its non-deprecated aliases, separated by commas. + If ALWAYS_FPUT_C_NAME, print the name of C even if it has no aliases. + If one or more names are printed, POSTFIX is printed after the last name. */ @@ -1370,17 +1372,39 @@ fput_command_names_styled (struct cmd_list_element *c, bool always_fput_c_name, const char *postfix, struct ui_file *stream) { - if (always_fput_c_name || c->aliases != nullptr) + /* Return true if ALIAS should be printed. */ + auto print_alias = [] (cmd_list_element *alias) + { + return !alias->cmd_deprecated; + }; + + /* See if we are going to print something, if either ALWAYS_FPUT_C_NAME is true + or there exists at least one non-deprecated alias. */ + bool print_something = always_fput_c_name; + for (cmd_list_element *alias = c->aliases; + alias != nullptr && !print_something; + alias = alias->alias_chain) + { + if (!print_alias (alias)) + continue; + + print_something = true; + } + + if (print_something) fput_command_name_styled (c, stream); - for (cmd_list_element *iter = c->aliases; iter; iter = iter->alias_chain) + for (cmd_list_element *alias = c->aliases; alias; alias = alias->alias_chain) { + if (!print_alias (alias)) + continue; + fputs_filtered (", ", stream); wrap_here (" "); - fput_command_name_styled (iter, stream); + fput_command_name_styled (alias, stream); } - if (always_fput_c_name || c->aliases != nullptr) + if (print_something) fputs_filtered (postfix, stream); } diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 308a97aeb82f..c435bc655b0d 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -21820,7 +21820,7 @@ differ according to local convention. There is no limit on the disk space used by index cache. It is perfectly safe to delete the content of that directory to free up disk space. -@item show index-cache stats +@item info index-cache stats Print the number of cache hits and misses since the launch of @value{GDBN}. @end table diff --git a/gdb/dwarf2/index-cache.c b/gdb/dwarf2/index-cache.c index f439b37db5ae..4a83213a6250 100644 --- a/gdb/dwarf2/index-cache.c +++ b/gdb/dwarf2/index-cache.c @@ -46,6 +46,9 @@ index_cache global_index_cache; static cmd_list_element *set_index_cache_prefix_list; static cmd_list_element *show_index_cache_prefix_list; +/* info index-cache commands. */ +static cmd_list_element *info_index_cache_prefix_list; + /* Default destructor of index_cache_resource. */ index_cache_resource::~index_cache_resource () = default; @@ -246,18 +249,11 @@ index_cache::make_index_filename (const bfd_build_id *build_id, return m_dir + SLASH_STRING + build_id_str + suffix; } -/* True when we are executing "show index-cache". This is used to improve the - printout a little bit. */ -static bool in_show_index_cache_command = false; - /* "show index-cache" handler. */ static void show_index_cache_command (const char *arg, int from_tty) { - /* Note that we are executing "show index-cache". */ - auto restore_flag = make_scoped_restore (&in_show_index_cache_command, true); - /* Call all "show index-cache" subcommands. */ cmd_show_list (show_index_cache_prefix_list, from_tty); @@ -296,25 +292,15 @@ set_index_cache_directory_command (const char *arg, int from_tty, global_index_cache.set_directory (index_cache_directory); } -/* "show index-cache stats" handler. */ +/* "info index-cache stats" handler. */ static void -show_index_cache_stats_command (const char *arg, int from_tty) +info_index_cache_stats_command (const char *arg, int from_tty) { - const char *indent = ""; - - /* If this command is invoked through "show index-cache", make the display a - bit nicer. */ - if (in_show_index_cache_command) - { - indent = " "; - printf_unfiltered ("\n"); - } - - printf_unfiltered (_("%s Cache hits (this session): %u\n"), - indent, global_index_cache.n_hits ()); - printf_unfiltered (_("%sCache misses (this session): %u\n"), - indent, global_index_cache.n_misses ()); + printf_unfiltered (_("Cache hits (this session): %u\n"), + global_index_cache.n_hits ()); + printf_unfiltered (_("Cache misses (this session): %u\n"), + global_index_cache.n_misses ()); } void _initialize_index_cache (); @@ -359,10 +345,23 @@ _initialize_index_cache () &set_index_cache_prefix_list, &show_index_cache_prefix_list); - /* show index-cache stats */ - add_cmd ("stats", class_files, show_index_cache_stats_command, - _("Show some stats about the index cache."), - &show_index_cache_prefix_list); + /* info index-cache */ + add_basic_prefix_cmd ("index-cache", class_files, + "Get information about the index-cache.", + &info_index_cache_prefix_list, 0, &infolist); + + /* info index-cache stats */ + cmd_list_element *info_index_cache_stats + = add_cmd ("stats", class_files, info_index_cache_stats_command, + _("Print some statistics about the index cache."), + &info_index_cache_prefix_list); + + /* "show index-cache stats", deprecated in favor of + "info index-cache stats". */ + cmd_list_element *show_index_cache_stats + = add_alias_cmd ("stats", info_index_cache_stats, class_files, 0, + &show_index_cache_prefix_list); + deprecate_cmd (show_index_cache_stats, "info index-cache stats"); /* set debug index-cache */ add_setshow_boolean_cmd ("index-cache", class_maintenance, diff --git a/gdb/testsuite/gdb.base/index-cache.exp b/gdb/testsuite/gdb.base/index-cache.exp index 8dd35ad80bd7..b6e2c3ec0223 100644 --- a/gdb/testsuite/gdb.base/index-cache.exp +++ b/gdb/testsuite/gdb.base/index-cache.exp @@ -61,16 +61,17 @@ proc ls_host { dir } { return [list 0 $filtered] } -# Execute "show index-cache stats" and verify the output against expected +# Execute "info index-cache stats" and verify the output against expected # values. proc check_cache_stats { expected_hits expected_misses } { set re [multi_line \ - " Cache hits .this session.: $expected_hits" \ + "Cache hits .this session.: $expected_hits" \ "Cache misses .this session.: $expected_misses" \ ] - gdb_test "show index-cache stats" $re "check index-cache stats" + gdb_test "info index-cache stats" $re "check index-cache stats" + gdb_test "show index-cache stats" $re "check index-cache stats using deprecated command" } # Run CODE using a fresh GDB configured based on the other parameters. diff --git a/gdb/testsuite/gdb.base/maint.exp b/gdb/testsuite/gdb.base/maint.exp index 0a0cc0f813c8..7d1f462f9739 100644 --- a/gdb/testsuite/gdb.base/maint.exp +++ b/gdb/testsuite/gdb.base/maint.exp @@ -124,7 +124,7 @@ set have_gdb_index [ exec_has_index_section ${binfile} ] # We can detect this by looking if the index-cache is enabled and if the number # of cache misses is 0. set index_cache_misses -1 -gdb_test_multiple "show index-cache stats" "check index cache stats" { +gdb_test_multiple "info index-cache stats" "check index cache stats" { -re ".*Cache misses \\(this session\\): (\\d+)\r\n.*$gdb_prompt $" { set index_cache_misses $expect_out(1,string) } -- 2.26.2