From patchwork Fri Mar 15 14:15:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 31863 Received: (qmail 49537 invoked by alias); 15 Mar 2019 14:15:30 -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 49483 invoked by uid 89); 15 Mar 2019 14:15:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 spammy=displays X-HELO: mail-wm1-f66.google.com Received: from mail-wm1-f66.google.com (HELO mail-wm1-f66.google.com) (209.85.128.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 15 Mar 2019 14:15:26 +0000 Received: by mail-wm1-f66.google.com with SMTP id t124so6187446wma.4 for ; Fri, 15 Mar 2019 07:15:26 -0700 (PDT) Return-Path: Received: from ?IPv6:2001:8a0:f913:f700:56ee:75ff:fe8d:232b? ([2001:8a0:f913:f700:56ee:75ff:fe8d:232b]) by smtp.gmail.com with ESMTPSA id u14sm2450124wrr.42.2019.03.15.07.15.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Mar 2019 07:15:24 -0700 (PDT) Subject: [PATCH v2] Fix first time you type UP or DOWN in TUI's command window (Re: [RFC 8.3 0/3] Some style fixes) To: Eli Zaretskii , Tom Tromey References: <20190308210433.32683-1-tromey@adacore.com> <83pnr08tc8.fsf@gnu.org> <83zhq26fcw.fsf@gnu.org> <874l899nh3.fsf@tromey.com> <8336ns3uv4.fsf@gnu.org> Cc: gdb-patches@sourceware.org From: Pedro Alves Message-ID: Date: Fri, 15 Mar 2019 14:15:23 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <8336ns3uv4.fsf@gnu.org> On 03/12/2019 04:44 PM, Eli Zaretskii wrote: > 3. This patch fixes another problem noticed by Pedro: the first time > you type UP or DOWN arrow in the command window, GDB should scroll the > source window, but instead it displays the line number and the file > name in the command window(?). What happens there is that the first > time we call tui_ui_out::do_field_int, it doesn't initialize m_line, > because m_start_of_line is -1, as set by the constructor; and then the > following call to tui_ui_out::do_field_string falls back to > cli_ui_out::do_field_string because m_line is zero. The fix below is > perhaps somewhat ad-hoc, mainly because I couldn't understand the > semantics of the values of m_start_of_line, especially its > non-positive values; please consider documenting them in the header. > Maybe if someone explains the semantics, I could come up with a more > sound patch (or conclude that the below is TRT). Also, it looks like > the second test for m_line > 0 in tui_ui_out::do_field_string is > redundant? > > --- gdb/tui/tui-out.c~4 2019-02-27 06:51:50.000000000 +0200 > +++ gdb/tui/tui-out.c 2019-03-12 12:30:23.924230000 +0200 > @@ -34,6 +34,9 @@ tui_ui_out::do_field_int (int fldno, int > if (suppress_output ()) > return; > > + if (m_start_of_line < 0 && m_line == 0) > + m_start_of_line = 0; > + > /* Don't print line number, keep it for later. */ > if (m_start_of_line == 0 && strcmp (fldname, "line") == 0) > { > I noticed that m_start_of_line never goes back to -1. It is reset to 0 here: void tui_ui_out::do_text (const char *string) { ... if (strchr (string, '\n') != 0) { m_line = -1; m_start_of_line = 0; } and notice how m_line is reset to -1. This is the exact opposite of how the fields are initialized in the ctor: tui_ui_out::tui_ui_out (ui_file *stream) : cli_ui_out (stream, 0), m_line (0), m_start_of_line (-1) { } ... which made me suspect of a typo in the C++ification of tui_ui_out. Looking at that commit, 112e8700a6f, we see: -struct ui_out * -tui_out_new (struct ui_file *stream) +tui_ui_out::tui_ui_out (ui_file *stream) +: cli_ui_out (stream, 0), + m_line (0), + m_start_of_line (-1) { - - /* Initialize our fields. */ - data->line = -1; - data->start_of_line = 0; Bingo. So I think this is the right fix: From 781ed3b6d82a4fb54f7bfe59185f0e6e9efd6b59 Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Fri, 15 Mar 2019 13:05:26 +0000 Subject: [PATCH] Fix first time you type UP or DOWN in TUI's command window The first time you type UP or DOWN arrow in the command window, GDB should scroll the source window, but instead it displays the line number and the file name in the command window(?). What happens there is that the first time we call tui_ui_out::do_field_int, it doesn't initialize m_line, because m_start_of_line is -1, as set by the constructor; and then the following call to tui_ui_out::do_field_string falls back to cli_ui_out::do_field_string because m_line is zero. The problem is caused by a typo in the C++ification of tui_ui_out, commit 112e8700a6f, where m_line and m_start_of_line's initial values were swapped from what they used to be: -struct ui_out * -tui_out_new (struct ui_file *stream) +tui_ui_out::tui_ui_out (ui_file *stream) +: cli_ui_out (stream, 0), + m_line (0), + m_start_of_line (-1) { - - /* Initialize our fields. */ - data->line = -1; - data->start_of_line = 0; This commit fixes it. gdb/ChangeLog: yyyy-mm-dd Pedro Alves Eli Zaretskii * tui/tui-out.c (tui_ui_out::tui_ui_out): Fix initialization of m_line and m_start_of_line. --- gdb/tui/tui-out.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gdb/tui/tui-out.c b/gdb/tui/tui-out.c index d5a173b94a..dd37736c4a 100644 --- a/gdb/tui/tui-out.c +++ b/gdb/tui/tui-out.c @@ -109,8 +109,8 @@ tui_ui_out::do_text (const char *string) tui_ui_out::tui_ui_out (ui_file *stream) : cli_ui_out (stream, 0), - m_line (0), - m_start_of_line (-1) + m_line (-1), + m_start_of_line (0) { }