From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 82458 invoked by alias); 10 May 2016 13:31:31 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 82444 invoked by uid 89); 10 May 2016 13:31:31 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.0 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=35m, Units, 6559, Hundreds X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Tue, 10 May 2016 13:31:28 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4C46AA78F for ; Tue, 10 May 2016 13:31:27 +0000 (UTC) Received: from c64.redhat.com (vpn-235-158.phx2.redhat.com [10.3.235.158]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u4ADVQHX032036; Tue, 10 May 2016 09:31:26 -0400 From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [committed] Add debugging ruler to diagnostic-show-locus.c Date: Tue, 10 May 2016 13:31:00 -0000 Message-Id: <1462888597-21574-1-git-send-email-dmalcolm@redhat.com> X-IsSubscribed: yes X-SW-Source: 2016-05/txt/msg00702.txt.bz2 When debugging diagnostic-show-locus.c, it's invaluable to have a "ruler" showing column numbers. This patch adds in support via a new "show_ruler_p" flag within the diagnostic_context. There's no direct way for end-users to enable this, but plugins can enable it by setting the flag, so the plugin that tests the diagnostic subsystem uses this to verify that the ruler is correctly printed. Successfully bootstrapped®rtested on x86_64-pc-linux-gnu. Committed to trunk as r236080. gcc/ChangeLog: * diagnostic-show-locus.c (layout::layout): Call show_ruler if show_ruler_p was set on the context. (layout::show_ruler): New method. * diagnostic.h (struct diagnostic_context): Add field "show_ruler_p". gcc/testsuite/ChangeLog: * gcc.dg/plugin/diagnostic-test-show-locus-bw.c (test_very_wide_line): Add ruler to expected output. * gcc.dg/plugin/diagnostic-test-show-locus-color.c (test_very_wide_line): Likewise. * gcc.dg/plugin/diagnostic_plugin_test_show_locus.c (test_show_locus): Within the handling of "test_very_wide_line", enable show_ruler_p on the diagnostic context. --- gcc/diagnostic-show-locus.c | 39 ++++++++++++++++++++++ gcc/diagnostic.h | 4 +++ .../gcc.dg/plugin/diagnostic-test-show-locus-bw.c | 3 ++ .../plugin/diagnostic-test-show-locus-color.c | 3 ++ .../plugin/diagnostic_plugin_test_show_locus.c | 2 ++ 5 files changed, 51 insertions(+) diff --git a/gcc/diagnostic-show-locus.c b/gcc/diagnostic-show-locus.c index bf95666..eeccee5 100644 --- a/gcc/diagnostic-show-locus.c +++ b/gcc/diagnostic-show-locus.c @@ -199,6 +199,8 @@ class layout void print_annotation_line (int row, const line_bounds lbounds); void print_any_fixits (int row, const rich_location *richloc); + void show_ruler (int max_column) const; + private: void calculate_line_spans (); @@ -653,6 +655,9 @@ layout::layout (diagnostic_context * context, m_x_offset = column - right_margin; gcc_assert (m_x_offset >= 0); } + + if (context->show_ruler_p) + show_ruler (m_x_offset + max_width); } /* Return true iff we should print a heading when starting the @@ -1084,6 +1089,40 @@ layout::move_to_column (int *column, int dest_column) } } +/* For debugging layout issues, render a ruler giving column numbers + (after the 1-column indent). */ + +void +layout::show_ruler (int max_column) const +{ + /* Hundreds. */ + if (max_column > 99) + { + pp_space (m_pp); + for (int column = 1 + m_x_offset; column <= max_column; column++) + if (0 == column % 10) + pp_character (m_pp, '0' + (column / 100) % 10); + else + pp_space (m_pp); + pp_newline (m_pp); + } + + /* Tens. */ + pp_space (m_pp); + for (int column = 1 + m_x_offset; column <= max_column; column++) + if (0 == column % 10) + pp_character (m_pp, '0' + (column / 10) % 10); + else + pp_space (m_pp); + pp_newline (m_pp); + + /* Units. */ + pp_space (m_pp); + for (int column = 1 + m_x_offset; column <= max_column; column++) + pp_character (m_pp, '0' + (column % 10)); + pp_newline (m_pp); +} + } /* End of anonymous namespace. */ /* Print the physical source code corresponding to the location of diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h index ff57357..48ae50d 100644 --- a/gcc/diagnostic.h +++ b/gcc/diagnostic.h @@ -201,6 +201,10 @@ struct diagnostic_context source code (to avoid e.g. colorizing just the first character in a token, which would look strange). */ bool colorize_source_p; + + /* Usable by plugins; if true, print a debugging ruler above the + source output. */ + bool show_ruler_p; }; static inline void diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw.c index 8d44078..2748fa1 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-bw.c @@ -117,6 +117,9 @@ void test_very_wide_line (void) #if 0 float f = foo * bar; /* { dg-warning "95: test" } */ /* { dg-begin-multiline-output "" } + 0 0 0 0 0 0 1 + 4 5 6 7 8 9 0 + 6789012345678901234567890123456789012345678901234567890123456789012345 float f = foo * bar; ~~~~^~~~~ { dg-end-multiline-output "" } */ diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-color.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-color.c index a590258..ff2f4d4 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-color.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus-color.c @@ -117,6 +117,9 @@ void test_very_wide_line (void) #if 0 float f = foo * bar; /* { dg-warning "95: test" } */ /* { dg-begin-multiline-output "" } + 0 0 0 0 0 0 1 + 4 5 6 7 8 9 0 + 6789012345678901234567890123456789012345678901234567890123456789012345 float f = foo * bar; ~~~~^~~~~ { dg-end-multiline-output "" } */ diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c index 95078ce..a5f8f0c 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c @@ -234,9 +234,11 @@ test_show_locus (function *fun) if (0 == strcmp (fnname, "test_very_wide_line")) { const int line = fnstart_line + 2; + global_dc->show_ruler_p = true; warning_at (make_location (get_loc (line, 94), get_loc (line, 90), get_loc (line, 98)), 0, "test"); + global_dc->show_ruler_p = false; } /* Example of multiple carets. */ -- 1.8.5.3