From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18179 invoked by alias); 4 Sep 2014 17:52:28 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 18170 invoked by uid 89); 4 Sep 2014 17:52:27 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.8 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS,SPF_PASS autolearn=ham version=3.3.2 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; Thu, 04 Sep 2014 17:52:26 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s84HpkPw027063 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 4 Sep 2014 13:51:46 -0400 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s84HpikN019716; Thu, 4 Sep 2014 13:51:45 -0400 Message-ID: <5408A6B0.5040702@redhat.com> Date: Thu, 04 Sep 2014 17:52:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.7.0 MIME-Version: 1.0 To: Patrick Palka CC: gdb-patches@sourceware.org Subject: Re: [PATCH] Ensure rl_get_screen_size() returns the actual terminal dimensions References: <1409534708-31981-1-git-send-email-patrick@parcs.ath.cx> <54084361.1020906@redhat.com> <54084454.5060207@redhat.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2014-09/txt/msg00127.txt.bz2 On 09/04/2014 12:58 PM, Patrick Palka wrote: >> readline's rl_sigwinch_handler already call rl_resize_terminal, and then >> chains into the TUI's handler. So, why do we need this? > Sometimes we overwrite readline's screen size by calling > tui_update_gdb_sizes() like done in tui_enable(). When that's done > rl_get_screen_size() will not return the real terminal dimensions, but > rather the dimensions that were set by tui_update_gdb_sizes(). So in > the following scenario the TUI will get resized to the wrong > dimensions: > > 0. Run GDB. > 1. Enter TUI mode. > 2. Exit TUI mode. > 3. Resize the terminal. > 4. Enter TUI mode again. > 5. Press a key so that the TUI will resize itself. > > Here we resize the terminal (causing RL's SIGWINCH handler to run, > updating RL's idea of the terminal size). Then we enter TUI mode > which calls tui_update_gdb_sizes() which resets RL's idea of the > terminal size. Then we call rl_get_screen_size() in tui_getc() which > returns not the terminal dimensions but the dimensions of the TUI's > command window as set by tui_update_gdb_sizes(). So in the end the > TUI gets resized to incorrect dimensions. Hmm, OK, but... I think the story is just unraveling though. :-) E.g., trying with your patch, I do: 0. Run GDB. 1. Enter TUI mode. 2. "show height" -> 15. Looks legit. 3. Exit TUI mode. 4. "show height" -> 45 5. Resize the terminal to something smaller than 45 lines. 6. "show height" -> still 45 (!?!?) 7. Enter TUI mode again. I have now about 3 visible lines in my cmd window. 8. "show height" -> 15 (!?!?) 9. Exit TUI mode. A. "show height" -> _14_ (looks like it's the legit size now.) B. Enter TUI mode again. I still still about 3 lines height. C. "show height" -> _3_ (finally ??) The screen size handling looks seriously confused. Hmm, if I instead enter/exit/enter in a row, then the height looks reasonable, like: 0. Run GDB. 1. "show height" -> 45 2. Resize the terminal to something smaller than 45 lines. 3. Enter TUI mode. 4. Exit TUI mode. 5. Enter TUI mode immediately again. 6. "show height" -> 3. Looks legit. 7. Exit TUI mode. 8. "show height" -> 14 (looks legit) I notice we don't really need the TUI to see misbehavior, though: 0. Run GDB. 1. "show height" -> 45 2. Resize the terminal to something smaller than 45 lines. 3. "show height" -> still 45 (!?!?) Sounds like GDB should have a SIGWINCH handler even if not running the TUI, that marks the height as invalid, so the next time GDB needs the height, it's refetched from readline. > > Also, when we are blocking inside a secondary prompt, readline's > SIGWINCH handler does not seem to trigger for some reason. So when we > resize the window during a secondary prompt, our SIGWINCH handler gets > triggered but readline's handler doesn't which means that the > dimensions returned by rl_get_screen_size() will be wrong. I'm not > really sure why this happens. > > Explicitly calling rl_resize_terminal() fixes both of these issues. So, it actually sounds like we _should_ be calling rl_resize_terminal to get the full "root" window's sizes, and then _always_ end up calling tui_update_gdb_sizes -> rl_set_screen_size ? That, and maybe set rl_catch_sigwinch=1 as it sounds like readline's signal handler would end up useless. Thanks, Pedro Alves