public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@efficios.com>
To: gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: [PATCH 2/3] gdb: switch "set language" to getter/setter
Date: Tue, 18 Apr 2023 16:27:50 -0400	[thread overview]
Message-ID: <20230418202751.117181-3-simon.marchi@efficios.com> (raw)
In-Reply-To: <20230418202751.117181-1-simon.marchi@efficios.com>

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
---
 gdb/language.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/gdb/language.c b/gdb/language.c
index 1ab356597d74..42bce92c647c 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);
 }
 \f
@@ -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.40.0


  parent reply	other threads:[~2023-04-18 20:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-18 20:27 [PATCH 0/3] Some language cleanups Simon Marchi
2023-04-18 20:27 ` [PATCH 1/3] gdb: remove return value of set_language Simon Marchi
2023-04-18 20:27 ` Simon Marchi [this message]
2023-04-18 20:27 ` [PATCH 3/3] gdb: remove language_auto Simon Marchi
2023-04-21 14:26 ` [PATCH 0/3] Some language cleanups Tom Tromey
2023-04-21 18:10   ` Simon Marchi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230418202751.117181-3-simon.marchi@efficios.com \
    --to=simon.marchi@efficios.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).