Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] gdb/tui: Fix unexpected reuse of color pairs
@ 2026-05-07  8:03 jakob.schaeffeler
  2026-05-08  9:23 ` Andrew Burgess
  2026-05-09 21:27 ` [PATCH v2] " jakob.schaeffeler
  0 siblings, 2 replies; 6+ messages in thread
From: jakob.schaeffeler @ 2026-05-07  8:03 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jakob Schäffeler

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] gdb/tui: Fix unexpected reuse of color pairs
  2026-05-07  8:03 [PATCH] gdb/tui: Fix unexpected reuse of color pairs jakob.schaeffeler
@ 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
  1 sibling, 2 replies; 6+ messages in thread
From: Andrew Burgess @ 2026-05-08  9:23 UTC (permalink / raw)
  To: jakob.schaeffeler, gdb-patches; +Cc: Jakob Schäffeler


Thanks for working on this.  This looks like it could be a good
improvement.

jakob.schaeffeler@tum.de writes:

> From: Jakob Schäffeler <jakob.schaeffeler@tum.de>

Commit message text should be line wrapped at around 72 characters, your
commit message will need to be reformatted so that it is readable in
'git log' output.

>
> 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.

typo: "Currently, this process uses COLOR_PAIR, which only returns values ..."

> 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.

typo: "...which TAKES int instead of short.".  They both return 'int'.

> This patch was tested with make check-gdb TESTS="gdb.tui/*.exp"

It would be good if there was a new test added which checks the new
extended colour range.  Is there a reason why this cannot be done?

I also wonder how widely available this extended colour API is?  Is this
supported on mingw?  Or FreeBSD?  Or Solaris (is this even
used/supported these days)?  I wonder if we should be adding configure
checks for this API, or if it's OK to just put a hard requirement in
place?   At the very least it would be nice to document in the commit
message if nowhere else, what version/package requirements this is now
placing on us.

Also, I suspect this patch is probably more than trivial, so we will
probably need a copyright assignment in agreement before we could accept
it.  Information on this process can be found here:

https://sourceware.org/gdb/wiki/ContributionChecklist#FSF_copyright_Assignment

If you have any questions, feel free to ask and we can help out.

Thanks,
Andrew


>
> 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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] gdb/tui: Fix unexpected reuse of color pairs
  2026-05-08  9:23 ` Andrew Burgess
@ 2026-05-08  9:55   ` Jakob Schäffeler
  2026-07-20 11:19   ` Jakob Schäffeler
  1 sibling, 0 replies; 6+ messages in thread
From: Jakob Schäffeler @ 2026-05-08  9:55 UTC (permalink / raw)
  To: gdb-patches, aburgess

[-- Attachment #1: Type: text/plain, Size: 5054 bytes --]

Thanks for the quick reply and the feedback!

On Fri, 2026-05-08 at 10:23 +0100, Andrew Burgess wrote:
> 
> Thanks for working on this.  This looks like it could be a good
> improvement.
> 
> jakob.schaeffeler@tum.de writes:
> 
> > From: Jakob Schäffeler <jakob.schaeffeler@tum.de>
> 
> Commit message text should be line wrapped at around 72 characters,
> your
> commit message will need to be reformatted so that it is readable in
> 'git log' output.
> 
> > 
> > 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.
> 
> typo: "Currently, this process uses COLOR_PAIR, which only returns
> values ..."
> 
> > 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.
> 
> typo: "...which TAKES int instead of short.".  They both return
> 'int'.

Thanks for the feedback. I will fix this.

> 
> > This patch was tested with make check-gdb TESTS="gdb.tui/*.exp"
> 
> It would be good if there was a new test added which checks the new
> extended colour range.  Is there a reason why this cannot be done?
> 
> I also wonder how widely available this extended colour API is?  Is
> this
> supported on mingw?  Or FreeBSD?  Or Solaris (is this even
> used/supported these days)?  I wonder if we should be adding
> configure
> checks for this API, or if it's OK to just put a hard requirement in
> place?   At the very least it would be nice to document in the commit
> message if nowhere else, what version/package requirements this is
> now
> placing on us.
> 

The extended functions were added in 6.1 (Jan 27, 2018). I could try to
add checks along with conditional tests based on the ncurses version
used. 

> Also, I suspect this patch is probably more than trivial, so we will
> probably need a copyright assignment in agreement before we could
> accept
> it.  Information on this process can be found here:
> 
> https://sourceware.org/gdb/wiki/ContributionChecklist#FSF_copyright_Assignment
> 

Okay, I will do that. I thought it is trivial because it is only a few
lines.

> If you have any questions, feel free to ask and we can help out.
> 
> Thanks,
> Andrew
> 
> 
> > 
> > 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

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 3517 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2] gdb/tui: Fix unexpected reuse of color pairs
  2026-05-07  8:03 [PATCH] gdb/tui: Fix unexpected reuse of color pairs jakob.schaeffeler
  2026-05-08  9:23 ` Andrew Burgess
