public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
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	[thread overview]
Message-ID: <20211101155009.457224-5-simon.marchi@efficios.com> (raw)
In-Reply-To: <20211101155009.457224-1-simon.marchi@efficios.com>

From: Simon Marchi <simon.marchi@polymtl.ca>

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


  parent reply	other threads:[~2021-11-01 15:50 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-01 15:50 [PATCH 0/5] Change some index-cache commands Simon Marchi
2021-11-01 15:50 ` [PATCH 1/5] gdb: pass/return setting setter/getter scalar values by value Simon Marchi
2021-11-04 18:27   ` Tom Tromey
2021-11-04 18:59     ` Simon Marchi
2021-11-04 19:51       ` Simon Marchi
2021-11-01 15:50 ` [PATCH 2/5] gdb: remove unnecessary cmd_list_element::aliases nullptr checks Simon Marchi
2021-11-04 18:29   ` Tom Tromey
2021-11-04 19:45     ` Simon Marchi
2021-11-01 15:50 ` [PATCH 3/5] gdb: remove command_class enum class_deprecated Simon Marchi
2021-11-04 18:30   ` Tom Tromey
2021-11-04 19:45     ` Simon Marchi
2021-11-01 15:50 ` Simon Marchi [this message]
2021-11-04 18:33   ` [PATCH 4/5] gdb: add "info index-cache stats", deprecate "show index-cache stats" Tom Tromey
2021-11-04 19:19     ` Simon Marchi
2021-11-01 15:50 ` [PATCH 5/5] gdb: introduce "set index-cache enabled", deprecate "set index-cache on/off" Simon Marchi
2021-11-04 18:36   ` Tom Tromey
2021-11-04 19:51     ` 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=20211101155009.457224-5-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.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).