This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFC] convert a host address to a string
- From: Kai Tietz <Kai dot Tietz at onevision dot com>
- To: Joel Brobecker <brobecker at adacore dot com>
- Cc: gdb-patches at sourceware dot org, Mark Kettenis <mark dot kettenis at xs4all dot nl>
- Date: Fri, 9 Jan 2009 15:27:12 +0100
- Subject: Re: [RFC] convert a host address to a string
Hi Joel,
gdb-patches-owner@sourceware.org wrote on 09.01.2009 14:12:27:
> > > 3. Work through uintptr_t.
> > >
> > > #ifdef PRINTF_HAS_LONG_LONG
> > > fprintf (buf, "0x%llx", (unsigned long long)
> (uintptr_t) address);
> > > #else
> > > fprintf (buf, "0x%lx", (unsigned long) (uintptr_t)
address);
> > > #endif
> >
> > This wouldn't be the first place where we'd use a double cast in
> > connection with intptr_t/uintptr_t. So I'd say that while this is a
> > bit ugly, it's certainly acceptable. It's by far the simplest way to
> > fix things.
>
> Here is a new patch implementing this approach. As I told Kai,
> it's probably not going to work for x86_64/XP, but it works for
> x86_64/Vista (I think Kai agreed to take on the job of improving
> this approach to work on XP as well :-).
>
> 2009-01-09 Joel Brobecker <brobecker@adacore.com>
>
> * utils.c (host_address_to_string): Cast the address to
uintptr_t
> first to avoid a possible compilation warning about casting to
> an integer of the wrong size. Then format the address using
> unsigned long long if supported by printf. Otherwise, fallback
> on using usingned long, hoping that long is large enough to hold
> an address.
>
> Tested on x86-linux. I also verified that it still builds on
> x86_64 Vista, as well as x86/Windows XP (on XP, PRINTF_HAS_LONG_LONG
> is undefined).
I think it is a sub-optimal solution to have just support for Vista64, but
not for XP. On a second thought, I remembered, that bfd does things right
;) There is the macro sprintf_vma in bfd.h, which handles things pretty
well and can be used here in utils.c, too.
Cheers,
Kai
| (\_/) This is Bunny. Copy and paste Bunny
| (='.'=) into your signature to help him gain
| (")_(") world domination.