From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id oERnIPZH/GlxsR0AWB0awg (envelope-from ) for ; Thu, 07 May 2026 04:06:14 -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=P6aQy9np; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 724101E093; Thu, 07 May 2026 04:06:14 -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 A8D831E093 for ; Thu, 07 May 2026 04:06:08 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9DD844BA2E1C for ; Thu, 7 May 2026 08:06:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9DD844BA2E1C 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=P6aQy9np Received: from postout1.mail.lrz.de (postout1.mail.lrz.de [IPv6:2001:4ca0:0:103::81bb:ff89]) by sourceware.org (Postfix) with ESMTPS id D12FB4BA2E1E for ; Thu, 7 May 2026 08:03:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D12FB4BA2E1E 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 D12FB4BA2E1E Authentication-Results: sourceware.org; arc=none smtp.remote-ip=2001:4ca0:0:103::81bb:ff89 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778141022; cv=none; b=s+eHYa8mG0Qu8G1XntZrUzxjNRtF9H+JPg9llKp8l+lfsrLAEqIyPooNZnK6mWtHSATlogajyKn8/UolTbZLGfTQaC/mZKTpwlq07BJPudVdsUmXuilhU3b5V0f+THecEQfitZt+FF7lP2/yKUpvz+9YXMJWjV6763HyIUOZRGk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1778141022; c=relaxed/simple; bh=wty8Cjo3RFEnnwht92sY6yl9ls8vJxmSFxmGZ3/hGn4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=WLL4oySHKbojG45OiJqMYjnZBUa/Lj/5sgHKn7LPnC+ev7bqrAbpEaiRPMsiGJCpVpJQUjEA9a0lpOSHywtUKvcR/7UWMtM3kyLVEM+t46AsAxBtQP4gVFRyyk8ba68U2p09maFKgHK2Y1Nb+oUS+ckY6k5trIIneWA6PUBOSUQ= 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=P6aQy9np DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D12FB4BA2E1E Received: from lxmhs51.srv.lrz.de (localhost [127.0.0.1]) by postout1.mail.lrz.de (Postfix) with ESMTP id 4gB4Wc0tP2zyYn; Thu, 7 May 2026 10:03:40 +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 :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=tu-postout21; t=1778141019; bh=jfsDfaLTZBo igI8H/P53IczCqKt3y1YOrFxdZUrxRQU=; b=P6aQy9nprD+mbVjovoD2gzOJyxv gIHa6YLnRdQm/BKqEMxog8HesMgp3MPG7v2fZvRy3w2B65NL2lryyIZH/+1IuSYz 143EltZB+Nr12lo7qiJtAw/ifgCaTN4+00r8Zx28d5s35tbzii9igWU9mnyv/Jhh m1PfgRWFWH5ZAU//RE3qYPD/xRpRpE48X6oZ9f0AEhQmqTLTuOaoZE7GuOspH0Sh Senf6mKS5wi7v50CDwoZVqvIxzd5d/nb37y+dXXI6uLxcgb65oPGuL9k9HGhmCtW wnCMR9KZ9v9CVav7ENaygMuHyxSq1kDsL0bNBtnAcwQ3VwGWRtJYZ/xdSUw== X-Virus-Scanned: by amavisd-new at lrz.de in lxmhs51.srv.lrz.de Received: from postout1.mail.lrz.de ([127.0.0.1]) by lxmhs51.srv.lrz.de (lxmhs51.srv.lrz.de [127.0.0.1]) (amavis, port 20024) with LMTP id 9R_hUENsu_b2; Thu, 7 May 2026 10:03:39 +0200 (CEST) Received: from yogamango (p200300eda72a3c00971195b06483f650.dip0.t-ipconnect.de [IPv6:2003:ed:a72a:3c00:9711:95b0:6483:f650]) (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 postout1.mail.lrz.de (Postfix) with ESMTPSA id 4gB4Wb3qYPzyYm; Thu, 7 May 2026 10:03:39 +0200 (CEST) From: jakob.schaeffeler@tum.de To: gdb-patches@sourceware.org Cc: =?UTF-8?q?Jakob=20Sch=C3=A4ffeler?= Subject: [PATCH] gdb/tui: Fix unexpected reuse of color pairs Date: Thu, 7 May 2026 10:03:27 +0200 Message-ID: <20260507080327.1690909-1-jakob.schaeffeler@tum.de> X-Mailer: git-send-email 2.54.0 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 in 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 returns an int instead of short. This patch was tested with make check-gdb TESTS="gdb.tui/*.exp" Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=34134 --- gdb/tui/tui-io.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/gdb/tui/tui-io.c b/gdb/tui/tui-io.c index 642b88ead0c..5e239179b5e 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,7 @@ get_color_pair (int fg, int bg) back to the default if we've used too many. */ if (next >= COLOR_PAIRS) return 0; - init_pair (next, fg, bg); + init_extended_pair (next, fg, bg); color_pair_map[c] = next; return next; } @@ -320,9 +316,7 @@ 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 +336,7 @@ 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; + wcolor_set (w, 0, &pair); } } @@ -907,7 +898,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