This is the mail archive of the
gdb-patches@sourceware.cygnus.com
mailing list for the GDB project.
RE: host_pointer_to_address() === (CORE_ADDR) (void*) (val)
- To: 'Andrew Cagney' <ac131313 at cygnus dot com>, GDB Patches <gdb-patches at sourceware dot cygnus dot com>
- Subject: RE: host_pointer_to_address() === (CORE_ADDR) (void*) (val)
- From: Donn Terry <donnte at microsoft dot com>
- Date: Fri, 26 May 2000 09:49:20 -0700
I was looking at Alpha/NT at one point in my life, and it
also is sign-extended pointers. Whether there are any other
instances of 32 bit Alpha implementations, I don't know.
Based on what I remember of that old code, this seems an
emminently reasonable thing to do.
Donn
> -----Original Message-----
> From: Andrew Cagney [mailto:ac131313@cygnus.com]
> Sent: Friday, May 26, 2000 4:02 AM
> To: GDB Patches
> Subject: host_pointer_to_address() === (CORE_ADDR) (void*) (val)
>
>
> Hello,
>
> If you look through code like procfs.c, you will find casts like:
>
> /* Stop looping if the callback returns non-zero. */
> if ((funcstat = (*func) (fd, (CORE_ADDR) map->pr_vaddr)) != 0)
>
> The problem is with ``(CORE_ADDR) map->pr_vaddr''.
> ``map->pr_vaddr'' is
> a ``void *'' (32bits) and ``CORE_ADDR'' is a ``long long'' (64bits).
> Some (one? mips/n32) targets assume that addresses sign-extended while
> others assume zero extension. The consequence is that the
> above code is
> potentially dangerous. GCC complains with a warning while some native
> compilers refuse to accept it at all :-/
>
> To address this, I'd like to propose two wrappers to JimB's
> POINTER_TO_ADDRESS and ADDRESS_TO_POINTER:
>
> CORE_ADDR host_pointer_to_address (void *ptr);
> ... check operation is sane ...
> return POINTER_TO_ADDRESS (builtin_type_ptr, ptr);
> void *address_to_host_pointer (CORE_ADDR addr);
> void *ptr;
> ... check operation is sane ...
> ADDRESS_TO_POINTER (builtin_type_ptr, &ptr, addr)
> return ptr;
>
> which would be used when ever a host void* <-> CORE_ADDR
> conversion was
> required. The above code would then be rewritten as:
>
> funcstat = func (fd, host_pointer_to_address (map->pr_vaddr));
> if (funcstat != 0)
> ....
>
> this would ensure that the code passed around a correct ``CORE_ADDR''
> (and not a truncated value that just happens to work). This becomes
> very important when you start debugging n32 abi's (32 bit pointers)
> where the target has 64 bit registers - the full sign extended value
> needs to be read/written.
>
> Thoughts? Making sense? I'll post a full patch for irix[56]/n32 once
> I've seen some test results.
>
> Andrew
>