From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [RFC 4/8] Add variable name styling
Date: Thu, 06 Sep 2018 21:13:00 -0000 [thread overview]
Message-ID: <20180906211303.11029-5-tom@tromey.com> (raw)
In-Reply-To: <20180906211303.11029-1-tom@tromey.com>
This adds style support for variable names. For the time being, this
is only done in backtraces, not in ptype or print; those places do not
use ui-out and so would need ad hoc changes.
Because "name" is a relatively common MI field name, simple name
recognition does not work for variable names. So, this patch changes
cli-out to track the enclosing list name, and only colorize "name"
when appearing somewhere within a list named "args".
This also adds styling to the names printed for local variables in
"backtrace full". This code does not use ui-out, so the styling is
done using the low-level API.
---
gdb/cli-out.c | 8 ++++++++
gdb/cli-out.h | 3 +++
gdb/cli/cli-style.c | 8 ++++++++
gdb/cli/cli-style.h | 1 +
gdb/printcmd.c | 7 ++++++-
5 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/gdb/cli-out.c b/gdb/cli-out.c
index eeb3a64cbae..4a5df6d3cff 100644
--- a/gdb/cli-out.c
+++ b/gdb/cli-out.c
@@ -80,6 +80,9 @@ cli_ui_out::do_table_header (int width, ui_align alignment,
void
cli_ui_out::do_begin (ui_out_type type, const char *id)
{
+ m_in_args.push_back (id != nullptr && strcmp (id, "args") == 0);
+ if (m_in_args.back ())
+ ++m_in_args_count;
}
/* Mark end of a list */
@@ -87,6 +90,9 @@ cli_ui_out::do_begin (ui_out_type type, const char *id)
void
cli_ui_out::do_end (ui_out_type type)
{
+ if (m_in_args.back ())
+ --m_in_args_count;
+ m_in_args.pop_back ();
}
/* output an int field */
@@ -167,6 +173,8 @@ cli_ui_out::do_field_string (int fldno, int width, ui_align align,
style = &file_name_style;
else if (!strcmp (fldname, "func") || !strcmp (fldname, "function"))
style = &function_name_style;
+ else if (m_in_args_count > 0 && !strcmp (fldname, "name"))
+ style = &variable_name_style;
if (style != nullptr)
set_output_style (m_streams.back (), style->style ());
diff --git a/gdb/cli-out.h b/gdb/cli-out.h
index f701da7bf38..2d26fd419a5 100644
--- a/gdb/cli-out.h
+++ b/gdb/cli-out.h
@@ -73,6 +73,9 @@ private:
std::vector<ui_file *> m_streams;
bool m_suppress_output;
+
+ std::vector<bool> m_in_args;
+ int m_in_args_count = 0;
};
extern cli_ui_out *cli_out_new (struct ui_file *stream);
diff --git a/gdb/cli/cli-style.c b/gdb/cli/cli-style.c
index 9b210863bd3..c5828d65c26 100644
--- a/gdb/cli/cli-style.c
+++ b/gdb/cli/cli-style.c
@@ -43,6 +43,7 @@ static const char * const cli_intensities[] = {
cli_style_option file_name_style (ui_file_style::GREEN);
cli_style_option function_name_style (ui_file_style::YELLOW);
+cli_style_option variable_name_style (ui_file_style::CYAN);
cli_style_option::cli_style_option (ui_file_style::color fg)
: m_foreground (cli_colors[fg - ui_file_style::NONE]),
@@ -204,4 +205,11 @@ Configure function name colors and display intensity"),
"style function",
&style_set_list,
&style_show_list);
+ variable_name_style.add_setshow_commands ("variable", no_class,
+ "style variable",
+ _("\
+Variable name display styling\n\
+Configure variable name colors and display intensity"),
+ &style_set_list,
+ &style_show_list);
}
diff --git a/gdb/cli/cli-style.h b/gdb/cli/cli-style.h
index d9c00003bd4..e2840c6f490 100644
--- a/gdb/cli/cli-style.h
+++ b/gdb/cli/cli-style.h
@@ -63,5 +63,6 @@ private:
extern cli_style_option file_name_style;
extern cli_style_option function_name_style;
+extern cli_style_option variable_name_style;
#endif /* CLI_STYLE_H */
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 8c999188d71..c63d567e487 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -2156,7 +2156,12 @@ print_variable_and_value (const char *name, struct symbol *var,
if (!name)
name = SYMBOL_PRINT_NAME (var);
- fprintf_filtered (stream, "%s%s = ", n_spaces (2 * indent), name);
+ fputs_filtered (n_spaces (2 * indent), stream);
+ set_output_style (stream, variable_name_style.style ());
+ fputs_filtered (name, stream);
+ set_output_style (stream, ui_file_style ());
+ fputs_filtered (" = ", stream);
+
TRY
{
struct value *val;
--
2.13.6
next prev parent reply other threads:[~2018-09-06 21:13 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-06 21:13 [RFC 0/8] add terminal styling to gdb Tom Tromey
2018-09-06 21:13 ` [RFC 6/8] Style print_address_symbolic Tom Tromey
2018-09-06 21:13 ` Tom Tromey [this message]
2018-10-06 16:34 ` [RFC 4/8] Add variable name styling Simon Marchi
2018-09-06 21:13 ` [RFC 2/8] Add a "context" argument to add_setshow_enum_cmd Tom Tromey
2018-09-06 21:13 ` [RFC 1/8] Change wrap buffering to use a std::string Tom Tromey
2018-10-06 15:19 ` Simon Marchi
2018-10-08 22:04 ` Tom Tromey
2018-10-18 22:16 ` Tom Tromey
2018-09-06 21:13 ` [RFC 3/8] Add output styles to gdb Tom Tromey
2018-10-06 15:53 ` Simon Marchi
2018-10-06 19:06 ` Tom Tromey
2018-10-07 21:58 ` Simon Marchi
2018-10-08 0:23 ` Tom Tromey
2018-10-08 2:02 ` Simon Marchi
2018-10-08 2:49 ` Tom Tromey
2018-10-08 11:10 ` Simon Marchi
2018-10-08 22:17 ` Tom Tromey
2018-09-06 21:13 ` [RFC 7/8] Style the gdb welcome message Tom Tromey
2018-09-06 21:14 ` [RFC 5/8] Style locations when setting a breakpoint Tom Tromey
2018-10-06 16:36 ` Simon Marchi
2018-09-06 21:14 ` [RFC 8/8] Style the "Reading symbols" message Tom Tromey
2018-09-07 6:23 ` [RFC 0/8] add terminal styling to gdb Eli Zaretskii
2018-09-07 14:36 ` Tom Tromey
2018-09-07 14:56 ` Eli Zaretskii
2018-09-07 15:01 ` Eli Zaretskii
2018-09-07 7:25 ` Joel Brobecker
2018-10-04 13:11 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180906211303.11029-5-tom@tromey.com \
--to=tom@tromey.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox