From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id oCemN4cRfl8SUQAAWB0awg (envelope-from ) for ; Wed, 07 Oct 2020 15:05:43 -0400 Received: by simark.ca (Postfix, from userid 112) id DE5701EF7B; Wed, 7 Oct 2020 15:05:43 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 ESMTPS id 6FEA01EF4A for ; Wed, 7 Oct 2020 15:05:41 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F2F3D386F462; Wed, 7 Oct 2020 19:05:40 +0000 (GMT) Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by sourceware.org (Postfix) with ESMTPS id 706FC38618BD for ; Wed, 7 Oct 2020 19:05:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 706FC38618BD Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embecosm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=andrew.burgess@embecosm.com Received: by mail-wr1-x443.google.com with SMTP id n6so3248408wrm.13 for ; Wed, 07 Oct 2020 12:05:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=embecosm.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DwGDW/vg5ChbCJX3qN1fcyzaifGu7sTc0WLnny5eEpc=; b=YQSZWLTfkOJA8ix0asc2/4l2e+GJEMS2MShxMQvuXfHgfUJqab0cfEMBPCDsk9d499 3k8rzl/dxNHHHnmczvYWu+awTMVV8hagDSSmv0wZnPccJwtrx5s0Vq0R/mgPgqGnbk/q w4zsa/gldzlIhRqfY0uDqUV2u+qU6F23a24bMnf+8Lx7H4F+nOmqtEzRrFJS4AIw3/Dp nsFDPx/OKGM6V2Nd70m/BRHdNtVKj8rrg68Eo71372Ra8MtmuD1E+BeN3OwcyqCP/YXU RfG/fzXPF5vEn2Fl3mqEzF4rEhqgk2aOKeyBduAXfw3KcS+fXXXXSB8fwSILbnr/UMyk da6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DwGDW/vg5ChbCJX3qN1fcyzaifGu7sTc0WLnny5eEpc=; b=og09eP2RfJK1CcVFXRRP4oMHJBAEHsOodZxGnBPns7vjNIRO2Kb6DpWGF3iHsElQR5 K75slf9JI7z+4ouaKTOH3GLHKYa911HIXDcRnq904MY8CeVA8IUIA/aCzKM6+q5Xa+jo F78njEtMrjU/g/O3c6JIZWjzRDqPCHRP5pX6YtZW47i8i5Cx3bOlTzB7NrejUxZnsbNJ CUAKT5oytKjT3U6OL1/oWOBBOV8mpzcGpkt9a+xlff6R8bVOxt2EE9l+pGnOOoGQ0841 94MqxIt4iqtPy80TSoU+r0fPez6JC9Eq853B2Pfz+fruZoTH6zroRqwdk8u1VNHG99IG mMlg== X-Gm-Message-State: AOAM530TiqX5rzBPNGMhl0iRhT5P+nB+HwFeWwMejSSLkzbQ0osVjQ+m YORnSTsMORauI/VifAhJFimRep3GHZdXxg== X-Google-Smtp-Source: ABdhPJy+PXnwGi8hjV5z5gfNVg+aQCXFEX3cCzlB78PU2/mW2RaYUTf5wuaVUfMyOosMayjGWHxMfA== X-Received: by 2002:adf:a306:: with SMTP id c6mr5047644wrb.160.1602097536792; Wed, 07 Oct 2020 12:05:36 -0700 (PDT) Received: from localhost (host109-151-14-50.range109-151.btcentralplus.com. [109.151.14.50]) by smtp.gmail.com with ESMTPSA id n2sm4065152wrt.82.2020.10.07.12.05.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Oct 2020 12:05:36 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Subject: [PATCH 6/7] Let the user control the startup style Date: Wed, 7 Oct 2020 21:05:10 +0100 Message-Id: X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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: , Cc: Tom Tromey Errors-To: gdb-patches-bounces@sourceware.org Sender: "Gdb-patches" From: Tom Tromey Some users find the startup text highlighting to be distracting. This patch provides a way to change this, building on the startup file infrastructure that was added earlier. 2020-07-05 Tom Tromey * NEWS: Add entry. * top.c (startup_style): Remove. (print_gdb_version): Update. * cli/cli-style.h (class cli_style_option) : Add intensity parameter. : Declare new method. (startup_style): Declare. * cli/cli-style.c (startup_style): New global. (cli_style_option): Add intensity parameter. (cli_style_option::write): New method. (_initialize_cli_style): Register new style and callbacks. gdb/doc/ChangeLog 2020-07-05 Tom Tromey * gdb.texinfo (Output Styling): Document "set style startup" commands. gdb/testsuite/ChangeLog 2020-07-05 Tom Tromey * gdb.base/persist.exp: New file. --- gdb/ChangeLog | 14 +++++++ gdb/NEWS | 7 ++++ gdb/cli/cli-style.c | 36 +++++++++++++++- gdb/cli/cli-style.h | 9 +++- gdb/doc/ChangeLog | 5 +++ gdb/doc/gdb.texinfo | 15 +++++++ gdb/testsuite/ChangeLog | 4 ++ gdb/testsuite/gdb.base/persist.exp | 67 ++++++++++++++++++++++++++++++ gdb/top.c | 6 +-- 9 files changed, 155 insertions(+), 8 deletions(-) create mode 100644 gdb/testsuite/gdb.base/persist.exp diff --git a/gdb/NEWS b/gdb/NEWS index bd3aca84d51..d72d51b18b6 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -132,6 +132,13 @@ show exec-file-mismatch -- Show exec-file-mismatch handling (ask|warn|off). executable file; if 'warn', just display a warning; if 'off', don't attempt to detect a mismatch. +set style startup foreground COLOR +set style startup background COLOR +set style startup intensity VALUE + Control the styling of startup text. This saves the setting into + a special configuration file, so that it can be read during startup + and applied. + tui new-layout NAME WINDOW WEIGHT [WINDOW WEIGHT]... Define a new TUI layout, specifying its name and the windows that will be displayed. diff --git a/gdb/cli/cli-style.c b/gdb/cli/cli-style.c index a0c3cc51801..c5842023223 100644 --- a/gdb/cli/cli-style.c +++ b/gdb/cli/cli-style.c @@ -19,6 +19,7 @@ #include "defs.h" #include "cli/cli-cmds.h" +#include "cli/cli-setshow.h" #include "cli/cli-style.h" #include "source-cache.h" #include "observable.h" @@ -98,13 +99,19 @@ cli_style_option metadata_style ("metadata", ui_file_style::DIM); /* See cli-style.h. */ +cli_style_option startup_style ("startup", ui_file_style::MAGENTA, + ui_file_style::BOLD); + +/* See cli-style.h. */ + cli_style_option::cli_style_option (const char *name, - ui_file_style::basic_color fg) + ui_file_style::basic_color fg, + ui_file_style::intensity intensity) : changed (name), m_name (name), m_foreground (cli_colors[fg - ui_file_style::NONE]), m_background (cli_colors[0]), - m_intensity (cli_intensities[ui_file_style::NORMAL]) + m_intensity (cli_intensities[intensity]) { } @@ -253,6 +260,17 @@ cli_style_option::add_setshow_commands (enum command_class theclass, &m_set_list, &m_show_list, (void *) this); } +void +cli_style_option::write (ui_file *outfile) +{ + fprintf_unfiltered (outfile, "set style %s background %s\n", + m_name, m_background); + fprintf_unfiltered (outfile, "set style %s foreground %s\n", + m_name, m_foreground); + fprintf_unfiltered (outfile, "set style %s intensity %s\n", + m_name, m_intensity); +} + static cmd_list_element *style_set_list; static cmd_list_element *style_show_list; @@ -382,4 +400,18 @@ TUI window that does have the focus."), &style_set_list, &style_show_list, true); + + startup_style.add_setshow_commands (no_class, _("\ +Startup display styling.\n\ +Configure colors used in some startup text."), + &style_set_list, &style_show_list, + false); + /* Ensure that the startup style is written to the startup file. */ + add_startup_writer ([] (ui_file *outfile, const cmd_list_element *cmd) + { + startup_style.write (outfile); + }); + /* Arrange to write the startup file whenever a startup style + setting changes. */ + startup_style.changed.attach (write_startup_file); } diff --git a/gdb/cli/cli-style.h b/gdb/cli/cli-style.h index 6422e5296a3..28859f88560 100644 --- a/gdb/cli/cli-style.h +++ b/gdb/cli/cli-style.h @@ -30,7 +30,8 @@ class cli_style_option public: /* Construct a CLI style option with a foreground color. */ - cli_style_option (const char *name, ui_file_style::basic_color fg); + cli_style_option (const char *name, ui_file_style::basic_color fg, + ui_file_style::intensity = ui_file_style::NORMAL); /* Construct a CLI style option with an intensity. */ cli_style_option (const char *name, ui_file_style::intensity i); @@ -56,6 +57,9 @@ class cli_style_option /* Same as SET_LIST but for the show command list. */ struct cmd_list_element *show_list () { return m_show_list; }; + /* Write this style to FILE. */ + void write (ui_file *outfile); + /* This style can be observed for any changes. */ gdb::observers::observable<> changed; @@ -124,6 +128,9 @@ extern cli_style_option tui_border_style; /* The border style of a TUI window that does have the focus. */ extern cli_style_option tui_active_border_style; +/* The style to use for (some) startup text. */ +extern cli_style_option startup_style; + /* True if source styling is enabled. */ extern bool source_styling; diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 66b87608b89..f11948e8c4f 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -25880,6 +25880,21 @@ @code{set style address} family of commands. By default, this style's foreground color is blue. +@item startup +Control the styling of some text that is printed at startup. These +are managed with the @code{set style startup} family of commands. By +default, this style's foreground color is magenta and it has bold +intensity. Changing these settings will cause them to automatically +be saved in a special configuration file, which is read by +@value{GDBN} early in its startup. + +The directory in which this file appears depends on the host platform. +On most systems, the file is in the @file{gdb} subdirectory of the +directory pointed to by the @env{XDG_CONFIG_HOME} environment +variable, if it is defined, else in the @file{.config/gdb} +subdirectory of your home directory. However, on some systems, the +default may differ according to local convention. + @item title Control the styling of titles. These are managed with the @code{set style title} family of commands. By default, this style's diff --git a/gdb/testsuite/gdb.base/persist.exp b/gdb/testsuite/gdb.base/persist.exp new file mode 100644 index 00000000000..e0525786feb --- /dev/null +++ b/gdb/testsuite/gdb.base/persist.exp @@ -0,0 +1,67 @@ +# Copyright 2020 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# This test relies on XDG_CONFIG_HOME, which does not work on all +# platforms; so limit it to Linux native. +if {![istarget "*-*-linux*"]} then { + continue +} +if { [target_info gdb_protocol] != "" } { + continue +} + +# Check that the contents of FILENAME changed and that the contents +# now contain the given command. CONTENTS is the old contents. +# COMMAND is the command to run, and also used to name the test. +# Returns the new contents. +proc require_changed {command filename contents} { + gdb_test_no_output $command + + set fd [open $filename r] + set new [read $fd] + close $fd + + set testname "$command check" + if {$contents == $new || [string first $command $new] == -1} { + fail $testname + } else { + pass $testname + } + + return $new +} + +save_vars { env(XDG_CONFIG_HOME) } { + set dirname [standard_output_file .] + file mkdir $dirname/gdb + set filename $dirname/gdb/gdbstartup + + # Create the file as empty. + set fd [open $filename w] + close $fd + + # Current contents. + set contents "" + + setenv XDG_CONFIG_HOME $dirname + clean_restart + + gdb_test_no_output "set startup-save-filename $filename" \ + "arrange to auto-save startup settings" + + set contents [require_changed "set style startup foreground green" $filename $contents] + set contents [require_changed "set style startup background green" $filename $contents] + set contents [require_changed "set style startup intensity dim" $filename $contents] +} diff --git a/gdb/top.c b/gdb/top.c index 6233575eed6..e4c80c6dadb 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -1399,11 +1399,7 @@ print_gdb_version (struct ui_file *stream, bool interactive) ui_file_style style; if (interactive) - { - ui_file_style nstyle = { ui_file_style::MAGENTA, ui_file_style::NONE, - ui_file_style::BOLD }; - style = nstyle; - } + style = startup_style.style (); fprintf_styled (stream, style, "GNU gdb %s%s\n", PKGVERSION, version); /* Second line is a copyright notice. */ -- 2.25.4