From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 9C5C43858D20 for ; Wed, 31 May 2023 13:35:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9C5C43858D20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685540121; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A70Cbs8r6GbGQaxOptEXjdDFsHjGQfTGHq7ugUsvqsc=; b=YBdBuFfquyTI7M7zZGhbuUVkHdzrgOtIzOQ7RbSx1HSeHEEq5Re6/pIlsxvTrucBNcG03N Sy1ysllL/h1Vp7YGisu+N+TM8veD50LXQqgVrdJ+1NaBwTV8YYeDG4B4HxhOmKhS/QqxuE awCCjEF/woh68Or7Cnwx+amp5iNDdfY= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-31-ZJJOkXrLNhK8aZESB1PxIw-1; Wed, 31 May 2023 09:35:19 -0400 X-MC-Unique: ZJJOkXrLNhK8aZESB1PxIw-1 Received: by mail-qv1-f72.google.com with SMTP id 6a1803df08f44-6261691ef6fso31309976d6.3 for ; Wed, 31 May 2023 06:35:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685540117; x=1688132117; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=A70Cbs8r6GbGQaxOptEXjdDFsHjGQfTGHq7ugUsvqsc=; b=j3phb+f47l3zTF3Mewm2EZOPEHqLR2NXx8VO9QLy4H+q+tPQ88v1Ly9u9uavrfc6CF dp4D5ejvAboISDuahmQzttTsYvJxgaI7wcBeQZgvFyYChAba8yd19JGtCJcOx6Aam7ej 0OLlE/3n4f06hyAgA/Q7SbZt4biuAMyDpbZAcyaFq2M1+ErniduFlcPTckXTSixhqrlM HsDSxzWR5wQJHqk3ZSZNmj4GRcEtEIR4mWXAOj+ABQisBxplzot4dCs+u4NMpi46dAOn TzPlZZ1kaDALiV1kapIzrWgYet1zXsAb1+6kbzVRcUVBTTWQd12PTEp4GYm5q/o5VjJJ EckQ== X-Gm-Message-State: AC+VfDyFKY6bnau054OKRJ+VpGD2d/WFTu2W9fjK+oOWFB4U+FCtZAA2 vynM9PeQrfNB6a+USazWd+OEcUuSDcHmzAwata5817A9lKgEVsFXY/c9ZIeLdXtfrEF2GOJDbpe LBnGmepie8xXqh85u9unxS3t3+amM0w== X-Received: by 2002:ad4:5ecc:0:b0:625:833e:8825 with SMTP id jm12-20020ad45ecc000000b00625833e8825mr6299714qvb.4.1685540117072; Wed, 31 May 2023 06:35:17 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7uE2X9mWrRlVHFaLiMt5e8CPgfbtzpC8T9CNDVe2mUCfGCSIctfgqSV7mAahLQvaBQZFGKUg== X-Received: by 2002:ad4:5ecc:0:b0:625:833e:8825 with SMTP id jm12-20020ad45ecc000000b00625833e8825mr6299693qvb.4.1685540116712; Wed, 31 May 2023 06:35:16 -0700 (PDT) Received: from [192.168.0.129] (ip-94-112-225-44.bb.vodafone.cz. [94.112.225.44]) by smtp.gmail.com with ESMTPSA id qh13-20020a0562144c0d00b00626204ad6fcsm3130280qvb.103.2023.05.31.06.35.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 31 May 2023 06:35:16 -0700 (PDT) Message-ID: <335f3833-a4ac-e85a-63ac-5212931cc206@redhat.com> Date: Wed, 31 May 2023 15:35:14 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH 1/3] [gdb/tui] Keep inferior output in cmd window with ^L To: Tom de Vries , gdb-patches@sourceware.org Cc: Tom Tromey References: <20230530105324.23089-1-tdevries@suse.de> <20230530105324.23089-2-tdevries@suse.de> From: Bruno Larsen In-Reply-To: <20230530105324.23089-2-tdevries@suse.de> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 30/05/2023 12:53, Tom de Vries via Gdb-patches wrote: > Consider a hello world compiled with -g into an a.out: > ... > int main (void) { > printf ("hello\n"); > return 0; > } > ... > > After starting TUI like this: > ... > $ gdb -q a.out -ex start -ex "tui enable" > ... > we do "echo \n" and type enter until the prompt is at the bottom of the screen. > > After doing next to execute the printf, we have: > ... > (gdb) next > hello > (gdb) > ... > but the entire screen scrolled, so: > - the src window is missing the top border, and > - the updates in the src and status window are misaligned with the current > screen. > > We can fix this by doing ^L, but that removes the "hello", giving us just: > ... > (gdb) next > (gdb) > ... > > The ^L key-combo (and likewise the command refresh) calls tui_refresh_all_win, > which works by: > - clearing the screen, and then > - refreshing all visible windows. > Since curses has no notion of the inferior output, this overwrites the > "hello". > > Fix this by excluding the command window from ^L. > > Tested on x86_64-linux. > --- Thank you for working on this, this has bugged me for years at this point. I can confirm that this fixes the issue you mentioned when the terminal scrolls. The problem is that now, if the output doesn't cause the screen to scroll, it doesn't show up on screen at all. I also am not a great fan of the test name, I would suggest calling it gdb.tui/inferior-stdout-output.exp or something like that, hello sounds a little too generic IMO. -- Cheers, Bruno > gdb/testsuite/gdb.tui/hello.c | 25 +++++++++++++++ > gdb/testsuite/gdb.tui/hello.exp | 57 +++++++++++++++++++++++++++++++++ > gdb/tui/tui-io.c | 2 +- > gdb/tui/tui-win.c | 18 ++++++++--- > gdb/tui/tui-win.h | 2 +- > gdb/tui/tui-wingeneral.c | 5 ++- > gdb/tui/tui-wingeneral.h | 2 +- > 7 files changed, 103 insertions(+), 8 deletions(-) > create mode 100644 gdb/testsuite/gdb.tui/hello.c > create mode 100644 gdb/testsuite/gdb.tui/hello.exp > > diff --git a/gdb/testsuite/gdb.tui/hello.c b/gdb/testsuite/gdb.tui/hello.c > new file mode 100644 > index 00000000000..c3f5c6ea2cb > --- /dev/null > +++ b/gdb/testsuite/gdb.tui/hello.c > @@ -0,0 +1,25 @@ > +/* This testcase is part of GDB, the GNU debugger. > + > + Copyright 2023 Free Software Foundation, Inc. > + > + This program is free software; you can redistribute it and/or modify > + it under the terms of the GNU General Public License as published by > + the Free Software Foundation; either version 3 of the License, or > + (at your option) any later version. > + > + This program is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + GNU General Public License for more details. > + > + You should have received a copy of the GNU General Public License > + along with this program. If not, see . */ > + > +#include > + > +int > +main (void) > +{ > + printf ("hello\n"); > + return 0; > +} > diff --git a/gdb/testsuite/gdb.tui/hello.exp b/gdb/testsuite/gdb.tui/hello.exp > new file mode 100644 > index 00000000000..9634d9d8059 > --- /dev/null > +++ b/gdb/testsuite/gdb.tui/hello.exp > @@ -0,0 +1,57 @@ > +# Copyright 2023 Free Software Foundation, Inc. > + > +# This program is free software; you can redistribute it and/or modify > +# it under the terms of the GNU General Public License as published by > +# the Free Software Foundation; either version 3 of the License, or > +# (at your option) any later version. > +# > +# This program is distributed in the hope that it will be useful, > +# but WITHOUT ANY WARRANTY; without even the implied warranty of > +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > +# GNU General Public License for more details. > +# > +# You should have received a copy of the GNU General Public License > +# along with this program. If not, see . > + > +# Check that a print by an inferior doesn't mess up the screen. > + > +tuiterm_env > + > +standard_testfile hello.c > + > +if {[build_executable "failed to prepare" ${testfile} ${srcfile}] == -1} { > + return -1 > +} > + > +Term::clean_restart 24 80 $testfile > + > +if {![runto_main]} { > + perror "test suppressed" > + return > +} > + > +if {![Term::enter_tui]} { > + unsupported "TUI not supported" > + return > +} > + > +# Make sure the prompt is at the last line. > +Term::command "echo \\n" > +Term::command "echo \\n" > +Term::command "echo \\n" > +Term::command "echo \\n" > + > +# Check the source box. > +Term::check_box "before next: source box" 0 0 80 15 > + > +# Make the inferior print "hello". > +Term::command "next" > + > +# Refresh to redraw the screen. > +Term::command "refresh" > + > +# Check the source box again. > +Term::check_box "after next: source box" 0 0 80 15 > + > +# Check that we can still see the printed "hello". > +Term::check_contents "hello" "\nhello" > diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c > index a1eadcd937d..6ae7948b786 100644 > --- a/gdb/tui/tui-io.c > +++ b/gdb/tui/tui-io.c > @@ -1219,7 +1219,7 @@ tui_getc_1 (FILE *fp) > /* Handle the CTRL-L refresh for each window. */ > if (ch == '\f') > { > - tui_refresh_all_win (); > + tui_refresh_all_win (false); > return ch; > } > > diff --git a/gdb/tui/tui-win.c b/gdb/tui/tui-win.c > index 7abd1e225b9..3b41b59cdd3 100644 > --- a/gdb/tui/tui-win.c > +++ b/gdb/tui/tui-win.c > @@ -508,10 +508,20 @@ tui_win_info::right_scroll (int num_to_scroll) > > > void > -tui_refresh_all_win (void) > +tui_refresh_all_win (bool cmd_window) > { > - clearok (curscr, TRUE); > - tui_refresh_all (); > + if (cmd_window) > + clearok (curscr, TRUE); > + else > + for (tui_win_info *wi : all_tui_windows ()) > + { > + if (wi == TUI_CMD_WIN) > + continue; > + > + redrawwin (wi->handle.get ()); > + } > + > + tui_refresh_all (cmd_window); > } > > void > @@ -827,7 +837,7 @@ tui_refresh_all_command (const char *arg, int from_tty) > /* Make sure the curses mode is enabled. */ > tui_enable (); > > - tui_refresh_all_win (); > + tui_refresh_all_win (false); > } > > #define DEFAULT_TAB_LEN 8 > diff --git a/gdb/tui/tui-win.h b/gdb/tui/tui-win.h > index 3d35f1dfb7f..41408a0af3d 100644 > --- a/gdb/tui/tui-win.h > +++ b/gdb/tui/tui-win.h > @@ -26,7 +26,7 @@ > > extern void tui_set_win_focus_to (struct tui_win_info *); > extern void tui_resize_all (void); > -extern void tui_refresh_all_win (void); > +extern void tui_refresh_all_win (bool cmd_win = true); > extern void tui_rehighlight_all (void); > > extern chtype tui_border_ulcorner; > diff --git a/gdb/tui/tui-wingeneral.c b/gdb/tui/tui-wingeneral.c > index 82a023d09fe..73c047a8ac4 100644 > --- a/gdb/tui/tui-wingeneral.c > +++ b/gdb/tui/tui-wingeneral.c > @@ -198,10 +198,13 @@ tui_win_info::make_visible (bool visible) > /* Function to refresh all the windows currently displayed. */ > > void > -tui_refresh_all () > +tui_refresh_all (bool cmd_window) > { > for (tui_win_info *win_info : all_tui_windows ()) > { > + if (!cmd_window && win_info == tui_win_list[CMD_WIN]) > + continue; > + > if (win_info->is_visible ()) > win_info->refresh_window (); > } > diff --git a/gdb/tui/tui-wingeneral.h b/gdb/tui/tui-wingeneral.h > index 5b82fcd6b21..051dbf3b5ca 100644 > --- a/gdb/tui/tui-wingeneral.h > +++ b/gdb/tui/tui-wingeneral.h > @@ -28,7 +28,7 @@ struct tui_win_info; > > extern void tui_unhighlight_win (struct tui_win_info *); > extern void tui_highlight_win (struct tui_win_info *); > -extern void tui_refresh_all (); > +extern void tui_refresh_all (bool cmd_window = true); > > /* An RAII class that suppresses output on construction (calling > wnoutrefresh on the existing windows), and then flushes the output