From patchwork Tue Apr 18 20:27:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 67958 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5DB113856DC0 for ; Tue, 18 Apr 2023 20:28:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5DB113856DC0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681849701; bh=t/q6s46/BrVaYepCDrViCoMZvuZpFXT85JX4FpLGEIM=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=nllZQMsB8IiBSxC09CCEXd1ZXi0HCgu99HRS81TBT1PSdjBXEeWrYZTFDKCSpf4aa JGMnFVTixXvjATssAHrceN4kAim8gcW15dqZNvSr4HO/3pSuMCz49+px8ub+H9hdvl n5Ibx/2jARgtuq5XjnkWBtvnYe8FzeCkGWa6fKRk= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id D76DB3858D32 for ; Tue, 18 Apr 2023 20:27:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D76DB3858D32 Received: from localhost.localdomain (unknown [167.248.160.41]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 456741E221; Tue, 18 Apr 2023 16:27:53 -0400 (EDT) To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH 2/3] gdb: switch "set language" to getter/setter Date: Tue, 18 Apr 2023 16:27:50 -0400 Message-Id: <20230418202751.117181-3-simon.marchi@efficios.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230418202751.117181-1-simon.marchi@efficios.com> References: <20230418202751.117181-1-simon.marchi@efficios.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1172.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_SOFTFAIL, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Simon Marchi via Gdb-patches From: Simon Marchi Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" 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); } @@ -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); }