Commit Graph

7 Commits

Author SHA1 Message Date
Joel Brobecker b811d2c292 Update copyright year range in all GDB files.
gdb/ChangeLog:

        Update copyright year range in all GDB files.
2020-01-01 10:20:53 +04:00
Pedro Alves 2a3c1174c3 Introduce gdb-specific %p format suffixes
This introduces a few gdb-specific %p format suffixes.  This is useful
for emitting gdb-specific output in an ergonomic way.  It also yields
code that is more i18n-friendly.

The comment before ui_out::message explains the details.

Note that the tests had to change a little.  When using one of the gdb
printf functions with styling, there can be spurious style changes
emitted to the output.  This did not seem worthwhile to fix, as the
low-level output functions are rather spaghetti-ish already, and I
didn't want to make them even worse.

This change also necessitated adding support for "*" as precision and
width in format_pieces.  These are used in various spots in gdb, and
it seemed better to me to implement them than to remove the uses.

gdb/ChangeLog
2019-10-01  Pedro Alves  <palves@redhat.com>
	    Tom Tromey  <tom@tromey.com>

	* unittests/format_pieces-selftests.c: Add gdb_format parameter.
	(test_gdb_formats): New function.
	(run_tests): Call it.
	(test_format_specifier): Update.
	* utils.h (fputs_filtered): Update comment.
	(vfprintf_styled, vfprintf_styled_no_gdbfmt)
	(fputs_styled_unfiltered): Declare.
	* utils.c (fputs_styled_unfiltered): New function.
	(vfprintf_maybe_filtered): Add gdbfmt parameter.
	(vfprintf_filtered): Update.
	(vfprintf_unfiltered, vprintf_filtered): Update.
	(vfprintf_styled, vfprintf_styled_no_gdbfmt): New functions.
	* ui-out.h (enum ui_out_flag) <unfiltered_output,
	disallow_ui_out_field>: New constants.
	(enum class field_kind): New.
	(struct base_field_s, struct signed_field_s): New.
	(signed_field): New function.
	(struct string_field_s): New.
	(string_field): New function.
	(struct styled_string_s): New.
	(styled_string): New function.
	(class ui_out) <message>: Add comment.
	<vmessage, call_do_message>: New methods.
	<do_message>: Add style parameter.
	* ui-out.c (ui_out::call_do_message, ui_out::vmessage): New
	methods.
	(ui_out::message): Rewrite.
	* mi/mi-out.h (class mi_ui_out) <do_message>: Add style
	parameter.
	* mi/mi-out.c (mi_ui_out::do_message): Add style parameter.
	* gdbsupport/format.h (class format_pieces) <format_pieces>: Add
	gdb_extensions parameter.
	(class format_piece): Add parameter to constructor.
	(n_int_args): New field.
	* gdbsupport/format.c (format_pieces::format_pieces): Add
	gdb_extensions parameter.  Handle '*'.
	* cli-out.h (class cli_ui_out) <do_message>: Add style parameter.
	* cli-out.c (cli_ui_out::do_message): Add style parameter.  Call
	vfprintf_styled_no_gdbfmt.
	(cli_ui_out::do_field_string, cli_ui_out::do_spaces)
	(cli_ui_out::do_text, cli_ui_out::field_separator): Allow
	unfiltered output.
	* ui-style.h (struct ui_file_style) <ptr>: New method.

gdb/testsuite/ChangeLog
2019-10-01  Tom Tromey  <tom@tromey.com>

	* gdb.base/style.exp: Update tests.
2019-10-01 15:12:38 -06:00
Tom Tromey 0735b091ab Do not emit style escape sequences to log file
PR gdb/24502 requests that the "set logging" log file not contain
style escape sequences emitted by gdb.

This seemed like a reasonable request to me, so this patch implements
filtering for the log file.

This also updates a comment in ui-style.h that I noticed while writing
the patch.

Tested on x86-64 Fedora 29.

gdb/ChangeLog
2019-06-14  Tom Tromey  <tromey@adacore.com>

	PR gdb/24502:
	* ui-style.h (skip_ansi_escape): Update comment.
	* ui-file.h (class no_terminal_escape_file): New class.
	* ui-file.c (no_terminal_escape_file::write)
	(no_terminal_escape_file::puts): New methods.
	* cli/cli-logging.c (handle_redirections): Use
	no_terminal_escape_file.

gdb/testsuite/ChangeLog
2019-06-14  Tom Tromey  <tromey@adacore.com>

	PR gdb/24502:
	* gdb.base/style-logging.exp: New file.
2019-06-14 14:13:29 -06:00
Pedro Alves 55c10aca2e Improve/fix the TUI's current source line highlight
With styling enabled, I think the way we display the TUI's
highlighted/current line is very ugly and distracting.  The problem in
my view is that we reverse foreground/background in colored text as
well, leading to rainbow of background colors.

This patch changes that to something that I find much more sensible --
only reverse the default foreground/background colors, leave styled
text colors alone.  If the foreground color is not the default
(because the text was styled), leave the foreground color as is.  If
e.g., the terminal is fg=BLACK, and bg=WHITE, and the style wants to
print text in RED, reverse the background color (print in BLACK), but
still print the text in RED.

Note: The new ui_file_style::set_fg method isn't called set_foreground
instead, because set_foreground is a macro in /usr/lib/term.h (ncurses).

gdb/ChangeLog:
2019-03-18  Pedro Alves  <palves@redhat.com>

	* tui/tui-io.c (reverse_mode_p, reverse_save_bg, reverse_save_fg):
	New globals.
	(apply_style): New, factored out from ...
	(apply_ansi_escape): ... this.  Handle reverse video mode.
	(tui_set_reverse_mode): New function.
	* tui/tui-io.h (tui_set_reverse_mode): New declaration.
	* tui/tui-winsource.c (tui_show_source_line): Use
	tui_set_reverse_mode instead of setting A_STANDOUT.
	* ui-style.h (struct ui_file_style) <set_reverse, set_fg, set_bg>:
	New setter methods.
2019-03-18 14:26:00 +00:00
Tom Tromey a008792038 Fix pager bugs with style output
I believe this fixes all the pager output problems with styling that
Philippe pointed out, plus at least one more.  The patch is somewhat
hard to reason about, so you may wish to give it a try.  Even writing
the tests was hard.

This removes the style caching, because it was difficult to keep the
style cache correct in all cases.  Since this would cause more style
escapes to be emitted, instead it changes fputs_styled to try to avoid
unnecessary changes.

Another bug was that the wrap buffer was not flushed in the case where
wrap_column==0.  In the old (pre-patch series) code, characters were
directly emitted in this case; so flushing the wrap buffer here
restores this behavior.

On error the wrap buffer must be emptied.  Otherwise, interrupting
output can leave characters in the buffer that will be emitted later.

As discussed on gdb-patches, this fixes the ada-lang.c problem where
filtered and unfiltered printing were mixed.  Now user_select_syms
uses filtered printing, which is what its callees were already doing.

Finally, it was possible for source line highlighting to be garbled
(and invalid escape sequences emitted) if the pager was invoked at the
wrong spot.  To fix this, the patch arranges for source line escapes
to always be emitted as a unit.

gdb/ChangeLog
2019-02-17  Tom Tromey  <tom@tromey.com>

	* ada-lang.c (user_select_syms): Use filtered printing.
	* utils.c (wrap_style): New global.
	(desired_style): Remove.
	(emit_style_escape): Add stream parameter.
	(set_output_style, reset_terminal_style, prompt_for_continue):
	Update.
	(flush_wrap_buffer): Only flush gdb_stdout.
	(wrap_here): Set wrap_style.
	(fputs_maybe_filtered): Clear the wrap buffer on exception.  Don't
	treat escape sequences as a character.  Change when wrap buffer is
	flushed.
	(fputs_styled): Do not set the output style when the default is
	requested.
	* ui-style.h (struct ui_file_style) <is_default>: New method.
	* source.c (print_source_lines_base): Emit escape sequences in one
	piece.

gdb/testsuite/ChangeLog
2019-02-17  Tom Tromey  <tom@tromey.com>

	* gdb.base/style.exp: Add line-wrapping tests.
	* gdb.base/page.exp: Add test for quitting during pagination.
2019-02-17 08:35:14 -07:00
Joel Brobecker 42a4f53d2b Update copyright year range in all GDB files.
This commit applies all changes made after running the gdb/copyright.py
script.

Note that one file was flagged by the script, due to an invalid
copyright header
(gdb/unittests/basic_string_view/element_access/char/empty.cc).
As the file was copied from GCC's libstdc++-v3 testsuite, this commit
leaves this file untouched for the time being; a patch to fix the header
was sent to gcc-patches first.

gdb/ChangeLog:

	Update copyright year range in all GDB files.
2019-01-01 10:01:51 +04:00
Tom Tromey eedeedd2a5 Introduce ui_file_style
This introduces the new ui_file_style class and various helpers.  This
class represents a terminal style and provides methods for parsing and
emitting the corresponding ANSI terminal escape sequences.

gdb/ChangeLog
2018-12-28  Tom Tromey  <tom@tromey.com>

	* unittests/style-selftests.c: New file.
	* ui-style.c: New file.
	* ui-style.h: New file.
	* ui-file.h: Include ui-style.h.
	* Makefile.in (COMMON_SFILES): Add ui-style.c.
	(HFILES_NO_SRCDIR): Add ui-style.h.
	(SUBDIR_UNITTESTS_SRCS): Add style-selftests.c.
2018-12-28 12:49:48 -07:00