From patchwork Sat Apr 15 06:09:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 67774 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 43A8A3857348 for ; Sat, 15 Apr 2023 06:09:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 43A8A3857348 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1681538956; bh=dy/pTT0/DZ7YX4PvGiQuM+t9eKp6c+7IcTHFJnKSj60=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Fax/Wh8loHDHpvF0Axh8d8Y/gMKjMTQJ8bhMxKG1DZRdMm1TsXuktDDzohOPk9ApK NQxda6qe1n8tMd91XO8TfijXW9bZSEcd2gI3FGCJluw1oPu7iWhrJuYlf++kyrrLTa 28H2cDnuThPb0DzV7KqvTD2QltgNhpzfSxY4vFfk= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 936B5385772C for ; Sat, 15 Apr 2023 06:08:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 936B5385772C Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id ACB351FDC2 for ; Sat, 15 Apr 2023 06:08:49 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 98C2F1390E for ; Sat, 15 Apr 2023 06:08:49 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id UzkNJHE/OmRVBAAAMHmgww (envelope-from ) for ; Sat, 15 Apr 2023 06:08:49 +0000 To: gdb-patches@sourceware.org Subject: [PATCH 2/2] [gdb/cli] Fix wrapping for TERM=ansi Date: Sat, 15 Apr 2023 08:09:05 +0200 Message-Id: <20230415060905.18498-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, 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.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" [ This patch requires readline_hidden_col, introduced by this patch ( https://sourceware.org/pipermail/gdb-patches/2023-April/198877.html ). ] Say we have: ... $ echo $COLUMNS 40 ... With xterm, we claim to wrap after 40 chars: ... $ TERM=xterm gdb (gdb) show width Number of characters gdb thinks are in a line is 40. ... And with ansi, after 39 chars: ... $ TERM=ansi gdb (gdb) show width Number of characters gdb thinks are in a line is 39. ... Let's see if that's correct. First, let's note that the prompt prefix "(gdb) " is 6 chars long: ... 123456 (gdb) ... so we'll tag on starting with 7. Let's try with xterm: ... $ TERM=xterm gdb (gdb) 7890123456789012345678901234567890 123 ... That looks as expected, wrapping occurs after 40 chars. Now, let's try with ansi: ... $ TERM=ansi gdb (gdb) 78901234567890123456789012345678 90123 ... It looks like wrapping occurred after 38 instead of 39 chars. This is caused by: - readline detecting the screen width: 40, - readline substracting one from the screen width because the ansi terminal does not support autowrap, setting the readline screen width to 39, - readline reporting 39 to gdb as screen width, - gdb setting readline screen width to 39, - again readline substracting one from the screen width, setting the readline screen width to 38. Fix this by taking readline_hidden_cols into account in set_screen_size. PR cli/30346 Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30346 Tested on x86_64-linux. --- gdb/testsuite/gdb.base/wrap-line.exp | 104 +++++++++++++++++++++++++++ gdb/utils.c | 2 +- 2 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.base/wrap-line.exp diff --git a/gdb/testsuite/gdb.base/wrap-line.exp b/gdb/testsuite/gdb.base/wrap-line.exp new file mode 100644 index 00000000000..2c4828c905b --- /dev/null +++ b/gdb/testsuite/gdb.base/wrap-line.exp @@ -0,0 +1,104 @@ +# 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 wrapping occurs at the expected location. + +# We set TERM on build, but we need to set it on host. That only works if +# build == host. +require {!is_remote host} + +# Test both ansi (no auto-wrap) and xterm (auto-wrap). +set terms {ansi xterm} + +foreach_with_prefix term $terms { + save_vars { env(TERM) INTERNAL_GDBFLAGS } { + + setenv TERM $term + + # Let's use the width as determined by readline to get correct + # wrapping in the auto-wrap case. Avoid "set width" argument. + set INTERNAL_GDBFLAGS \ + [string map {{-iex "set width 0"} ""} $INTERNAL_GDBFLAGS] + + # Avoid "set width" in default_gdb_start. + gdb_exit + gdb_spawn + } + + set test "initial prompt" + gdb_test_multiple "" $test { + -re "^$gdb_prompt $" { + pass "$test" + } + } + + if { ! [readline_is_used] } { + continue + } + + set width 0 + set show_width_re \ + "Number of characters gdb thinks are in a line is ($decimal)\\." + gdb_test_multiple "show width" "" { + -re -wrap $show_width_re { + set width $expect_out(1,string) + pass $gdb_test_name + } + } + + if { $width == 0 } { + continue + } + + # New prompt, but avoid emitting a pass in order to avoid ending the line + # after the prompt in gdb.log. This make it a bit easier in gdb.log to + # understand where wrapping occurred. + gdb_test_multiple "print 1" "" { + -re -wrap " = 1" { + } + } + + # Take into account that the prompt also takes space. + set prefix [string length "(gdb) "] + set start [expr $prefix + 1] + + # Print chars without wrapping. + set i $start + while { 1 } { + send_gdb [expr $i % 10] + if { $i == $width } { + break + } + incr i + } + + # Now print the first char we expect to wrap. + send_gdb "W" + + # Generate a prompt. + send_gdb "\003" + + # Note the difference between autowrap and no autowrap. In the autowrap + # case, readline doesn't emit a '\n', the terminal takes care of that. + if { $term == "xterm" } { + # xterm, autowrap. + set re "^$start\[^\r\n\]* \rWQuit" + } else { + # ansi, no autowrap. + set re "^$start\[^\r\n\]*\r\n\rWQuit" + } + + gdb_test "" $re "wrap" +} diff --git a/gdb/utils.c b/gdb/utils.c index 82138a1fc2c..eda09cf9c6b 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -1228,7 +1228,7 @@ static void set_screen_size (void) { int rows = lines_per_page; - int cols = chars_per_line; + int cols = chars_per_line + readline_hidden_cols; /* If we get 0 or negative ROWS or COLS, treat as "infinite" size. A negative number can be seen here with the "set width/height"