@ 2026-05-09 21:27 ` jakob.schaeffeler
  2026-07-21 11:09   ` Andrew Burgess
  1 sibling, 1 reply; 6+ messages in thread
From: jakob.schaeffeler @ 2026-05-09 21:27 UTC (permalink / raw)
  To: gdb-patches; +Cc: Jakob Schäffeler

From: Jakob Schäffeler <jakob.schaeffeler@tum.de>

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 <inttypes.h> 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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] gdb/tui: Fix unexpected reuse of color pairs
  2026-05-08  9:23 ` Andrew Burgess
  2026-05-08  9:55   ` Jakob Schäffeler
@ 2026-07-20 11:19   ` Jakob Schäffeler
  1 sibling, 0 replies; 6+ messages in thread
From: Jakob Schäffeler @ 2026-07-20 11:19 UTC (permalink / raw)
  To: gdb-patches, aburgess

[-- Attachment #1: Type: text/plain, Size: 5052 bytes --]

I addressed all your comments in a new version of the patch in
https://sourceware.org/pipermail/gdb-patches/2026-May/227275.html 

However, I needed to figure out who at my company could sign the
copyright assignment so this took a while. But this is now done.

Do you need anything else from my side?

Thanks,
Jakob 


On Fri, 2026-05-08 at 10:23 +0100, Andrew Burgess wrote:
> 
> Thanks for working on this.  This looks like it could be a good
> improvement.
> 
> jakob.schaeffeler@tum.de writes:
> 
> > From: Jakob Schäffeler <jakob.schaeffeler@tum.de>
> 
> Commit message text should be line wrapped at around 72 characters,
> your
> commit message will need to be reformatted so that it is readable in
> 'git log' output.
> 
> > 
> > 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.
> 
> typo: "Currently, this process uses COLOR_PAIR, which only returns
> values ..."
> 
> > 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.
> 
> typo: "...which TAKES int instead of short.".  They both return
> 'int'.
> 
> > This patch was tested with make check-gdb TESTS="gdb.tui/*.exp"
> 
> It would be good if there was a new test added which checks the new
> extended colour range.  Is there a reason why this cannot be done?
> 
> I also wonder how widely available this extended colour API is?  Is
> this
> supported on mingw?  Or FreeBSD?  Or Solaris (is this even
> used/supported these days)?  I wonder if we should be adding
> configure
> checks for this API, or if it's OK to just put a hard requirement in
> place?   At the very least it would be nice to document in the commit
> message if nowhere else, what version/package requirements this is
> now
> placing on us.
> 
> Also, I suspect this patch is probably more than trivial, so we will
> probably need a copyright assignment in agreement before we could
> accept
> it.  Information on this process can be found here:
> 
> https://sourceware.org/gdb/wiki/ContributionChecklist#FSF_copyright_Assignment
> 
> If you have any questions, feel free to ask and we can help out.
> 
> Thanks,
> Andrew
> 
> 
> > 
> > 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

[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 3517 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] gdb/tui: Fix unexpected reuse of color pairs
  2026-05-09 21:27 ` [PATCH v2] " jakob.schaeffeler
@ 2026-07-21 11:09   ` Andrew Burgess
  0 siblings, 0 replies; 6+ messages in thread
From: Andrew Burgess @ 2026-07-21 11:09 UTC (permalink / raw)
  To: jakob.schaeffeler, gdb-patches; +Cc: Jakob Schäffeler

jakob.schaeffeler@tum.de writes:

> From: Jakob Schäffeler <jakob.schaeffeler@tum.de>
>
> 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.

Thank you for the revisions.  I fixed a trailing white space issue in
the code, and reworded the commit message a bit to (I think) make some
things clearer.  I then pushed this patch.

I did look at possibly using the Python code from the bug to create a
test case, but that will require extending GDB's terminal emulation to
support the extended set of colours, which feels like a big task, so I
left that for now.

Thanks,
Andrew


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-07-21 11:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-05-07  8:03 [PATCH] gdb/tui: Fix unexpected reuse of color pairs jakob.schaeffeler
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox