From patchwork Mon Mar 11 20:13:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 31817 Received: (qmail 116328 invoked by alias); 11 Mar 2019 20:13:56 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 116307 invoked by uid 89); 11 Mar 2019 20:13:56 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=consulted, highlighting, intensity, TERM X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 11 Mar 2019 20:13:54 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 7528D56107; Mon, 11 Mar 2019 16:13:53 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id e6Ww4i2ch1Tk; Mon, 11 Mar 2019 16:13:53 -0400 (EDT) Received: from murgatroyd (75-166-85-218.hlrn.qwest.net [75.166.85.218]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id F372E56104; Mon, 11 Mar 2019 16:13:52 -0400 (EDT) From: Tom Tromey To: Philippe Waroquiers Cc: Tom Tromey , gdb-patches@sourceware.org Subject: Re: [RFC 8.3 2/3] Add the "set style source" command References: <20190308210433.32683-1-tromey@adacore.com> <20190308210433.32683-3-tromey@adacore.com> <1552130320.6197.4.camel@skynet.be> Date: Mon, 11 Mar 2019 14:13:52 -0600 In-Reply-To: <1552130320.6197.4.camel@skynet.be> (Philippe Waroquiers's message of "Sat, 09 Mar 2019 12:18:40 +0100") Message-ID: <878sxl9njz.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 >>>>> "Philippe" == Philippe Waroquiers writes: Philippe> Also, this NEWS entry explains that 'on' takes effect only Philippe> if styling is on, but neither the help nor the user manual Philippe> are explaining this. Philippe> Maybe the help and/or user manual should also explain this ? Seems reasonable, let me know what you think of the appended. Tom commit 82897b4c31ad6d65073c64529325830a9c70c65f Author: Tom Tromey Date: Fri Mar 8 13:54:07 2019 -0700 Add the "set style source" command This adds "set style source" (and "show style source") commands. This gives the user control over whether source code is highlighted. gdb/ChangeLog 2019-03-08 Tom Tromey * NEWS: Add item for "style sources" commands. * source-cache.c (source_cache::get_source_lines): Check source_styling. * cli/cli-style.c (source_styling): New global. (_initialize_cli_style): Add "style sources" commands. (show_style_sources): New function. * cli/cli-style.h (source_styling): Declare. gdb/doc/ChangeLog 2019-03-08 Tom Tromey * gdb.texinfo (Output Styling): Document "set style source" and "show style source". gdb/testsuite/ChangeLog 2019-03-08 Tom Tromey * gdb.base/style.exp: Add "set style sources" test. diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 6d58321c0d6..efaa82f3a00 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,13 @@ +2019-03-08 Tom Tromey + + * NEWS: Add item for "style sources" commands. + * source-cache.c (source_cache::get_source_lines): Check + source_styling. + * cli/cli-style.c (source_styling): New global. + (_initialize_cli_style): Add "style sources" commands. + (show_style_sources): New function. + * cli/cli-style.h (source_styling): Declare. + 2019-03-08 Tom Tromey * cli/cli-style.c (set_style_enabled): Notify new observable. diff --git a/gdb/NEWS b/gdb/NEWS index cc7c35c0642..3f465856cc4 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -145,6 +145,12 @@ show style enabled Enable or disable terminal styling. Styling is enabled by default on most hosts, but disabled by default when in batch mode. +set style sources [on|off] +show style sources + Enable or disable source code styling. Source code styling is + enabled by default, but only takes effect if styling in general is + enabled, and if GDB was linked with GNU Source Highlight. + set style filename foreground COLOR set style filename background COLOR set style filename intensity VALUE diff --git a/gdb/cli/cli-style.c b/gdb/cli/cli-style.c index fc91504d1f8..f6f6c7be5d9 100644 --- a/gdb/cli/cli-style.c +++ b/gdb/cli/cli-style.c @@ -31,6 +31,11 @@ int cli_styling = 0; int cli_styling = 1; #endif +/* True if source styling is enabled. Note that this is only + consulted when cli_styling is true. */ + +int source_styling = 1; + /* Name of colors; must correspond to ui_file_style::basic_color. */ static const char * const cli_colors[] = { "none", @@ -230,6 +235,16 @@ show_style_enabled (struct ui_file *file, int from_tty, fprintf_filtered (file, _("CLI output styling is disabled.\n")); } +static void +show_style_sources (struct ui_file *file, int from_tty, + struct cmd_list_element *c, const char *value) +{ + if (source_styling) + fprintf_filtered (file, _("Source code styling is enabled.\n")); + else + fprintf_filtered (file, _("Source code styling is disabled.\n")); +} + void _initialize_cli_style () { @@ -249,6 +264,20 @@ If enabled, output to the terminal is styled."), set_style_enabled, show_style_enabled, &style_set_list, &style_show_list); + add_setshow_boolean_cmd ("sources", no_class, &source_styling, _("\ +Set whether source code styling is enabled."), _("\ +Show whether source code styling is enabled."), _("\ +If enabled, source code is styled.\n" +#ifdef HAVE_SOURCE_HIGHLIGHT +"Note that source styling only works if styling in general is enabled,\n\ +see \"show style enabled\"." +#else +"Source highlighting is disabled in this installation of gdb, because\n\ +it was not linked against GNU Source Highlight." +#endif + ), set_style_enabled, show_style_sources, + &style_set_list, &style_show_list); + #define STYLE_ADD_SETSHOW_COMMANDS(STYLE, NAME, PREFIX_DOC) \ STYLE.add_setshow_commands (NAME, no_class, PREFIX_DOC, \ &style_set_list, \ diff --git a/gdb/cli/cli-style.h b/gdb/cli/cli-style.h index 287bad7d201..c0520f9e23f 100644 --- a/gdb/cli/cli-style.h +++ b/gdb/cli/cli-style.h @@ -93,6 +93,9 @@ extern cli_style_option variable_name_style; /* The address style. */ extern cli_style_option address_style; +/* True if source styling is enabled. */ +extern int source_styling; + /* True if styling is enabled. */ extern int cli_styling; diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog index 0380322dfee..1f10b346866 100644 --- a/gdb/doc/ChangeLog +++ b/gdb/doc/ChangeLog @@ -1,3 +1,8 @@ +2019-03-08 Tom Tromey + + * gdb.texinfo (Output Styling): Document "set style source" and + "show style source". + 2019-03-05 Simon Marchi * python.texi (Values From Inferior): Change synopsys of the diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index f2028f86b0d..27c996b33f9 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -24525,6 +24525,16 @@ most hosts defaulting to @samp{on}. @item show style enabled Show the current state of styling. + +@item set style sources @samp{on|off} +Enable or disable source code styling. This affects whether source +code, such as the output of the @code{list} command, is styled. Note +that source styling only works if styling in general is enabled, and +if @value{GDBN} was linked with the GNU Source Highlight library. The +default is @samp{on}. + +@item show style sources +Show the current state of source code styling. @end table Subcommands of @code{set style} control specific forms of styling. diff --git a/gdb/source-cache.c b/gdb/source-cache.c index 097c8a3ae12..27a0ade959c 100644 --- a/gdb/source-cache.c +++ b/gdb/source-cache.c @@ -174,7 +174,7 @@ source_cache::get_source_lines (struct symtab *s, int first_line, return false; #ifdef HAVE_SOURCE_HIGHLIGHT - if (can_emit_style_escape (gdb_stdout)) + if (source_styling && can_emit_style_escape (gdb_stdout)) { const char *fullname = symtab_to_fullname (s); diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 57f80b49b59..d75c2386fdb 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2019-03-08 Tom Tromey + + * gdb.base/style.exp: Add "set style sources" test. + 2019-03-06 Andrew Burgess * gdb.fortran/type-kinds.exp: Extend to cover TYPE*SIZE cases. diff --git a/gdb/testsuite/gdb.base/style.exp b/gdb/testsuite/gdb.base/style.exp index 2778001fed5..369c1f59a88 100644 --- a/gdb/testsuite/gdb.base/style.exp +++ b/gdb/testsuite/gdb.base/style.exp @@ -50,6 +50,12 @@ save_vars { env(TERM) } { "$main_expr.*$arg_expr.*$arg_expr.*$file_expr.*" gdb_test "info breakpoints" "$main_expr at $file_expr.*" + gdb_test_no_output "set style sources off" + gdb_test "frame" \ + "\r\n\[^\033\]*break here.*" \ + "frame without styling" + gdb_test_no_output "set style sources on" + gdb_test "break main" "file $base_file_expr.*" gdb_test "print &main" " = .* \033\\\[34m$hex\033\\\[m <$main_expr>"