From f57d81815f865817c8b4bc9a521cb0f71710d871 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Mon, 17 Apr 2023 12:36:51 -0400 Subject: [PATCH] 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 --- gdb/language.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/gdb/language.c b/gdb/language.c index 1ab356597d7..42bce92c647 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); } -- 2.30.2