From patchwork Thu Sep 6 21:12:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 29221 Received: (qmail 111299 invoked by alias); 6 Sep 2018 21:13:26 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 111281 invoked by uid 89); 6 Sep 2018 21:13:25 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.1 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_STOCKGEN, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=yellow, intensity, 1738 X-HELO: gateway36.websitewelcome.com Received: from gateway36.websitewelcome.com (HELO gateway36.websitewelcome.com) (192.185.192.36) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 06 Sep 2018 21:13:23 +0000 Received: from cm11.websitewelcome.com (cm11.websitewelcome.com [100.42.49.5]) by gateway36.websitewelcome.com (Postfix) with ESMTP id 3DAAB400F0040 for ; Thu, 6 Sep 2018 15:18:00 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id y1aTfTNjrRPojy1aYfrreY; Thu, 06 Sep 2018 16:13:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=JLDGcr887EZm0WMS2MEngIw3mO94mC/eFeWdQKomEuw=; b=k/8fTKoVCkmlux0uq068dUPmFF IMcmAqmSB1TfSEp01PSTeRHsC+0/Tw2aphpakFAz4AikEzWCshHQ7S7Z4W42vr5TwuVuuML7sQsgA 53/+i0GOtwtqEbt/491uFt+KF; Received: from 75-166-85-72.hlrn.qwest.net ([75.166.85.72]:34550 helo=bapiya.Home) by box5379.bluehost.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91) (envelope-from ) id 1fy1aS-0013U4-UX; Thu, 06 Sep 2018 16:13:13 -0500 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [RFC 4/8] Add variable name styling Date: Thu, 6 Sep 2018 15:12:59 -0600 Message-Id: <20180906211303.11029-5-tom@tromey.com> In-Reply-To: <20180906211303.11029-1-tom@tromey.com> References: <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 m_streams; bool m_suppress_output; + + std::vector 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;