diff options
author | Simon Marchi <simon.marchi@efficios.com> | 2023-04-17 12:36:51 -0400 |
---|---|---|
committer | Simon Marchi <simon.marchi@efficios.com> | 2023-04-21 14:09:42 -0400 |
commit | f57d81815f865817c8b4bc9a521cb0f71710d871 (patch) | |
tree | 7879a04980529c130d9dbde8e3a4e4695bfecbc0 /gdb | |
parent | 6fc39605e69e5c4d76990e2cf4eaf5d294195ca1 (diff) | |
download | gdb-f57d81815f865817c8b4bc9a521cb0f71710d871.zip gdb-f57d81815f865817c8b4bc9a521cb0f71710d871.tar.gz gdb-f57d81815f865817c8b4bc9a521cb0f71710d871.tar.bz2 |
gdb: switch "set language" to getter/setter
The `language` global variable is mostly a scratch variable used for the
setting. The source of truth is really current_language and
language_mode (auto vs manual), which are set by the
set_language_command callback.
Switch the setting to use the add_setshow_enum_cmd overload that takes a
value getter and setter.
Change-Id: Ief5b2f93fd7337eed7ec96023639ae3dfe62250b
Reviewed-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/language.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/gdb/language.c b/gdb/language.c index 1ab3565..42bce92 100644 --- a/gdb/language.c +++ b/gdb/language.c @@ -93,7 +93,6 @@ const struct language_defn *language_defn::languages[nr_languages]; /* The current values of the "set language/range/case-sensitive" enum commands. */ -static const char *language; static const char *range; static const char *case_sensitive; @@ -135,10 +134,10 @@ show_language_command (struct ui_file *file, int from_tty, } } -/* Set command. Change the current working language. */ +/* Set callback for the "set/show language" setting. */ + static void -set_language_command (const char *ignore, - int from_tty, struct cmd_list_element *c) +set_language (const char *language) { enum language flang = language_unknown; @@ -192,6 +191,17 @@ set_language_command (const char *ignore, language); } +/* Get callback for the "set/show language" setting. */ + +static const char * +get_language () +{ + if (language_mode == language_mode_auto) + return "auto"; + + return current_language->name (); +} + /* Show command. Display a warning if the range setting does not match the current language. */ static void @@ -372,7 +382,7 @@ language_info () return; expected_language = current_language; - gdb_printf (_("Current language: %s\n"), language); + gdb_printf (_("Current language: %s\n"), get_language ()); show_language_command (gdb_stdout, 1, NULL, NULL); } @@ -465,8 +475,7 @@ add_set_language_command () /* Display "auto", "local" and "unknown" first, and then the rest, alpha sorted. */ const char **language_names_p = language_names; - language = language_def (language_auto)->name (); - *language_names_p++ = language; + *language_names_p++ = language_def (language_auto)->name ();; *language_names_p++ = "local"; *language_names_p++ = language_def (language_unknown)->name (); const char **sort_begin = language_names_p; @@ -509,10 +518,11 @@ add_set_language_command () add_setshow_enum_cmd ("language", class_support, language_names, - &language, doc.c_str (), _("Show the current source language."), - NULL, set_language_command, + NULL, + set_language, + get_language, show_language_command, &setlist, &showlist); } |