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/ui-file.h | |
parent | 136afab8c7d8a8a91dbf38e79be4f9dc4125d552 (diff) | |
download | gdb-8a522c6cab56bd55f1454638786f999f6f636354.zip gdb-8a522c6cab56bd55f1454638786f999f6f636354.tar.gz gdb-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/ui-file.h')
-rw-r--r-- | gdb/ui-file.h | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/gdb/ui-file.h b/gdb/ui-file.h index 6e6ca1c..56f0c0f 100644 --- a/gdb/ui-file.h +++ b/gdb/ui-file.h @@ -70,6 +70,17 @@ public: virtual bool isatty () { return false; } + /* true indicates terminal output behaviour such as cli_styling. + This default implementation indicates to do terminal output + behaviour if the UI_FILE is a tty. A derived class can override + TERM_OUT to have cli_styling behaviour without being a tty. */ + virtual bool term_out () + { return isatty (); } + + /* true if ANSI escapes can be used on STREAM. */ + virtual bool can_emit_style_escape () + { return false; } + virtual void flush () {} }; @@ -109,7 +120,13 @@ extern int gdb_console_fputs (const char *, FILE *); class string_file : public ui_file { public: - string_file () {} + /* Construct a string_file to collect 'raw' output, i.e. without + 'terminal' behaviour such as cli_styling. */ + string_file () : m_term_out (false) {}; + /* If TERM_OUT, construct a string_file with terminal output behaviour + such as cli_styling) + else collect 'raw' output like the previous constructor. */ + explicit string_file (bool term_out) : m_term_out (term_out) {}; ~string_file () override; /* Override ui_file methods. */ @@ -119,6 +136,9 @@ public: long read (char *buf, long length_buf) override { gdb_assert_not_reached ("a string_file is not readable"); } + bool term_out () override; + bool can_emit_style_escape () override; + /* string_file-specific public API. */ /* Accesses the std::string containing the entire output collected @@ -145,6 +165,8 @@ public: private: /* The internal buffer. */ std::string m_string; + + bool m_term_out; }; /* A ui_file implementation that maps directly onto <stdio.h>'s FILE. @@ -183,6 +205,8 @@ public: bool isatty () override; + bool can_emit_style_escape () override; + private: /* Sets the internal stream to FILE, and saves the FILE's file descriptor in M_FD. */ @@ -255,6 +279,8 @@ public: void puts (const char *) override; bool isatty () override; + bool term_out () override; + bool can_emit_style_escape () override; void flush () override; private: |