From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id Aa5gAA2n/2lMvikAWB0awg (envelope-from ) for ; Sat, 09 May 2026 17:28:45 -0400 Authentication-Results: simark.ca; dkim=pass (2048-bit key; secure) header.d=tum.de header.i=@tum.de header.a=rsa-sha256 header.s=tu-postout21 header.b=ihfrrYgF; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id E99321E0C3; Sat, 09 May 2026 17:28:44 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.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 73D6B1E067 for ; Sat, 09 May 2026 17:28:37 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2011F4BA23C9 for ; Sat, 9 May 2026 21:28:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2011F4BA23C9 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, secure) header.d=tum.de header.i=@tum.de header.a=rsa-sha256 header.s=tu-postout21 header.b=ihfrrYgF Received: from postout2.mail.lrz.de (postout2.mail.lrz.de [129.187.255.138]) by sourceware.org (Postfix) with ESMTPS id CBF244BA2E1C for ; Sat, 9 May 2026 21:27:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CBF244BA2E1C Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=tum.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tum.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CBF244BA2E1C Authentication-Results: sourceware.org; arc=none smtp.remote-ip=129.187.255.138 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778362079; cv=none; b=RvoDMN8/Tlvut+lTr4vqWHK2R9HN0JvTh696Te8+XbSUrAhW+hPlvRZ2BD48YlX17P/S83/NCIg6lfYFp/3KIr5Ms2kmeDEuWmljpMd3bmxZDaPy+gMEW/bZAH0YWL7CRwCVTDZK10b6c0N5j9cHZcdPZdVCmuFWwYIjEw803AA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778362079; c=relaxed/simple; bh=AZ2XAoNy4vC6bJJ/5B3FS7Kp8naN/CpkfXXhnG5dIJU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=u36aQ6kRMVIgBmsQnYXxPFPN8Zv+FRGBjTpEQwTrY/0gbgQovYOd05ZFmyE+IHXLBTXkubezCU+92D/DP7cIOsTSv80DpKj+Ei78DY9gHk+KjV/+pWOh3ccywkb+emn2+iHZK3euE/7MZYpzXEY7AnvXGXRHhE7GArkwfsPCA7I= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, secure) header.d=tum.de header.i=@tum.de header.a=rsa-sha256 header.s=tu-postout21 header.b=ihfrrYgF DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CBF244BA2E1C Received: from lxmhs52.srv.lrz.de (localhost [127.0.0.1]) by postout2.mail.lrz.de (Postfix) with ESMTP id 4gCfGh4nPtzyTL; Sat, 9 May 2026 23:27:56 +0200 (CEST) Authentication-Results: postout.lrz.de (amavis); dkim=pass (2048-bit key) reason="pass (just generated, assumed good)" header.d=tum.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tum.de; h= content-transfer-encoding:content-type:content-type:mime-version :references:in-reply-to:x-mailer:message-id:date:date:subject :subject:from:from:received:received; s=tu-postout21; t= 1778362076; bh=xq9u6fSMSlf2VMziQvDJUqggUFKo1i9eEH4tiEQG2v8=; b=i hfrrYgFI+JZVSf8OiejqrL7sIHtw6yZ/choqpz/grHTww+qJc8CQkYemjuLwzCH6 d1msran8iThpFUo/5M0bsDQTIbI85D572jrJGF7U1F2YaenCvcAQiuaRF6HSXQi2 CP9DFZkVY6hVx4UrkUQCDPTJdR3MyQAQvnYXlmHKyER2ddkbbUIpwYCv3Kf5hkPo qOu/zE3f0IMMEiSDmenyIOMgHY7Ytsrl2juDkNhaPpjX4WP65ER7adBQRV7hW8Jy 9GDm2SckL8TzahTBgXmrlbZXhFst5kQ4J2G1k8t7833p9uerFQPvWxGlhsg3fDr+ ZA+xMWdXxsIJsg02B8ggg== X-Virus-Scanned: by amavisd-new at lrz.de in lxmhs52.srv.lrz.de Received: from postout2.mail.lrz.de ([127.0.0.1]) by lxmhs52.srv.lrz.de (lxmhs52.srv.lrz.de [127.0.0.1]) (amavis, port 20024) with LMTP id TCManWVSDUOP; Sat, 9 May 2026 23:27:56 +0200 (CEST) Received: from yogamango (p200300eda73390000252b04f6e0e5f05.dip0.t-ipconnect.de [IPv6:2003:ed:a733:9000:252:b04f:6e0e:5f05]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by postout2.mail.lrz.de (Postfix) with ESMTPSA id 4gCfGg6g9HzyTG; Sat, 9 May 2026 23:27:55 +0200 (CEST) From: jakob.schaeffeler@tum.de To: gdb-patches@sourceware.org Cc: =?UTF-8?q?Jakob=20Sch=C3=A4ffeler?= Subject: [PATCH v2] gdb/tui: Fix unexpected reuse of color pairs Date: Sat, 9 May 2026 23:27:43 +0200 Message-ID: <20260509212744.2071791-1-jakob.schaeffeler@tum.de> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260507080327.1690909-1-jakob.schaeffeler@tum.de> References: <20260507080327.1690909-1-jakob.schaeffeler@tum.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 From: Jakob Schäffeler TUI translates ANSI styling sequences to curses color pairs. Currently, this process uses COLOR_PAIR, which only returns values from 0 to 255 which results in unexpected reuse of color pairs. This patch avoids calling COLOR_PAIR(pair) to be able to render more than 256 color pairs. For this, the wattron call is replaced with wcolor_set. This also results in last_color_pair no longer being needed since we set the color directly with wcolor_set and do not need wattron/off pairs any longer. This results in SHRT_MAX different color pairs to be available. To get all 65535 color pairs, init_pair is replaced with init_extended_pair, which takes an int instead of a short. Since this is not available with ncurses versions older than 6.1, a configure check was added. This patch was tested with make check-gdb TESTS="gdb.tui/*.exp" Additionally, I tested this with the python extension from the bug report. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34134 --- gdb/config.in | 3 +++ gdb/configure | 1 + gdb/configure.ac | 1 + gdb/tui/tui-io.c | 23 +++++++++++------------ 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/gdb/config.in b/gdb/config.in index e357c22e411..fa436f32fbf 100644 --- a/gdb/config.in +++ b/gdb/config.in @@ -250,6 +250,9 @@ /* Define to 1 if you have the `iconvlist' function. */ #undef HAVE_ICONVLIST +/* Define to 1 if you have the `init_extended_pair' function. */ +#undef HAVE_INIT_EXTENDED_PAIR + /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H diff --git a/gdb/configure b/gdb/configure index 2fc0b583702..6fcba0ba454 100755 --- a/gdb/configure +++ b/gdb/configure @@ -30235,6 +30235,7 @@ for ac_func in \ getrlimit \ getuid \ iconvlist \ + init_extended_pair \ libiconvlist \ posix_madvise \ pread \ diff --git a/gdb/configure.ac b/gdb/configure.ac index 56ab86d9356..998e2947f03 100644 --- a/gdb/configure.ac +++ b/gdb/configure.ac @@ -1507,6 +1507,7 @@ AC_CHECK_FUNCS([ \ getrlimit \ getuid \ iconvlist \ + init_extended_pair \ libiconvlist \ posix_madvise \ pread \ diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c index 642b88ead0c..943b158be58 100644 --- a/gdb/tui/tui-io.c +++ b/gdb/tui/tui-io.c @@ -265,10 +265,6 @@ get_color (const ui_file_style::color &color, int *result) return true; } -/* The most recently emitted color pair. */ - -static int last_color_pair = -1; - /* The most recently applied style. */ static ui_file_style last_style; @@ -299,7 +295,11 @@ get_color_pair (int fg, int bg) back to the default if we've used too many. */ if (next >= COLOR_PAIRS) return 0; +#ifdef HAVE_INIT_EXTENDED_PAIR + init_extended_pair (next, fg, bg); +#else init_pair (next, fg, bg); +#endif color_pair_map[c] = next; return next; } @@ -320,9 +320,8 @@ tui_apply_style (WINDOW *w, ui_file_style style) #endif wattroff (w, A_UNDERLINE); wattroff (w, A_REVERSE); - if (last_color_pair != -1) - wattroff (w, COLOR_PAIR (last_color_pair)); - wattron (w, COLOR_PAIR (0)); + + wcolor_set (w, 0, nullptr); const ui_file_style::color &fg = style.get_foreground (); const ui_file_style::color &bg = style.get_background (); @@ -342,10 +341,11 @@ tui_apply_style (WINDOW *w, ui_file_style style) bgi = (ncurses_norm_attr >> 4) & 15; #endif int pair = get_color_pair (fgi, bgi); - if (last_color_pair != -1) - wattroff (w, COLOR_PAIR (last_color_pair)); - wattron (w, COLOR_PAIR (pair)); - last_color_pair = pair; +#ifdef HAVE_INIT_EXTENDED_PAIR + wcolor_set (w, 0, &pair); +#else + wcolor_set (w, pair, nullptr); +#endif } } @@ -907,7 +907,6 @@ tui_setup_io (int mode) savetty (); /* Clean up color information. */ - last_color_pair = -1; last_style = ui_file_style (); color_map.clear (); color_pair_map.clear (); -- 2.54.0