From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id fSwQGcZ/BWbXlhkAWB0awg (envelope-from ) for ; Thu, 28 Mar 2024 10:33:42 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=0O4R4+FM; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=vX6Y1sQX; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 56E541E0C0; Thu, 28 Mar 2024 10:33:42 -0400 (EDT) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id CDF561E030 for ; Thu, 28 Mar 2024 10:33:39 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 79B443858C36 for ; Thu, 28 Mar 2024 14:33:39 +0000 (GMT) Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id 1D4333858D1E for ; Thu, 28 Mar 2024 14:33:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1D4333858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1D4333858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711636397; cv=none; b=xq3aqUVmYYgV8iD6JoJv4lmXEB7Y7asR2zXMRTKyxLkRPR5NjsnkQeFsi3KZEFi3AxvJ1noE4qIMTKUad/T2LnT9FXSZE3tBOXUKFE5F90vBz7jpVr42j8R2L57SobhWFBL8d15eU9n2leOfX3r07+0NvhUK0pjUZ8g5Yc2w/as= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711636397; c=relaxed/simple; bh=dVvVpYnU99VYELadN2iz1/Wox5BT44ydvdhLkWFCzY8=; h=DKIM-Signature:DKIM-Signature:From:To:Subject:Date:Message-Id: MIME-Version; b=YNY8rdltGcbsD6Aiq5dQqk/UkSNUmKgt5KwEJvyarj7VhZ3M/Ee8iEm7gPQVtFTw1fMZBGVKOoJb6p4g4RI1cIPDCFXg6wRnmdOS2gM2roU8JZRpH8NfamAx3+lA4jbu/XsnOC9F20axqM9baZlPya6j96wQAF7ODMQyGCi/U/4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap2.dmz-prg2.suse.org (imap2.dmz-prg2.suse.org [10.150.64.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E4E0C20A2D for ; Thu, 28 Mar 2024 14:33:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1711636391; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fL5BtS22gGETjOiisTW4lpnVRb1sLt3PAe5Fes3VlNE=; b=0O4R4+FMiD4wUBux+ViodRCY5jPYsF7Lss0J+uphL0KPsKUSkbp9cbHUAQ9+ifjLtlSsTo iK107O9MbUS2Jkw1KLM6hBmm2MqGgyZeKfmZK24jOcZG3DbhsvCC1RlUfBkfz/Rhzez7cX QzNS0OG8QykVV+mgPTJ/XnEu0u4VsIk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1711636391; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=fL5BtS22gGETjOiisTW4lpnVRb1sLt3PAe5Fes3VlNE=; b=vX6Y1sQXzdMtUJb8eaDHyeQDn5qkvhCdsqELXYkpbzJF3+tVL3+FpuzQSlDZEyjqaCwFYc 401cYUdpvze0VmCQ== Authentication-Results: smtp-out2.suse.de; none Received: from imap2.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap2.dmz-prg2.suse.org (Postfix) with ESMTPS id CF06413A94 for ; Thu, 28 Mar 2024 14:33:11 +0000 (UTC) Received: from dovecot-director2.suse.de ([10.150.64.162]) by imap2.dmz-prg2.suse.org with ESMTPSA id Jk8mMad/BWbtUwAAn2gu4w (envelope-from ) for ; Thu, 28 Mar 2024 14:33:11 +0000 From: Tom de Vries To: gdb-patches@sourceware.org Subject: [PATCH] [gdb/tui] Fix centering and highlighting of current line Date: Thu, 28 Mar 2024 15:33:13 +0100 Message-Id: <20240328143313.24460-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -3.12 X-Spamd-Result: default: False [-3.12 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[gdb-patches@sourceware.org]; TO_DN_NONE(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; RCVD_COUNT_THREE(0.00)[3]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.02)[-0.117]; MID_CONTAINS_FROM(1.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Spam-Level: X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org After starting TUI like this with a hello world a.out: ... $ gdb -q a.out -ex start -ex "tui enable" ... we get: ... ┌─hello.c──────────────────────────────┐ │ 5 { │ │ 6 printf ("hello\n"); │ │ 7 │ │ 8 return 0; │ │ 9 } │ │ │ └──────────────────────────────────────┘ ... This is a regression since commit ee1e9bbb513 ("[gdb/tui] Fix displaying main after resizing"), before which we had instead: ... ┌─hello.c──────────────────────────────┐ │ 4 main (void) │ │ 5 { │ │ > 6  printf ("hello\n"); │ │ 7 │ │ 8 return 0; │ │ 9 } │ └──────────────────────────────────────┘ ... In other words, the problems are: - the active line (source line 6) is no longer highlighted, and - the active line is not veritically centered (screen line 2 out 6 instead of screen line 3 out of 6). Fix these problems respectively by: - in tui_enable, instead of "tui_show_frame_info (0)" using 'tui_show_frame_info (deprecated_safe_get_selected_frame ())", and - in tui_source_window_base::rerender, adding centering functionality. Tested on aarch64-linux. Co-Authored-By: Tom Tromey PR tui/31522 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31522 --- gdb/testsuite/gdb.tui/main-2.exp | 47 ++++++++++++++++++++++++++++++++ gdb/tui/tui-winsource.c | 10 +++++++ gdb/tui/tui.c | 2 +- 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.tui/main-2.exp diff --git a/gdb/testsuite/gdb.tui/main-2.exp b/gdb/testsuite/gdb.tui/main-2.exp new file mode 100644 index 00000000000..1dcb3cfc6d4 --- /dev/null +++ b/gdb/testsuite/gdb.tui/main-2.exp @@ -0,0 +1,47 @@ +# Copyright 2024 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 . + +# Test that enabling tui while having a current frame results in +# centering and highlighting the associated line. + +require allow_tui_tests + +tuiterm_env + +standard_testfile tui-layout.c + +if { [build_executable "failed to prepare" $testfile $srcfile ] == -1} { + return -1 +} + +Term::clean_restart 24 80 $binfile + +if {![runto_main]} { + perror "test suppressed" + return +} + +if {![Term::enter_tui]} { + unsupported "TUI not supported" + return +} + +set line " return 0;" +set nr [gdb_get_line_number $line] + +set screen_line [Term::get_line_with_attrs 6] +verbose -log "screen line 6: '$screen_line'" +gdb_assert { [regexp "$nr $line" $screen_line] } \ + "highlighted line in middle of source window" diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c index 4dbbe922256..61c8e00589d 100644 --- a/gdb/tui/tui-winsource.c +++ b/gdb/tui/tui-winsource.c @@ -467,6 +467,16 @@ tui_source_window_base::rerender () struct symtab *s = find_pc_line_symtab (get_frame_pc (frame)); if (this != TUI_SRC_WIN) find_line_pc (s, cursal.line, &cursal.pc); + + /* This centering code is copied from tui_source_window::maybe_update. + It would be nice to do centering more often, and do it in just one + location. But since this is a regression fix, handle this + conservatively for now. */ + int start_line = (cursal.line - ((height - box_size ()) / 2)) + 1; + if (start_line <= 0) + start_line = 1; + cursal.line = start_line; + update_source_window (gdbarch, cursal); } else diff --git a/gdb/tui/tui.c b/gdb/tui/tui.c index 19f09609a2f..eaee85f82b4 100644 --- a/gdb/tui/tui.c +++ b/gdb/tui/tui.c @@ -466,7 +466,7 @@ tui_enable (void) tui_set_term_width_to (COLS); def_prog_mode (); - tui_show_frame_info (0); + tui_show_frame_info (deprecated_safe_get_selected_frame ()); tui_set_initial_layout (); tui_set_win_focus_to (TUI_SRC_WIN); keypad (TUI_CMD_WIN->handle.get (), TRUE); base-commit: 4ef6173d2dfeafd33deedf7ce0d384cfbcf1170d -- 2.35.3