gdb: introduce "set index-cache enabled", deprecate "set index-cache on/off"

The "set index-cache" command is used at the same time as a prefix
command (prefix for "set index-cache directory", for example), and a
boolean setting for turning the index-cache on and off.  Even though I
did introduce that, I now don't think it's a good idea to do something
non-standard like this.

First, there's no dedicated CLI command to show whether the index-cache
is enabled, so it has to be custom output in the "show index-cache
handler".  Also, it means there's no good way a MI frontend can find out
if the index-cache is enabled.  "-gdb-show index-cache" doesn't show it
in the MI output record:

    (gdb) interpreter-exec mi "-gdb-show index-cache"
    ~"\n"
    ~"The index cache is currently disabled.\n"
    ^done,showlist={option={name="directory",value="/home/simark/.cache/gdb"}}

Fix this by introducing "set/show index-cache enabled on/off", regular
boolean setting commands.  Keep commands "set index-cache on" and "set
index-cache off" as deprecated aliases of "set index-cache enabled",
with respectively the default arguments "on" and "off".

Update tests using "set index-cache on/off" to use the new command.
Update the regexps in gdb.base/maint.exp to figure out whether the
index-cache is enabled or not.  Update the doc to mention the new
commands.

Change-Id: I7d5aaaf7fd22bf47bd03e0023ef4fbb4023b37b3
This commit is contained in:
Simon Marchi
2021-11-04 15:31:28 -04:00
parent fcef6471ed
commit 7bc5c369fa
5 changed files with 71 additions and 27 deletions

View File

@ -21795,14 +21795,14 @@ Indices only work when using DWARF debugging information, not stabs.
@cindex automatic symbol index cache @cindex automatic symbol index cache
It is possible for @value{GDBN} to automatically save a copy of this index in a It is possible for @value{GDBN} to automatically save a copy of this index in a
cache on disk and retrieve it from there when loading the same binary in the cache on disk and retrieve it from there when loading the same binary in the
future. This feature can be turned on with @kbd{set index-cache on}. The future. This feature can be turned on with @kbd{set index-cache enabled on}.
following commands can be used to tweak the behavior of the index cache. The following commands can be used to tweak the behavior of the index cache.
@table @code @table @code
@kindex set index-cache @kindex set index-cache
@item set index-cache on @item set index-cache enabled on
@itemx set index-cache off @itemx set index-cache enabled off
Enable or disable the use of the symbol index cache. Enable or disable the use of the symbol index cache.
@item set index-cache directory @var{directory} @item set index-cache directory @var{directory}

View File

