diff options
author | Pedro Alves <palves@redhat.com> | 2019-06-05 21:15:24 +0100 |
---|---|---|
committer | Pedro Alves <palves@redhat.com> | 2019-06-05 21:30:46 +0100 |
commit | 52bf8432db926e2ce2ff8bdbececd242e93b4ca7 (patch) | |
tree | b9aac12631f0b98d9831df283c5fc1406431fc44 | |
parent | 8f1d8637839fc953d089f4816a12531fbf35202b (diff) | |
download | binutils-gdb-52bf8432db926e2ce2ff8bdbececd242e93b4ca7.tar.gz |
Introduce %ps / styled_string
-rw-r--r-- | gdb/common/format.c | 1 | ||||
-rw-r--r-- | gdb/symtab.c | 24 | ||||
-rw-r--r-- | gdb/ui-out.c | 6 | ||||
-rw-r--r-- | gdb/ui-out.h | 20 |
4 files changed, 38 insertions, 13 deletions
diff --git a/gdb/common/format.c b/gdb/common/format.c index d33eab2b2b0..177f79afee3 100644 --- a/gdb/common/format.c +++ b/gdb/common/format.c @@ -256,6 +256,7 @@ format_pieces::format_pieces (const char **arg, bool gdb_extensions) { switch (f[1]) { + case 's': case 'S': case 'F': case 'N': diff --git a/gdb/symtab.c b/gdb/symtab.c index 5696d6fa890..7dbf24eb7c5 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -4603,10 +4603,9 @@ print_symbol_info (enum search_domain kind, if (filename_cmp (last, s_filename) != 0) { - current_uiout->message ("\nFile %pS%s%pN:\n", - ptr (ui_out_style_kind::FILE), - s_filename, - nullptr); + current_uiout->message + (_("\nFile %ps:\n"), + styled_string (ui_out_style_kind::FILE, s_filename).ptr ()); } if (SYMBOL_LINE (sym) != 0) @@ -4653,15 +4652,14 @@ print_msymbol_info (struct bound_minimal_symbol msymbol) tmp = hex_string_custom (BMSYMBOL_VALUE_ADDRESS (msymbol), 16); - current_uiout->message (_("%pS%s%pN %pS%s%pN\n"), - ptr (ui_out_style_kind::ADDRESS), - tmp, - nullptr, - (msymbol.minsym->text_p () - ? ptr (ui_out_style_kind::FUNCTION) - : ptr (ui_out_style_kind::DEFAULT)), - MSYMBOL_PRINT_NAME (msymbol.minsym), - nullptr); + ui_out_style_kind sym_style = (msymbol.minsym->text_p () + ? ui_out_style_kind::FUNCTION + : ui_out_style_kind::DEFAULT); + + current_uiout->message + (_("%ps %ps\n"), + styled_string (ui_out_style_kind::ADDRESS, tmp).ptr (), + styled_string (sym_style, MSYMBOL_PRINT_NAME (msymbol.minsym)).ptr ()); } /* This is the guts of the commands "info functions", "info types", and diff --git a/gdb/ui-out.c b/gdb/ui-out.c index 6e1c87ab841..4169fdcb935 100644 --- a/gdb/ui-out.c +++ b/gdb/ui-out.c @@ -612,6 +612,12 @@ ui_out::message (const char *format, ...) field_int (field->name (), field->val ()); } break; + case 's': + { + styled_string *ss = va_arg (args, styled_string *); + call_do_message (ss->style (), "%s", ss->str ()); + } + break; case 'S': style = *va_arg (args, ui_out_style_kind *); break; diff --git a/gdb/ui-out.h b/gdb/ui-out.h index 18af856313d..059d1e376aa 100644 --- a/gdb/ui-out.h +++ b/gdb/ui-out.h @@ -103,6 +103,26 @@ private: int m_val; }; +struct styled_string +{ + styled_string (ui_out_style_kind style, const char *str) + : m_style (style), + m_str (str) + { + } + + /* We need this because we can't pass a reference via + va_args. */ + const styled_string *ptr () const { return this; } + + ui_out_style_kind style () const {return m_style; } + const char *str () const {return m_str; } + +private: + ui_out_style_kind m_style; + const char *m_str; +}; + /* Wrap a ui_out_style_kind in a pointer to a temporary. */ /* XXX: Make a template? */ |