[binutils-gdb] [gdb/build] Fix x86_64-w64-mingw32 build by avoiding SCNx8

Tom de Vries vries@sourceware.org
Fri Feb 7 14:57:28 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=4fed821ed67c3fb4c57aa43926cf5b1a02a25ccd

commit 4fed821ed67c3fb4c57aa43926cf5b1a02a25ccd
Author: Tom de Vries <tdevries@suse.de>
Date:   Fri Feb 7 15:57:24 2025 +0100

    [gdb/build] Fix x86_64-w64-mingw32 build by avoiding SCNx8
    
    With an x86_64-w64-mingw32 targeted cross-build on x86_64-linux, I run into:
    ...
    gdb/cli/cli-decode.c: \
      In function 'ui_file_style::color parse_cli_var_color(const char**)':
    gdb/cli/cli-decode.c:2917:41: error: expected ')' before 'SCNx8'
      int parsed_args = sscanf (*args, "#%2" SCNx8 "%2" SCNx8 "%2" SCNx8 "%n",
    ...
    
    Apparantly, the definition of SCNx8 is missing in inttypes.h.
    
    Rewrite the sscanf call to use SCNx32, which is available.
    
    Tested by:
    - completing aforementioned cross-build, and
    - build & test on x86_64-linux.
    
    Suggested-By: Tom Tromey <tom@tromey.com>
    Approved-By: Tom Tromey <tom@tromey.com>

Diff:
---
 gdb/cli/cli-decode.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c
index c5eab2f4437..e5de7024ebc 100644
--- a/gdb/cli/cli-decode.c
+++ b/gdb/cli/cli-decode.c
@@ -2912,14 +2912,20 @@ parse_cli_var_color (const char **args)
   if (len != 7)
     error_no_arg (_("invalid RGB hex triplet format"));
 
+  uint32_t rgb;
   uint8_t r, g, b;
   int scanned_chars = 0;
-  int parsed_args = sscanf (*args, "#%2" SCNx8 "%2" SCNx8 "%2" SCNx8 "%n",
-			    &r, &g, &b, &scanned_chars);
+  int parsed_args = sscanf (*args, "#%6" SCNx32 "%n",
+			    &rgb, &scanned_chars);
 
-  if (parsed_args != 3 || scanned_chars != 7)
+  if (parsed_args != 1 || scanned_chars != 7)
     error_no_arg (_("invalid RGB hex triplet format"));
 
+  gdb_assert ((rgb >> 24) == 0);
+  r = (rgb >> 16) & 0xff;
+  g = (rgb >> 8) & 0xff;
+  b = rgb & 0xff;
+
   *args += len;
   return ui_file_style::color (r, g, b);
 }


More information about the Gdb-cvs mailing list