From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 261593858D1E for ; Tue, 18 Apr 2023 06:10:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 261593858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de 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 434F51F8D4; Tue, 18 Apr 2023 06:10:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1681798214; h=from:from:reply-to: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=4JxPoF0qqwg0N8NCVNcXDmRY06i9Qxi2GfdhBVQWMqo=; b=iCHbzK2+lZoBGIOWGt7YpWPDJYpTqjdlajcvMZnyAK8jSvou7OELiflxMo5uGi12kaaisE 45AMjPPaTTTVr8tlfK5ixH4WGom7sygggHA5ewM3TmPH1rAFfjiZj9+FZw4y6rLMjKqRpf MxP/2SrCknoBX3DR9IYCHf/7FOTp85M= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1681798214; h=from:from:reply-to: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=4JxPoF0qqwg0N8NCVNcXDmRY06i9Qxi2GfdhBVQWMqo=; b=HBopG/5YHOQWOyZFhGljGGrGuQqOX0LXFQBp1ZE/zbF3NU17RNiUc2lUrfyoPoKLHc7odO DZjq0jndASbMaeBg== 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 2C7DA139CC; Tue, 18 Apr 2023 06:10:14 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id tMK0CUY0PmT1OgAAMHmgww (envelope-from ); Tue, 18 Apr 2023 06:10:14 +0000 Message-ID: Date: Tue, 18 Apr 2023 08:10:14 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Subject: Re: [PATCH 8/8] [gdb/tui] Fix TUI for TERM=ansi Content-Language: en-US To: gdb-patches@sourceware.org Cc: Tom Tromey References: <20230413140827.19412-1-tdevries@suse.de> <20230413140827.19412-9-tdevries@suse.de> <7087394a-5cac-45c4-5c6d-6229db3c4915@suse.de> From: Tom de Vries In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,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 4/14/23 13:02, Tom de Vries via Gdb-patches wrote: > On 4/13/23 16:17, Tom de Vries via Gdb-patches wrote: >> On 4/13/23 16:08, Tom de Vries via Gdb-patches wrote: >>> @@ -1144,6 +1148,11 @@ init_page_info (void) >>>         /* Get the screen size from Readline.  */ >>>         rl_get_screen_size (&rows, &cols); >>> +      if (gdb_stdout->isatty ()) { >>> +    readline_hidden_cols = COLS - cols; >>> +    gdb_assert (readline_hidden_cols >= 0); >>> +    gdb_assert (readline_hidden_cols <= 1); >>> +      } >>>         lines_per_page = rows; >>>         chars_per_line = cols; >> >> Reading this over once more, I noticed this is missing a fix for an >> assertion failure we run into when doing: >> ... >> $ TERM=blabla gdb >> ... >> >> So, this bit is missing: >> ... >> -      if (gdb_stdout->isatty ()) { >> +      if (gdb_stdout->isatty () && COLS != 0) { >> ... >> > > I also ran into trouble with this version.  It's not a good idea to use > COLS, because it's just a copy of the env variable COLUMNS at the time > of curses startup.  So, I can trigger one of the asserts by doing: > ... > $ COLUMNS= gdb > ... > > Here's an updated version, using the COLUMNS value as written by > readline instead. > @@ -1144,6 +1148,24 @@ init_page_info (void) > > /* Get the screen size from Readline. */ > rl_get_screen_size (&rows, &cols); > + > + /* Readline: > + - ignores the COLUMNS variable when detecting screen width > + (because rl_prefer_env_winsize defaults to 0) > + - puts the detected screen width in the COLUMNS variable > + (because rl_change_environment defaults to 1) > + - may report one less than the detected screen width in > + rl_get_screen_size (when _rl_term_autowrap == 0). > + Set readline_hidden_cols by comparing COLUMNS to cols as returned by > + rl_get_screen_size. */ > + char *columns_env = getenv ("COLUMNS"); > + gdb_assert (columns_env != nullptr); > + int columns_env_val = atoi (columns_env); > + gdb_assert (columns_env_val != 0); > + readline_hidden_cols = columns_env_val - cols; > + gdb_assert (readline_hidden_cols >= 0); > + gdb_assert (readline_hidden_cols <= 1); > + > lines_per_page = rows; > chars_per_line = cols; > Hmm, it seems there is precedent for using private functions and variables of readline, the ones advertised as "functions and variables global to the readline library, but not intended for use by applications": ... $ find gdb* -type f | grep -v ChangeLog | xargs grep -i "extern.*[^a-zA-Z]_rl_" gdb/tui/tui-io.c: extern int _rl_echoing_p; gdb/completer.c: extern int _rl_complete_mark_directories; gdb/completer.c:extern int _rl_completion_prefix_display_length; gdb/completer.c:extern int _rl_print_completions_horizontally; gdb/completer.c:EXTERN_C int _rl_qsort_string_compare (const void *, const void *); gdb/cli-out.c:EXTERN_C void _rl_erase_entire_line (void); ... So, this patch could be simplified by just using _rl_term_autowrap. Thanks, - Tom