From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id oX3rNwkXLGpxTAMAWB0awg (envelope-from ) for ; Fri, 12 Jun 2026 10:26:17 -0400 Authentication-Results: simark.ca; dkim=fail reason="signature verification failed" (768-bit key; unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=S7o8neRg; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id E17621E070; Fri, 12 Jun 2026 10:26:17 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.8 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::32]) (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 39CEF1E070 for ; Fri, 12 Jun 2026 10:26:17 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0A22C4B99F60 for ; Fri, 12 Jun 2026 14:26:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0A22C4B99F60 Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (768-bit key, unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=S7o8neRg Received: from omta40.uswest2.a.cloudfilter.net (omta40.uswest2.a.cloudfilter.net [35.89.44.39]) by sourceware.org (Postfix) with ESMTPS id 681004BA799B for ; Fri, 12 Jun 2026 14:25:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 681004BA799B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 681004BA799B Authentication-Results: sourceware.org; arc=none smtp.remote-ip=35.89.44.39 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1781274327; cv=none; b=O+BzO76huU2JmzALGN4Mp1RaSqnjjv19mBRV65XkIdZaG27rnvcqkgRrAUDUoYWd0Bu8F9AQdJ+xL1vX65Yn40+sRf9/sjIx5O4Uazic5Vkmlihpbe2tHLTgWsAgyktQy7e662t476ZrTn082P87p+JVAOU5hqIVUU/sho1CUiI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1781274327; c=relaxed/simple; bh=RIMcaFd3zWc9mKsdHIK1TjI99adt/RTk6yfRlqJC/Vo=; h=DKIM-Signature:From:Date:Subject:MIME-Version:Message-Id:To; b=ktBvjrLIWNUgFyfy0cXK3Qeeeg+1fCRTq1blhpOATi/qSLXydmAaGMV8WM4EIKBbFyrWf9wAyCnHGb7iBr7Dv02MK2TnIl6Pv53yCwBuwm/fjM/MK4TPJDSzvQGTOD2KC/+4WBoru38pPbPdQBTUSwgfnxqtAYzaJbJ+vsAfUkg= ARC-Authentication-Results: i=1; sourceware.org; dkim=policy (768-bit key, unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=S7o8neRg reason="signing key too small" DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 681004BA799B Received: from eig-obgw-5001b.ext.cloudfilter.net ([10.0.29.181]) by cmsmtp with ESMTPS id Xd8ow9ZQVjgweY2p3weuUN; Fri, 12 Jun 2026 14:25:26 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id Y2p2wc2yc5zk0Y2p2w6FBm; Fri, 12 Jun 2026 14:25:24 +0000 X-Authority-Analysis: v=2.4 cv=GPEIEvNK c=1 sm=1 tr=0 ts=6a2c16d5 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=IkcTkHD0fZMA:10 a=FelO9ux0wxsA:10 a=ItBw4LHWJt0A:10 a=avLQ7BjAPwFzqbIKO_sA:9 a=QEXdDO2ut3YA:10 a=DCx65vhANUyCzuf5D8fC:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Kol9Gh0yp0dLpf0md7flp59CIMyEW3N1JlbGPkFGxmQ=; b=S7o8neRgT4h+i+3tKWuyGS6IQl Tfa+e5BkCorkeadm1Zc1Q30lMnAQ6ORdZUdZuW2Zobr7mWnghZb4K4CvYR48GxzuwRccNmM4ASPf3 SP/GgL5fQyeZRCNVyJ+wEJuq0; Received: from 75-166-225-82.hlrn.qwest.net ([75.166.225.82]:50348 helo=[192.168.122.1]) by box5379.bluehost.com with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.99.2) (envelope-from ) id 1wY2p1-00000001fM4-3hQg; Fri, 12 Jun 2026 08:25:23 -0600 From: Tom Tromey Date: Fri, 12 Jun 2026 08:25:21 -0600 Subject: [PATCH 1/5] Ensure tgetent is called before tgetnum MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260612-submit-zebra-style-v1-1-cfd00b5c984c@tromey.com> References: <20260612-submit-zebra-style-v1-0-cfd00b5c984c@tromey.com> In-Reply-To: <20260612-submit-zebra-style-v1-0-cfd00b5c984c@tromey.com> To: gdb-patches@sourceware.org Cc: Tom Tromey X-Mailer: b4 0.14.3 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 75.166.225.82 X-Source-L: No X-Exim-ID: 1wY2p1-00000001fM4-3hQg X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-225-82.hlrn.qwest.net ([192.168.122.1]) [75.166.225.82]:50348 X-Source-Auth: tom+tromey.com X-Email-Count: 2 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfNqd2D3t0k8wZCXwEelYPdWu8YeR2q0TbBCRDW6lkDiFmxhX96vzPsvaVW8qmXYvCnuWpoER2RTAdXI7af1+7PA2mL9b9HWz/TSW6vxQLT6brc0Wc4YU xd0Jc/w6H10Pzto//htUc1yEWRip+XIyA63SpE0ts9KKFibiujIk0oqVj6s9YYME3PMODn2SrpkaUMlEv8B7cu2GalVkIoM7CLE= 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 A patch in this series will cause gdb_get_ncolors to be called earlier in startup. I was surprised to find that this function was failing when gdb was run from the test suite, and eventually I tracked this down to the fact that gdb_get_ncolors calls tgetnum but does not first ensure that tgetent is called. This patch changes the code to ensure tgetent is always called first. I believe tgetent is idempotent so this is safe to do. The new test case is distilled from the test that was failing for me. Note that it does not actually fail without this patch -- the current gdb passes here. However by the end of the series this test would fail without this patch, so it just assures there won't be a failure here. --- gdb/mingw-hdep.c | 6 +----- gdb/posix-hdep.c | 6 +----- gdb/testsuite/gdb.base/style.exp | 14 ++++++++++++++ gdb/ui-style.c | 30 ++++++++++++++++++++++++++++++ gdb/ui-style.h | 3 +++ 5 files changed, 49 insertions(+), 10 deletions(-) diff --git a/gdb/mingw-hdep.c b/gdb/mingw-hdep.c index 90ebe252f57..d4607b1214f 100644 --- a/gdb/mingw-hdep.c +++ b/gdb/mingw-hdep.c @@ -273,11 +273,7 @@ mingw_deinitialize_console () int gdb_get_ncolors () { - /* ncurses versions prior to 6.1 (and other curses - implementations) declare the tgetnum argument to be - 'char *', so we need the const_cast, since C++ will not - implicitly convert. */ - int nc = tgetnum (const_cast ("Co")); + int nc = basic_gdb_get_ncolors (); /* MS-Windows terminal generally doesn't have "Co" in its terminfo, but always supports at least 8 colors. */ if (nc <= 0) diff --git a/gdb/posix-hdep.c b/gdb/posix-hdep.c index b9aff9ede1f..a87d55a3957 100644 --- a/gdb/posix-hdep.c +++ b/gdb/posix-hdep.c @@ -46,11 +46,7 @@ gdb_console_fputs (const char *buf, FILE *f) int gdb_get_ncolors () { - /* ncurses versions prior to 6.1 (and other curses - implementations) declare the tgetnum argument to be - 'char *', so we need the const_cast, since C++ will not - implicitly convert. */ - return tgetnum (const_cast ("Co")); + return basic_gdb_get_ncolors (); } /* See inferior.h. */ diff --git a/gdb/testsuite/gdb.base/style.exp b/gdb/testsuite/gdb.base/style.exp index 8a49d1c5973..eb1cdf46112 100644 --- a/gdb/testsuite/gdb.base/style.exp +++ b/gdb/testsuite/gdb.base/style.exp @@ -1086,6 +1086,18 @@ proc test_logging_styling {} { "No symbol table is loaded\\. Use the \"[style file command]\" command\\." } +# Test that colors "round trip" in ANSI mode. +proc test_ansi_round_trip {} { + with_test_prefix "round-trip" { + with_ansi_styling_terminal { + clean_restart + gdb_test_no_output "set style address background red" + gdb_test "show style address background" \ + "The .*address.* background color is: red" + } + } +} + # Check to see if the Python styling of disassembler output is # expected or not, this styling requires Python support in GDB, and # the Python pygments module to be available. @@ -1133,3 +1145,5 @@ test_pagination_prompt_styling test_pagination_continue_styling test_finish_styling test_logging_styling + +test_ansi_round_trip diff --git a/gdb/ui-style.c b/gdb/ui-style.c index ab2b0ad5de4..3dd26fbc79a 100644 --- a/gdb/ui-style.c +++ b/gdb/ui-style.c @@ -578,6 +578,36 @@ examine_ansi_escape (const char *buf, int *n_read) /* See ui-style.h. */ +int +basic_gdb_get_ncolors () +{ + static std::optional result; + + if (!result.has_value ()) + { + const char *term_name = getenv ("TERM"); + if (term_name == nullptr) + result = -1; + else + { + char desc[4096]; + /* Ignore the result here. Some versions of termcap are + confused about this. */ + tgetent (desc, term_name); + + /* ncurses versions prior to 6.1 (and other curses + implementations) declare the tgetnum argument to be + 'char *', so we need the const_cast, since C++ will not + implicitly convert. */ + result = tgetnum (const_cast ("Co")); + } + } + + return *result; +} + +/* See ui-style.h. */ + const std::vector & colorsupport () { diff --git a/gdb/ui-style.h b/gdb/ui-style.h index fc40b93709d..52f5a5a104d 100644 --- a/gdb/ui-style.h +++ b/gdb/ui-style.h @@ -51,6 +51,9 @@ extern const char * color_space_name (color_space c); /* Cast C to RESULT and return true if it's value is valid; false otherwise. */ extern bool color_space_safe_cast (color_space *result, long c); +/* Basic implementation of gdb_get_ncolors that checks tgetent. */ +extern int basic_gdb_get_ncolors (); + /* Get the number of colors supported by the terminal where GDB is running. */ extern int gdb_get_ncolors (); -- 2.49.0