[RFA] new set/show multiple-choice-auto-select commands

Joel Brobecker
2008-01-01T14:36:56Z

[-- Attachment #1: Type: text/plain, Size: 1962 bytes --]

Hello,

The user sometimes enters an expression which is ambiguous. For instance,
the name of a function or a variable which has homonyms... In that case,
the debugger is expected to display the list of possibilities and ask
the user to choose which one he meant (with an additional 2 possible
choices: "all" and "cancel").

This has been a very practical solution when in interactive mode
(ie when a user is driving the session), but an annoyance when driving
the debugger with a tool. So we added a new set/show command that
allowed the user to configure the behavior of the debugger so that:
1. Either the menu is still displayed (default behavior);
2. The choice "all" is always automatically selected;
3. The choice "cancel" is always automatically selected.
Some of the AdaCore engineers actually disliked the menu and started
using this new command to always select all options, even in
interactive mode.

The syntax is as follow:

(gdb) set multiple-choice-auto-select (off|all|cancel)
(gdb) show multiple-choice-auto-select

As said above, the default is "off", which preserves the current
behavior by default.

The reason why I am proposing this as an RFA is that I'm wondering
if others might be interested in sharing this setting. I noticed
from a comment that Paul wrote that menus are also printed by
linespec:decode_line_2. Otherwise, I'm happy to keep it in ada-lang.c
(less work for me :-).

2008-01-01 Joel Brobecker <brobecker@adacore.com>

* ada-lang.c (auto_select_off, auto_select_all, auto_select_cancel)
(auto_select_choices, auto_select_choice): New static global variables.
(user_select_syms): Add handling of new multiple-choice-auto-select
setting.
(_initialize_ada_language): Add new multiple-choice-auto-select option.

Tested on x86-linux. No regression.

A testcase and documentation will follow as soon as we agree on
the patch itself.

Thoughts?

Thanks,
--
Joel

[-- Attachment #2: auto-select.diff --]
[-- Type: text/plain, Size: 2125 bytes --]

Index: ada-lang.c
===================================================================
--- ada-lang.c (revision 32)
+++ ada-lang.c (revision 33)
@@ -293,6 +293,21 @@ static void ada_forward_operator_length
/* Maximum-sized dynamic type. */
static unsigned int varsize_limit;

+/* Allow the user to configure the debugger behavior with respect
+ to multiple-choice menus. */
+
+static const char auto_select_off[] = "off";
+static const char auto_select_all[] = "all";
+static const char auto_select_cancel[] = "cancel";
+static const char *auto_select_choices[] =
+{
+ auto_select_off,
+ auto_select_all,
+ auto_select_cancel,
+ NULL
+};
+static const char *auto_select_choice = auto_select_off;
+
/* FIXME: brobecker/2003-09-17: No longer a const because it is
returned by a function that does not return a const char *. */
static char *ada_completer_word_break_characters =
@@ -3341,6 +3356,15 @@ user_select_syms (struct ada_symbol_info
if (nsyms <= 1)
return nsyms;

+ if (auto_select_choice == auto_select_cancel
+ || (auto_select_choice == auto_select_all && max_results <= 1))
+ error (_("\
+canceled because the command is ambiguous and the multiple-choice menu\n\
+has been deactivated. See set/show multiple-choice-auto-select."));
+
+ if (auto_select_choice == auto_select_all)
+ return nsyms;
+
printf_unfiltered (_("[0] cancel\n"));
if (max_results > 1)
printf_unfiltered (_("[1] all\n"));
@@ -10993,6 +11017,15 @@ _initialize_ada_language (void)

varsize_limit = 65536;

+ add_setshow_enum_cmd ("multiple-choice-auto-select", no_class,
+ auto_select_choices, &auto_select_choice,
+ _("\
+Set the debugger behavior when part of a command is ambiguous and\n\
+a multiple-choice menu would normally be printed."), _("\
+Show how the debugger handles ambiguities in commands."), _("\
+Valid values are \"off\", \"all\", \"cancel\", and the default is \"off\"."),
+ NULL, NULL, &setlist, &showlist);
+
obstack_init (&symbol_list_obstack);

decoded_names_store = htab_create_alloc