The "set style" commands which set colors are broken on MS-Windows (was: [ANNOUNCEMENT] GDB 17.1 released!)

Message ID 86h5t1gsp9.fsf@gnu.org
State New
Headers
Series The "set style" commands which set colors are broken on MS-Windows (was: [ANNOUNCEMENT] GDB 17.1 released!) |

Commit Message

Eli Zaretskii Jan. 4, 2026, 6:04 p.m. UTC
  > Date: Sat, 20 Dec 2025 09:30:09 +0400 (+04)
> From: Joel Brobecker via Gdb-announce via Gdb <gdb@sourceware.org>
> Cc: Joel Brobecker via Gdb-announce <gdb-announce@sourceware.org>
> 
> 
>             GDB 17.1 released!
> 
> Release 17.1 of GDB, the GNU Debugger, is now available.  GDB is
> a source-level debugger for Ada, C, C++, Fortran, Go, Rust, and many
> other languages.  GDB can target (i.e., debug programs running on)
> more than a dozen different processor architectures, and GDB itself
> can run on most popular GNU/Linux, Unix and Microsoft Windows variants.
> GDB is free (libre) software.
> 
> You can download GDB from the GNU HTTPS server in the directory:
> 
>         https://ftp.gnu.org/gnu/gdb/?C=M;O=D

I've built GDB 17.1 today on MS-Windows with MinGW, and found that the
commands which set colors of styling are broken.  Specifically, the
default colors do work, and are displayed as expected, but as soon as
one types a "set style SOMETHING foreground COLOR" command, the
specified color is reset to "none".

The reason is this code in ui-style.c:

