public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix build failure for 32-bit targets
@ 2021-10-01 11:50 Luis Machado
  2021-10-01 15:25 ` Mike Frysinger
  0 siblings, 1 reply; 6+ messages in thread
From: Luis Machado @ 2021-10-01 11:50 UTC (permalink / raw)
  To: gdb-patches

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


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

* Re: [PATCH] Fix build failure for 32-bit targets
  2021-10-01 11:50 [PATCH] Fix build failure for 32-bit targets Luis Machado
@ 2021-10-01 15:25 ` Mike Frysinger
  2021-10-01 15:53   ` Luis Machado
  0 siblings, 1 reply; 6+ messages in thread
From: Mike Frysinger @ 2021-10-01 15:25 UTC (permalink / raw)
  To: Luis Machado; +Cc: gdb-patches

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

On 01 Oct 2021 08:50, Luis Machado via Gdb-patches wrote:
> 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.

wouldn't PRIxPTR fix it and be simpler ?
-mike

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: [PATCH] Fix build failure for 32-bit targets
  2021-10-01 15:25 ` Mike Frysinger
@ 2021-10-01 15:53   ` Luis Machado
  2021-10-01 16:08     ` Simon Marchi
  0 siblings, 1 reply; 6+ messages in thread
From: Luis Machado @ 2021-10-01 15:53 UTC (permalink / raw)
  To: gdb-patches

On 10/1/21 12:25 PM, Mike Frysinger wrote:
> On 01 Oct 2021 08:50, Luis Machado via Gdb-patches wrote:
>> 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.
> 
> wouldn't PRIxPTR fix it and be simpler ?
> -mike
> 

I'm happy either way, but GDB uses phex/phex_nz/pulongest much more often.

grep "phex" gdb -R | wc -l
143

grep "PRIx" gdb -R | wc -l
25

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

* Re: [PATCH] Fix build failure for 32-bit targets
  2021-10-01 15:53   ` Luis Machado
@ 2021-10-01 16:08     ` Simon Marchi
  2021-10-01 16:11       ` Simon Marchi
  2021-10-01 16:32       ` Luis Machado
  0 siblings, 2 replies; 6+ messages in thread
From: Simon Marchi @ 2021-10-01 16:08 UTC (permalink / raw)
  To: Luis Machado, gdb-patches

On 2021-10-01 11:53 a.m., Luis Machado via Gdb-patches wrote:
> On 10/1/21 12:25 PM, Mike Frysinger wrote:
>> On 01 Oct 2021 08:50, Luis Machado via Gdb-patches wrote:
>>> 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.
>>
>> wouldn't PRIxPTR fix it and be simpler ?
>> -mike
>>
>
> I'm happy either way, but GDB uses phex/phex_nz/pulongest much more often.
>
> grep "phex" gdb -R | wc -l
> 143
>
> grep "PRIx" gdb -R | wc -l
> 25

That's probably because GDB (for historical reasons I suppose) uses
these LONGEST/ULONGEST types, so we can't use standard things like
PRIx64 directly.  Although we could also define, say, PRIxLONGEST and
PRIxULONGEST and use them in format strings.

But here, since we want to print a uintptr_t, I would also go for
PRIxPTR, it's standard after all:

  https://en.cppreference.com/w/cpp/types/integer

Simon

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

* Re: [PATCH] Fix build failure for 32-bit targets
  2021-10-01 16:08     ` Simon Marchi
@ 2021-10-01 16:11       ` Simon Marchi
  2021-10-01 16:32       ` Luis Machado
  1 sibling, 0 replies; 6+ messages in thread
From: Simon Marchi @ 2021-10-01 16:11 UTC (permalink / raw)
  To: Luis Machado, gdb-patches

On 2021-10-01 12:08 p.m., Simon Marchi wrote:
> On 2021-10-01 11:53 a.m., Luis Machado via Gdb-patches wrote:
>> On 10/1/21 12:25 PM, Mike Frysinger wrote:
>>> On 01 Oct 2021 08:50, Luis Machado via Gdb-patches wrote:
>>>> 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.
>>>
>>> wouldn't PRIxPTR fix it and be simpler ?
>>> -mike
>>>
>>
>> I'm happy either way, but GDB uses phex/phex_nz/pulongest much more often.
>>
>> grep "phex" gdb -R | wc -l
>> 143
>>
>> grep "PRIx" gdb -R | wc -l
>> 25
> 
> That's probably because GDB (for historical reasons I suppose) uses
> these LONGEST/ULONGEST types, so we can't use standard things like
> PRIx64 directly.  Although we could also define, say, PRIxLONGEST and
> PRIxULONGEST and use them in format strings.
> 
> But here, since we want to print a uintptr_t, I would also go for
> PRIxPTR, it's standard after all:
> 
>   https://en.cppreference.com/w/cpp/types/integer
> 
> Simon

Or, maybe %p since the goal is to print a pointer for the local host, but
I suppose the value would have to be cast to void*.

Simon



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

* Re: [PATCH] Fix build failure for 32-bit targets
  2021-10-01 16:08     ` Simon Marchi
  2021-10-01 16:11       ` Simon Marchi
@ 2021-10-01 16:32       ` Luis Machado
  1 sibling, 0 replies; 6+ messages in thread
From: Luis Machado @ 2021-10-01 16:32 UTC (permalink / raw)
  To: Simon Marchi, gdb-patches

On 10/1/21 1:08 PM, Simon Marchi wrote:
> On 2021-10-01 11:53 a.m., Luis Machado via Gdb-patches wrote:
>> On 10/1/21 12:25 PM, Mike Frysinger wrote:
>>> On 01 Oct 2021 08:50, Luis Machado via Gdb-patches wrote:
>>>> 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.
>>>
>>> wouldn't PRIxPTR fix it and be simpler ?
>>> -mike
>>>
>>
>> I'm happy either way, but GDB uses phex/phex_nz/pulongest much more often.
>>
>> grep "phex" gdb -R | wc -l
>> 143
>>
>> grep "PRIx" gdb -R | wc -l
>> 25
> 
> That's probably because GDB (for historical reasons I suppose) uses
> these LONGEST/ULONGEST types, so we can't use standard things like
> PRIx64 directly.  Although we could also define, say, PRIxLONGEST and
> PRIxULONGEST and use them in format strings.
> 
> But here, since we want to print a uintptr_t, I would also go for
> PRIxPTR, it's standard after all:

I pushed it with this format. Thanks!

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

end of thread, other threads:[~2021-10-01 16:32 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-01 11:50 [PATCH] Fix build failure for 32-bit targets Luis Machado
2021-10-01 15:25 ` Mike Frysinger
2021-10-01 15:53   ` Luis Machado
2021-10-01 16:08     ` Simon Marchi
2021-10-01 16:11       ` Simon Marchi
2021-10-01 16:32       ` Luis Machado

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).