* [PATCH 6/8] Introduce metadata style
2019-09-27 21:25 [PATCH 0/8] More gdb styling improvements Tom Tromey
@ 2019-09-27 21:25 ` Tom Tromey
2019-09-30 14:07 ` Pedro Alves
2019-09-27 21:25 ` [PATCH 1/8] Remove the ui_out_style_kind enum Tom Tromey
` (7 subsequent siblings)
8 siblings, 1 reply; 16+ messages in thread
From: Tom Tromey @ 2019-09-27 21:25 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This introduces a new "metadata" style and changes many places in gdb
to use it. The idea here is to let the user distinguish gdb output
from output that (conceptually at least) comes directly from the
inferior. The newly-styled category includes text that gdb
traditionally surrounds in "<...>", like "<unavailable>".
I only added a single test for this. In many cases this output is
difficult to test. Also, while developing this errors in the
implementation of the new printf formats showed up as regressions.
gdb/ChangeLog
2019-09-27 Tom Tromey <tom@tromey.com>
* p-lang.c (pascal_printstr): Use metadata style.
* value.c (show_convenience): Use metadata style.
* valprint.c (valprint_check_validity, val_print_optimized_out)
(val_print_not_saved, val_print_unavailable)
(val_print_invalid_address, generic_val_print, val_print)
(value_check_printable, val_print_array_elements): Use metadata
style.
* ui-out.h (class ui_out) <field_fmt>: New overload.
<do_field_fmt>: Add style parameter.
* ui-out.c (ui_out::field_fmt): New overload.
* typeprint.c (type_print_unknown_return_type)
(val_print_not_allocated, val_print_not_associated): Use metadata
style.
* tui/tui-out.h (class tui_ui_out) <do_field_fmt>: Add style
parameter.
* tui/tui-out.c (tui_ui_out::do_field_fmt): Update.
* tracepoint.c (tvariables_info_1): Use metadata style.
* stack.c (print_frame_arg, print_frame_info, print_frame)
(info_frame_command_core): Use metadata style.
* skip.c (info_skip_command): Use metadata style.
* rust-lang.c (rust_print_enum): Use metadata style.
* python/py-prettyprint.c (print_stack_unless_memory_error): Use
metadata style.
* python/py-framefilter.c (py_print_single_arg): Use metadata
style.
* printcmd.c (do_one_display, print_variable_and_value): Use
metadata style.
* p-valprint.c (pascal_val_print)
(pascal_object_print_value_fields): Use metadata style.
* p-typeprint.c (pascal_type_print_base): Use metadata style.
* mi/mi-out.h (class mi_ui_out) <do_field_fmt>: Add style
parameter.
* mi/mi-out.c (mi_ui_out::do_field_fmt): Update.
* m2-valprint.c (m2_print_long_set): Use metadata style.
* m2-typeprint.c (m2_print_type): Use metadata style.
* infcmd.c (print_return_value_1): Use metadata style.
* gnu-v3-abi.c (print_one_vtable): Use metadata style.
* f-valprint.c (info_common_command_for_block): Use metadata
style.
* f-typeprint.c (f_type_print_base): Use metadata style.
* expprint.c (print_subexp_standard): Use metadata style.
* cp-valprint.c (cp_print_value_fields): Use metadata style.
* cli/cli-style.h (class cli_style_option): Add constructor.
(metadata_style): Declare.
* cli/cli-style.c (metadata_style): New global.
(_initialize_cli_style): Register metadata style.
* cli-out.h (class cli_ui_out) <do_field_fmt>: Add style
parameter.
* cli-out.c (cli_ui_out::do_field_fmt): Update.
* c-typeprint.c (c_type_print_base_struct_union)
(c_type_print_base_1): Use metadata style.
* breakpoint.c (watchpoint_value_print)
(print_one_breakpoint_location): Use metadata style.
* break-catch-syscall.c (print_one_catch_syscall): Use metadata
style.
* break-catch-sig.c (signal_catchpoint_print_one): Use metadata
style.
* ada-valprint.c (val_print_packed_array_elements, printstr)
(print_field_values, ada_val_print_ref, ada_val_print): Use
metadata style.
* ada-typeprint.c (print_array_type, ada_print_type): Use metadata
style.
* ada-tasks.c (print_ada_task_info, info_task): Use metadata
style.
* ada-lang.c (user_select_syms): Use metadata style.
gdb/testsuite/ChangeLog
2019-09-27 Tom Tromey <tom@tromey.com>
* lib/gdb-utils.exp (style): Handle "metadata" argument.
* gdb.base/style.exp: Add metadata style test.
---
gdb/ChangeLog | 68 ++++++++++++++++++++++++++++++++
gdb/ada-lang.c | 5 ++-
gdb/ada-tasks.c | 14 +++++--
gdb/ada-typeprint.c | 15 ++++---
gdb/ada-valprint.c | 18 ++++++---
gdb/break-catch-sig.c | 4 +-
gdb/break-catch-syscall.c | 3 +-
gdb/breakpoint.c | 8 ++--
gdb/c-typeprint.c | 32 +++++++++------
gdb/cli-out.c | 7 ++--
gdb/cli-out.h | 6 +--
gdb/cli/cli-style.c | 11 ++++++
gdb/cli/cli-style.h | 5 +++
gdb/cp-valprint.c | 19 +++++----
gdb/expprint.c | 6 ++-
gdb/f-typeprint.c | 3 +-
gdb/f-valprint.c | 6 ++-
gdb/gnu-v3-abi.c | 4 +-
gdb/infcmd.c | 4 +-
gdb/m2-typeprint.c | 3 +-
gdb/m2-valprint.c | 10 +++--
gdb/mi/mi-out.c | 4 +-
gdb/mi/mi-out.h | 5 ++-
gdb/p-lang.c | 5 ++-
gdb/p-typeprint.c | 8 ++--
gdb/p-valprint.c | 16 +++++---
gdb/printcmd.c | 13 +++---
gdb/python/py-framefilter.c | 2 +-
gdb/python/py-prettyprint.c | 8 ++--
gdb/rust-lang.c | 5 ++-
gdb/skip.c | 8 +++-
gdb/stack.c | 24 ++++++-----
gdb/testsuite/ChangeLog | 5 +++
gdb/testsuite/gdb.base/style.exp | 4 ++
gdb/testsuite/lib/gdb-utils.exp | 1 +
gdb/tracepoint.c | 17 +++++---
gdb/tui/tui-out.c | 6 +--
gdb/tui/tui-out.h | 5 ++-
gdb/typeprint.c | 8 ++--
gdb/ui-out.c | 20 +++++++++-
gdb/ui-out.h | 9 +++--
gdb/valprint.c | 30 ++++++++------
gdb/value.c | 4 +-
43 files changed, 331 insertions(+), 127 deletions(-)
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 063b98bde5b..846c9b4dec5 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -54,6 +54,7 @@
#include "gdbsupport/gdb_vecs.h"
#include "typeprint.h"
#include "namespace.h"
+#include "cli/cli-style.h"
#include "psymtab.h"
#include "value.h"
@@ -3877,8 +3878,8 @@ See set/show multiple-symbol."));
ada_print_symbol_signature (gdb_stdout, syms[i].symbol,
&type_print_raw_options);
if (sal.symtab == NULL)
- printf_filtered (_(" at <no source file available>:%d\n"),
- sal.line);
+ printf_filtered (_(" at %p[<no source file available>%p]:%d\n"),
+ metadata_style.style ().ptr (), nullptr, sal.line);
else
printf_filtered (_(" at %s:%d\n"),
symtab_to_filename_for_display (sal.symtab),
diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c
index 24ceab1fcab..e4a52976dcb 100644
--- a/gdb/ada-tasks.c
+++ b/gdb/ada-tasks.c
@@ -25,6 +25,7 @@
#include "gdbthread.h"
#include "progspace.h"
#include "objfiles.h"
+#include "cli/cli-style.h"
static int ada_build_task_list ();
@@ -1163,9 +1164,14 @@ print_ada_task_info (struct ui_out *uiout,
/* Finally, print the task name, without quotes around it, as mi like
is not expecting quotes, and in non mi-like no need for quotes
as there is a specific column for the name. */
- uiout->field_string ("name",
- task_info->name[0] != '\0' ? task_info->name
- : _("<no name>"));
+ uiout->field_fmt ("name",
+ (task_info->name[0] != '\0'
+ ? ui_file_style ()
+ : metadata_style.style ()),
+ "%s",
+ (task_info->name[0] != '\0'
+ ? task_info->name
+ : _("<no name>")));
uiout->text ("\n");
}
@@ -1201,7 +1207,7 @@ info_task (struct ui_out *uiout, const char *taskno_str, struct inferior *inf)
if (task_info->name[0] != '\0')
printf_filtered (_("Name: %s\n"), task_info->name);
else
- printf_filtered (_("<no name>\n"));
+ fprintf_styled (gdb_stdout, metadata_style.style (), _("<no name>\n"));
/* Print the TID and LWP. */
printf_filtered (_("Thread: %#lx\n"), task_info->ptid.tid ());
diff --git a/gdb/ada-typeprint.c b/gdb/ada-typeprint.c
index 89a69e9bd44..c2461660ad4 100644
--- a/gdb/ada-typeprint.c
+++ b/gdb/ada-typeprint.c
@@ -393,7 +393,8 @@ print_array_type (struct type *type, struct ui_file *stream, int show,
if (type == NULL)
{
- fprintf_filtered (stream, _("<undecipherable array type>"));
+ fprintf_styled (stream, metadata_style.style (),
+ _("<undecipherable array type>"));
return;
}
@@ -838,7 +839,7 @@ ada_print_type (struct type *type0, const char *varstring,
if (is_var_decl)
fprintf_filtered (stream, "%.*s: ",
ada_name_prefix_len (varstring), varstring);
- fprintf_filtered (stream, "<null type?>");
+ fprintf_styled (stream, metadata_style.style (), "<null type?>");
return;
}
@@ -894,8 +895,9 @@ ada_print_type (struct type *type0, const char *varstring,
const char *name = ada_type_name (type);
if (!ada_is_range_type_name (name))
- fprintf_filtered (stream, _("<%s-byte integer>"),
- pulongest (TYPE_LENGTH (type)));
+ fprintf_styled (stream, metadata_style.style (),
+ _("<%s-byte integer>"),
+ pulongest (TYPE_LENGTH (type)));
else
{
fprintf_filtered (stream, "range ");
@@ -916,8 +918,9 @@ ada_print_type (struct type *type0, const char *varstring,
}
break;
case TYPE_CODE_FLT:
- fprintf_filtered (stream, _("<%s-byte float>"),
- pulongest (TYPE_LENGTH (type)));
+ fprintf_styled (stream, metadata_style.style (),
+ _("<%s-byte float>"),
+ pulongest (TYPE_LENGTH (type)));
break;
case TYPE_CODE_ENUM:
if (show < 0)
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index 3060eb676b6..714b6259ec0 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -32,6 +32,7 @@
#include "infcall.h"
#include "objfiles.h"
#include "target-float.h"
+#include "cli/cli-style.h"
static int print_field_values (struct type *, const gdb_byte *,
int,
@@ -237,7 +238,8 @@ val_print_packed_array_elements (struct type *type, const gdb_byte *valaddr,
value_embedded_offset (v0), 0, stream,
recurse + 1, v0, &opts, current_language);
annotate_elt_rep (i - i0);
- fprintf_filtered (stream, _(" <repeats %u times>"), i - i0);
+ fprintf_filtered (stream, _(" %p[<repeats %u times>%p]"),
+ metadata_style.style ().ptr (), i - i0, nullptr);
annotate_elt_rep_end ();
}
@@ -527,7 +529,8 @@ printstr (struct ui_file *stream, struct type *elttype, const gdb_byte *string,
ada_emit_char (char_at (string, i, type_len, byte_order),
elttype, stream, '\'', type_len);
fputs_filtered ("'", stream);
- fprintf_filtered (stream, _(" <repeats %u times>"), reps);
+ fprintf_filtered (stream, _(" %p[<repeats %u times>%p]"),
+ metadata_style.style ().ptr (), reps, nullptr);
i = rep1 - 1;
things_printed += options->repeat_count_threshold;
need_comma = 1;
@@ -671,7 +674,8 @@ print_field_values (struct type *type, const gdb_byte *valaddr,
order problems. */
if (HAVE_CPLUS_STRUCT (type) && TYPE_FIELD_IGNORE (type, i))
{
- fputs_filtered (_("<optimized out or zero length>"), stream);
+ fputs_styled (_("<optimized out or zero length>"),
+ metadata_style.style (), stream);
}
else
{
@@ -1069,7 +1073,8 @@ ada_val_print_ref (struct type *type, const gdb_byte *valaddr,
if (TYPE_CODE (elttype) == TYPE_CODE_UNDEF)
{
- fputs_filtered ("<ref to undefined type>", stream);
+ fputs_styled ("<ref to undefined type>", metadata_style.style (),
+ stream);
return;
}
@@ -1212,8 +1217,9 @@ ada_val_print (struct type *type,
}
catch (const gdb_exception_error &except)
{
- fprintf_filtered (stream, _("<error reading variable: %s>"),
- except.what ());
+ fprintf_styled (stream, metadata_style.style (),
+ _("<error reading variable: %s>"),
+ except.what ());
}
}
diff --git a/gdb/break-catch-sig.c b/gdb/break-catch-sig.c
index 53540ee8320..c475e8aca57 100644
--- a/gdb/break-catch-sig.c
+++ b/gdb/break-catch-sig.c
@@ -28,6 +28,7 @@
#include "valprint.h"
#include "cli/cli-utils.h"
#include "completer.h"
+#include "cli/cli-style.h"
#include <string>
@@ -241,7 +242,8 @@ signal_catchpoint_print_one (struct breakpoint *b,
}
else
uiout->field_string ("what",
- c->catch_all ? "<any signal>" : "<standard signals>");
+ c->catch_all ? "<any signal>" : "<standard signals>",
+ metadata_style.style ());
uiout->text ("\" ");
if (uiout->is_mi_like_p ())
diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c
index a165be62be1..dde80b54a2f 100644
--- a/gdb/break-catch-syscall.c
+++ b/gdb/break-catch-syscall.c
@@ -29,6 +29,7 @@
#include "arch-utils.h"
#include "observable.h"
#include "xml-syscall.h"
+#include "cli/cli-style.h"
/* An instance of this type is used to represent a syscall catchpoint.
A breakpoint is really of this type iff its ops pointer points to
@@ -273,7 +274,7 @@ print_one_catch_syscall (struct breakpoint *b,
xfree (text);
}
else
- uiout->field_string ("what", "<any syscall>");
+ uiout->field_string ("what", "<any syscall>", metadata_style.style ());
uiout->text ("\" ");
if (uiout->is_mi_like_p ())
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 2030687728c..0a705163386 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -4457,7 +4457,7 @@ static void
watchpoint_value_print (struct value *val, struct ui_file *stream)
{
if (val == NULL)
- fprintf_unfiltered (stream, _("<unreadable>"));
+ fprintf_styled (stream, metadata_style.style (), _("<unreadable>"));
else
{
struct value_print_options opts;
@@ -6055,9 +6055,11 @@ print_one_breakpoint_location (struct breakpoint *b,
{
annotate_field (4);
if (header_of_multiple)
- uiout->field_string ("addr", "<MULTIPLE>");
+ uiout->field_string ("addr", "<MULTIPLE>",
+ metadata_style.style ());
else if (b->loc == NULL || loc->shlib_disabled)
- uiout->field_string ("addr", "<PENDING>");
+ uiout->field_string ("addr", "<PENDING>",
+ metadata_style.style ());
else
uiout->field_core_addr ("addr",
loc->gdbarch, loc->address);
diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index 43ad3b3e0e6..1a37c4edfb8 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -1116,10 +1116,12 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
{
if (TYPE_STUB (type))
fprintfi_filtered (level + 4, stream,
- _("<incomplete type>\n"));
+ _("%p[<incomplete type>%p]\n"),
+ metadata_style.style ().ptr (), nullptr);
else
fprintfi_filtered (level + 4, stream,
- _("<no data fields>\n"));
+ _("%p[<no data fields>%p]\n"),
+ metadata_style.style ().ptr (), nullptr);
}
/* Start off with no specific section type, so we can print
@@ -1277,7 +1279,8 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
{
/* Keep GDB from crashing here. */
fprintf_filtered (stream,
- _("<undefined type> %s;\n"),
+ _("%p[<undefined type>%p] %s;\n"),
+ metadata_style.style ().ptr (), nullptr,
TYPE_FN_FIELD_PHYSNAME (f, j));
break;
}
@@ -1325,9 +1328,9 @@ c_type_print_base_struct_union (struct type *type, struct ui_file *stream,
&local_flags);
}
else
- fprintf_filtered (stream,
- _("<badly mangled name '%s'>"),
- mangled_name);
+ fprintf_styled (stream, metadata_style.style (),
+ _("<badly mangled name '%s'>"),
+ mangled_name);
}
else
{
@@ -1465,7 +1468,7 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
if (type == NULL)
{
- fputs_filtered (_("<type unknown>"), stream);
+ fputs_styled (_("<type unknown>"), metadata_style.style (), stream);
return;
}
@@ -1511,7 +1514,8 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
couldn't resolve TYPE_TARGET_TYPE. Not much we can do. */
gdb_assert (TYPE_NAME (type) == NULL);
gdb_assert (TYPE_TARGET_TYPE (type) == NULL);
- fprintf_filtered (stream, _("<unnamed typedef>"));
+ fprintf_styled (stream, metadata_style.style (),
+ _("<unnamed typedef>"));
break;
case TYPE_CODE_FUNC:
@@ -1622,10 +1626,12 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
{
if (TYPE_STUB (type))
fprintfi_filtered (level + 4, stream,
- _("<incomplete type>\n"));
+ _("%p[<incomplete type>%p]\n"),
+ metadata_style.style ().ptr (), nullptr);
else
fprintfi_filtered (level + 4, stream,
- _("<no data fields>\n"));
+ _("%p[<no data fields>%p]\n"),
+ metadata_style.style ().ptr (), nullptr);
}
len = TYPE_NFIELDS (type);
for (i = 0; i < len; i++)
@@ -1668,7 +1674,7 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
case TYPE_CODE_RANGE:
/* This should not occur. */
- fprintf_filtered (stream, _("<range type>"));
+ fprintf_styled (stream, metadata_style.style (), _("<range type>"));
break;
case TYPE_CODE_NAMESPACE:
@@ -1690,8 +1696,8 @@ c_type_print_base_1 (struct type *type, struct ui_file *stream,
{
/* At least for dump_symtab, it is important that this not
be an error (). */
- fprintf_filtered (stream, _("<invalid type code %d>"),
- TYPE_CODE (type));
+ fprintf_styled (stream, metadata_style.style (),
+ _("<invalid type code %d>"), TYPE_CODE (type));
}
break;
}
diff --git a/gdb/cli-out.c b/gdb/cli-out.c
index c713607e068..702e4e4dfe2 100644
--- a/gdb/cli-out.c
+++ b/gdb/cli-out.c
@@ -188,16 +188,15 @@ cli_ui_out::do_field_string (int fldno, int width, ui_align align,
void
cli_ui_out::do_field_fmt (int fldno, int width, ui_align align,
- const char *fldname, const char *format,
- va_list args)
+ const char *fldname, const ui_file_style &style,
+ const char *format, va_list args)
{
if (m_suppress_output)
return;
std::string str = string_vprintf (format, args);
- do_field_string (fldno, width, align, fldname, str.c_str (),
- ui_file_style ());
+ do_field_string (fldno, width, align, fldname, str.c_str (), style);
}
void
diff --git a/gdb/cli-out.h b/gdb/cli-out.h
index d7bd23b0ef2..7d5b4febba5 100644
--- a/gdb/cli-out.h
+++ b/gdb/cli-out.h
@@ -59,9 +59,9 @@ protected:
const char *string,
const ui_file_style &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);
+ const char *fldname, const ui_file_style &style,
+ const char *format, va_list args)
+ override ATTRIBUTE_PRINTF (7, 0);
virtual void do_spaces (int numspaces) override;
virtual void do_text (const char *string) override;
virtual void do_message (const ui_file_style &style,
diff --git a/gdb/cli/cli-style.c b/gdb/cli/cli-style.c
index ea301774d22..2016935f2e5 100644
--- a/gdb/cli/cli-style.c
+++ b/gdb/cli/cli-style.c
@@ -85,6 +85,10 @@ cli_style_option title_style ("title", ui_file_style::BOLD);
/* See cli-style.h. */
+cli_style_option metadata_style ("metadata", ui_file_style::DIM);
+
+/* See cli-style.h. */
+
cli_style_option::cli_style_option (const char *name,
ui_file_style::basic_color fg)
: m_name (name),
@@ -372,4 +376,11 @@ Highlight display styling.\n\
Configure highlight colors and display intensity\n\
Some commands use the highlight style to draw the attention to a part\n\
of their output."));
+
+ STYLE_ADD_SETSHOW_COMMANDS (metadata_style,
+ _("\
+Metadata display styling\n\
+Configure metadata colors and display intensity\n\
+The \"metadata\" style is used when GDB displays information about\n\
+your data, for example \"<unavailable\""));
}
diff --git a/gdb/cli/cli-style.h b/gdb/cli/cli-style.h
index 826162f5788..6716471dec3 100644
--- a/gdb/cli/cli-style.h
+++ b/gdb/cli/cli-style.h
@@ -34,6 +34,9 @@ public:
/* Construct a CLI style option with an intensity. */
cli_style_option (const char *name, ui_file_style::intensity i);
+ /* Construct a CLI style option with an intensity. */
+ cli_style_option (ui_file_style::intensity val);
+
/* Return a ui_file_style corresponding to the settings in this CLI
style. */
ui_file_style style () const;
@@ -108,6 +111,8 @@ extern cli_style_option highlight_style;
/* The title style. */
extern cli_style_option title_style;
+/* The metadata style. */
+extern cli_style_option metadata_style;
/* True if source styling is enabled. */
extern bool source_styling;
diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
index 530d8c52691..e73b0e27faf 100644
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -37,6 +37,7 @@
#include "typeprint.h"
#include "gdbsupport/byte-vector.h"
#include "gdbarch.h"
+#include "cli/cli-style.h"
static struct obstack dont_print_vb_obstack;
static struct obstack dont_print_statmem_obstack;
@@ -170,7 +171,7 @@ cp_print_value_fields (struct type *type, struct type *real_type,
/* If there are no data fields, skip this part */
if (len == n_baseclasses || !len)
- fprintf_filtered (stream, "<No data fields>");
+ fprintf_styled (stream, metadata_style.style (), "<No data fields>");
else
{
size_t statmem_obstack_initial_size = 0;
@@ -268,7 +269,8 @@ cp_print_value_fields (struct type *type, struct type *real_type,
byte order problems. */
if (TYPE_FIELD_IGNORE (type, i))
{
- fputs_filtered ("<optimized out or zero length>", stream);
+ fputs_styled ("<optimized out or zero length>",
+ metadata_style.style (), stream);
}
else if (value_bits_synthetic_pointer (val,
TYPE_FIELD_BITPOS (type,
@@ -276,7 +278,8 @@ cp_print_value_fields (struct type *type, struct type *real_type,
TYPE_FIELD_BITSIZE (type,
i)))
{
- fputs_filtered (_("<synthetic pointer>"), stream);
+ fputs_styled (_("<synthetic pointer>"),
+ metadata_style.style (), stream);
}
else
{
@@ -292,8 +295,8 @@ cp_print_value_fields (struct type *type, struct type *real_type,
{
if (TYPE_FIELD_IGNORE (type, i))
{
- fputs_filtered ("<optimized out or zero length>",
- stream);
+ fputs_styled ("<optimized out or zero length>",
+ metadata_style.style (), stream);
}
else if (field_is_static (&TYPE_FIELD (type, i)))
{
@@ -307,9 +310,9 @@ cp_print_value_fields (struct type *type, struct type *real_type,
}
catch (const gdb_exception_error &ex)
{
- fprintf_filtered (stream,
- _("<error reading variable: %s>"),
- ex.what ());
+ fprintf_styled (stream, metadata_style.style (),
+ _("<error reading variable: %s>"),
+ ex.what ());
}
}
else if (i == vptr_fieldno && type == vptr_basetype)
diff --git a/gdb/expprint.c b/gdb/expprint.c
index d7ad1a71878..c98638ab7fe 100644
--- a/gdb/expprint.c
+++ b/gdb/expprint.c
@@ -29,6 +29,7 @@
#include "block.h"
#include "objfiles.h"
#include "valprint.h"
+#include "cli/cli-style.h"
#include <ctype.h>
@@ -510,8 +511,9 @@ print_subexp_standard (struct expression *exp, int *pos,
if (exp->language_defn->la_name_of_this)
fputs_filtered (exp->language_defn->la_name_of_this, stream);
else
- fprintf_filtered (stream, _("<language %s has no 'this'>"),
- exp->language_defn->la_name);
+ fprintf_styled (stream, metadata_style.style (),
+ _("<language %s has no 'this'>"),
+ exp->language_defn->la_name);
return;
/* Modula-2 ops */
diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c
index 92b50938740..0093aebddc2 100644
--- a/gdb/f-typeprint.c
+++ b/gdb/f-typeprint.c
@@ -31,6 +31,7 @@
#include "target.h"
#include "f-lang.h"
#include "typeprint.h"
+#include "cli/cli-style.h"
#if 0 /* Currently unused. */
static void f_type_print_args (struct type *, struct ui_file *);
@@ -325,7 +326,7 @@ f_type_print_base (struct type *type, struct ui_file *stream, int show,
wrap_here (" ");
if (type == NULL)
{
- fputs_filtered ("<type unknown>", stream);
+ fputs_styled ("<type unknown>", metadata_style.style (), stream);
return;
}
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
index 264416ec540..f9d49233fca 100644
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
@@ -33,6 +33,7 @@
#include "command.h"
#include "block.h"
#include "dictionary.h"
+#include "cli/cli-style.h"
static void f77_get_dynamic_length_of_aggregate (struct type *);
@@ -415,8 +416,9 @@ info_common_command_for_block (const struct block *block, const char *comname,
catch (const gdb_exception_error &except)
{
- printf_filtered ("<error reading variable: %s>",
- except.what ());
+ fprintf_styled (gdb_stdout, metadata_style.style (),
+ "<error reading variable: %s>",
+ except.what ());
}
putchar_filtered ('\n');
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
index 6407c9beb82..1d4e43ad7f6 100644
--- a/gdb/gnu-v3-abi.c
+++ b/gdb/gnu-v3-abi.c
@@ -28,6 +28,7 @@
#include "c-lang.h"
#include "typeprint.h"
#include <algorithm>
+#include "cli/cli-style.h"
static struct cp_abi_ops gnu_v3_abi_ops;
@@ -912,7 +913,8 @@ print_one_vtable (struct gdbarch *gdbarch, struct value *value,
}
catch (const gdb_exception_error &ex)
{
- printf_filtered (_("<error: %s>"), ex.what ());
+ fprintf_styled (gdb_stdout, metadata_style.style (),
+ _("<error: %s>"), ex.what ());
got_error = 1;
}
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index dc82ef043fe..20523fed534 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -60,6 +60,7 @@
#include "interps.h"
#include "gdbsupport/gdb_optional.h"
#include "source.h"
+#include "cli/cli-style.h"
/* Local functions: */
@@ -1628,7 +1629,8 @@ print_return_value_1 (struct ui_out *uiout, struct return_value_info *rv)
uiout->field_stream ("return-value", stb);
}
else
- uiout->field_string ("return-value", _("<not displayed>"));
+ uiout->field_string ("return-value", _("<not displayed>"),
+ metadata_style.style ());
uiout->text ("\n");
}
else
diff --git a/gdb/m2-typeprint.c b/gdb/m2-typeprint.c
index dae07d1c531..3c1a8d2aed3 100644
--- a/gdb/m2-typeprint.c
+++ b/gdb/m2-typeprint.c
@@ -31,6 +31,7 @@
#include "c-lang.h"
#include "typeprint.h"
#include "cp-abi.h"
+#include "cli/cli-style.h"
static void m2_print_bounds (struct type *type,
struct ui_file *stream, int show, int level,
@@ -81,7 +82,7 @@ m2_print_type (struct type *type, const char *varstring,
wrap_here (" ");
if (type == NULL)
{
- fputs_filtered (_("<type unknown>"), stream);
+ fputs_styled (_("<type unknown>"), metadata_style.style (), stream);
return;
}
diff --git a/gdb/m2-valprint.c b/gdb/m2-valprint.c
index 74f89ee45fb..4dc0fe18e6a 100644
--- a/gdb/m2-valprint.c
+++ b/gdb/m2-valprint.c
@@ -28,6 +28,7 @@
#include "c-lang.h"
#include "m2-lang.h"
#include "target.h"
+#include "cli/cli-style.h"
static int print_unpacked_pointer (struct type *type,
CORE_ADDR address, CORE_ADDR addr,
@@ -92,7 +93,8 @@ m2_print_long_set (struct type *type, const gdb_byte *valaddr,
}
else
{
- fprintf_filtered (stream, " %s }", _("<unknown bounds of set>"));
+ fprintf_styled (stream, metadata_style.style (),
+ " %s }", _("<unknown bounds of set>"));
return;
}
@@ -407,7 +409,8 @@ m2_val_print (struct type *type, int embedded_offset,
elttype = check_typedef (elttype);
if (TYPE_STUB (elttype))
{
- fprintf_filtered (stream, _("<incomplete type>"));
+ fprintf_styled (stream, metadata_style.style (),
+ _("<incomplete type>"));
break;
}
else
@@ -423,7 +426,8 @@ m2_val_print (struct type *type, int embedded_offset,
maybe_bad_bstring:
if (i < 0)
{
- fputs_filtered (_("<error value>"), stream);
+ fputs_styled (_("<error value>"), metadata_style.style (),
+ stream);
goto done;
}
diff --git a/gdb/mi/mi-out.c b/gdb/mi/mi-out.c
index 71af4865e97..ad4252f7122 100644
--- a/gdb/mi/mi-out.c
+++ b/gdb/mi/mi-out.c
@@ -141,8 +141,8 @@ mi_ui_out::do_field_string (int fldno, int width, ui_align align,
void
mi_ui_out::do_field_fmt (int fldno, int width, ui_align align,
- const char *fldname, const char *format,
- va_list args)
+ const char *fldname, const ui_file_style &style,
+ const char *format, va_list args)
{
ui_file *stream = m_streams.back ();
field_separator ();
diff --git a/gdb/mi/mi-out.h b/gdb/mi/mi-out.h
index 9393809b5f2..c8b42c295ee 100644
--- a/gdb/mi/mi-out.h
+++ b/gdb/mi/mi-out.h
@@ -68,8 +68,9 @@ protected:
const char *fldname, const char *string,
const ui_file_style &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);
+ const char *fldname, const ui_file_style &style,
+ const char *format, va_list args)
+ override ATTRIBUTE_PRINTF (7,0);
virtual void do_spaces (int numspaces) override;
virtual void do_text (const char *string) override;
virtual void do_message (const ui_file_style &style,
diff --git a/gdb/p-lang.c b/gdb/p-lang.c
index cfe2a888722..95911158d15 100644
--- a/gdb/p-lang.c
+++ b/gdb/p-lang.c
@@ -32,6 +32,7 @@
#include <ctype.h>
#include "c-lang.h"
#include "gdbarch.h"
+#include "cli/cli-style.h"
/* All GPC versions until now (2007-09-27) also define a symbol called
'_p_initialize'. Check for the presence of this symbol first. */
@@ -292,7 +293,9 @@ pascal_printstr (struct ui_file *stream, struct type *type,
in_quotes = 0;
}
pascal_printchar (current_char, type, stream);
- fprintf_filtered (stream, " <repeats %u times>", reps);
+ fprintf_filtered (stream, " %p[<repeats %u times>%p]",
+ metadata_style.style ().ptr (),
+ reps, nullptr);
i = rep1 - 1;
things_printed += options->repeat_count_threshold;
need_comma = 1;
diff --git a/gdb/p-typeprint.c b/gdb/p-typeprint.c
index d90b8ceb6ea..fadc44eaee8 100644
--- a/gdb/p-typeprint.c
+++ b/gdb/p-typeprint.c
@@ -32,6 +32,7 @@
#include "typeprint.h"
#include "gdb-demangle.h"
#include <ctype.h>
+#include "cli/cli-style.h"
static void pascal_type_print_varspec_suffix (struct type *, struct ui_file *,
int, int, int,
@@ -470,7 +471,7 @@ pascal_type_print_base (struct type *type, struct ui_file *stream, int show,
wrap_here (" ");
if (type == NULL)
{
- fputs_filtered ("<type unknown>", stream);
+ fputs_styled ("<type unknown>", metadata_style.style (), stream);
return;
}
@@ -827,8 +828,9 @@ pascal_type_print_base (struct type *type, struct ui_file *stream, int show,
{
/* At least for dump_symtab, it is important that this not be
an error (). */
- fprintf_filtered (stream, "<invalid unnamed pascal type code %d>",
- TYPE_CODE (type));
+ fprintf_styled (stream, metadata_style.style (),
+ "<invalid unnamed pascal type code %d>",
+ TYPE_CODE (type));
}
break;
}
diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c
index a3738a9252d..10612f3babe 100644
--- a/gdb/p-valprint.c
+++ b/gdb/p-valprint.c
@@ -39,6 +39,7 @@
#include "cp-support.h"
#include "objfiles.h"
#include "gdbsupport/byte-vector.h"
+#include "cli/cli-style.h"
\f
/* Decorations for Pascal. */
@@ -347,7 +348,7 @@ pascal_val_print (struct type *type,
elttype = check_typedef (elttype);
if (TYPE_STUB (elttype))
{
- fprintf_filtered (stream, "<incomplete type>");
+ fprintf_styled (stream, metadata_style.style (), "<incomplete type>");
break;
}
else
@@ -370,7 +371,7 @@ pascal_val_print (struct type *type,
maybe_bad_bstring:
if (bound_info < 0)
{
- fputs_filtered ("<error value>", stream);
+ fputs_styled ("<error value>", metadata_style.style (), stream);
goto done;
}
@@ -557,7 +558,7 @@ pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr,
options, dont_print_vb);
if (!len && n_baseclasses == 1)
- fprintf_filtered (stream, "<No data fields>");
+ fprintf_styled (stream, metadata_style.style (), "<No data fields>");
else
{
struct obstack tmp_obstack = dont_print_statmem_obstack;
@@ -622,7 +623,8 @@ pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr,
order problems. */
if (TYPE_FIELD_IGNORE (type, i))
{
- fputs_filtered ("<optimized out or zero length>", stream);
+ fputs_styled ("<optimized out or zero length>",
+ metadata_style.style (), stream);
}
else if (value_bits_synthetic_pointer (val,
TYPE_FIELD_BITPOS (type,
@@ -630,7 +632,8 @@ pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr,
TYPE_FIELD_BITSIZE (type,
i)))
{
- fputs_filtered (_("<synthetic pointer>"), stream);
+ fputs_styled (_("<synthetic pointer>"),
+ metadata_style.style (), stream);
}
else
{
@@ -647,7 +650,8 @@ pascal_object_print_value_fields (struct type *type, const gdb_byte *valaddr,
{
if (TYPE_FIELD_IGNORE (type, i))
{
- fputs_filtered ("<optimized out or zero length>", stream);
+ fputs_styled ("<optimized out or zero length>",
+ metadata_style.style (), stream);
}
else if (field_is_static (&TYPE_FIELD (type, i)))
{
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index c17afe29bb2..ea00f083b12 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -2001,8 +2001,9 @@ do_one_display (struct display *d)
}
catch (const gdb_exception_error &ex)
{
- fprintf_filtered (gdb_stdout, _("<error: %s>\n"),
- ex.what ());
+ fprintf_filtered (gdb_stdout, _("%p[<error: %s>%p]\n"),
+ metadata_style.style ().ptr (), ex.what (),
+ nullptr);
}
}
else
@@ -2035,7 +2036,8 @@ do_one_display (struct display *d)
}
catch (const gdb_exception_error &ex)
{
- fprintf_filtered (gdb_stdout, _("<error: %s>"), ex.what ());
+ fprintf_styled (gdb_stdout, metadata_style.style (),
+ _("<error: %s>"), ex.what ());
}
printf_filtered ("\n");
@@ -2237,8 +2239,9 @@ print_variable_and_value (const char *name, struct symbol *var,
}
catch (const gdb_exception_error &except)
{
- fprintf_filtered (stream, "<error reading variable %s (%s)>", name,
- except.what ());
+ fprintf_styled (stream, metadata_style.style (),
+ "<error reading variable %s (%s)>", name,
+ except.what ());
}
fprintf_filtered (stream, "\n");
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index f82a239c2a8..4dd6243ae99 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -397,7 +397,7 @@ py_print_single_arg (struct ui_out *out,
if (val == NULL)
{
gdb_assert (fa != NULL && fa->error != NULL);
- out->field_fmt ("value",
+ out->field_fmt ("value", metadata_style.style (),
_("<error reading variable: %s>"),
fa->error.get ());
}
diff --git a/gdb/python/py-prettyprint.c b/gdb/python/py-prettyprint.c
index fdc520d8443..a4df48fe19a 100644
--- a/gdb/python/py-prettyprint.c
+++ b/gdb/python/py-prettyprint.c
@@ -25,6 +25,7 @@
#include "extension-priv.h"
#include "python.h"
#include "python-internal.h"
+#include "cli/cli-style.h"
/* Return type of print_string_repr. */
@@ -259,10 +260,11 @@ print_stack_unless_memory_error (struct ui_file *stream)
gdb::unique_xmalloc_ptr<char> msg = fetched_error.to_string ();
if (msg == NULL || *msg == '\0')
- fprintf_filtered (stream, _("<error reading variable>"));
+ fprintf_styled (stream, metadata_style.style (),
+ _("<error reading variable>"));
else
- fprintf_filtered (stream, _("<error reading variable: %s>"),
- msg.get ());
+ fprintf_styled (stream, metadata_style.style (),
+ _("<error reading variable: %s>"), msg.get ());
}
else
gdbpy_print_stack ();
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 79f13311cd8..cef0a9cb092 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -37,6 +37,7 @@
#include <algorithm>
#include <string>
#include <vector>
+#include "cli/cli-style.h"
/* See rust-lang.h. */
@@ -473,7 +474,9 @@ rust_print_enum (struct type *type, int embedded_offset,
if (rust_empty_enum_p (type))
{
/* Print the enum type name here to be more clear. */
- fprintf_filtered (stream, _("%s {<No data fields>}"), TYPE_NAME (type));
+ fprintf_filtered (stream, _("%s {%p[<No data fields>%p]}"),
+ TYPE_NAME (type),
+ metadata_style.style ().ptr (), nullptr);
return;
}
diff --git a/gdb/skip.c b/gdb/skip.c
index fcf41bf79a7..cc10692f493 100644
--- a/gdb/skip.c
+++ b/gdb/skip.c
@@ -415,7 +415,9 @@ info_skip_command (const char *arg, int from_tty)
current_uiout->field_string ("file",
e.file ().empty () ? "<none>"
: e.file ().c_str (),
- file_name_style.style ()); /* 4 */
+ e.file ().empty ()
+ ? metadata_style.style ()
+ : file_name_style.style ()); /* 4 */
if (e.function_is_regexp ())
current_uiout->field_string ("regexp", "y"); /* 5 */
else
@@ -424,7 +426,9 @@ info_skip_command (const char *arg, int from_tty)
current_uiout->field_string ("function",
e.function ().empty () ? "<none>"
: e.function ().c_str (),
- function_name_style.style ()); /* 6 */
+ e.function ().empty ()
+ ? metadata_style.style ()
+ : function_name_style.style ()); /* 6 */
current_uiout->text ("\n");
}
diff --git a/gdb/stack.c b/gdb/stack.c
index 4899d0f4169..cb07e28b671 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -386,12 +386,16 @@ print_frame_arg (const frame_print_options &fp_opts,
annotate_arg_name_end ();
uiout->text ("=");
+ ui_file_style style;
if (!arg->val && !arg->error)
uiout->text ("...");
else
{
if (arg->error)
- stb.printf (_("<error reading variable: %s>"), arg->error.get ());
+ {
+ stb.printf (_("<error reading variable: %s>"), arg->error.get ());
+ style = metadata_style.style ();
+ }
else
{
try
@@ -428,11 +432,12 @@ print_frame_arg (const frame_print_options &fp_opts,
{
stb.printf (_("<error reading variable: %s>"),
except.what ());
+ style = metadata_style.style ();
}
}
}
- uiout->field_stream ("value", stb);
+ uiout->field_stream ("value", stb, style);
}
/* Read in inferior function local SYM at FRAME into ARGP. Caller is
@@ -1006,18 +1011,18 @@ print_frame_info (const frame_print_options &fp_opts,
{
annotate_function_call ();
uiout->field_string ("func", "<function called from gdb>",
- function_name_style.style ());
+ metadata_style.style ());
}
else if (get_frame_type (frame) == SIGTRAMP_FRAME)
{
annotate_signal_handler_caller ();
uiout->field_string ("func", "<signal handler called>",
- function_name_style.style ());
+ metadata_style.style ());
}
else if (get_frame_type (frame) == ARCH_FRAME)
{
uiout->field_string ("func", "<cross-architecture call>",
- function_name_style.style ());
+ metadata_style.style ());
}
uiout->text ("\n");
annotate_frame_end ();
@@ -1311,7 +1316,7 @@ print_frame (const frame_print_options &fp_opts,
print_pc (uiout, gdbarch, frame, pc);
else
uiout->field_string ("addr", "<unavailable>",
- address_style.style ());
+ metadata_style.style ());
annotate_frame_address_end ();
uiout->text (" in ");
}
@@ -1508,7 +1513,7 @@ info_frame_command_core (struct frame_info *fi, bool selected_frame_p)
if (frame_pc_p)
fputs_filtered (paddress (gdbarch, get_frame_pc (fi)), gdb_stdout);
else
- fputs_filtered ("<unavailable>", gdb_stdout);
+ fputs_styled ("<unavailable>", metadata_style.style (), gdb_stdout);
wrap_here (" ");
if (funname)
@@ -1545,8 +1550,9 @@ info_frame_command_core (struct frame_info *fi, bool selected_frame_p)
val_print_not_saved (gdb_stdout);
break;
default:
- fprintf_filtered (gdb_stdout, _("<error: %s>"),
- ex.what ());
+ fprintf_styled (gdb_stdout, metadata_style.style (),
+ _("<error: %s>"),
+ ex.what ());
break;
}
}
diff --git a/gdb/testsuite/gdb.base/style.exp b/gdb/testsuite/gdb.base/style.exp
index fb0dfed0061..0f812f7f1bc 100644
--- a/gdb/testsuite/gdb.base/style.exp
+++ b/gdb/testsuite/gdb.base/style.exp
@@ -133,4 +133,8 @@ save_vars { env(TERM) } {
"filename is styled when loading symbol file"
gdb_test "pwd" "Working directory [style .*? file].*"
+
+ gdb_test_no_output "set print repeat 3"
+ gdb_test "print {0,0,0,0,0,0,0,0}" \
+ " = \\{0 [style {<repeats.*8.*times>} metadata]\\}"
}
diff --git a/gdb/testsuite/lib/gdb-utils.exp b/gdb/testsuite/lib/gdb-utils.exp
index 89767dc51c4..95ca348dc33 100644
--- a/gdb/testsuite/lib/gdb-utils.exp
+++ b/gdb/testsuite/lib/gdb-utils.exp
@@ -54,6 +54,7 @@ proc style {str style} {
highlight { set style 31 }
variable { set style 36 }
address { set style 34 }
+ metadata { set style 2 }
}
return "\033\\\[${style}m${str}\033\\\[m"
}
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index 2f91e49efd3..843341aaae1 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -436,6 +436,7 @@ tvariables_info_1 (void)
uiout->field_string ("name", std::string ("$") + tsv.name);
uiout->field_string ("initial", plongest (tsv.initial_value));
+ ui_file_style style;
if (tsv.value_known)
c = plongest (tsv.value);
else if (uiout->is_mi_like_p ())
@@ -444,13 +445,19 @@ tvariables_info_1 (void)
undefined does not seem important enough to represent. */
c = NULL;
else if (current_trace_status ()->running || traceframe_number >= 0)
- /* The value is/was defined, but we don't have it. */
- c = "<unknown>";
+ {
+ /* The value is/was defined, but we don't have it. */
+ c = "<unknown>";
+ style = metadata_style.style ();
+ }
else
- /* It is not meaningful to ask about the value. */
- c = "<undefined>";
+ {
+ /* It is not meaningful to ask about the value. */
+ c = "<undefined>";
+ style = metadata_style.style ();
+ }
if (c)
- uiout->field_string ("current", c);
+ uiout->field_string ("current", c, style);
uiout->text ("\n");
}
}
diff --git a/gdb/tui/tui-out.c b/gdb/tui/tui-out.c
index d415e7b64a0..0d3f3be9880 100644
--- a/gdb/tui/tui-out.c
+++ b/gdb/tui/tui-out.c
@@ -70,15 +70,15 @@ tui_ui_out::do_field_string (int fldno, int width, ui_align align,
void
tui_ui_out::do_field_fmt (int fldno, int width, ui_align align,
- const char *fldname, const char *format,
- va_list args)
+ const char *fldname, const ui_file_style &style,
+ const char *format, va_list args)
{
if (suppress_output ())
return;
m_start_of_line++;
- cli_ui_out::do_field_fmt (fldno, width, align, fldname, format, args);
+ cli_ui_out::do_field_fmt (fldno, width, align, fldname, style, format, args);
}
void
diff --git a/gdb/tui/tui-out.h b/gdb/tui/tui-out.h
index 9df9e93aa9d..2b856af4883 100644
--- a/gdb/tui/tui-out.h
+++ b/gdb/tui/tui-out.h
@@ -37,8 +37,9 @@ protected:
void do_field_string (int fldno, int width, ui_align align, const char *fldname,
const char *string, const ui_file_style &style) override;
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);
+ const ui_file_style &style,
+ const char *format, va_list args) override
+ ATTRIBUTE_PRINTF (7, 0);
void do_text (const char *string) override;
private:
diff --git a/gdb/typeprint.c b/gdb/typeprint.c
index 41d95c2afb2..357b88db531 100644
--- a/gdb/typeprint.c
+++ b/gdb/typeprint.c
@@ -36,6 +36,7 @@
#include "cli/cli-utils.h"
#include "extension.h"
#include "completer.h"
+#include "cli/cli-style.h"
const struct type_print_options type_print_raw_options =
{
@@ -415,7 +416,8 @@ type_to_string (struct type *type)
void
type_print_unknown_return_type (struct ui_file *stream)
{
- fprintf_filtered (stream, _("<unknown return type>"));
+ fprintf_styled (stream, metadata_style.style (),
+ _("<unknown return type>"));
}
/* See typeprint.h. */
@@ -862,7 +864,7 @@ Show the number of recursive nested type definitions to print."), NULL,
void
val_print_not_allocated (struct ui_file *stream)
{
- fprintf_filtered (stream, _("<not allocated>"));
+ fprintf_styled (stream, metadata_style.style (), _("<not allocated>"));
}
/* Print <not associated> status to stream STREAM. */
@@ -870,5 +872,5 @@ val_print_not_allocated (struct ui_file *stream)
void
val_print_not_associated (struct ui_file *stream)
{
- fprintf_filtered (stream, _("<not associated>"));
+ fprintf_styled (stream, metadata_style.style (), _("<not associated>"));
}
diff --git a/gdb/ui-out.c b/gdb/ui-out.c
index 8cbaa4e0bc1..a64c79481ca 100644
--- a/gdb/ui-out.c
+++ b/gdb/ui-out.c
@@ -545,7 +545,25 @@ ui_out::field_fmt (const char *fldname, const char *format, ...)
va_start (args, format);
- do_field_fmt (fldno, width, align, fldname, format, args);
+ do_field_fmt (fldno, width, align, fldname, ui_file_style (), format, args);
+
+ va_end (args);
+}
+
+void
+ui_out::field_fmt (const char *fldname, const ui_file_style &style,
+ const char *format, ...)
+{
+ va_list args;
+ int fldno;
+ int width;
+ ui_align align;
+
+ verify_field (&fldno, &width, &align);
+
+ va_start (args, format);
+
+ do_field_fmt (fldno, width, align, fldname, style, format, args);
va_end (args);
}
diff --git a/gdb/ui-out.h b/gdb/ui-out.h
index d8adf7b7f0d..d2e95b2c838 100644
--- a/gdb/ui-out.h
+++ b/gdb/ui-out.h
@@ -194,6 +194,9 @@ class ui_out
void field_skip (const char *fldname);
void field_fmt (const char *fldname, const char *format, ...)
ATTRIBUTE_PRINTF (3, 4);
+ void field_fmt (const char *fldname, const ui_file_style &style,
+ const char *format, ...)
+ ATTRIBUTE_PRINTF (4, 5);
void spaces (int numspaces);
void text (const char *string);
@@ -291,9 +294,9 @@ class ui_out
const char *fldname, const char *string,
const ui_file_style &style) = 0;
virtual void do_field_fmt (int fldno, int width, ui_align align,
- const char *fldname, const char *format,
- va_list args)
- ATTRIBUTE_PRINTF (6,0) = 0;
+ const char *fldname, const ui_file_style &style,
+ const char *format, va_list args)
+ ATTRIBUTE_PRINTF (7, 0) = 0;
virtual void do_spaces (int numspaces) = 0;
virtual void do_text (const char *string) = 0;
virtual void do_message (const ui_file_style &style,
diff --git a/gdb/valprint.c b/gdb/valprint.c
index e5b28f3ee9e..919ab938213 100644
--- a/gdb/valprint.c
+++ b/gdb/valprint.c
@@ -38,6 +38,7 @@
#include "gdbsupport/byte-vector.h"
#include "cli/cli-option.h"
#include "gdbarch.h"
+#include "cli/cli-style.h"
/* Maximum number of wchars returned from wchar_iterate. */
#define MAX_WCHARS 4
@@ -347,7 +348,8 @@ valprint_check_validity (struct ui_file *stream,
}
if (!is_ref || !ref_is_addressable)
- fputs_filtered (_("<synthetic pointer>"), stream);
+ fputs_styled (_("<synthetic pointer>"), metadata_style.style (),
+ stream);
/* C++ references should be valid even if they're synthetic. */
return is_ref;
@@ -369,25 +371,25 @@ val_print_optimized_out (const struct value *val, struct ui_file *stream)
if (val != NULL && value_lval_const (val) == lval_register)
val_print_not_saved (stream);
else
- fprintf_filtered (stream, _("<optimized out>"));
+ fprintf_styled (stream, metadata_style.style (), _("<optimized out>"));
}
void
val_print_not_saved (struct ui_file *stream)
{
- fprintf_filtered (stream, _("<not saved>"));
+ fprintf_styled (stream, metadata_style.style (), _("<not saved>"));
}
void
val_print_unavailable (struct ui_file *stream)
{
- fprintf_filtered (stream, _("<unavailable>"));
+ fprintf_styled (stream, metadata_style.style (), _("<unavailable>"));
}
void
val_print_invalid_address (struct ui_file *stream)
{
- fprintf_filtered (stream, _("<invalid address>"));
+ fprintf_styled (stream, metadata_style.style (), _("<invalid address>"));
}
/* Print a pointer based on the type of its target.
@@ -988,7 +990,7 @@ generic_val_print (struct type *type,
/* This happens (without TYPE_STUB set) on systems which don't use
dbx xrefs (NO_DBX_XREFS in gcc) if a file has a "struct foo *bar"
and no complete type for struct foo in that file. */
- fprintf_filtered (stream, _("<incomplete type>"));
+ fprintf_styled (stream, metadata_style.style (), _("<incomplete type>"));
break;
case TYPE_CODE_COMPLEX:
@@ -1047,7 +1049,7 @@ val_print (struct type *type, LONGEST embedded_offset,
if (TYPE_STUB (real_type))
{
- fprintf_filtered (stream, _("<incomplete type>"));
+ fprintf_styled (stream, metadata_style.style (), _("<incomplete type>"));
return;
}
@@ -1084,7 +1086,8 @@ val_print (struct type *type, LONGEST embedded_offset,
}
catch (const gdb_exception_error &except)
{
- fprintf_filtered (stream, _("<error reading variable>"));
+ fprintf_styled (stream, metadata_style.style (),
+ _("<error reading variable>"));
}
}
@@ -1115,7 +1118,8 @@ value_check_printable (struct value *val, struct ui_file *stream,
{
if (val == 0)
{
- fprintf_filtered (stream, _("<address of value unknown>"));
+ fprintf_styled (stream, metadata_style.style (),
+ _("<address of value unknown>"));
return 0;
}
@@ -1139,8 +1143,9 @@ value_check_printable (struct value *val, struct ui_file *stream,
if (TYPE_CODE (value_type (val)) == TYPE_CODE_INTERNAL_FUNCTION)
{
- fprintf_filtered (stream, _("<internal function %s>"),
- value_internal_function_name (val));
+ fprintf_styled (stream, metadata_style.style (),
+ _("<internal function %s>"),
+ value_internal_function_name (val));
return 0;
}
@@ -2069,7 +2074,8 @@ val_print_array_elements (struct type *type,
address, stream, recurse + 1, val, options,
current_language);
annotate_elt_rep (reps);
- fprintf_filtered (stream, " <repeats %u times>", reps);
+ fprintf_filtered (stream, " %p[<repeats %u times>%p]",
+ metadata_style.style ().ptr (), reps, nullptr);
annotate_elt_rep_end ();
i = rep1 - 1;
diff --git a/gdb/value.c b/gdb/value.c
index d58a964649b..67fe2f17c05 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -43,6 +43,7 @@
#include "completer.h"
#include "gdbsupport/selftest.h"
#include "gdbsupport/array-view.h"
+#include "cli/cli-style.h"
/* Definition of a user function. */
struct internal_function
@@ -2539,7 +2540,8 @@ show_convenience (const char *ignore, int from_tty)
}
catch (const gdb_exception_error &ex)
{
- fprintf_filtered (gdb_stdout, _("<error: %s>"), ex.what ());
+ fprintf_styled (gdb_stdout, metadata_style.style (),
+ _("<error: %s>"), ex.what ());
}
printf_filtered (("\n"));
--
2.17.2
^ permalink raw reply [flat|nested] 16+ messages in thread* Re: [PATCH 6/8] Introduce metadata style
2019-09-27 21:25 ` [PATCH 6/8] Introduce metadata style Tom Tromey
@ 2019-09-30 14:07 ` Pedro Alves
0 siblings, 0 replies; 16+ messages in thread
From: Pedro Alves @ 2019-09-30 14:07 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
On 9/27/19 10:25 PM, Tom Tromey wrote:
> @@ -372,4 +376,11 @@ Highlight display styling.\n\
> Configure highlight colors and display intensity\n\
> Some commands use the highlight style to draw the attention to a part\n\
> of their output."));
> +
> + STYLE_ADD_SETSHOW_COMMANDS (metadata_style,
> + _("\
> +Metadata display styling\n\
> +Configure metadata colors and display intensity\n\
> +The \"metadata\" style is used when GDB displays information about\n\
> +your data, for example \"<unavailable\""));
Missing ">" in "<unavailable>".
Thanks,
Pedro Alves
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 1/8] Remove the ui_out_style_kind enum
2019-09-27 21:25 [PATCH 0/8] More gdb styling improvements Tom Tromey
2019-09-27 21:25 ` [PATCH 6/8] Introduce metadata style Tom Tromey
@ 2019-09-27 21:25 ` Tom Tromey
2019-09-27 21:25 ` [PATCH 8/8] Use styled_string for "show logging filename" Tom Tromey
` (6 subsequent siblings)
8 siblings, 0 replies; 16+ messages in thread
From: Tom Tromey @ 2019-09-27 21:25 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This removes the ui_out_style_kind enum, in favor of simply using
ui_file_style references. This simplifies the code somewhat.
gdb/ChangeLog
2019-09-27 Tom Tromey <tom@tromey.com>
* ui-out.h (enum class ui_out_style_kind): Remove.
(class ui_out) <field_string, field_stsream, do_field_string>:
Change type of "style".
* ui-out.c (ui_out::field_core_addr, ui_out::field_stream)
(ui_out::field_string): Update.
* tui/tui-out.h (class tui_ui_out) <do_field_string>: Change type
of "style".
* tui/tui-out.c (tui_ui_out::do_field_string): Update.
* tracepoint.c (print_one_static_tracepoint_marker): Update.
* stack.c (print_frame_arg, print_frame_info, print_frame):
Update.
* source.c (print_source_lines_base): Update.
* solib.c (info_sharedlibrary_command): Update.
* skip.c (info_skip_command): Update.
* record-btrace.c (btrace_call_history_src_line)
(btrace_call_history): Update.
* python/py-framefilter.c (py_print_frame): Update.
* mi/mi-out.h (class mi_ui_out) <do_field_string>: Change type of
"style".
* mi/mi-out.c (mi_ui_out::do_table_header)
(mi_ui_out::do_field_signed, mi_ui_out::do_field_unsigned)
(mi_ui_out::do_field_string): Update.
* disasm.c (gdb_pretty_print_disassembler::pretty_print_insn):
Update.
* cli-out.h (class cli_ui_out) <do_field_string>: Change type of
"style".
* cli-out.c (cli_ui_out::do_table_header)
(cli_ui_out::do_field_signed, cli_ui_out::do_field_unsigned)
(cli_ui_out::do_field_skip, cli_ui_out::do_field_string)
(cli_ui_out::do_field_fmt): Update.
* breakpoint.c (print_breakpoint_location): Update.
(update_static_tracepoint): Update.
---
gdb/ChangeLog | 35 ++++++++++++++++++++++++++++++++++
gdb/breakpoint.c | 8 ++++----
gdb/cli-out.c | 38 +++++++------------------------------
gdb/cli-out.h | 2 +-
gdb/disasm.c | 3 ++-
gdb/mi/mi-out.c | 10 +++++-----
gdb/mi/mi-out.h | 2 +-
gdb/python/py-framefilter.c | 5 +++--
gdb/record-btrace.c | 9 +++++----
gdb/skip.c | 5 +++--
gdb/solib.c | 3 ++-
gdb/source.c | 3 ++-
gdb/stack.c | 16 +++++++++-------
gdb/tracepoint.c | 5 +++--
gdb/tui/tui-out.c | 2 +-
gdb/tui/tui-out.h | 2 +-
gdb/ui-out.c | 8 +++++---
gdb/ui-out.h | 23 ++++------------------
18 files changed, 93 insertions(+), 86 deletions(-)
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 838c9d136fd..dd8fe4c8620 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -5823,14 +5823,14 @@ print_breakpoint_location (struct breakpoint *b,
{
uiout->text ("in ");
uiout->field_string ("func", SYMBOL_PRINT_NAME (sym),
- ui_out_style_kind::FUNCTION);
+ function_name_style.style ());
uiout->text (" ");
uiout->wrap_hint (wrap_indent_at_field (uiout, "what"));
uiout->text ("at ");
}
uiout->field_string ("file",
symtab_to_filename_for_display (loc->symtab),
- ui_out_style_kind::FILE);
+ file_name_style.style ());
uiout->text (":");
if (uiout->is_mi_like_p ())
@@ -13317,12 +13317,12 @@ update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal)
if (sym)
{
uiout->field_string ("func", SYMBOL_PRINT_NAME (sym),
- ui_out_style_kind::FUNCTION);
+ function_name_style.style ());
uiout->text (" at ");
}
uiout->field_string ("file",
symtab_to_filename_for_display (sal2.symtab),
- ui_out_style_kind::FILE);
+ file_name_style.style ());
uiout->text (":");
if (uiout->is_mi_like_p ())
diff --git a/gdb/cli-out.c b/gdb/cli-out.c
index 549d518d60f..fa72a1d344f 100644
--- a/gdb/cli-out.c
+++ b/gdb/cli-out.c
@@ -73,7 +73,7 @@ cli_ui_out::do_table_header (int width, ui_align alignment,
return;
do_field_string (0, width, alignment, 0, col_hdr.c_str (),
- ui_out_style_kind::DEFAULT);
+ ui_file_style ());
}
/* Mark beginning of a list */
@@ -100,7 +100,7 @@ cli_ui_out::do_field_signed (int fldno, int width, ui_align alignment,
return;
do_field_string (fldno, width, alignment, fldname, plongest (value),
- ui_out_style_kind::DEFAULT);
+ ui_file_style ());
}
/* output an unsigned field */
@@ -113,7 +113,7 @@ cli_ui_out::do_field_unsigned (int fldno, int width, ui_align alignment,
return;
do_field_string (fldno, width, alignment, fldname, pulongest (value),
- ui_out_style_kind::DEFAULT);
+ ui_file_style ());
}
/* used to omit a field */
@@ -126,7 +126,7 @@ cli_ui_out::do_field_skip (int fldno, int width, ui_align alignment,
return;
do_field_string (fldno, width, alignment, fldname, "",
- ui_out_style_kind::DEFAULT);
+ ui_file_style ());
}
/* other specific cli_field_* end up here so alignment and field
@@ -135,7 +135,7 @@ cli_ui_out::do_field_skip (int fldno, int width, ui_align alignment,
void
cli_ui_out::do_field_string (int fldno, int width, ui_align align,
const char *fldname, const char *string,
- ui_out_style_kind style)
+ const ui_file_style &style)
{
int before = 0;
int after = 0;
@@ -170,31 +170,7 @@ cli_ui_out::do_field_string (int fldno, int width, ui_align align,
spaces (before);
if (string)
- {
- ui_file_style fstyle;
- switch (style)
- {
- case ui_out_style_kind::DEFAULT:
- /* Nothing. */
- break;
- case ui_out_style_kind::FILE:
- /* Nothing. */
- fstyle = file_name_style.style ();
- break;
- case ui_out_style_kind::FUNCTION:
- fstyle = function_name_style.style ();
- break;
- case ui_out_style_kind::VARIABLE:
- fstyle = variable_name_style.style ();
- break;
- case ui_out_style_kind::ADDRESS:
- fstyle = address_style.style ();
- break;
- default:
- gdb_assert_not_reached ("missing case");
- }
- fputs_styled (string, fstyle, m_streams.back ());
- }
+ fputs_styled (string, style, m_streams.back ());
if (after)
spaces (after);
@@ -216,7 +192,7 @@ cli_ui_out::do_field_fmt (int fldno, int width, ui_align align,
std::string str = string_vprintf (format, args);
do_field_string (fldno, width, align, fldname, str.c_str (),
- ui_out_style_kind::DEFAULT);
+ ui_file_style ());
}
void
diff --git a/gdb/cli-out.h b/gdb/cli-out.h
index f38c1cc0571..bc8b781d605 100644
--- a/gdb/cli-out.h
+++ b/gdb/cli-out.h
@@ -57,7 +57,7 @@ protected:
virtual void do_field_string (int fldno, int width, ui_align align,
const char *fldname,
const char *string,
- ui_out_style_kind style) override;
+ const ui_file_style &style) override;
virtual void do_field_fmt (int fldno, int width, ui_align align,
const char *fldname, const char *format,
va_list args)
diff --git a/gdb/disasm.c b/gdb/disasm.c
index 68da682c15e..f483a5e5cd0 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -31,6 +31,7 @@
#include <algorithm>
#include "gdbsupport/gdb_optional.h"
#include "valprint.h"
+#include "cli/cli-style.h"
/* Disassemble functions.
FIXME: We should get rid of all the duplicate code in gdb that does
@@ -245,7 +246,7 @@ gdb_pretty_print_disassembler::pretty_print_insn (const struct disasm_insn *insn
m_uiout->text (" <");
if (!omit_fname)
m_uiout->field_string ("func-name", name.c_str (),
- ui_out_style_kind::FUNCTION);
+ function_name_style.style ());
/* For negative offsets, avoid displaying them as +-N; the sign of
the offset takes the place of the "+" here. */
if (offset >= 0)
diff --git a/gdb/mi/mi-out.c b/gdb/mi/mi-out.c
index a6687178259..0b930738f1d 100644
--- a/gdb/mi/mi-out.c
+++ b/gdb/mi/mi-out.c
@@ -70,9 +70,9 @@ mi_ui_out::do_table_header (int width, ui_align alignment,
do_field_signed (0, 0, ui_center, "width", width);
do_field_signed (0, 0, ui_center, "alignment", alignment);
do_field_string (0, 0, ui_center, "col_name", col_name.c_str (),
- ui_out_style_kind::DEFAULT);
+ ui_file_style ());
do_field_string (0, width, alignment, "colhdr", col_hdr.c_str (),
- ui_out_style_kind::DEFAULT);
+ ui_file_style ());
close (ui_out_type_tuple);
}
@@ -99,7 +99,7 @@ mi_ui_out::do_field_signed (int fldno, int width, ui_align alignment,
const char *fldname, LONGEST value)
{
do_field_string (fldno, width, alignment, fldname, plongest (value),
- ui_out_style_kind::DEFAULT);
+ ui_file_style ());
}
/* Output an unsigned field. */
@@ -109,7 +109,7 @@ mi_ui_out::do_field_unsigned (int fldno, int width, ui_align alignment,
const char *fldname, ULONGEST value)
{
do_field_string (fldno, width, alignment, fldname, pulongest (value),
- ui_out_style_kind::DEFAULT);
+ ui_file_style ());
}
/* Used to omit a field. */
@@ -126,7 +126,7 @@ 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,
- ui_out_style_kind style)
+ const ui_file_style &style)
{
ui_file *stream = m_streams.back ();
field_separator ();
diff --git a/gdb/mi/mi-out.h b/gdb/mi/mi-out.h
index fe96658b59b..90528fd4e84 100644
--- a/gdb/mi/mi-out.h
+++ b/gdb/mi/mi-out.h
@@ -66,7 +66,7 @@ protected:
const char *fldname) override;
virtual void do_field_string (int fldno, int width, ui_align align,
const char *fldname, const char *string,
- ui_out_style_kind style) override;
+ const ui_file_style &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);
diff --git a/gdb/python/py-framefilter.c b/gdb/python/py-framefilter.c
index ecd633ab695..f82a239c2a8 100644
--- a/gdb/python/py-framefilter.c
+++ b/gdb/python/py-framefilter.c
@@ -33,6 +33,7 @@
#include "mi/mi-cmds.h"
#include "python-internal.h"
#include "gdbsupport/gdb_optional.h"
+#include "cli/cli-style.h"
enum mi_print_types
{
@@ -947,7 +948,7 @@ py_print_frame (PyObject *filter, frame_filter_flags flags,
if (function == NULL)
out->field_skip ("func");
else
- out->field_string ("func", function, ui_out_style_kind::FUNCTION);
+ out->field_string ("func", function, function_name_style.style ());
}
}
@@ -987,7 +988,7 @@ py_print_frame (PyObject *filter, frame_filter_flags flags,
out->text (" at ");
annotate_frame_source_file ();
out->field_string ("file", filename.get (),
- ui_out_style_kind::FILE);
+ file_name_style.style ());
annotate_frame_source_file_end ();
}
}
diff --git a/gdb/record-btrace.c b/gdb/record-btrace.c
index b55459e4ad1..c923b365c48 100644
--- a/gdb/record-btrace.c
+++ b/gdb/record-btrace.c
@@ -42,6 +42,7 @@
#include "inferior.h"
#include <algorithm>
#include "gdbarch.h"
+#include "cli/cli-style.h"
static const target_info record_btrace_target_info = {
"record-btrace",
@@ -1084,7 +1085,7 @@ btrace_call_history_src_line (struct ui_out *uiout,
uiout->field_string ("file",
symtab_to_filename_for_display (symbol_symtab (sym)),
- ui_out_style_kind::FILE);
+ file_name_style.style ());
btrace_compute_src_line_range (bfun, &begin, &end);
if (end < begin)
@@ -1176,13 +1177,13 @@ btrace_call_history (struct ui_out *uiout,
if (sym != NULL)
uiout->field_string ("function", SYMBOL_PRINT_NAME (sym),
- ui_out_style_kind::FUNCTION);
+ function_name_style.style ());
else if (msym != NULL)
uiout->field_string ("function", MSYMBOL_PRINT_NAME (msym),
- ui_out_style_kind::FUNCTION);
+ function_name_style.style ());
else if (!uiout->is_mi_like_p ())
uiout->field_string ("function", "??",
- ui_out_style_kind::FUNCTION);
+ function_name_style.style ());
if ((flags & RECORD_PRINT_INSN_RANGE) != 0)
{
diff --git a/gdb/skip.c b/gdb/skip.c
index a549aca897c..fcf41bf79a7 100644
--- a/gdb/skip.c
+++ b/gdb/skip.c
@@ -36,6 +36,7 @@
#include "gdb_regex.h"
#include "gdbsupport/gdb_optional.h"
#include <list>
+#include "cli/cli-style.h"
/* True if we want to print debug printouts related to file/function
skipping. */
@@ -414,7 +415,7 @@ info_skip_command (const char *arg, int from_tty)
current_uiout->field_string ("file",
e.file ().empty () ? "<none>"
: e.file ().c_str (),
- ui_out_style_kind::FILE); /* 4 */
+ file_name_style.style ()); /* 4 */
if (e.function_is_regexp ())
current_uiout->field_string ("regexp", "y"); /* 5 */
else
@@ -423,7 +424,7 @@ info_skip_command (const char *arg, int from_tty)
current_uiout->field_string ("function",
e.function ().empty () ? "<none>"
: e.function ().c_str (),
- ui_out_style_kind::FUNCTION); /* 6 */
+ function_name_style.style ()); /* 6 */
current_uiout->text ("\n");
}
diff --git a/gdb/solib.c b/gdb/solib.c
index 5b1246929b5..db6a52d2c14 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -47,6 +47,7 @@
#include "gdb_bfd.h"
#include "gdbsupport/filestuff.h"
#include "source.h"
+#include "cli/cli-style.h"
/* Architecture-specific operations. */
@@ -1104,7 +1105,7 @@ info_sharedlibrary_command (const char *pattern, int from_tty)
else
uiout->field_string ("syms-read", so->symbols_loaded ? "Yes" : "No");
- uiout->field_string ("name", so->so_name, ui_out_style_kind::FILE);
+ uiout->field_string ("name", so->so_name, file_name_style.style ());
uiout->text ("\n");
}
diff --git a/gdb/source.c b/gdb/source.c
index 0171f2748b4..ff218189495 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -46,6 +46,7 @@
#include <algorithm>
#include "gdbsupport/pathstuff.h"
#include "source-cache.h"
+#include "cli/cli-style.h"
#define OPEN_MODE (O_RDONLY | O_BINARY)
#define FDOPEN_MODE FOPEN_RB
@@ -1235,7 +1236,7 @@ print_source_lines_base (struct symtab *s, int line, int stopline,
not for TUI. */
if (uiout->is_mi_like_p () || uiout->test_flags (ui_source_list))
uiout->field_string ("file", symtab_to_filename_for_display (s),
- ui_out_style_kind::FILE);
+ file_name_style.style ());
if (uiout->is_mi_like_p () || !uiout->test_flags (ui_source_list))
{
const char *s_fullname = symtab_to_fullname (s);
diff --git a/gdb/stack.c b/gdb/stack.c
index 0f7fbf5e6ef..4899d0f4169 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -54,6 +54,7 @@
#include "observable.h"
#include "gdbsupport/def-vector.h"
#include "cli/cli-option.h"
+#include "cli/cli-style.h"
/* The possible choices of "set print frame-arguments", and the value
of this setting. */
@@ -381,7 +382,7 @@ print_frame_arg (const frame_print_options &fp_opts,
if (arg->entry_kind == print_entry_values_only
|| arg->entry_kind == print_entry_values_compact)
stb.puts ("@entry");
- uiout->field_stream ("name", stb, ui_out_style_kind::VARIABLE);
+ uiout->field_stream ("name", stb, variable_name_style.style ());
annotate_arg_name_end ();
uiout->text ("=");
@@ -1005,18 +1006,18 @@ print_frame_info (const frame_print_options &fp_opts,
{
annotate_function_call ();
uiout->field_string ("func", "<function called from gdb>",
- ui_out_style_kind::FUNCTION);
+ function_name_style.style ());
}
else if (get_frame_type (frame) == SIGTRAMP_FRAME)
{
annotate_signal_handler_caller ();
uiout->field_string ("func", "<signal handler called>",
- ui_out_style_kind::FUNCTION);
+ function_name_style.style ());
}
else if (get_frame_type (frame) == ARCH_FRAME)
{
uiout->field_string ("func", "<cross-architecture call>",
- ui_out_style_kind::FUNCTION);
+ function_name_style.style ());
}
uiout->text ("\n");
annotate_frame_end ();
@@ -1310,7 +1311,7 @@ print_frame (const frame_print_options &fp_opts,
print_pc (uiout, gdbarch, frame, pc);
else
uiout->field_string ("addr", "<unavailable>",
- ui_out_style_kind::ADDRESS);
+ address_style.style ());
annotate_frame_address_end ();
uiout->text (" in ");
}
@@ -1319,7 +1320,7 @@ print_frame (const frame_print_options &fp_opts,
string_file stb;
fprintf_symbol_filtered (&stb, funname ? funname.get () : "??",
funlang, DMGL_ANSI);
- uiout->field_stream ("func", stb, ui_out_style_kind::FUNCTION);
+ uiout->field_stream ("func", stb, function_name_style.style ());
uiout->wrap_hint (" ");
annotate_frame_args ();
@@ -1361,7 +1362,8 @@ print_frame (const frame_print_options &fp_opts,
uiout->wrap_hint (" ");
uiout->text (" at ");
annotate_frame_source_file ();
- uiout->field_string ("file", filename_display, ui_out_style_kind::FILE);
+ uiout->field_string ("file", filename_display,
+ file_name_style.style ());
if (uiout->is_mi_like_p ())
{
const char *fullname = symtab_to_fullname (sal.symtab);
diff --git a/gdb/tracepoint.c b/gdb/tracepoint.c
index c2c5f422462..2f91e49efd3 100644
--- a/gdb/tracepoint.c
+++ b/gdb/tracepoint.c
@@ -57,6 +57,7 @@
#include "tracefile.h"
#include "location.h"
#include <algorithm>
+#include "cli/cli-style.h"
#include <unistd.h>
@@ -3683,7 +3684,7 @@ print_one_static_tracepoint_marker (int count,
{
uiout->text ("in ");
uiout->field_string ("func", SYMBOL_PRINT_NAME (sym),
- ui_out_style_kind::FUNCTION);
+ function_name_style.style ());
uiout->wrap_hint (wrap_indent);
uiout->text (" at ");
}
@@ -3694,7 +3695,7 @@ print_one_static_tracepoint_marker (int count,
{
uiout->field_string ("file",
symtab_to_filename_for_display (sal.symtab),
- ui_out_style_kind::FILE);
+ file_name_style.style ());
uiout->text (":");
if (uiout->is_mi_like_p ())
diff --git a/gdb/tui/tui-out.c b/gdb/tui/tui-out.c
index 50865ba0465..d415e7b64a0 100644
--- a/gdb/tui/tui-out.c
+++ b/gdb/tui/tui-out.c
@@ -52,7 +52,7 @@ tui_ui_out::do_field_signed (int fldno, int width, ui_align alignment,
void
tui_ui_out::do_field_string (int fldno, int width, ui_align align,
const char *fldname, const char *string,
- ui_out_style_kind style)
+ const ui_file_style &style)
{
if (suppress_output ())
return;
diff --git a/gdb/tui/tui-out.h b/gdb/tui/tui-out.h
index 083094ba75e..9df9e93aa9d 100644
--- a/gdb/tui/tui-out.h
+++ b/gdb/tui/tui-out.h
@@ -35,7 +35,7 @@ protected:
void do_field_signed (int fldno, int width, ui_align align, const char *fldname,
LONGEST value) override;
void do_field_string (int fldno, int width, ui_align align, const char *fldname,
- const char *string, ui_out_style_kind style) override;
+ const char *string, const ui_file_style &style) override;
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);
diff --git a/gdb/ui-out.c b/gdb/ui-out.c
index 91662fac4a2..e8fe44c8268 100644
--- a/gdb/ui-out.c
+++ b/gdb/ui-out.c
@@ -24,6 +24,8 @@
#include "expression.h" /* For language.h */
#include "language.h"
#include "ui-out.h"
+#include "gdbsupport/format.h"
+#include "cli/cli-style.h"
#include <vector>
#include <memory>
@@ -483,12 +485,12 @@ ui_out::field_core_addr (const char *fldname, struct gdbarch *gdbarch,
CORE_ADDR address)
{
field_string (fldname, print_core_address (gdbarch, address),
- ui_out_style_kind::ADDRESS);
+ address_style.style ());
}
void
ui_out::field_stream (const char *fldname, string_file &stream,
- ui_out_style_kind style)
+ const ui_file_style &style)
{
if (!stream.empty ())
field_string (fldname, stream.c_str (), style);
@@ -513,7 +515,7 @@ ui_out::field_skip (const char *fldname)
void
ui_out::field_string (const char *fldname, const char *string,
- ui_out_style_kind style)
+ const ui_file_style &style)
{
int fldno;
int width;
diff --git a/gdb/ui-out.h b/gdb/ui-out.h
index 7041d9690e5..6732f046719 100644
--- a/gdb/ui-out.h
+++ b/gdb/ui-out.h
@@ -26,6 +26,7 @@
#include <vector>
#include "gdbsupport/enum-flags.h"
+#include "ui-style.h"
class ui_out_level;
class ui_out_table;
@@ -67,22 +68,6 @@ enum ui_out_type
ui_out_type_list
};
-/* Possible kinds of styling. */
-
-enum class ui_out_style_kind
-{
- /* The default (plain) style. */
- DEFAULT,
- /* File name. */
- FILE,
- /* Function name. */
- FUNCTION,
- /* Variable name. */
- VARIABLE,
- /* Address. */
- ADDRESS
-};
-
class ui_out
{
public:
@@ -115,10 +100,10 @@ class ui_out
void field_core_addr (const char *fldname, struct gdbarch *gdbarch,
CORE_ADDR address);
void field_string (const char *fldname, const char *string,
- ui_out_style_kind style = ui_out_style_kind::DEFAULT);
+ const ui_file_style &style = ui_file_style ());
void field_string (const char *fldname, const std::string &string);
void field_stream (const char *fldname, string_file &stream,
- ui_out_style_kind style = ui_out_style_kind::DEFAULT);
+ const ui_file_style &style = ui_file_style ());
void field_skip (const char *fldname);
void field_fmt (const char *fldname, const char *format, ...)
ATTRIBUTE_PRINTF (3, 4);
@@ -169,7 +154,7 @@ class ui_out
const char *fldname) = 0;
virtual void do_field_string (int fldno, int width, ui_align align,
const char *fldname, const char *string,
- ui_out_style_kind style) = 0;
+ const ui_file_style &style) = 0;
virtual void do_field_fmt (int fldno, int width, ui_align align,
const char *fldname, const char *format,
va_list args)
--
2.17.2
^ permalink raw reply [flat|nested] 16+ messages in thread* [PATCH 8/8] Use styled_string for "show logging filename"
2019-09-27 21:25 [PATCH 0/8] More gdb styling improvements Tom Tromey
2019-09-27 21:25 ` [PATCH 6/8] Introduce metadata style Tom Tromey
2019-09-27 21:25 ` [PATCH 1/8] Remove the ui_out_style_kind enum Tom Tromey
@ 2019-09-27 21:25 ` Tom Tromey
2019-09-27 21:25 ` [PATCH 4/8] Use new %p format suffixes in gdb Tom Tromey
` (5 subsequent siblings)
8 siblings, 0 replies; 16+ messages in thread
From: Tom Tromey @ 2019-09-27 21:25 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changes "show logging filename" to style its output.
gdb/ChangeLog
2019-09-27 Tom Tromey <tom@tromey.com>
* cli/cli-logging.c (show_logging_filename): Use styled_string.
gdb/testsuite/ChangeLog
2019-09-27 Tom Tromey <tom@tromey.com>
* gdb.base/style.exp: Test "show logging filename".
---
gdb/ChangeLog | 4 ++++
gdb/cli/cli-logging.c | 5 +++--
gdb/testsuite/ChangeLog | 4 ++++
gdb/testsuite/gdb.base/style.exp | 3 +++
4 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/gdb/cli/cli-logging.c b/gdb/cli/cli-logging.c
index 22b540b4812..e20ebd5dc82 100644
--- a/gdb/cli/cli-logging.c
+++ b/gdb/cli/cli-logging.c
@@ -21,6 +21,7 @@
#include "gdbcmd.h"
#include "ui-out.h"
#include "interps.h"
+#include "cli/cli-style.h"
static char *saved_filename;
@@ -29,8 +30,8 @@ static void
show_logging_filename (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
- fprintf_filtered (file, _("The current logfile is \"%s\".\n"),
- value);
+ fprintf_filtered (file, _("The current logfile is \"%ps\".\n"),
+ styled_string (file_name_style.style (), value));
}
static bool logging_overwrite;
diff --git a/gdb/testsuite/gdb.base/style.exp b/gdb/testsuite/gdb.base/style.exp
index 0f812f7f1bc..72b5f4efb21 100644
--- a/gdb/testsuite/gdb.base/style.exp
+++ b/gdb/testsuite/gdb.base/style.exp
@@ -137,4 +137,7 @@ save_vars { env(TERM) } {
gdb_test_no_output "set print repeat 3"
gdb_test "print {0,0,0,0,0,0,0,0}" \
" = \\{0 [style {<repeats.*8.*times>} metadata]\\}"
+
+ gdb_test "show logging file" \
+ "The current logfile is \"[style .*? file]\"\\..*"
}
--
2.17.2
^ permalink raw reply [flat|nested] 16+ messages in thread* [PATCH 4/8] Use new %p format suffixes in gdb
2019-09-27 21:25 [PATCH 0/8] More gdb styling improvements Tom Tromey
` (2 preceding siblings ...)
2019-09-27 21:25 ` [PATCH 8/8] Use styled_string for "show logging filename" Tom Tromey
@ 2019-09-27 21:25 ` Tom Tromey
2019-09-30 14:05 ` Pedro Alves
2019-09-27 21:25 ` [PATCH 5/8] Style "pwd" output Tom Tromey
` (4 subsequent siblings)
8 siblings, 1 reply; 16+ messages in thread
From: Tom Tromey @ 2019-09-27 21:25 UTC (permalink / raw)
To: gdb-patches; +Cc: Pedro Alves
From: Pedro Alves <palves@redhat.com>
This changes various spots in gdb to use the new %p format suffixes.
gdb/ChangeLog
2019-09-27 Pedro Alves <palves@redhat.com>
Tom Tromey <tom@tromey.com>
* symtab.c (print_symbol_info): Uew %ps.
(print_msymbol_info): Use %ps.
* symfile.c (symbol_file_add_with_addrs): Use %ps.
* printcmd.c (print_variable_and_value): Use %ps.
* macrocmd.c (show_pp_source_pos): Use %ps.
* infrun.c (print_exited_reason): Use ui_out::message.
* breakpoint.c (watchpoint_check, print_one_breakpoint_location)
(describe_other_breakpoints): Use ui_out::message and new
formats.
(say_where): Use new formats.
(bkpt_print_it, tracepoint_print_one_detail): Use ui_out::message
and new formats.
---
gdb/ChangeLog | 16 ++++++++++++
gdb/breakpoint.c | 65 ++++++++++++++++++++++--------------------------
gdb/infrun.c | 19 ++++++--------
gdb/macrocmd.c | 6 +++--
gdb/printcmd.c | 5 ++--
gdb/symfile.c | 13 +++++-----
gdb/symtab.c | 24 +++++++++---------
7 files changed, 77 insertions(+), 71 deletions(-)
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index dd8fe4c8620..2030687728c 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -4912,10 +4912,10 @@ watchpoint_check (bpstat bs)
if (uiout->is_mi_like_p ())
uiout->field_string
("reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE));
- uiout->text ("\nWatchpoint ");
- uiout->field_signed ("wpnum", b->number);
- uiout->text (" deleted because the program has left the block in\n"
- "which its expression is valid.\n");
+ uiout->message ("\nWatchpoint %pF deleted because the program has "
+ "left the block in\n"
+ "which its expression is valid.\n",
+ signed_field ("wpnum", b->number));
}
/* Make sure the watchpoint's commands aren't executed. */
@@ -6141,10 +6141,9 @@ print_one_breakpoint_location (struct breakpoint *b,
&& breakpoint_condition_evaluation_mode ()
== condition_evaluation_target)
{
- uiout->text (" (");
- uiout->field_string ("evaluated-by",
- bp_condition_evaluator (b));
- uiout->text (" evals)");
+ uiout->message (" (%pF evals)",
+ string_field ("evaluated-by",
+ bp_condition_evaluator (b)));
}
uiout->text ("\n");
}
@@ -6193,9 +6192,8 @@ print_one_breakpoint_location (struct breakpoint *b,
if (!part_of_multiple && b->ignore_count)
{
annotate_field (8);
- uiout->text ("\tignore next ");
- uiout->field_signed ("ignore", b->ignore_count);
- uiout->text (" hits\n");
+ uiout->message ("\tignore next %pF hits\n",
+ signed_field ("ignore", b->ignore_count));
}
/* Note that an enable count of 1 corresponds to "enable once"
@@ -6658,9 +6656,9 @@ describe_other_breakpoints (struct gdbarch *gdbarch,
(others > 1) ? ","
: ((others == 1) ? " and" : ""));
}
- printf_filtered (_("also set at pc "));
- fputs_styled (paddress (gdbarch, pc), address_style.style (), gdb_stdout);
- printf_filtered (".\n");
+ current_uiout->message (_("also set at pc %ps.\n"),
+ styled_string (address_style.style (),
+ paddress (gdbarch, pc)));
}
}
\f
@@ -12075,23 +12073,21 @@ say_where (struct breakpoint *b)
else
{
if (opts.addressprint || b->loc->symtab == NULL)
- {
- printf_filtered (" at ");
- fputs_styled (paddress (b->loc->gdbarch, b->loc->address),
- address_style.style (),
- gdb_stdout);
- }
+ printf_filtered (" at %ps",
+ styled_string (address_style.style (),
+ paddress (b->loc->gdbarch,
+ b->loc->address)));
if (b->loc->symtab != NULL)
{
/* If there is a single location, we can print the location
more nicely. */
if (b->loc->next == NULL)
{
- puts_filtered (": file ");
- fputs_styled (symtab_to_filename_for_display (b->loc->symtab),
- file_name_style.style (),
- gdb_stdout);
- printf_filtered (", line %d.",
+ const char *filename
+ = symtab_to_filename_for_display (b->loc->symtab);
+ printf_filtered (": file %ps, line %d.",
+ styled_string (file_name_style.style (),
+ filename),
b->loc->line_number);
}
else
@@ -12389,18 +12385,18 @@ bkpt_print_it (bpstat bs)
annotate_breakpoint (b->number);
maybe_print_thread_hit_breakpoint (uiout);
- if (bp_temp)
- uiout->text ("Temporary breakpoint ");
- else
- uiout->text ("Breakpoint ");
if (uiout->is_mi_like_p ())
{
uiout->field_string ("reason",
async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT));
uiout->field_string ("disp", bpdisp_text (b->disposition));
}
- uiout->field_signed ("bkptno", b->number);
- uiout->text (", ");
+ if (bp_temp)
+ uiout->message ("Temporary breakpoint %pF, ",
+ signed_field ("bkptno", b->number));
+ else
+ uiout->message ("Breakpoint %pF, ",
+ signed_field ("bkptno", b->number));
return PRINT_SRC_AND_LOC;
}
@@ -12716,10 +12712,9 @@ tracepoint_print_one_detail (const struct breakpoint *self,
{
gdb_assert (self->type == bp_static_tracepoint);
- uiout->text ("\tmarker id is ");
- uiout->field_string ("static-tracepoint-marker-string-id",
- tp->static_trace_marker_id);
- uiout->text ("\n");
+ uiout->message ("\tmarker id is %pF\n",
+ string_field ("static-tracepoint-marker-string-id",
+ tp->static_trace_marker_id.c_str ()));
}
}
diff --git a/gdb/infrun.c b/gdb/infrun.c
index be29cbe4f51..07aebfa678f 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -7656,24 +7656,19 @@ print_exited_reason (struct ui_out *uiout, int exitstatus)
{
if (uiout->is_mi_like_p ())
uiout->field_string ("reason", async_reason_lookup (EXEC_ASYNC_EXITED));
- uiout->text ("[Inferior ");
- uiout->text (plongest (inf->num));
- uiout->text (" (");
- uiout->text (pidstr.c_str ());
- uiout->text (") exited with code ");
- uiout->field_fmt ("exit-code", "0%o", (unsigned int) exitstatus);
- uiout->text ("]\n");
+ std::string exit_code_str
+ = string_printf ("0%o", (unsigned int) exitstatus);
+ uiout->message ("[Inferior %s (%s) exited with code %pF]\n",
+ plongest (inf->num), pidstr.c_str (),
+ string_field ("exit-code", exit_code_str.c_str ()));
}
else
{
if (uiout->is_mi_like_p ())
uiout->field_string
("reason", async_reason_lookup (EXEC_ASYNC_EXITED_NORMALLY));
- uiout->text ("[Inferior ");
- uiout->text (plongest (inf->num));
- uiout->text (" (");
- uiout->text (pidstr.c_str ());
- uiout->text (") exited normally]\n");
+ uiout->message ("[Inferior %s (%s) exited normally]\n",
+ plongest (inf->num), pidstr.c_str ());
}
}
diff --git a/gdb/macrocmd.c b/gdb/macrocmd.c
index 0f81c3d5da4..cb7267d07a3 100644
--- a/gdb/macrocmd.c
+++ b/gdb/macrocmd.c
@@ -120,8 +120,10 @@ show_pp_source_pos (struct ui_file *stream,
int line)
{
std::string fullname = macro_source_fullname (file);
- fputs_styled (fullname.c_str (), file_name_style.style (), stream);
- fprintf_filtered (stream, ":%d\n", line);
+ fprintf_filtered (stream, "%ps:%d\n",
+ styled_string (file_name_style.style (),
+ fullname.c_str ()),
+ line);
while (file->included_by)
{
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index b3f7b59863b..c17afe29bb2 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -2214,9 +2214,8 @@ print_variable_and_value (const char *name, struct symbol *var,
if (!name)
name = SYMBOL_PRINT_NAME (var);
- fputs_filtered (n_spaces (2 * indent), stream);
- fputs_styled (name, variable_name_style.style (), stream);
- fputs_filtered (" = ", stream);
+ fprintf_filtered (stream, "%s%ps = ", n_spaces (2 * indent),
+ styled_string (variable_name_style.style (), name));
try
{
diff --git a/gdb/symfile.c b/gdb/symfile.c
index b914b05a175..ca1360f0a7e 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1106,11 +1106,8 @@ symbol_file_add_with_addrs (bfd *abfd, const char *name,
if (deprecated_pre_add_symbol_hook)
deprecated_pre_add_symbol_hook (name);
else
- {
- puts_filtered (_("Reading symbols from "));
- fputs_styled (name, file_name_style.style (), gdb_stdout);
- puts_filtered ("...\n");
- }
+ printf_filtered (_("Reading symbols from %ps...\n"),
+ styled_string (file_name_style.style (), name));
}
syms_from_objfile (objfile, addrs, add_flags);
@@ -1122,7 +1119,8 @@ symbol_file_add_with_addrs (bfd *abfd, const char *name,
if ((flags & OBJF_READNOW))
{
if (should_print)
- printf_filtered (_("Expanding full symbols from %s...\n"), name);
+ printf_filtered (_("Expanding full symbols from %ps...\n"),
+ styled_string (file_name_style.style (), name));
if (objfile->sf)
objfile->sf->qf->expand_all_symtabs (objfile);
@@ -1134,7 +1132,8 @@ symbol_file_add_with_addrs (bfd *abfd, const char *name,
file, and so printing it twice is just redundant. */
if (should_print && !objfile_has_symbols (objfile)
&& objfile->separate_debug_objfile == nullptr)
- printf_filtered (_("(No debugging symbols found in %s)\n"), name);
+ printf_filtered (_("(No debugging symbols found in %ps)\n"),
+ styled_string (file_name_style.style (), name));
if (should_print)
{
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 6ea9fc6971e..df6b87f9483 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -4748,9 +4748,9 @@ print_symbol_info (enum search_domain kind,
if (filename_cmp (last, s_filename) != 0)
{
- fputs_filtered ("\nFile ", gdb_stdout);
- fputs_styled (s_filename, file_name_style.style (), gdb_stdout);
- fputs_filtered (":\n", gdb_stdout);
+ printf_filtered (_("\nFile %ps:\n"),
+ styled_string (file_name_style.style (),
+ s_filename));
}
if (SYMBOL_LINE (sym) != 0)
@@ -4812,15 +4812,15 @@ print_msymbol_info (struct bound_minimal_symbol msymbol)
else
tmp = hex_string_custom (BMSYMBOL_VALUE_ADDRESS (msymbol),
16);
- fputs_styled (tmp, address_style.style (), gdb_stdout);
- fputs_filtered (" ", gdb_stdout);
- if (msymbol.minsym->text_p ())
- fputs_styled (MSYMBOL_PRINT_NAME (msymbol.minsym),
- function_name_style.style (),
- gdb_stdout);
- else
- fputs_filtered (MSYMBOL_PRINT_NAME (msymbol.minsym), gdb_stdout);
- fputs_filtered ("\n", gdb_stdout);
+
+ ui_file_style sym_style = (msymbol.minsym->text_p ()
+ ? function_name_style.style ()
+ : ui_file_style ());
+
+ printf_filtered (_("%ps %ps\n"),
+ styled_string (address_style.style (), tmp),
+ styled_string (sym_style,
+ MSYMBOL_PRINT_NAME (msymbol.minsym)));
}
/* This is the guts of the commands "info functions", "info types", and
--
2.17.2
^ permalink raw reply [flat|nested] 16+ messages in thread* [PATCH 5/8] Style "pwd" output
2019-09-27 21:25 [PATCH 0/8] More gdb styling improvements Tom Tromey
` (3 preceding siblings ...)
2019-09-27 21:25 ` [PATCH 4/8] Use new %p format suffixes in gdb Tom Tromey
@ 2019-09-27 21:25 ` Tom Tromey
2019-09-27 21:25 ` [PATCH 3/8] Introduce gdb-specific %p format suffixes Tom Tromey
` (3 subsequent siblings)
8 siblings, 0 replies; 16+ messages in thread
From: Tom Tromey @ 2019-09-27 21:25 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changes the "pwd" command to style its output.
gdb/ChangeLog
2019-09-27 Tom Tromey <tom@tromey.com>
* cli/cli-cmds.c (pwd_command): Style output.
gdb/testsuite/ChangeLog
2019-09-27 Tom Tromey <tom@tromey.com>
* gdb.base/style.exp: Test "pwd".
---
gdb/ChangeLog | 4 ++++
gdb/cli/cli-cmds.c | 11 ++++++++---
gdb/testsuite/ChangeLog | 4 ++++
gdb/testsuite/gdb.base/style.exp | 2 ++
4 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 59c71f67561..9f7b052d8e0 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -49,6 +49,7 @@
#include "cli/cli-script.h"
#include "cli/cli-setshow.h"
#include "cli/cli-cmds.h"
+#include "cli/cli-style.h"
#include "cli/cli-utils.h"
#include "extension.h"
@@ -451,10 +452,14 @@ pwd_command (const char *args, int from_tty)
safe_strerror (errno));
if (strcmp (cwd.get (), current_directory) != 0)
- printf_unfiltered (_("Working directory %s\n (canonically %s).\n"),
- current_directory, cwd.get ());
+ printf_unfiltered (_("Working directory %ps\n (canonically %ps).\n"),
+ styled_string (file_name_style.style (),
+ current_directory),
+ styled_string (file_name_style.style (), cwd.get ()));
else
- printf_unfiltered (_("Working directory %s.\n"), current_directory);
+ printf_unfiltered (_("Working directory %ps.\n"),
+ styled_string (file_name_style.style (),
+ current_directory));
}
void
diff --git a/gdb/testsuite/gdb.base/style.exp b/gdb/testsuite/gdb.base/style.exp
index d2c3105bb9f..fb0dfed0061 100644
--- a/gdb/testsuite/gdb.base/style.exp
+++ b/gdb/testsuite/gdb.base/style.exp
@@ -131,4 +131,6 @@ save_vars { env(TERM) } {
gdb_test "file $binfile" \
"Reading symbols from [style $quoted file]..." \
"filename is styled when loading symbol file"
+
+ gdb_test "pwd" "Working directory [style .*? file].*"
}
--
2.17.2
^ permalink raw reply [flat|nested] 16+ messages in thread* [PATCH 3/8] Introduce gdb-specific %p format suffixes
2019-09-27 21:25 [PATCH 0/8] More gdb styling improvements Tom Tromey
` (4 preceding siblings ...)
2019-09-27 21:25 ` [PATCH 5/8] Style "pwd" output Tom Tromey
@ 2019-09-27 21:25 ` Tom Tromey
2019-09-30 14:06 ` Pedro Alves
2021-08-18 9:02 ` Andreas Schwab
2019-09-27 21:25 ` [PATCH 2/8] Don't create empty literal pieces Tom Tromey
` (2 subsequent siblings)
8 siblings, 2 replies; 16+ messages in thread
From: Tom Tromey @ 2019-09-27 21:25 UTC (permalink / raw)
To: gdb-patches; +Cc: Pedro Alves
From: Pedro Alves <palves@redhat.com>
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-09-27 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-09-27 Tom Tromey <tom@tromey.com>
* gdb.base/style.exp: Update tests.
---
gdb/ChangeLog | 47 ++++++
gdb/cli-out.c | 31 +++-
gdb/cli-out.h | 5 +-
gdb/gdbsupport/format.c | 166 +++++++++++++--------
gdb/gdbsupport/format.h | 11 +-
gdb/mi/mi-out.c | 3 +-
gdb/mi/mi-out.h | 5 +-
gdb/testsuite/ChangeLog | 4 +
gdb/testsuite/gdb.base/style.exp | 10 +-
gdb/ui-out.c | 182 +++++++++++++++++++++++-
gdb/ui-out.h | 142 +++++++++++++++++-
gdb/ui-style.h | 6 +
gdb/unittests/format_pieces-selftests.c | 35 +++--
gdb/utils.c | 81 +++++++++--
gdb/utils.h | 25 +++-
15 files changed, 646 insertions(+), 107 deletions(-)
diff --git a/gdb/cli-out.c b/gdb/cli-out.c
index fa72a1d344f..c713607e068 100644
--- a/gdb/cli-out.c
+++ b/gdb/cli-out.c
@@ -170,7 +170,12 @@ cli_ui_out::do_field_string (int fldno, int width, ui_align align,
spaces (before);
if (string)
- fputs_styled (string, style, m_streams.back ());
+ {
+ if (test_flags (unfiltered_output))
+ fputs_styled_unfiltered (string, style, m_streams.back ());
+ else
+ fputs_styled (string, style, m_streams.back ());
+ }
if (after)
spaces (after);
@@ -201,7 +206,10 @@ cli_ui_out::do_spaces (int numspaces)
if (m_suppress_output)
return;
- print_spaces_filtered (numspaces, m_streams.back ());
+ if (test_flags (unfiltered_output))
+ print_spaces (numspaces, m_streams.back ());
+ else
+ print_spaces_filtered (numspaces, m_streams.back ());
}
void
@@ -210,16 +218,24 @@ cli_ui_out::do_text (const char *string)
if (m_suppress_output)
return;
- fputs_filtered (string, m_streams.back ());
+ if (test_flags (unfiltered_output))
+ fputs_unfiltered (string, m_streams.back ());
+ else
+ fputs_filtered (string, m_streams.back ());
}
void
-cli_ui_out::do_message (const char *format, va_list args)
+cli_ui_out::do_message (const ui_file_style &style,
+ const char *format, va_list args)
{
if (m_suppress_output)
return;
- vfprintf_unfiltered (m_streams.back (), format, args);
+ /* Use the "no_gdbfmt" variant here to avoid recursion.
+ vfprintf_styled calls into cli_ui_out::message to handle the
+ gdb-specific printf formats. */
+ vfprintf_styled_no_gdbfmt (m_streams.back (), style,
+ !test_flags (unfiltered_output), format, args);
}
void
@@ -255,7 +271,10 @@ cli_ui_out::do_redirect (ui_file *outstream)
void
cli_ui_out::field_separator ()
{
- fputc_filtered (' ', m_streams.back ());
+ if (test_flags (unfiltered_output))
+ fputc_unfiltered (' ', m_streams.back ());
+ else
+ fputc_filtered (' ', m_streams.back ());
}
/* Constructor for cli_ui_out. */
diff --git a/gdb/cli-out.h b/gdb/cli-out.h
index bc8b781d605..d7bd23b0ef2 100644
--- a/gdb/cli-out.h
+++ b/gdb/cli-out.h
@@ -64,8 +64,9 @@ protected:
override ATTRIBUTE_PRINTF (6,0);
virtual void do_spaces (int numspaces) override;
virtual void do_text (const char *string) override;
- virtual void do_message (const char *format, va_list args) override
- ATTRIBUTE_PRINTF (2,0);
+ virtual void do_message (const ui_file_style &style,
+ const char *format, va_list args) override
+ ATTRIBUTE_PRINTF (3,0);
virtual void do_wrap_hint (const char *identstring) override;
virtual void do_flush () override;
virtual void do_redirect (struct ui_file *outstream) override;
diff --git a/gdb/gdbsupport/format.c b/gdb/gdbsupport/format.c
index a5a367015f1..1e803501ae6 100644
--- a/gdb/gdbsupport/format.c
+++ b/gdb/gdbsupport/format.c
@@ -20,10 +20,10 @@
#include "common-defs.h"
#include "format.h"
-format_pieces::format_pieces (const char **arg)
+format_pieces::format_pieces (const char **arg, bool gdb_extensions)
{
const char *s;
- char *f, *string;
+ const char *string;
const char *prev_start;
const char *percent_loc;
char *sub_start, *current_substring;
@@ -31,70 +31,79 @@ format_pieces::format_pieces (const char **arg)
s = *arg;
- /* Parse the format-control string and copy it into the string STRING,
- processing some kinds of escape sequence. */
+ if (gdb_extensions)
+ {
+ string = *arg;
+ *arg += strlen (*arg);
+ }
+ else
+ {
+ /* Parse the format-control string and copy it into the string STRING,
+ processing some kinds of escape sequence. */
- f = string = (char *) alloca (strlen (s) + 1);
+ char *f = (char *) alloca (strlen (s) + 1);
+ string = f;
- while (*s != '"' && *s != '\0')
- {
- int c = *s++;
- switch (c)
+ while ((gdb_extensions || *s != '"') && *s != '\0')
{
- case '\0':
- continue;
-
- case '\\':
- switch (c = *s++)
+ int c = *s++;
+ switch (c)
{
+ case '\0':
+ continue;
+
case '\\':
- *f++ = '\\';
- break;
- case 'a':
- *f++ = '\a';
- break;
- case 'b':
- *f++ = '\b';
- break;
- case 'e':
- *f++ = '\e';
- break;
- case 'f':
- *f++ = '\f';
- break;
- case 'n':
- *f++ = '\n';
- break;
- case 'r':
- *f++ = '\r';
- break;
- case 't':
- *f++ = '\t';
- break;
- case 'v':
- *f++ = '\v';
- break;
- case '"':
- *f++ = '"';
+ switch (c = *s++)
+ {
+ case '\\':
+ *f++ = '\\';
+ break;
+ case 'a':
+ *f++ = '\a';
+ break;
+ case 'b':
+ *f++ = '\b';
+ break;
+ case 'e':
+ *f++ = '\e';
+ break;
+ case 'f':
+ *f++ = '\f';
+ break;
+ case 'n':
+ *f++ = '\n';
+ break;
+ case 'r':
+ *f++ = '\r';
+ break;
+ case 't':
+ *f++ = '\t';
+ break;
+ case 'v':
+ *f++ = '\v';
+ break;
+ case '"':
+ *f++ = '"';
+ break;
+ default:
+ /* ??? TODO: handle other escape sequences. */
+ error (_("Unrecognized escape character \\%c in format string."),
+ c);
+ }
break;
+
default:
- /* ??? TODO: handle other escape sequences. */
- error (_("Unrecognized escape character \\%c in format string."),
- c);
+ *f++ = c;
}
- break;
-
- default:
- *f++ = c;
}
- }
- /* Terminate our escape-processed copy. */
- *f++ = '\0';
+ /* Terminate our escape-processed copy. */
+ *f++ = '\0';
- /* Whether the format string ended with double-quote or zero, we're
- done with it; it's up to callers to complain about syntax. */
- *arg = s;
+ /* Whether the format string ended with double-quote or zero, we're
+ done with it; it's up to callers to complain about syntax. */
+ *arg = s;
+ }
/* Need extra space for the '\0's. Doubling the size is sufficient. */
@@ -105,7 +114,7 @@ format_pieces::format_pieces (const char **arg)
argclass classifies the %-specs so we can give printf-type functions
something of the right size. */
- f = string;
+ const char *f = string;
prev_start = string;
while (*f)
if (*f++ == '%')
@@ -115,6 +124,7 @@ format_pieces::format_pieces (const char **arg)
int seen_big_l = 0, seen_h = 0, seen_big_h = 0;
int seen_big_d = 0, seen_double_big_d = 0;
int bad = 0;
+ int n_int_args = 0;
/* Skip over "%%", it will become part of a literal piece. */
if (*f == '%')
@@ -130,7 +140,7 @@ format_pieces::format_pieces (const char **arg)
*current_substring++ = '\0';
if (*sub_start != '\0')
- m_pieces.emplace_back (sub_start, literal_piece);
+ m_pieces.emplace_back (sub_start, literal_piece, 0);
percent_loc = f - 1;
@@ -155,16 +165,32 @@ format_pieces::format_pieces (const char **arg)
}
/* The next part of a format specifier is a width. */
- while (*f != '\0' && strchr ("0123456789", *f))
- f++;
+ if (gdb_extensions && *f == '*')
+ {
+ ++f;
+ ++n_int_args;
+ }
+ else
+ {
+ while (*f != '\0' && strchr ("0123456789", *f))
+ f++;
+ }
/* The next part of a format specifier is a precision. */
if (*f == '.')
{
seen_prec = 1;
f++;
- while (*f != '\0' && strchr ("0123456789", *f))
- f++;
+ if (gdb_extensions && *f == '*')
+ {
+ ++f;
+ ++n_int_args;
+ }
+ else
+ {
+ while (*f != '\0' && strchr ("0123456789", *f))
+ f++;
+ }
}
/* The next part of a format specifier is a length modifier. */
@@ -252,6 +278,20 @@ format_pieces::format_pieces (const char **arg)
bad = 1;
if (seen_hash || seen_zero || seen_space || seen_plus)
bad = 1;
+
+ if (gdb_extensions)
+ {
+ switch (f[1])
+ {
+ case 's':
+ case 'F':
+ case '[':
+ case ']':
+ f++;
+ break;
+ }
+ }
+
break;
case 's':
@@ -336,7 +376,7 @@ format_pieces::format_pieces (const char **arg)
prev_start = f;
- m_pieces.emplace_back (sub_start, this_argclass);
+ m_pieces.emplace_back (sub_start, this_argclass, n_int_args);
}
/* Record the remainder of the string. */
@@ -349,6 +389,6 @@ format_pieces::format_pieces (const char **arg)
current_substring += f - prev_start;
*current_substring++ = '\0';
- m_pieces.emplace_back (sub_start, literal_piece);
+ m_pieces.emplace_back (sub_start, literal_piece, 0);
}
}
diff --git a/gdb/gdbsupport/format.h b/gdb/gdbsupport/format.h
index 08ef66a7602..e2a47ba5187 100644
--- a/gdb/gdbsupport/format.h
+++ b/gdb/gdbsupport/format.h
@@ -50,9 +50,10 @@ enum argclass
struct format_piece
{
- format_piece (const char *str, enum argclass argc)
+ format_piece (const char *str, enum argclass argc, int n)
: string (str),
- argclass (argc)
+ argclass (argc),
+ n_int_args (n)
{
}
@@ -64,13 +65,17 @@ struct format_piece
const char *string;
enum argclass argclass;
+ /* Count the number of preceding 'int' arguments that must be passed
+ along. This is used for a width or precision of '*'. Note that
+ this feature is only available in "gdb_extensions" mode. */
+ int n_int_args;
};
class format_pieces
{
public:
- format_pieces (const char **arg);
+ format_pieces (const char **arg, bool gdb_extensions = false);
~format_pieces () = default;
DISABLE_COPY_AND_ASSIGN (format_pieces);
diff --git a/gdb/mi/mi-out.c b/gdb/mi/mi-out.c
index 0b930738f1d..71af4865e97 100644
--- a/gdb/mi/mi-out.c
+++ b/gdb/mi/mi-out.c
@@ -166,7 +166,8 @@ mi_ui_out::do_text (const char *string)
}
void
-mi_ui_out::do_message (const char *format, va_list args)
+mi_ui_out::do_message (const ui_file_style &style,
+ const char *format, va_list args)
{
}
diff --git a/gdb/mi/mi-out.h b/gdb/mi/mi-out.h
index 90528fd4e84..9393809b5f2 100644
--- a/gdb/mi/mi-out.h
+++ b/gdb/mi/mi-out.h
@@ -72,8 +72,9 @@ protected:
override ATTRIBUTE_PRINTF (6,0);
virtual void do_spaces (int numspaces) override;
virtual void do_text (const char *string) override;
- virtual void do_message (const char *format, va_list args) override
- ATTRIBUTE_PRINTF (2,0);
+ virtual void do_message (const ui_file_style &style,
+ const char *format, va_list args) override
+ ATTRIBUTE_PRINTF (3,0);
virtual void do_wrap_hint (const char *identstring) override;
virtual void do_flush () override;
virtual void do_redirect (struct ui_file *outstream) override;
diff --git a/gdb/testsuite/gdb.base/style.exp b/gdb/testsuite/gdb.base/style.exp
index 41c43dc8f7c..d2c3105bb9f 100644
--- a/gdb/testsuite/gdb.base/style.exp
+++ b/gdb/testsuite/gdb.base/style.exp
@@ -94,13 +94,13 @@ save_vars { env(TERM) } {
gdb_test "" "${vers}.*" \
"version is styled"
- set address_style_expr [style "\"address\" style" address]
+ set address_style_expr [style ".*\".*address.*\".*style.*" address]
gdb_test "show style address foreground" \
"The ${address_style_expr} foreground color is: blue" \
"style name and style word styled using its own style in show style"
- set aliases_expr [style "aliases" title]
- set breakpoints_expr [style "breakpoints" title]
+ set aliases_expr [style ".*aliases.*" title]
+ set breakpoints_expr [style ".*breakpoints.*" title]
gdb_test "help" \
[multi_line \
"List of classes of commands:" \
@@ -111,8 +111,8 @@ save_vars { env(TERM) } {
] \
"help classes of commands styled with title"
- set taas_expr [style "taas" title]
- set tfaas_expr [style "tfaas" title]
+ set taas_expr [style ".*taas.*" title]
+ set tfaas_expr [style ".*tfaas.*" title]
set cut_for_thre_expr [style "cut for 'thre" highlight]
gdb_test "apropos -v cut for 'thre" \
[multi_line \
diff --git a/gdb/ui-out.c b/gdb/ui-out.c
index e8fe44c8268..8cbaa4e0bc1 100644
--- a/gdb/ui-out.c
+++ b/gdb/ui-out.c
@@ -563,12 +563,190 @@ ui_out::text (const char *string)
}
void
-ui_out::message (const char *format, ...)
+ui_out::call_do_message (const ui_file_style &style, const char *format,
+ ...)
{
va_list args;
va_start (args, format);
- do_message (format, args);
+ do_message (style, format, args);
+ va_end (args);
+}
+
+void
+ui_out::vmessage (const ui_file_style &in_style, const char *format,
+ va_list args)
+{
+ format_pieces fpieces (&format, true);
+
+ ui_file_style style = in_style;
+
+ for (auto &&piece : fpieces)
+ {
+ const char *current_substring = piece.string;
+
+ gdb_assert (piece.n_int_args >= 0 && piece.n_int_args <= 2);
+ int intvals[2] = { 0, 0 };
+ for (int i = 0; i < piece.n_int_args; ++i)
+ intvals[i] = va_arg (args, int);
+
+ /* The only ones we support for now. */
+ gdb_assert (piece.n_int_args == 0
+ || piece.argclass == string_arg
+ || piece.argclass == int_arg
+ || piece.argclass == long_arg);
+
+ switch (piece.argclass)
+ {
+ case string_arg:
+ {
+ const char *str = va_arg (args, const char *);
+ switch (piece.n_int_args)
+ {
+ case 0:
+ call_do_message (style, current_substring, str);
+ break;
+ case 1:
+ call_do_message (style, current_substring, intvals[0], str);
+ break;
+ case 2:
+ call_do_message (style, current_substring,
+ intvals[0], intvals[1], str);
+ break;
+ }
+ }
+ break;
+ case wide_string_arg:
+ gdb_assert_not_reached (_("wide_string_arg not supported in vmessage"));
+ break;
+ case wide_char_arg:
+ gdb_assert_not_reached (_("wide_char_arg not supported in vmessage"));
+ break;
+ case long_long_arg:
+ call_do_message (style, current_substring, va_arg (args, long long));
+ break;
+ case int_arg:
+ {
+ int val = va_arg (args, int);
+ switch (piece.n_int_args)
+ {
+ case 0:
+ call_do_message (style, current_substring, val);
+ break;
+ case 1:
+ call_do_message (style, current_substring, intvals[0], val);
+ break;
+ case 2:
+ call_do_message (style, current_substring,
+ intvals[0], intvals[1], val);
+ break;
+ }
+ }
+ break;
+ case long_arg:
+ {
+ long val = va_arg (args, long);
+ switch (piece.n_int_args)
+ {
+ case 0:
+ call_do_message (style, current_substring, val);
+ break;
+ case 1:
+ call_do_message (style, current_substring, intvals[0], val);
+ break;
+ case 2:
+ call_do_message (style, current_substring,
+ intvals[0], intvals[1], val);
+ break;
+ }
+ }
+ break;
+ case double_arg:
+ call_do_message (style, current_substring, va_arg (args, double));
+ break;
+ case long_double_arg:
+ gdb_assert_not_reached (_("long_double_arg not supported in vmessage"));
+ break;
+ case dec32float_arg:
+ gdb_assert_not_reached (_("dec32float_arg not supported in vmessage"));
+ break;
+ case dec64float_arg:
+ gdb_assert_not_reached (_("dec64float_arg not supported in vmessage"));
+ break;
+ case dec128float_arg:
+ gdb_assert_not_reached (_("dec128float_arg not supported in vmessage"));
+ break;
+ case ptr_arg:
+ switch (current_substring[2])
+ {
+ case 'F':
+ {
+ gdb_assert (!test_flags (disallow_ui_out_field));
+ base_field_s *bf = va_arg (args, base_field_s *);
+ switch (bf->kind)
+ {
+ case field_kind::SIGNED:
+ {
+ auto *f = (signed_field_s *) bf;
+ field_signed (f->name, f->val);
+ }
+ break;
+ case field_kind::STRING:
+ {
+ auto *f = (string_field_s *) bf;
+ field_string (f->name, f->str);
+ }
+ break;
+ }
+ }
+ break;
+ case 's':
+ {
+ styled_string_s *ss = va_arg (args, styled_string_s *);
+ call_do_message (ss->style, "%s", ss->str);
+ }
+ break;
+ case '[':
+ style = *va_arg (args, const ui_file_style *);
+ break;
+ case ']':
+ {
+ void *arg = va_arg (args, void *);
+ gdb_assert (arg == nullptr);
+
+ style = {};
+ }
+ break;
+ default:
+ call_do_message (style, current_substring, va_arg (args, void *));
+ break;
+ }
+ break;
+ case literal_piece:
+ /* Print a portion of the format string that has no
+ directives. Note that this will not include any ordinary
+ %-specs, but it might include "%%". That is why we use
+ call_do_message here. Also, we pass a dummy argument
+ because some platforms have modified GCC to include
+ -Wformat-security by default, which will warn here if
+ there is no argument. */
+ call_do_message (style, current_substring, 0);
+ break;
+ default:
+ internal_error (__FILE__, __LINE__,
+ _("failed internal consistency check"));
+ }
+ }
+}
+
+void
+ui_out::message (const char *format, ...)
+{
+ va_list args;
+ va_start (args, format);
+
+ vmessage (ui_file_style (), format, args);
+
va_end (args);
}
diff --git a/gdb/ui-out.h b/gdb/ui-out.h
index 6732f046719..d8adf7b7f0d 100644
--- a/gdb/ui-out.h
+++ b/gdb/ui-out.h
@@ -53,6 +53,12 @@ enum ui_out_flag
{
ui_source_list = (1 << 0),
fix_multi_location_breakpoint_output = (1 << 1),
+ /* For CLI output, this flag is set if unfiltered output is desired.
+ This should only be used by low-level formatting functions. */
+ unfiltered_output = (1 << 2),
+ /* This indicates that %pF should be disallowed in a printf format
+ string. */
+ disallow_ui_out_field = (1 << 3)
};
DEF_ENUM_FLAGS_TYPE (ui_out_flag, ui_out_flags);
@@ -68,6 +74,87 @@ enum ui_out_type
ui_out_type_list
};
+/* The possible kinds of fields. */
+enum class field_kind
+ {
+ SIGNED,
+ STRING,
+ };
+
+/* An int field, to be passed to %pF in format strings. */
+
+struct base_field_s
+{
+ const char *name;
+ field_kind kind;
+};
+
+/* An int field, to be passed to %pF in format strings. */
+
+struct signed_field_s : base_field_s
+{
+ LONGEST val;
+};
+
+/* Construct a temporary signed_field_s on the caller's stack and
+ return a pointer to the constructed object. We use this because
+ it's not possible to pass a reference via va_args. */
+
+static inline signed_field_s *
+signed_field (const char *name, LONGEST val,
+ signed_field_s &&tmp = {})
+{
+ tmp.name = name;
+ tmp.kind = field_kind::SIGNED;
+ tmp.val = val;
+ return &tmp;
+}
+
+/* A string field, to be passed to %pF in format strings. */
+
+struct string_field_s : base_field_s
+{
+ const char *str;
+};
+
+/* Construct a temporary string_field_s on the caller's stack and
+ return a pointer to the constructed object. We use this because
+ it's not possible to pass a reference via va_args. */
+
+static inline string_field_s *
+string_field (const char *name, const char *str,
+ string_field_s &&tmp = {})
+{
+ tmp.name = name;
+ tmp.kind = field_kind::STRING;
+ tmp.str = str;
+ return &tmp;
+}
+
+/* A styled string. */
+
+struct styled_string_s
+{
+ /* The style. */
+ ui_file_style style;
+
+ /* The string. */
+ const char *str;
+};
+
+/* Construct a temporary styled_string_s on the caller's stack and
+ return a pointer to the constructed object. We use this because
+ it's not possible to pass a reference via va_args. */
+
+static inline styled_string_s *
+styled_string (const ui_file_style &style, const char *str,
+ styled_string_s &&tmp = {})
+{
+ tmp.style = style;
+ tmp.str = str;
+ return &tmp;
+}
+
class ui_out
{
public:
@@ -110,7 +197,55 @@ class ui_out
void spaces (int numspaces);
void text (const char *string);
+
+ /* Output a printf-style formatted string. In addition to the usual
+ printf format specs, this supports a few GDB-specific
+ formatters:
+
+ - '%pF' - output a field.
+
+ The argument is a field, wrapped in any of the base_field_s
+ subclasses. signed_field for integer fields, styled_field for
+ string fields. This is preferred over separate
+ uiout->field_int(), uiout_>field_string() etc. calls when the
+ formatted message is translatable. E.g.:
+
+ uiout->message (_("\nWatchpoint %pF deleted because the program has "
+ "left the block in\n"
+ "which its expression is valid.\n"),
+ signed_field ("wpnum", b->number));
+
+ - '%p[' - output the following text in a specified style.
+ '%p]' - output the following text in the default style.
+
+ The argument to '%p[' is a ui_file_style pointer. The argument
+ to '%p]' must be nullptr.
+
+ This is useful when you want to output some portion of a string
+ literal in some style. E.g.:
+
+ uiout->message (_(" %p[<repeats %u times>%p]"),
+ metadata_style.style ().ptr (),
+ reps, repeats, nullptr);
+
+ - '%ps' - output a styled string.
+
+ The argument is the result of a call to styled_string. This is
+ useful when you want to output some runtime-generated string in
+ some style. E.g.:
+
+ uiout->message (_("this is a target address %ps.\n"),
+ styled_string (address_style.style (),
+ paddress (gdbarch, pc)));
+
+ Note that these all "abuse" the %p printf format spec, in order
+ to be compatible with GCC's printf format checking. This is OK
+ because code in GDB that wants to print a host address should use
+ host_address_to_string instead of %p. */
void message (const char *format, ...) ATTRIBUTE_PRINTF (2, 3);
+ void vmessage (const ui_file_style &in_style,
+ const char *format, va_list args) ATTRIBUTE_PRINTF (3, 0);
+
void wrap_hint (const char *identstring);
void flush ();
@@ -161,8 +296,9 @@ class ui_out
ATTRIBUTE_PRINTF (6,0) = 0;
virtual void do_spaces (int numspaces) = 0;
virtual void do_text (const char *string) = 0;
- virtual void do_message (const char *format, va_list args)
- ATTRIBUTE_PRINTF (2,0) = 0;
+ virtual void do_message (const ui_file_style &style,
+ const char *format, va_list args)
+ ATTRIBUTE_PRINTF (3,0) = 0;
virtual void do_wrap_hint (const char *identstring) = 0;
virtual void do_flush () = 0;
virtual void do_redirect (struct ui_file *outstream) = 0;
@@ -174,6 +310,8 @@ class ui_out
{ return false; }
private:
+ void call_do_message (const ui_file_style &style, const char *format,
+ ...);
ui_out_flags m_flags;
diff --git a/gdb/ui-style.h b/gdb/ui-style.h
index 24b4b59ed9f..d2e9c136263 100644
--- a/gdb/ui-style.h
+++ b/gdb/ui-style.h
@@ -223,6 +223,12 @@ struct ui_file_style
BUF. */
bool parse (const char *buf, size_t *n_read);
+ /* We need this because we can't pass a reference via va_args. */
+ const ui_file_style *ptr () const
+ {
+ return this;
+ }
+
private:
color m_foreground = NONE;
diff --git a/gdb/unittests/format_pieces-selftests.c b/gdb/unittests/format_pieces-selftests.c
index 862b2da0f48..ed83d9670fd 100644
--- a/gdb/unittests/format_pieces-selftests.c
+++ b/gdb/unittests/format_pieces-selftests.c
@@ -27,9 +27,10 @@ namespace format_pieces {
/* Verify that parsing STR gives pieces equal to EXPECTED_PIECES. */
static void
-check (const char *str, const std::vector<format_piece> &expected_pieces)
+check (const char *str, const std::vector<format_piece> &expected_pieces,
+ bool gdb_format = false)
{
- ::format_pieces pieces (&str);
+ ::format_pieces pieces (&str, gdb_format);
SELF_CHECK ((pieces.end () - pieces.begin ()) == expected_pieces.size ());
SELF_CHECK (std::equal (pieces.begin (), pieces.end (),
@@ -41,7 +42,7 @@ test_escape_sequences ()
{
check ("This is an escape sequence: \\e",
{
- format_piece ("This is an escape sequence: \e", literal_piece),
+ format_piece ("This is an escape sequence: \e", literal_piece, 0),
});
}
@@ -50,21 +51,37 @@ test_format_specifier ()
{
/* The format string here ends with a % sequence, to ensure we don't
see a trailing empty literal piece. */
- check ("Hello %d%llx%%d%d", /* ARI: %ll */
+ check ("Hello\\t %d%llx%%d%d", /* ARI: %ll */
{
- format_piece ("Hello ", literal_piece),
- format_piece ("%d", int_arg),
- format_piece ("%llx", long_long_arg), /* ARI: %ll */
- format_piece ("%%d", literal_piece),
- format_piece ("%d", int_arg),
+ format_piece ("Hello\t ", literal_piece, 0),
+ format_piece ("%d", int_arg, 0),
+ format_piece ("%llx", long_long_arg, 0), /* ARI: %ll */
+ format_piece ("%%d", literal_piece, 0),
+ format_piece ("%d", int_arg, 0),
});
}
+static void
+test_gdb_formats ()
+{
+ check ("Hello\\t \"%p[%pF%ps%*.*d%p]\"",
+ {
+ format_piece ("Hello\\t \"", literal_piece, 0),
+ format_piece ("%p[", ptr_arg, 0),
+ format_piece ("%pF", ptr_arg, 0),
+ format_piece ("%ps", ptr_arg, 0),
+ format_piece ("%*.*d", int_arg, 2),
+ format_piece ("%p]", ptr_arg, 0),
+ format_piece ("\"", literal_piece, 0),
+ }, true);
+}
+
static void
run_tests ()
{
test_escape_sequences ();
test_format_specifier ();
+ test_gdb_formats ();
}
} /* namespace format_pieces */
diff --git a/gdb/utils.c b/gdb/utils.c
index b7d380073ff..e685cc20847 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -73,13 +73,15 @@
#include "cli/cli-style.h"
#include "gdbsupport/scope-exit.h"
#include "gdbarch.h"
+#include "cli-out.h"
void (*deprecated_error_begin_hook) (void);
/* Prototypes for local functions */
static void vfprintf_maybe_filtered (struct ui_file *, const char *,
- va_list, int) ATTRIBUTE_PRINTF (2, 0);
+ va_list, bool, bool)
+ ATTRIBUTE_PRINTF (2, 0);
static void fputs_maybe_filtered (const char *, struct ui_file *, int);
@@ -1854,6 +1856,24 @@ fputs_styled (const char *linebuffer, const ui_file_style &style,
/* See utils.h. */
+void
+fputs_styled_unfiltered (const char *linebuffer, const ui_file_style &style,
+ struct ui_file *stream)
+{
+ /* This just makes it so we emit somewhat fewer escape
+ sequences. */
+ if (style.is_default ())
+ fputs_maybe_filtered (linebuffer, stream, 0);
+ else
+ {
+ set_output_style (stream, style);
+ fputs_maybe_filtered (linebuffer, stream, 0);
+ set_output_style (stream, ui_file_style ());
+ }
+}
+
+/* See utils.h. */
+
void
fputs_highlighted (const char *str, const compiled_regex &highlight,
struct ui_file *stream)
@@ -2021,34 +2041,46 @@ puts_debug (char *prefix, char *string, char *suffix)
We implement three variants, vfprintf (takes a vararg list and stream),
fprintf (takes a stream to write on), and printf (the usual).
- Note also that a longjmp to top level may occur in this routine
- (since prompt_for_continue may do so) so this routine should not be
- called when cleanups are not in place. */
+ Note also that this may throw a quit (since prompt_for_continue may
+ do so). */
static void
vfprintf_maybe_filtered (struct ui_file *stream, const char *format,
- va_list args, int filter)
+ va_list args, bool filter, bool gdbfmt)
{
- std::string linebuffer = string_vprintf (format, args);
- fputs_maybe_filtered (linebuffer.c_str (), stream, filter);
+ if (gdbfmt)
+ {
+ ui_out_flags flags = disallow_ui_out_field;
+ if (!filter)
+ flags |= unfiltered_output;
+ cli_ui_out (stream, flags).vmessage (applied_style, format, args);
+ }
+ else
+ {
+ std::string str = string_vprintf (format, args);
+ fputs_maybe_filtered (str.c_str (), stream, filter);
+ }
}
void
vfprintf_filtered (struct ui_file *stream, const char *format, va_list args)
{
- vfprintf_maybe_filtered (stream, format, args, 1);
+ vfprintf_maybe_filtered (stream, format, args, true, true);
}
void
vfprintf_unfiltered (struct ui_file *stream, const char *format, va_list args)
{
- std::string linebuffer = string_vprintf (format, args);
if (debug_timestamp && stream == gdb_stdlog)
{
using namespace std::chrono;
int len, need_nl;
+ string_file sfile;
+ cli_ui_out (&sfile, 0).vmessage (ui_file_style (), format, args);
+ std::string linebuffer = std::move (sfile.string ());
+
steady_clock::time_point now = steady_clock::now ();
seconds s = duration_cast<seconds> (now.time_since_epoch ());
microseconds us = duration_cast<microseconds> (now.time_since_epoch () - s);
@@ -2064,13 +2096,13 @@ vfprintf_unfiltered (struct ui_file *stream, const char *format, va_list args)
fputs_unfiltered (timestamp.c_str (), stream);
}
else
- fputs_unfiltered (linebuffer.c_str (), stream);
+ vfprintf_maybe_filtered (stream, format, args, false, true);
}
void
vprintf_filtered (const char *format, va_list args)
{
- vfprintf_maybe_filtered (gdb_stdout, format, args, 1);
+ vfprintf_maybe_filtered (gdb_stdout, format, args, true, false);
}
void
@@ -2130,6 +2162,33 @@ fprintf_styled (struct ui_file *stream, const ui_file_style &style,
set_output_style (stream, ui_file_style ());
}
+/* See utils.h. */
+
+void
+vfprintf_styled (struct ui_file *stream, const ui_file_style &style,
+ const char *format, va_list args)
+{
+ set_output_style (stream, style);
+ vfprintf_filtered (stream, format, args);
+ set_output_style (stream, ui_file_style ());
+}
+
+/* See utils.h. */
+
+void
+vfprintf_styled_no_gdbfmt (struct ui_file *stream, const ui_file_style &style,
+ bool filter, const char *format, va_list args)
+{
+ std::string str = string_vprintf (format, args);
+ if (!str.empty ())
+ {
+ if (!style.is_default ())
+ set_output_style (stream, style);
+ fputs_maybe_filtered (str.c_str (), stream, filter);
+ if (!style.is_default ())
+ set_output_style (stream, ui_file_style ());
+ }
+}
void
printf_filtered (const char *format, ...)
diff --git a/gdb/utils.h b/gdb/utils.h
index 7df86beec47..76f0da69f71 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -350,7 +350,10 @@ extern struct ui_file *gdb_stdtargin;
extern void set_screen_width_and_height (int width, int height);
/* More generic printf like operations. Filtered versions may return
- non-locally on error. */
+ non-locally on error. As an extension over plain printf, these
+ support some GDB-specific format specifiers. Particularly useful
+ here are the styling formatters: '%p[', '%p]' and '%ps'. See
+ ui_out::message for details. */
extern void fputs_filtered (const char *, struct ui_file *);
@@ -430,6 +433,20 @@ extern void fprintf_styled (struct ui_file *stream,
...)
ATTRIBUTE_PRINTF (3, 4);
+extern void vfprintf_styled (struct ui_file *stream,
+ const ui_file_style &style,
+ const char *fmt,
+ va_list args)
+ ATTRIBUTE_PRINTF (3, 0);
+
+/* Like vfprintf_styled, but do not process gdb-specific format
+ specifiers. */
+extern void vfprintf_styled_no_gdbfmt (struct ui_file *stream,
+ const ui_file_style &style,
+ bool filter,
+ const char *fmt, va_list args)
+ ATTRIBUTE_PRINTF (4, 0);
+
/* Like fputs_filtered, but styles the output according to STYLE, when
appropriate. */
@@ -437,6 +454,12 @@ extern void fputs_styled (const char *linebuffer,
const ui_file_style &style,
struct ui_file *stream);
+/* Unfiltered variant of fputs_styled. */
+
+extern void fputs_styled_unfiltered (const char *linebuffer,
+ const ui_file_style &style,
+ struct ui_file *stream);
+
/* Like fputs_styled, but uses highlight_style to highlight the
parts of STR that match HIGHLIGHT. */
--
2.17.2
^ permalink raw reply [flat|nested] 16+ messages in thread* Re: [PATCH 3/8] Introduce gdb-specific %p format suffixes
2019-09-27 21:25 ` [PATCH 3/8] Introduce gdb-specific %p format suffixes Tom Tromey
@ 2019-09-30 14:06 ` Pedro Alves
2021-08-18 9:02 ` Andreas Schwab
1 sibling, 0 replies; 16+ messages in thread
From: Pedro Alves @ 2019-09-30 14:06 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
Hi,
I noticed a coupled typos while reading this, probably mine...
On 9/27/19 10:25 PM, Tom Tromey wrote:
> +/* The possible kinds of fields. */
> +enum class field_kind
> + {
> + SIGNED,
> + STRING,
> + };
> +
> +/* An int field, to be passed to %pF in format strings. */
This should read something like:
/* The base type of all fields. */
> +
> +struct base_field_s
> +{
> + const char *name;
> + field_kind kind;
> +};
> +
> +/* An int field, to be passed to %pF in format strings. */
This used to be called int_field_s, before the
'uiout->field_int -> uiout->field_signed' rename.
Should now read:
/* A signed integer field, to be passed to %pF in format strings. */
> +
> +struct signed_field_s : base_field_s
> +{
> + LONGEST val;
> +};
> +
> +/* Construct a temporary signed_field_s on the caller's stack and
> + return a pointer to the constructed object. We use this because
> + it's not possible to pass a reference via va_args. */
> +
> +static inline signed_field_s *
> +signed_field (const char *name, LONGEST val,
> + signed_field_s &&tmp = {})
> +{
> + tmp.name = name;
> + tmp.kind = field_kind::SIGNED;
> + tmp.val = val;
> + return &tmp;
> +}
> +
> +/* A string field, to be passed to %pF in format strings. */
> +
> +struct string_field_s : base_field_s
> +{
> + const char *str;
> +};
> +
> +/* Construct a temporary string_field_s on the caller's stack and
> + return a pointer to the constructed object. We use this because
> + it's not possible to pass a reference via va_args. */
> +
> +static inline string_field_s *
> +string_field (const char *name, const char *str,
> + string_field_s &&tmp = {})
> +{
> + tmp.name = name;
> + tmp.kind = field_kind::STRING;
> + tmp.str = str;
> + return &tmp;
> +}
> +
> +/* A styled string. */
> +
> +struct styled_string_s
> +{
> + /* The style. */
> + ui_file_style style;
> +
> + /* The string. */
> + const char *str;
> +};
> +
> +/* Construct a temporary styled_string_s on the caller's stack and
> + return a pointer to the constructed object. We use this because
> + it's not possible to pass a reference via va_args. */
> +
> +static inline styled_string_s *
> +styled_string (const ui_file_style &style, const char *str,
> + styled_string_s &&tmp = {})
> +{
> + tmp.style = style;
> + tmp.str = str;
> + return &tmp;
> +}
> +
> class ui_out
> {
> public:
> @@ -110,7 +197,55 @@ class ui_out
>
> void spaces (int numspaces);
> void text (const char *string);
> +
> + /* Output a printf-style formatted string. In addition to the usual
> + printf format specs, this supports a few GDB-specific
> + formatters:
> +
> + - '%pF' - output a field.
> +
> + The argument is a field, wrapped in any of the base_field_s
> + subclasses. signed_field for integer fields, styled_field for
styled_field -> string_field
> + string fields. This is preferred over separate
> + uiout->field_int(), uiout_>field_string() etc. calls when the
field_int -> field_signed
> + formatted message is translatable. E.g.:
> +
Thanks,
Pedro Alves
^ permalink raw reply [flat|nested] 16+ messages in thread* Re: [PATCH 3/8] Introduce gdb-specific %p format suffixes
2019-09-27 21:25 ` [PATCH 3/8] Introduce gdb-specific %p format suffixes Tom Tromey
2019-09-30 14:06 ` Pedro Alves
@ 2021-08-18 9:02 ` Andreas Schwab
2021-08-27 20:17 ` Tom Tromey
1 sibling, 1 reply; 16+ messages in thread
From: Andreas Schwab @ 2021-08-18 9:02 UTC (permalink / raw)
To: Tom Tromey; +Cc: Pedro Alves, gdb-patches
On Sep 27 2019, Tom Tromey wrote:
> void
> vfprintf_filtered (struct ui_file *stream, const char *format, va_list args)
> {
> - vfprintf_maybe_filtered (stream, format, args, 1);
> + vfprintf_maybe_filtered (stream, format, args, true, true);
> }
> void
> vprintf_filtered (const char *format, va_list args)
> {
> - vfprintf_maybe_filtered (gdb_stdout, format, args, 1);
> + vfprintf_maybe_filtered (gdb_stdout, format, args, true, false);
> }
Why is vprintf_filtered different from vfprintf_filtered (gdb_stdout)?
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
^ permalink raw reply [flat|nested] 16+ messages in thread* Re: [PATCH 3/8] Introduce gdb-specific %p format suffixes
2021-08-18 9:02 ` Andreas Schwab
@ 2021-08-27 20:17 ` Tom Tromey
0 siblings, 0 replies; 16+ messages in thread
From: Tom Tromey @ 2021-08-27 20:17 UTC (permalink / raw)
To: Andreas Schwab; +Cc: Pedro Alves, Tom Tromey, gdb-patches
>>>>> "Andreas" == Andreas Schwab <schwab@linux-m68k.org> writes:
Andreas> On Sep 27 2019, Tom Tromey wrote:
>> void
>> vfprintf_filtered (struct ui_file *stream, const char *format, va_list args)
>> {
>> - vfprintf_maybe_filtered (stream, format, args, 1);
>> + vfprintf_maybe_filtered (stream, format, args, true, true);
>> }
>> void
>> vprintf_filtered (const char *format, va_list args)
>> {
>> - vfprintf_maybe_filtered (gdb_stdout, format, args, 1);
>> + vfprintf_maybe_filtered (gdb_stdout, format, args, true, false);
>> }
Andreas> Why is vprintf_filtered different from vfprintf_filtered (gdb_stdout)?
I don't know. Changing that 'false' to 'true' doesn't cause any
regressions. And abstractly that seems like the right thing to do.
There's another thread about this as well, I'll reply there too.
Tom
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 2/8] Don't create empty literal pieces
2019-09-27 21:25 [PATCH 0/8] More gdb styling improvements Tom Tromey
` (5 preceding siblings ...)
2019-09-27 21:25 ` [PATCH 3/8] Introduce gdb-specific %p format suffixes Tom Tromey
@ 2019-09-27 21:25 ` Tom Tromey
2019-09-27 21:25 ` [PATCH 7/8] Use styled_string in more places Tom Tromey
2019-09-30 14:09 ` [PATCH 0/8] More gdb styling improvements Pedro Alves
8 siblings, 0 replies; 16+ messages in thread
From: Tom Tromey @ 2019-09-27 21:25 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
I noticed that format_pieces can create an empty literal piece.
However, there's never a need for one, so this patch removes the
possibility.
gdb/ChangeLog
2019-09-27 Tom Tromey <tom@tromey.com>
* unittests/format_pieces-selftests.c: Update. Add final format.
* gdbsupport/format.c (format_pieces::format_pieces): Don't add
empty literal pieces.
---
gdb/ChangeLog | 6 ++++++
gdb/gdbsupport/format.c | 16 ++++++++++------
gdb/unittests/format_pieces-selftests.c | 6 ++++--
3 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/gdb/gdbsupport/format.c b/gdb/gdbsupport/format.c
index fb3421e62bf..a5a367015f1 100644
--- a/gdb/gdbsupport/format.c
+++ b/gdb/gdbsupport/format.c
@@ -129,7 +129,8 @@ format_pieces::format_pieces (const char **arg)
current_substring += f - 1 - prev_start;
*current_substring++ = '\0';
- m_pieces.emplace_back (sub_start, literal_piece);
+ if (*sub_start != '\0')
+ m_pieces.emplace_back (sub_start, literal_piece);
percent_loc = f - 1;
@@ -340,11 +341,14 @@ format_pieces::format_pieces (const char **arg)
/* Record the remainder of the string. */
- sub_start = current_substring;
+ if (f > prev_start)
+ {
+ sub_start = current_substring;
- strncpy (current_substring, prev_start, f - prev_start);
- current_substring += f - prev_start;
- *current_substring++ = '\0';
+ strncpy (current_substring, prev_start, f - prev_start);
+ current_substring += f - prev_start;
+ *current_substring++ = '\0';
- m_pieces.emplace_back (sub_start, literal_piece);
+ m_pieces.emplace_back (sub_start, literal_piece);
+ }
}
diff --git a/gdb/unittests/format_pieces-selftests.c b/gdb/unittests/format_pieces-selftests.c
index 7d31b3cb93f..862b2da0f48 100644
--- a/gdb/unittests/format_pieces-selftests.c
+++ b/gdb/unittests/format_pieces-selftests.c
@@ -48,13 +48,15 @@ test_escape_sequences ()
static void
test_format_specifier ()
{
- check ("Hello %d%llx%%d", /* ARI: %ll */
+ /* The format string here ends with a % sequence, to ensure we don't
+ see a trailing empty literal piece. */
+ check ("Hello %d%llx%%d%d", /* ARI: %ll */
{
format_piece ("Hello ", literal_piece),
format_piece ("%d", int_arg),
- format_piece ("", literal_piece),
format_piece ("%llx", long_long_arg), /* ARI: %ll */
format_piece ("%%d", literal_piece),
+ format_piece ("%d", int_arg),
});
}
--
2.17.2
^ permalink raw reply [flat|nested] 16+ messages in thread* [PATCH 7/8] Use styled_string in more places
2019-09-27 21:25 [PATCH 0/8] More gdb styling improvements Tom Tromey
` (6 preceding siblings ...)
2019-09-27 21:25 ` [PATCH 2/8] Don't create empty literal pieces Tom Tromey
@ 2019-09-27 21:25 ` Tom Tromey
2019-09-30 14:09 ` [PATCH 0/8] More gdb styling improvements Pedro Alves
8 siblings, 0 replies; 16+ messages in thread
From: Tom Tromey @ 2019-09-27 21:25 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This adds more uses of styled_string, changing gdb to style some
output that was previously left unstyled.
gdb/ChangeLog
2019-09-27 Tom Tromey <tom@tromey.com>
* stack.c (print_frame, info_frame_command_core): Use
styled_string.
* linux-thread-db.c (try_thread_db_load_1)
(try_thread_db_load_from_pdir_1): Use styled_string.
* auto-load.c (file_is_auto_load_safe, execute_script_contents)
(auto_load_section_scripts, info_auto_load_local_gdbinit)
(maybe_print_unsupported_script_warning)
(maybe_print_script_not_found_warning): Use styled_string.
* ada-lang.c (user_select_syms): Use styled_string.
---
gdb/ChangeLog | 12 ++++++++++++
gdb/ada-lang.c | 8 +++++---
gdb/auto-load.c | 40 ++++++++++++++++++++++++++--------------
gdb/linux-thread-db.c | 9 ++++++---
gdb/stack.c | 9 ++++++---
5 files changed, 55 insertions(+), 23 deletions(-)
diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 846c9b4dec5..48a400daa7d 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -3881,9 +3881,11 @@ See set/show multiple-symbol."));
printf_filtered (_(" at %p[<no source file available>%p]:%d\n"),
metadata_style.style ().ptr (), nullptr, sal.line);
else
- printf_filtered (_(" at %s:%d\n"),
- symtab_to_filename_for_display (sal.symtab),
- sal.line);
+ printf_filtered
+ (_(" at %ps:%d\n"),
+ styled_string (file_name_style.style (),
+ symtab_to_filename_for_display (sal.symtab)),
+ sal.line);
continue;
}
else
diff --git a/gdb/auto-load.c b/gdb/auto-load.c
index 136d53ffe13..0864ad38a76 100644
--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -41,6 +41,7 @@
#include "gdb/section-scripts.h"
#include <algorithm>
#include "gdbsupport/pathstuff.h"
+#include "cli/cli-style.h"
/* The section to look in for auto-loaded scripts (in file formats that
support sections).
@@ -490,9 +491,10 @@ file_is_auto_load_safe (const char *filename, const char *debug_fmt, ...)
if (filename_is_in_auto_load_safe_path_vec (filename, &filename_real))
return 1;
- warning (_("File \"%s\" auto-loading has been declined by your "
+ warning (_("File \"%ps\" auto-loading has been declined by your "
"`auto-load safe-path' set to \"%s\"."),
- filename_real.get (), auto_load_safe_path);
+ styled_string (file_name_style.style (), filename_real.get ()),
+ auto_load_safe_path);
if (!advice_printed)
{
@@ -989,8 +991,10 @@ execute_script_contents (struct auto_load_pspace_info *pspace_info,
/* We don't throw an error, the program is still debuggable. */
warning (_("\
Missing/bad script name in entry at offset %u in section %s\n\
-of file %s."),
- offset, section_name, objfile_name (objfile));
+of file %ps."),
+ offset, section_name,
+ styled_string (file_name_style.style (),
+ objfile_name (objfile)));
return;
}
script_text = newline + 1;
@@ -1120,8 +1124,10 @@ auto_load_section_scripts (struct objfile *objfile, const char *section_name)
return;
if (!bfd_get_full_section_contents (abfd, scripts_sect, &data))
- warning (_("Couldn't read %s section of %s"),
- section_name, bfd_get_filename (abfd));
+ warning (_("Couldn't read %s section of %ps"),
+ section_name,
+ styled_string (file_name_style.style (),
+ bfd_get_filename (abfd)));
else
{
gdb::unique_xmalloc_ptr<bfd_byte> data_holder (data);
@@ -1349,11 +1355,13 @@ info_auto_load_local_gdbinit (const char *args, int from_tty)
if (auto_load_local_gdbinit_pathname == NULL)
printf_filtered (_("Local .gdbinit file was not found.\n"));
else if (auto_load_local_gdbinit_loaded)
- printf_filtered (_("Local .gdbinit file \"%s\" has been loaded.\n"),
- auto_load_local_gdbinit_pathname);
+ printf_filtered (_("Local .gdbinit file \"%ps\" has been loaded.\n"),
+ styled_string (file_name_style.style (),
+ auto_load_local_gdbinit_pathname));
else
- printf_filtered (_("Local .gdbinit file \"%s\" has not been loaded.\n"),
- auto_load_local_gdbinit_pathname);
+ printf_filtered (_("Local .gdbinit file \"%ps\" has not been loaded.\n"),
+ styled_string (file_name_style.style (),
+ auto_load_local_gdbinit_pathname));
}
/* Print an "unsupported script" warning if it has not already been printed.
@@ -1370,9 +1378,11 @@ maybe_print_unsupported_script_warning
{
warning (_("\
Unsupported auto-load script at offset %u in section %s\n\
-of file %s.\n\
+of file %ps.\n\
Use `info auto-load %s-scripts [REGEXP]' to list them."),
- offset, section_name, objfile_name (objfile),
+ offset, section_name,
+ styled_string (file_name_style.style (),
+ objfile_name (objfile)),
ext_lang_name (language));
pspace_info->unsupported_script_warning_printed = true;
}
@@ -1392,9 +1402,11 @@ maybe_print_script_not_found_warning
{
warning (_("\
Missing auto-load script at offset %u in section %s\n\
-of file %s.\n\
+of file %ps.\n\
Use `info auto-load %s-scripts [REGEXP]' to list them."),
- offset, section_name, objfile_name (objfile),
+ offset, section_name,
+ styled_string (file_name_style.style (),
+ objfile_name (objfile)),
ext_lang_name (language));
pspace_info->script_not_found_warning_printed = true;
}
diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c
index 100434e2c9d..b7c4f245b95 100644
--- a/gdb/linux-thread-db.c
+++ b/gdb/linux-thread-db.c
@@ -48,6 +48,7 @@
#include <algorithm>
#include "gdbsupport/pathstuff.h"
#include "valprint.h"
+#include "cli/cli-style.h"
/* GNU/Linux libthread_db support.
@@ -933,8 +934,9 @@ try_thread_db_load_1 (struct thread_db_info *info)
enabled. User visible output should not depend on debug
settings. */
file = *libthread_db_search_path != '\0' ? gdb_stdout : gdb_stdlog;
- fprintf_unfiltered (file, _("Using host libthread_db library \"%s\".\n"),
- library);
+ fprintf_unfiltered (file,
+ _("Using host libthread_db library \"%ps\".\n"),
+ styled_string (file_name_style.style (), library));
}
/* The thread library was detected. Activate the thread_db target
@@ -1028,7 +1030,8 @@ try_thread_db_load_from_pdir_1 (struct objfile *obj, const char *subdir)
if (obj_name[0] != '/')
{
warning (_("Expected absolute pathname for libpthread in the"
- " inferior, but got %s."), obj_name);
+ " inferior, but got %ps."),
+ styled_string (file_name_style.style (), obj_name));
return false;
}
diff --git a/gdb/stack.c b/gdb/stack.c
index cb07e28b671..c7c67fc7d5c 100644
--- a/gdb/stack.c
+++ b/gdb/stack.c
@@ -1393,7 +1393,7 @@ print_frame (const frame_print_options &fp_opts,
annotate_frame_where ();
uiout->wrap_hint (" ");
uiout->text (" from ");
- uiout->field_string ("from", lib);
+ uiout->field_string ("from", lib, file_name_style.style ());
}
}
if (uiout->is_mi_like_p ())
@@ -1524,8 +1524,11 @@ info_frame_command_core (struct frame_info *fi, bool selected_frame_p)
}
wrap_here (" ");
if (sal.symtab)
- printf_filtered (" (%s:%d)", symtab_to_filename_for_display (sal.symtab),
- sal.line);
+ printf_filtered
+ (" (%ps:%d)",
+ styled_string (file_name_style.style (),
+ symtab_to_filename_for_display (sal.symtab)),
+ sal.line);
puts_filtered ("; ");
wrap_here (" ");
printf_filtered ("saved %s = ", pc_regname);
--
2.17.2
^ permalink raw reply [flat|nested] 16+ messages in thread* Re: [PATCH 0/8] More gdb styling improvements
2019-09-27 21:25 [PATCH 0/8] More gdb styling improvements Tom Tromey
` (7 preceding siblings ...)
2019-09-27 21:25 ` [PATCH 7/8] Use styled_string in more places Tom Tromey
@ 2019-09-30 14:09 ` Pedro Alves
2019-10-01 21:11 ` Tom Tromey
8 siblings, 1 reply; 16+ messages in thread
From: Pedro Alves @ 2019-09-30 14:09 UTC (permalink / raw)
To: Tom Tromey, gdb-patches
On 9/27/19 10:25 PM, Tom Tromey wrote:
> This series improves gdb CLI styling some more.
>
> It adds the %p extensions proposed by Pedro, then applies these in
> various places in gdb.
>
Thanks much for cleaning up my bits and finishing it
all off / extending it.
I replied to patches 3,4,6 just to point out some typos.
This all looks good to me.
Thanks,
Pedro Alves
^ permalink raw reply [flat|nested] 16+ messages in thread* Re: [PATCH 0/8] More gdb styling improvements
2019-09-30 14:09 ` [PATCH 0/8] More gdb styling improvements Pedro Alves
@ 2019-10-01 21:11 ` Tom Tromey
0 siblings, 0 replies; 16+ messages in thread
From: Tom Tromey @ 2019-10-01 21:11 UTC (permalink / raw)
To: Pedro Alves; +Cc: Tom Tromey, gdb-patches
>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
Pedro> On 9/27/19 10:25 PM, Tom Tromey wrote:
>> This series improves gdb CLI styling some more.
>>
>> It adds the %p extensions proposed by Pedro, then applies these in
>> various places in gdb.
>>
Pedro> Thanks much for cleaning up my bits and finishing it
Pedro> all off / extending it.
Pedro> I replied to patches 3,4,6 just to point out some typos.
Pedro> This all looks good to me.
Thanks. I have fixed the things you pointed out, and I'm going to push
it now.
Tom
^ permalink raw reply [flat|nested] 16+ messages in thread