const std::vector<color_space> &
colorsupport ()
{
  static const std::vector<color_space> value = []
    {
      std::vector<color_space> result = {color_space::MONOCHROME};

      int colors = tgetnum ("Co");
      if (colors >= 8)
	result.push_back (color_space::ANSI_8COLOR);
      if (colors >= 16)
	result.push_back (color_space::AIXTERM_16COLOR);
      if (colors >= 256)
	result.push_back (color_space::XTERM_256COLOR);

This relies on the terminfo's "Co" capability for determining the
number of colors supported by the terminal.  However, Windows
terminals usually lack terminfo entries, so the above code decides
that the terminal doesn't support colors at all.

The simplest fix is below.  I filed a Bugzilla bug 33761 due to this.
I think this should be fixed both on master and on the branch.

Here's the proposed patch:
  

Comments

Eli Zaretskii Jan. 17, 2026, 12:29 p.m. UTC | #1
> Date: Sun, 04 Jan 2026 20:04:34 +0200
> From: Eli Zaretskii <eliz@gnu.org>
> 
> > Date: Sat, 20 Dec 2025 09:30:09 +0400 (+04)
> > From: Joel Brobecker via Gdb-announce via Gdb <gdb@sourceware.org>
> > Cc: Joel Brobecker via Gdb-announce <gdb-announce@sourceware.org>
> > 
> > 
> >             GDB 17.1 released!
> > 
> > Release 17.1 of GDB, the GNU Debugger, is now available.  GDB is
> > a source-level debugger for Ada, C, C++, Fortran, Go, Rust, and many
> > other languages.  GDB can target (i.e., debug programs running on)
> > more than a dozen different processor architectures, and GDB itself
> > can run on most popular GNU/Linux, Unix and Microsoft Windows variants.
> > GDB is free (libre) software.
> > 
> > You can download GDB from the GNU HTTPS server in the directory:
> > 
> >         https://ftp.gnu.org/gnu/gdb/?C=M;O=D
> 
> I've built GDB 17.1 today on MS-Windows with MinGW, and found that the
> commands which set colors of styling are broken.  Specifically, the
> default colors do work, and are displayed as expected, but as soon as
> one types a "set style SOMETHING foreground COLOR" command, the
> specified color is reset to "none".
> 
> The reason is this code in ui-style.c:
> 
> const std::vector<color_space> &
> colorsupport ()
> {
>   static const std::vector<color_space> value = []
>     {
>       std::vector<color_space> result = {color_space::MONOCHROME};
> 
>       int colors = tgetnum ("Co");
>       if (colors >= 8)
> 	result.push_back (color_space::ANSI_8COLOR);
>       if (colors >= 16)
> 	result.push_back (color_space::AIXTERM_16COLOR);
>       if (colors >= 256)
> 	result.push_back (color_space::XTERM_256COLOR);
> 
> This relies on the terminfo's "Co" capability for determining the
> number of colors supported by the terminal.  However, Windows
> terminals usually lack terminfo entries, so the above code decides
> that the terminal doesn't support colors at all.
> 
> The simplest fix is below.  I filed a Bugzilla bug 33761 due to this.
> I think this should be fixed both on master and on the branch.
> 
> Here's the proposed patch:

Ping!  Any objections to installing this patch, both on master and on
the branch?
  
Andrew Burgess Jan. 17, 2026, 1:02 p.m. UTC | #2
Eli Zaretskii <eliz@gnu.org> writes:

>> Date: Sun, 04 Jan 2026 20:04:34 +0200
>> From: Eli Zaretskii <eliz@gnu.org>
>> 
>> > Date: Sat, 20 Dec 2025 09:30:09 +0400 (+04)
>> > From: Joel Brobecker via Gdb-announce via Gdb <gdb@sourceware.org>
>> > Cc: Joel Brobecker via Gdb-announce <gdb-announce@sourceware.org>
>> > 
>> > 
>> >             GDB 17.1 released!
>> > 
>> > Release 17.1 of GDB, the GNU Debugger, is now available.  GDB is
>> > a source-level debugger for Ada, C, C++, Fortran, Go, Rust, and many
>> > other languages.  GDB can target (i.e., debug programs running on)
>> > more than a dozen different processor architectures, and GDB itself
>> > can run on most popular GNU/Linux, Unix and Microsoft Windows variants.
>> > GDB is free (libre) software.
>> > 
>> > You can download GDB from the GNU HTTPS server in the directory:
>> > 
>> >         https://ftp.gnu.org/gnu/gdb/?C=M;O=D
>> 
>> I've built GDB 17.1 today on MS-Windows with MinGW, and found that the
>> commands which set colors of styling are broken.  Specifically, the
>> default colors do work, and are displayed as expected, but as soon as
>> one types a "set style SOMETHING foreground COLOR" command, the
>> specified color is reset to "none".
>> 
>> The reason is this code in ui-style.c:
>> 
>> const std::vector<color_space> &
>> colorsupport ()
>> {
>>   static const std::vector<color_space> value = []
>>     {
>>       std::vector<color_space> result = {color_space::MONOCHROME};
>> 
>>       int colors = tgetnum ("Co");
>>       if (colors >= 8)
>> 	result.push_back (color_space::ANSI_8COLOR);
>>       if (colors >= 16)
>> 	result.push_back (color_space::AIXTERM_16COLOR);
>>       if (colors >= 256)
>> 	result.push_back (color_space::XTERM_256COLOR);
>> 
>> This relies on the terminfo's "Co" capability for determining the
>> number of colors supported by the terminal.  However, Windows
>> terminals usually lack terminfo entries, so the above code decides
>> that the terminal doesn't support colors at all.
>> 
>> The simplest fix is below.  I filed a Bugzilla bug 33761 due to this.
>> I think this should be fixed both on master and on the branch.
>> 
>> Here's the proposed patch:
>
> Ping!  Any objections to installing this patch, both on master and on
> the branch?

Sorry, I meant to get back to you on this.  I've got no objections.

Thanks,
Andrew
  
Eli Zaretskii Jan. 18, 2026, 10:13 a.m. UTC | #3
> From: Andrew Burgess <aburgess@redhat.com>
> Date: Sat, 17 Jan 2026 13:02:11 +0000
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> >> const std::vector<color_space> &
> >> colorsupport ()
> >> {
> >>   static const std::vector<color_space> value = []
> >>     {
> >>       std::vector<color_space> result = {color_space::MONOCHROME};
> >> 
> >>       int colors = tgetnum ("Co");
> >>       if (colors >= 8)
> >> 	result.push_back (color_space::ANSI_8COLOR);
> >>       if (colors >= 16)
> >> 	result.push_back (color_space::AIXTERM_16COLOR);
> >>       if (colors >= 256)
> >> 	result.push_back (color_space::XTERM_256COLOR);
> >> 
> >> This relies on the terminfo's "Co" capability for determining the
> >> number of colors supported by the terminal.  However, Windows
> >> terminals usually lack terminfo entries, so the above code decides
> >> that the terminal doesn't support colors at all.
> >> 
> >> The simplest fix is below.  I filed a Bugzilla bug 33761 due to this.
> >> I think this should be fixed both on master and on the branch.
> >> 
> >> Here's the proposed patch:
> >
> > Ping!  Any objections to installing this patch, both on master and on
> > the branch?
> 
> Sorry, I meant to get back to you on this.  I've got no objections.

Thanks, now installed on master and on the branch.
  

Patch

--- gdb/ui-style.c~	2025-12-20 04:53:21.000000000 +0200
+++ gdb/ui-style.c	2026-01-04 19:13:51.707357200 +0200
@@ -595,6 +595,12 @@  colorsupport ()
       std::vector<color_space> result = {color_space::MONOCHROME};
 
       int colors = tgetnum ("Co");
+#ifdef __MINGW32__
+      /* MS-Windows terminal generally doesn't have "Co" in its
+         terminfo, but always supports 8 colors.  */
+      if (colors <= 0)
+	colors = 8;
+#endif
       if (colors >= 8)
 	result.push_back (color_space::ANSI_8COLOR);
       if (colors >= 16)