diff options
author | Philippe Waroquiers <philippe.waroquiers@skynet.be> | 2019-03-09 23:55:44 +0100 |
---|---|---|
committer | Philippe Waroquiers <philippe.waroquiers@skynet.be> | 2019-04-27 14:25:28 +0200 |
commit | 8a522c6cab56bd55f1454638786f999f6f636354 (patch) | |
tree | a73bb0f05e55c318a7026e0aee00c74853f410d9 /gdb/utils.c | |
parent | 136afab8c7d8a8a91dbf38e79be4f9dc4125d552 (diff) | |
download | binutils-8a522c6cab56bd55f1454638786f999f6f636354.zip binutils-8a522c6cab56bd55f1454638786f999f6f636354.tar.gz binutils-8a522c6cab56bd55f1454638786f999f6f636354.tar.bz2 |
Have 'thread|frame apply' style their output.
'thread|frame apply CMD' launches CMD so that CMD output goes to a string_file.
This patch ensures that string_file for such CMD output contains
style escape sequences that 'thread|frame apply' will later on
output on the real terminal, so as to have CMD output properly styled.
The idea is to have the class ui_file having overridable methods
to indicate that the output to this ui_file should be done using
'terminal' behaviour such as styling.
Then these methods are overriden in string_file so that a specially
constructed string_file will get output with style escape sequences.
After this patch, the output of CMD by thread|frame apply CMD is styled
similarly as when CMD is launched directly.
Note that string_file (term_out true) could also support wrapping,
but this is not done (yet?).
Tested on debian/amd64.
gdb/ChangeLog
2019-04-27 Philippe Waroquiers <philippe.waroquiers@skynet.be>
Support style in 'frame|thread apply'
* gdbcmd.h (execute_command_to_string): New term_out parameter.
* record.c (record_start, record_stop): Update callers of
execute_command_to_string with false.
* ui-file.h (class ui_file): New term_out and can_emit_style_escape
methods.
(class string_file): New constructor with term_out parameter.
Override methods term_out and can_emit_style_escape. New member
term_out.
(class stdio_file): Override can_emit_style_escape.
(class tee_file): Override term_out and can_emit_style_escape.
* utils.h (can_emit_style_escape): Remove.
* utils.c (can_emit_style_escape): Likewise.
Update all callers of can_emit_style_escape (SOMESTREAM) to
SOMESTREAM->can_emit_style_escape.
* source-cache.c (source_cache::get_source_lines): Likewise.
* stack.c (frame_apply_command_count): Call execute_command_to_string
passing the term_out characteristic of the current gdb_stdout.
* thread.c (thr_try_catch_cmd): Likewise.
* top.c (execute_command_to_string): pass term_out parameter
to construct the string_file for the command output.
* ui-file.c (term_cli_styling): New function (most code moved
from utils.c can_emit_style_escape).
(string_file::string_file, string_file::can_emit_style_escape,
stdio_file::can_emit_style_escape, tee_file::term_out,
tee_file::can_emit_style_escape): New functions.
Diffstat (limited to 'gdb/utils.c')
-rw-r--r-- | gdb/utils.c | 35 |
1 files changed, 5 insertions, 30 deletions
diff --git a/gdb/utils.c b/gdb/utils.c index fa7a267..fd4427d 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -1435,38 +1435,13 @@ emit_style_escape (const ui_file_style &style, fputs_unfiltered (style.to_ansi ().c_str (), stream); } -/* See utils.h. */ - -bool -can_emit_style_escape (struct ui_file *stream) -{ - if (stream != gdb_stdout - || !cli_styling - || !ui_file_isatty (stream)) - return false; - const char *term = getenv ("TERM"); - /* Windows doesn't by default define $TERM, but can support styles - regardless. */ -#ifndef _WIN32 - if (term == nullptr || !strcmp (term, "dumb")) - return false; -#else - /* But if they do define $TERM, let us behave the same as on Posix - platforms, for the benefit of programs which invoke GDB as their - back-end. */ - if (term && !strcmp (term, "dumb")) - return false; -#endif - return true; -} - /* Set the current output style. This will affect future uses of the _filtered output functions. */ static void set_output_style (struct ui_file *stream, const ui_file_style &style) { - if (!can_emit_style_escape (stream)) + if (!stream->can_emit_style_escape ()) return; /* Note that we don't pass STREAM here, because we want to emit to @@ -1479,7 +1454,7 @@ set_output_style (struct ui_file *stream, const ui_file_style &style) void reset_terminal_style (struct ui_file *stream) { - if (can_emit_style_escape (stream)) + if (stream->can_emit_style_escape ()) { /* Force the setting, regardless of what we think the setting might already be. */ @@ -1504,7 +1479,7 @@ prompt_for_continue (void) bool disable_pagination = pagination_disabled_for_command; /* Clear the current styling. */ - if (can_emit_style_escape (gdb_stdout)) + if (gdb_stdout->can_emit_style_escape ()) emit_style_escape (ui_file_style (), gdb_stdout); if (annotation_level > 1) @@ -1801,7 +1776,7 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream, lines_printed++; if (wrap_column) { - if (can_emit_style_escape (stream)) + if (stream->can_emit_style_escape ()) emit_style_escape (ui_file_style (), stream); /* If we aren't actually wrapping, don't output newline -- if chars_per_line is right, we @@ -1823,7 +1798,7 @@ fputs_maybe_filtered (const char *linebuffer, struct ui_file *stream, if (wrap_column) { fputs_unfiltered (wrap_indent, stream); - if (can_emit_style_escape (stream)) + if (stream->can_emit_style_escape ()) emit_style_escape (wrap_style, stream); /* FIXME, this strlen is what prevents wrap_indent from containing tabs. However, if we recurse to print it |