Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tromey@adacore.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tromey@adacore.com>
Subject: [RFC 8.3 2/3] Add the "set style source" command
Date: Fri, 08 Mar 2019 21:04:00 -0000	[thread overview]
Message-ID: <20190308210433.32683-3-tromey@adacore.com> (raw)
In-Reply-To: <20190308210433.32683-1-tromey@adacore.com>

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  <tromey@adacore.com>

	* 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  <tromey@adacore.com>

	* gdb.texinfo (Output Styling): Document "set style source" and
	"show style source".

gdb/testsuite/ChangeLog
2019-03-08  Tom Tromey  <tromey@adacore.com>

	* gdb.base/style.exp: Add "set style sources" test.
---
 gdb/ChangeLog                    | 10 ++++++++++
 gdb/NEWS                         |  6 ++++++
 gdb/cli/cli-style.c              | 22 ++++++++++++++++++++++
 gdb/cli/cli-style.h              |  3 +++
 gdb/doc/ChangeLog                |  5 +++++
 gdb/doc/gdb.texinfo              |  9 +++++++++
 gdb/source-cache.c               |  2 +-
 gdb/testsuite/ChangeLog          |  4 ++++
 gdb/testsuite/gdb.base/style.exp |  6 ++++++
 9 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index cc7c35c0642..06564311643 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, if 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 729a024c47a..6b3e92f9ec4 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,13 @@ 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."),
+			   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/gdb.texinfo b/gdb/doc/gdb.texinfo
index f2028f86b0d..346d3c8d6be 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -24525,6 +24525,15 @@ 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.  This
+only works 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/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>"
-- 
2.20.1


  parent reply	other threads:[~2019-03-08 21:04 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-08 21:04 [RFC 8.3 0/3] Some style fixes Tom Tromey
2019-03-08 21:04 ` [RFC 8.3 3/3] Avoid a crash in source_cache::extract_lines Tom Tromey
2019-03-13 17:07   ` Pedro Alves
2019-03-13 17:20     ` Tom Tromey
2019-03-13 18:06       ` Pedro Alves
2019-03-14 11:37         ` Tom Tromey
2019-03-08 21:04 ` Tom Tromey [this message]
2019-03-09  6:17   ` [RFC 8.3 2/3] Add the "set style source" command Eli Zaretskii
2019-03-11 20:13     ` Tom Tromey
2019-03-09 11:18   ` Philippe Waroquiers
2019-03-11 20:13     ` Tom Tromey
2019-03-11 20:25       ` Eli Zaretskii
2019-03-08 21:04 ` [RFC 8.3 1/3] Make TUI react to "set style enabled" Tom Tromey
2019-03-13 19:28   ` Pedro Alves
2019-03-14 11:43     ` Tom Tromey
2019-03-09  6:17 ` [RFC 8.3 0/3] Some style fixes Eli Zaretskii
2019-03-10 13:14   ` Eli Zaretskii
2019-03-11 20:15     ` Tom Tromey
2019-03-12 16:44       ` Eli Zaretskii
2019-03-13 15:50         ` Eli Zaretskii
2019-03-14 12:21           ` Tom Tromey
2019-03-14 14:40             ` Pedro Alves
2019-03-14 15:36               ` Eli Zaretskii
2019-03-15 12:34         ` Fix pressing down in the TUI (Re: [RFC 8.3 0/3] Some style fixes) Pedro Alves
2019-03-15 13:37           ` Eli Zaretskii
2019-03-15 13:56             ` Pedro Alves
2019-03-16 17:59               ` Eli Zaretskii
2019-03-24 15:35                 ` Simon Marchi
2019-03-25  1:36                   ` Simon Marchi
2019-03-25 15:14                     ` Tom Tromey
2019-03-26  0:52                       ` Simon Marchi
2019-03-15 15:33           ` Tom Tromey
2019-03-15 12:43         ` Avoid overwriting the TUI source window frame " Pedro Alves
2019-03-16 12:17           ` Eli Zaretskii
2019-03-15 14:15         ` [PATCH v2] Fix first time you type UP or DOWN in TUI's command window " Pedro Alves
2019-03-15 15:38           ` Eli Zaretskii
2019-03-18 20:24             ` Pedro Alves
2019-03-19  6:09               ` Eli Zaretskii
2019-03-19 18:14                 ` Pedro Alves
2019-03-09 14:28 ` [RFC 8.3 0/3] Some style fixes Hannes Domani via gdb-patches
2019-03-12 16:48   ` Tom Tromey
2019-03-12 17:09     ` Hannes Domani via gdb-patches
2019-03-13 15:44       ` Eli Zaretskii
2019-03-14 20:25         ` "next" into line longer than the source window-width (Re: [RFC 8.3 0/3] Some style fixes) Pedro Alves
2019-03-17 16:05           ` Eli Zaretskii
2019-03-14 20:58         ` [PATCH] Fix scrolling right in the TUI " Pedro Alves
2019-03-15 12:34           ` Hannes Domani via gdb-patches
2019-03-15 21:51           ` Tom Tromey
2019-03-18 14:41             ` Pedro Alves
2019-03-17 16:06           ` Eli Zaretskii
2019-03-12 17:29     ` [RFC 8.3 0/3] Some style fixes Eli Zaretskii
2019-03-12 17:32       ` Eli Zaretskii
2019-03-12 17:29     ` Eli Zaretskii
2019-03-26 20:52     ` Pedro Franco de Carvalho
2019-03-14 11:44 ` Tom Tromey

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=20190308210433.32683-3-tromey@adacore.com \
    --to=tromey@adacore.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