@ -22,6 +22,7 @@
#include "build-id.h" #include "build-id.h"
#include "cli/cli-cmds.h" #include "cli/cli-cmds.h"
#include "cli/cli-decode.h"
#include "command.h" #include "command.h"
#include "gdbsupport/scoped_mmap.h" #include "gdbsupport/scoped_mmap.h"
#include "gdbsupport/pathstuff.h" #include "gdbsupport/pathstuff.h"
@ -267,20 +268,32 @@ show_index_cache_command (const char *arg, int from_tty)
global_index_cache.enabled () ? _("enabled") : _("disabled")); global_index_cache.enabled () ? _("enabled") : _("disabled"));
} }
/* "set index-cache on" handler. */ /* "set/show index-cache enabled" set callback. */
static void static void
set_index_cache_on_command (const char *arg, int from_tty) set_index_cache_enabled_command (bool value)
{ {
if (value)
global_index_cache.enable (); global_index_cache.enable ();
else
global_index_cache.disable ();
} }
/* "set index-cache off" handler. */ /* "set/show index-cache enabled" get callback. */
static bool
get_index_cache_enabled_command ()
{
return global_index_cache.enabled ();
}
/* "set/show index-cache enabled" show callback. */
static void static void
set_index_cache_off_command (const char *arg, int from_tty) show_index_cache_enabled_command (ui_file *stream, int from_tty,
cmd_list_element *cmd, const char *value)
{ {
global_index_cache.disable (); fprintf_filtered (stream, _("The index cache is %s.\n"), value);
} }
/* "set index-cache directory" handler. */ /* "set index-cache directory" handler. */
@ -342,13 +355,31 @@ _initialize_index_cache ()
_("Show index-cache options."), &show_index_cache_prefix_list, _("Show index-cache options."), &show_index_cache_prefix_list,
false, &showlist); false, &showlist);
/* set/show index-cache enabled */
set_show_commands setshow_index_cache_enabled_cmds
= add_setshow_boolean_cmd ("enabled", class_files,
_("Enable the index cache."),
_("Show whether the index cache is enabled."),
_("help doc"),
set_index_cache_enabled_command,
get_index_cache_enabled_command,
show_index_cache_enabled_command,
&set_index_cache_prefix_list,
&show_index_cache_prefix_list);
/* set index-cache on */ /* set index-cache on */
add_cmd ("on", class_files, set_index_cache_on_command, cmd_list_element *set_index_cache_on_cmd
_("Enable the index cache."), &set_index_cache_prefix_list); = add_alias_cmd ("on", setshow_index_cache_enabled_cmds.set, class_files,
false, &set_index_cache_prefix_list);
deprecate_cmd (set_index_cache_on_cmd, "set index-cache enabled on");
set_index_cache_on_cmd->default_args = "on";
/* set index-cache off */ /* set index-cache off */
add_cmd ("off", class_files, set_index_cache_off_command, cmd_list_element *set_index_cache_off_cmd
_("Disable the index cache."), &set_index_cache_prefix_list); = add_alias_cmd ("off", setshow_index_cache_enabled_cmds.set, class_files,
false, &set_index_cache_prefix_list);
deprecate_cmd (set_index_cache_off_cmd, "set index-cache enabled off");
set_index_cache_off_cmd->default_args = "off";
/* set index-cache directory */ /* set index-cache directory */
add_setshow_filename_cmd ("directory", class_files, &index_cache_directory, add_setshow_filename_cmd ("directory", class_files, &index_cache_directory,

View File

@ -80,7 +80,7 @@ proc run_test_with_flags { cache_dir cache_enabled code } {
save_vars { GDBFLAGS } { save_vars { GDBFLAGS } {
set GDBFLAGS "$GDBFLAGS -iex \"set index-cache directory $cache_dir\"" set GDBFLAGS "$GDBFLAGS -iex \"set index-cache directory $cache_dir\""
set GDBFLAGS "$GDBFLAGS -iex \"set index-cache $cache_enabled\"" set GDBFLAGS "$GDBFLAGS -iex \"set index-cache enabled $cache_enabled\""
clean_restart ${testfile} clean_restart ${testfile}
@ -97,17 +97,30 @@ proc_with_prefix test_basic_stuff { } {
# Check that the index cache is disabled by default. # Check that the index cache is disabled by default.
gdb_test \ gdb_test \
"show index-cache" \ "show index-cache enabled" \
" is currently disabled." \ "The index cache is off." \
"index-cache is disabled by default" "index-cache is disabled by default"
# Test that we can enable it and "show index-cache" reflects that. # Test that we can enable it and "show index-cache enabled" reflects that.
gdb_test_no_output "set index-cache on" "enable index cache" gdb_test_no_output "set index-cache enabled on" "enable index cache"
gdb_test \ gdb_test \
"show index-cache" \ "show index-cache enabled" \
" is currently enabled." \ "The index cache is on." \
"index-cache is now enabled" "index-cache is now enabled"
with_test_prefix "deprecated commands" {
gdb_test "set index-cache off" ".*is deprecated.*" "disable index cache"
gdb_test \
"show index-cache enabled" \
"The index cache is off." \
"index-cache is now disabled"
gdb_test "set index-cache on" ".*is deprecated.*" "enable index cache"
gdb_test \
"show index-cache enabled" \
"The index cache is on." \
"index-cache is now enabled"
}
# Test the "set/show index-cache directory" commands. # Test the "set/show index-cache directory" commands.
gdb_test "set index-cache directory" "Argument required.*" "set index-cache directory without arg" gdb_test "set index-cache directory" "Argument required.*" "set index-cache directory without arg"
gdb_test_no_output "set index-cache directory /tmp" "change the index cache directory" gdb_test_no_output "set index-cache directory /tmp" "change the index cache directory"

View File

@ -131,11 +131,11 @@ gdb_test_multiple "show index-cache stats" "check index cache stats" {
} }
set using_index_cache 0 set using_index_cache 0
gdb_test_multiple "show index-cache" "check index cache status" { gdb_test_multiple "show index-cache enabled" "check index cache status" {
-re ".*is currently disabled.\r\n$gdb_prompt $" { -re ".*is off.\r\n$gdb_prompt $" {
set using_index_cache 0 set using_index_cache 0
} }
-re ".*is currently enabled.\r\n$gdb_prompt $" { -re ".*is on.\r\n$gdb_prompt $" {
set using_index_cache 1 set using_index_cache 1
} }
} }

View File

@ -45,7 +45,7 @@ with_test_prefix "populate index cache" {
gdb_test_no_output "set index-cache directory $cache_dir" \ gdb_test_no_output "set index-cache directory $cache_dir" \
"set index-cache directory" "set index-cache directory"
gdb_test_no_output "set index-cache on" gdb_test_no_output "set index-cache enabled on"
gdb_test "file $binfile" "Reading symbols from .*" "file" gdb_test "file $binfile" "Reading symbols from .*" "file"
} }
@ -56,9 +56,9 @@ proc load_binary { method } {
if { $method == "standard" } { if { $method == "standard" } {
gdb_test "file $binfile" "Reading symbols from .*" "file" gdb_test "file $binfile" "Reading symbols from .*" "file"
} elseif { $method == "index" } { } elseif { $method == "index" } {
gdb_test_no_output "set index-cache on" gdb_test_no_output "set index-cache enabled on"
gdb_test "file $binfile" "Reading symbols from .*" "file index" gdb_test "file $binfile" "Reading symbols from .*" "file index"
gdb_test_no_output "set index-cache off" gdb_test_no_output "set index-cache enabled off"
} elseif { $method == "readnow" } { } elseif { $method == "readnow" } {
gdb_test "file -readnow $binfile" \ gdb_test "file -readnow $binfile" \
"Reading symbols from .*Expanding full symbols from .*" \ "Reading symbols from .*Expanding full symbols from .*" \