]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb/tui: Fix build for older ncurses
authorCiaran Woodward <ciaranwoodward@xmos.com>
Thu, 11 Sep 2025 16:20:00 +0000 (16:20 +0000)
committerCiaran Woodward <ciaranwoodward@xmos.com>
Fri, 12 Sep 2025 17:15:37 +0000 (18:15 +0100)
Older versions of ncurses (including the version that ships inside
macos, and Centos 7) do not include the A_ITALIC macro. This patch
simply hides any use of A_ITALIC behind a preprocessor guard.

The result of this is that italics won't be rendered in the tui
if ncurses isn't supported. We do have other options if we think
it's important - for instance we could show italics as bold if
italics aren't supported. From my understanding, that might be
overthinking it - so I took the simplest approach here, just to
fix the build.

Those versions also define tgetnum as:
  int tgetnum(char *id);
so attempting to compile for c++ results in the error:
  ISO C++ forbids converting a string constant to 'char*' [-Werror=write-strings]

This is just a dated API issue, so a const cast resolves the issue.

Approved-By: Tom Tromey <tom@tromey.com>
gdb/tui/tui-io.c
gdb/ui-style.c

index c97e8fd17174c068fd4d805ba01887f3fed85652..84cad9366d51e3870b6135c6ec6cdc167b2e002e 100644 (file)
@@ -319,7 +319,9 @@ tui_apply_style (WINDOW *w, ui_file_style style)
   wattron (w, A_NORMAL);
   wattroff (w, A_BOLD);
   wattroff (w, A_DIM);
+#ifdef  A_ITALIC
   wattroff (w, A_ITALIC);
+#endif
   wattroff (w, A_UNDERLINE);
   wattroff (w, A_REVERSE);
   if (last_color_pair != -1)
@@ -368,8 +370,10 @@ tui_apply_style (WINDOW *w, ui_file_style style)
       gdb_assert_not_reached ("invalid intensity");
     }
 
+#ifdef  A_ITALIC
   if (style.is_italic ())
     wattron (w, A_ITALIC);
+#endif
 
   if (style.is_underline ())
     wattron (w, A_UNDERLINE);
index 9a58e4dd2aeea3ccb2c548d9876589a26b3edb82..d450c3e607947cbd3a52d655c1875101c329d7a5 100644 (file)
@@ -594,7 +594,11 @@ colorsupport ()
     {
       std::vector<color_space> result = {color_space::MONOCHROME};
 
-      int colors = tgetnum ("Co");
+      /* ncurses versions prior to 6.1 (and other curses
+        implementations) declare the tgetnum argument to be
+        'char *', so we need the const_cast, since C++ will not
+        implicitly convert.  */
+      int colors = tgetnum (const_cast<char*> ("Co"));
       if (colors >= 8)
        result.push_back (color_space::ANSI_8COLOR);
       if (colors >= 16)