From: jakob.schaeffeler@tum.de
To: gdb-patches@sourceware.org
Cc: "Jakob Schäffeler" <jakob.schaeffeler@tum.de>
Subject: [PATCH] gdb/tui: Fix unexpected reuse of color pairs
Date: Thu, 7 May 2026 10:03:27 +0200 [thread overview]
Message-ID: <20260507080327.1690909-1-jakob.schaeffeler@tum.de> (raw)
From: Jakob Schäffeler <jakob.schaeffeler@tum.de>
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
next reply other threads:[~2026-05-07 8:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-07 8:03 jakob.schaeffeler [this message]
2026-05-08 9:23 ` Andrew Burgess
2026-05-08 9:55 ` Jakob Schäffeler
2026-07-20 11:19 ` Jakob Schäffeler
2026-05-09 21:27 ` [PATCH v2] " jakob.schaeffeler
2026-07-21 11:09 ` Andrew Burgess
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260507080327.1690909-1-jakob.schaeffeler@tum.de \
--to=jakob.schaeffeler@tum.de \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox