This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
RFA: fix PR 1764
- From: Tom Tromey <tromey at redhat dot com>
- To: gdb-patches at sourceware dot org
- Date: Mon, 11 Aug 2008 19:09:09 -0600
- Subject: RFA: fix PR 1764
- Reply-to: Tom Tromey <tromey at redhat dot com>
This patch fixes PR 1764, a small bug in completion.
Completion for "set language" and a couple other "set" commands in
language.c does not work properly.
The code has some FIXMEs about using enums, but that looked like a
pain. So, I just implemented specialized completion functions. This
doesn't seem notably worse to me.
However, to do this I had to expose add_setshow_cmd_full. I'm not
sure if this is desirable or not... though to me it seems like no big
deal, given the number of already-exported add_ functions.
Built & regtested on x86-64 (compile farm).
Ok?
Tom
2008-08-11 Tom Tromey <tromey@redhat.com>
PR gdb/1764:
* language.c (language_completer): New function.
(range_or_type_completer): New function.
(case_completer): New function.
(_initialize_language): Set completers.
* cli/cli-decode.c (add_setshow_cmd_full): No longer static.
* command.h (add_setshow_cmd_full): Declare.
diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index 5b1a7e0..ef810b5 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -340,7 +340,7 @@ add_set_or_show_cmd (char *name,
and SHOW_RESULT, if not NULL, are set to the resulting command
structures. */
-static void
+void
add_setshow_cmd_full (char *name,
enum command_class class,
var_types var_type, void *var,
diff --git a/gdb/command.h b/gdb/command.h
index cf09c01..b5b4b6c 100644
--- a/gdb/command.h
+++ b/gdb/command.h
@@ -224,6 +224,18 @@ typedef void (show_value_ftype) (struct ui_file *file,
instead print the value out directly. */
extern show_value_ftype deprecated_show_value_hack;
+extern void add_setshow_cmd_full (char *name,
+ enum command_class class,
+ var_types var_type, void *var,
+ const char *set_doc, const char *show_doc,
+ const char *help_doc,
+ cmd_sfunc_ftype *set_func,
+ show_value_ftype *show_func,
+ struct cmd_list_element **set_list,
+ struct cmd_list_element **show_list,
+ struct cmd_list_element **set_result,
+ struct cmd_list_element **show_result);
+
extern void add_setshow_enum_cmd (char *name,
enum command_class class,
const char *enumlist[],
diff --git a/gdb/language.c b/gdb/language.c
index 66e5542..ae1123b 100644
--- a/gdb/language.c
+++ b/gdb/language.c
@@ -218,6 +218,20 @@ local or auto Automatic setting based on source file\n"));
error (_("Unknown language `%s'."), err_lang);
}
+static char **
+language_completer (char *text, char *word)
+{
+ int i;
+ const char **langnames
+ = (const char **) alloca ((languages_size + 1) * sizeof (const char *));
+
+ for (i = 0; i < languages_size; ++i)
+ langnames[i] = languages[i]->la_name;
+ langnames[i] = NULL;
+
+ return complete_on_enum (langnames, text, word);
+}
+
/* Show command. Display a warning if the type setting does
not match the current language. */
static void
@@ -312,6 +326,14 @@ set_range_command (char *ignore, int from_tty, struct cmd_list_element *c)
show_range_command (NULL, from_tty, NULL, NULL);
}
+/* Completer for range and type parameters. */
+static char **
+range_or_type_completer (char *text, char *word)
+{
+ static const char *values[] = { "on", "off", "warn", "auto", NULL };
+ return complete_on_enum (values, text, word);
+}
+
/* Show command. Display a warning if the case sensitivity setting does
not match the current language. */
static void
@@ -356,6 +378,14 @@ set_case_command (char *ignore, int from_tty, struct cmd_list_element *c)
show_case_command (NULL, from_tty, NULL, NULL);
}
+/* Completer for case-sensitive parameter. */
+static char **
+case_completer (char *text, char *word)
+{
+ static const char *values[] = { "on", "off", "auto", NULL };
+ return complete_on_enum (values, text, word);
+}
+
/* Set the status of range and type checking and case sensitivity based on
the current modes and the current language.
If SHOW is non-zero, then print out the current language,
@@ -1339,21 +1369,22 @@ language_lookup_primitive_type_by_name (const struct language_defn *la,
void
_initialize_language (void)
{
- struct cmd_list_element *set, *show;
+ struct cmd_list_element *command;
language_gdbarch_data
= gdbarch_data_register_post_init (language_gdbarch_post_init);
/* GDB commands for language specific stuff */
- /* FIXME: cagney/2005-02-20: This should be implemented using an
- enum. */
- add_setshow_string_noescape_cmd ("language", class_support, &language, _("\
+ add_setshow_cmd_full ("language", class_support, var_string_noescape,
+ &language, _("\
Set the current source language."), _("\
Show the current source language."), NULL,
- set_language_command,
- show_language_command,
- &setlist, &showlist);
+ set_language_command,
+ show_language_command,
+ &setlist, &showlist,
+ &command, NULL);
+ set_cmd_completer (command, language_completer);
add_prefix_cmd ("check", no_class, set_check,
_("Set the status of the type/range checker."),
@@ -1367,34 +1398,36 @@ Show the current source language."), NULL,
add_alias_cmd ("c", "check", no_class, 1, &showlist);
add_alias_cmd ("ch", "check", no_class, 1, &showlist);
- /* FIXME: cagney/2005-02-20: This should be implemented using an
- enum. */
- add_setshow_string_noescape_cmd ("type", class_support, &type, _("\
+ add_setshow_cmd_full ("type", class_support, var_string_noescape,
+ &type, _("\
Set type checking. (on/warn/off/auto)"), _("\
Show type checking. (on/warn/off/auto)"), NULL,
- set_type_command,
- show_type_command,
- &setchecklist, &showchecklist);
-
- /* FIXME: cagney/2005-02-20: This should be implemented using an
- enum. */
- add_setshow_string_noescape_cmd ("range", class_support, &range, _("\
+ set_type_command,
+ show_type_command,
+ &setchecklist, &showchecklist,
+ &command, NULL);
+ set_cmd_completer (command, range_or_type_completer);
+
+ add_setshow_cmd_full ("range", class_support, var_string_noescape,
+ &range, _("\
Set range checking. (on/warn/off/auto)"), _("\
Show range checking. (on/warn/off/auto)"), NULL,
- set_range_command,
- show_range_command,
- &setchecklist, &showchecklist);
-
- /* FIXME: cagney/2005-02-20: This should be implemented using an
- enum. */
- add_setshow_string_noescape_cmd ("case-sensitive", class_support,
- &case_sensitive, _("\
+ set_range_command,
+ show_range_command,
+ &setchecklist, &showchecklist,
+ &command, NULL);
+ set_cmd_completer (command, range_or_type_completer);
+
+ add_setshow_cmd_full ("case-sensitive", class_support, var_string_noescape,
+ &case_sensitive, _("\
Set case sensitivity in name search. (on/off/auto)"), _("\
Show case sensitivity in name search. (on/off/auto)"), _("\
For Fortran the default is off; for other languages the default is on."),
- set_case_command,
- show_case_command,
- &setlist, &showlist);
+ set_case_command,
+ show_case_command,
+ &setlist, &showlist,
+ &command, NULL);
+ set_cmd_completer (command, case_completer);
add_language (&unknown_language_defn);
add_language (&local_language_defn);