aboutsummaryrefslogtreecommitdiff
path: root/gdb/mi
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-09-03 22:56:33 -0600
committerTom Tromey <tom@tromey.com>2018-12-28 12:49:49 -0700
commitcbe5657196d0d3acbeca39973f93f333ecedacda (patch)
tree4d7545de22d1941cb820ae9e078e8be7f78b96b6 /gdb/mi
parent9162a27c5f5828240b53379d735679e2a69a9f41 (diff)
downloadgdb-cbe5657196d0d3acbeca39973f93f333ecedacda.zip
gdb-cbe5657196d0d3acbeca39973f93f333ecedacda.tar.gz
gdb-cbe5657196d0d3acbeca39973f93f333ecedacda.tar.bz2
Add output styles to gdb
This adds some output styling to the CLI. A style is currently a foreground color, a background color, and an intensity (dim or bold). (This list could be expanded depending on terminal capabilities.) A style can be applied while printing. For ui-out, this is done by passing the style constant as an argument. For low-level cases, fprintf_styled and fputs_styled are provided. Users can control the style via a number of new set/show commands. In the interest of not typing many nearly-identical documentation strings, I automated this. On the down side, this is not very i18n-friendly. I've chose some default colors to use. I think it would be good to enable this by default, so that when users start the new gdb, they will see the new feature. Stylizing is done if TERM is set and is not "dumb". This could be improved when the TUI is available by using the curses has_colors call. That is, the lowest layer could call this without committing to using curses everywhere; see my other patch for TUI colorizing. I considered adding a new "set_style" method to ui_file. However, because the implementation had to interact with the pager code, I didn't take this approach. But, one idea might be to put the isatty check there and then have it defer to the lower layers. gdb/ChangeLog 2018-12-28 Tom Tromey <tom@tromey.com> * utils.h (set_output_style, fprintf_styled) (fputs_styled): Declare. * utils.c (applied_style, desired_style): New globals. (emit_style_escape, set_output_style): New function. (prompt_for_continue): Emit style escapes. (fputs_maybe_filtered): Likewise. (fputs_styled, fprintf_styled): New functions. * ui-out.h (enum class ui_out_style_kind): New. (class ui_out) <field_string, field_stream, do_field_string>: Add style parameter. * ui-out.c (ui_out::field_stream, ui_out::field_string): Add style parameter. * tui/tui-out.h (class tui_ui_out) <do_field_string>: Add style parameter. * tui/tui-out.c (tui_ui_out::do_field_string): Add style parameter. (tui_ui_out::do_field_string): Update. * tracepoint.c (print_one_static_tracepoint_marker): Style output. * stack.c (print_frame_info, print_frame): Style output. * source.c (print_source_lines_base): Style output. * skip.c (info_skip_command): Style output. * record-btrace.c (btrace_call_history_src_line): Style output. (btrace_call_history): Likewise. * python/py-framefilter.c (py_print_frame): Style output. * mi/mi-out.h (class mi_ui_out) <do_field_string>: Add style parameter. * mi/mi-out.c (mi_ui_out::do_table_header) (mi_ui_out::do_field_int): Update. (mi_ui_out::do_field_string): Update. * disasm.c (gdb_pretty_print_disassembler::pretty_print_insn): Style output. * cli/cli-style.h: New file. * cli/cli-style.c: New file. * cli-out.h (class cli_ui_out) <do_field_string>: Add style parameter. * cli-out.c (cli_ui_out::do_table_header) (cli_ui_out::do_field_int, cli_ui_out::do_field_skip): Update. (cli_ui_out::do_field_string): Add style parameter. Style the output. * breakpoint.c (print_breakpoint_location): Style output. (update_static_tracepoint): Likewise. * Makefile.in (SUBDIR_CLI_SRCS): Add cli-style.c. (HFILES_NO_SRCDIR): Add cli-style.h. gdb/testsuite/ChangeLog 2018-12-28 Tom Tromey <tom@tromey.com> * gdb.base/style.exp: New file. * gdb.base/style.c: New file.
Diffstat (limited to 'gdb/mi')
-rw-r--r--gdb/mi/mi-out.c12
-rw-r--r--gdb/mi/mi-out.h3
2 files changed, 10 insertions, 5 deletions
diff --git a/gdb/mi/mi-out.c b/gdb/mi/mi-out.c
index 39b18b0..4aa4a5c 100644
--- a/gdb/mi/mi-out.c
+++ b/gdb/mi/mi-out.c
@@ -65,8 +65,10 @@ mi_ui_out::do_table_header (int width, ui_align alignment,
open (NULL, ui_out_type_tuple);
do_field_int (0, 0, ui_center, "width", width);
do_field_int (0, 0, ui_center, "alignment", alignment);
- do_field_string (0, 0, ui_center, "col_name", col_name.c_str ());
- do_field_string (0, width, alignment, "colhdr", col_hdr.c_str ());
+ do_field_string (0, 0, ui_center, "col_name", col_name.c_str (),
+ ui_out_style_kind::DEFAULT);
+ do_field_string (0, width, alignment, "colhdr", col_hdr.c_str (),
+ ui_out_style_kind::DEFAULT);
close (ui_out_type_tuple);
}
@@ -95,7 +97,8 @@ mi_ui_out::do_field_int (int fldno, int width, ui_align alignment,
char buffer[20]; /* FIXME: how many chars long a %d can become? */
xsnprintf (buffer, sizeof (buffer), "%d", value);
- do_field_string (fldno, width, alignment, fldname, buffer);
+ do_field_string (fldno, width, alignment, fldname, buffer,
+ ui_out_style_kind::DEFAULT);
}
/* Used to omit a field. */
@@ -111,7 +114,8 @@ mi_ui_out::do_field_skip (int fldno, int width, ui_align alignment,
void
mi_ui_out::do_field_string (int fldno, int width, ui_align align,
- const char *fldname, const char *string)
+ const char *fldname, const char *string,
+ ui_out_style_kind style)
{
ui_file *stream = m_streams.back ();
field_separator ();
diff --git a/gdb/mi/mi-out.h b/gdb/mi/mi-out.h
index 89ff88c..b576263 100644
--- a/gdb/mi/mi-out.h
+++ b/gdb/mi/mi-out.h
@@ -57,7 +57,8 @@ protected:
virtual void do_field_skip (int fldno, int width, ui_align align,
const char *fldname) override;
virtual void do_field_string (int fldno, int width, ui_align align,
- const char *fldname, const char *string) override;
+ const char *fldname, const char *string,
+ ui_out_style_kind style) override;
virtual void do_field_fmt (int fldno, int width, ui_align align,
const char *fldname, const char *format, va_list args)
override ATTRIBUTE_PRINTF (6,0);