[PATCH] Fix build failure for 32-bit targets

Luis Machado luis.machado@linaro.org
Fri Oct 1 11:50:02 GMT 2021


When building master GDB, I ran into the following:

binutils-gdb/gdb/bt-utils.c: In function ‘int libbacktrace_print(void*, uintptr_t, const char*, int, const char*)’:
binutils-gdb/gdb/bt-utils.c:93:44: error: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 4 has type ‘uintptr_t {aka unsigned int}’ [-Werror=format=]
   snprintf (buf, sizeof (buf), "0x%lx ", pc);

Fix this by using phex and %s as opposed to 0x%lx.
---
 gdb/bt-utils.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/bt-utils.c b/gdb/bt-utils.c
index 79e6e090d42..51791ccb9f6 100644
--- a/gdb/bt-utils.c
+++ b/gdb/bt-utils.c
@@ -90,7 +90,7 @@ libbacktrace_print (void *data, uintptr_t pc, const char *filename,
      files.  We are also careful to ensure we don't overflow this buffer.  */
   char buf[20];
 
-  snprintf (buf, sizeof (buf), "0x%lx ", pc);
+  snprintf (buf, sizeof (buf), "%s ", phex (pc, sizeof (pc));
   buf[sizeof (buf) - 1] = '\0';
   sig_write (buf);
   sig_write (function == nullptr ? "???" : function);
-- 
2.25.1



More information about the Gdb-patches mailing list