[patch] Fix BZ15121 -- x/a broken for addresses in shared libraries

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

[patch] Fix BZ15121 -- x/a broken for addresses in shared libraries

Paul Pluzhnikov
Greetings,

Attached patch fixes BZ #15121 -- x/a broken for addresses in shared libraries.
Not adding a new test since this is already covered by gdb.base/long_long.exp

Tested on Linux/x86_64, no new failures.

Thanks,

ChangeLog:

2015-09-06  Paul Pluzhnikov  <[hidden email]>

        [BZ #15121]
        * gdb/value.c (unpack_pointer): Don't sign-extend.

testsuite/ChangeLog:

2015-09-06  Paul Pluzhnikov  <[hidden email]>

        * gdb.base/long_long.exp: Adjust.

--
Paul Pluzhnikov

gdb-bz15121.20150906.txt (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [patch] Fix BZ15121 -- x/a broken for addresses in shared libraries

Pedro Alves-7
On 09/06/2015 09:03 PM, Paul Pluzhnikov wrote:

> index 91bf49e..0624b90 100644
> --- a/gdb/value.c
> +++ b/gdb/value.c
> @@ -2927,7 +2927,13 @@ unpack_pointer (struct type *type, const gdb_byte *valaddr)
>  {
>    /* Assume a CORE_ADDR can fit in a LONGEST (for now).  Not sure
>       whether we want this to be true eventually.  */
> -  return unpack_long (type, valaddr);
> +  LONGEST ret = unpack_long (type, valaddr);
> +  int len = TYPE_LENGTH (type);
> +  if (sizeof (CORE_ADDR) > len && ret < 0) {
> +    /* Don't sign-extend 32-bit pointer.  BZ 15121.  */
> +    return ret & ((1UL << (8 * len)) - 1);
> +  }
> +  return ret;
>  }

Do we need to keep sign-extending on MIPS?  Adding Maciej.

Thanks,
Pedro Alves

Reply | Threaded
Open this post in threaded view
|

Re: [patch] Fix BZ15121 -- x/a broken for addresses in shared libraries

Mark Kettenis
> Date: Thu, 10 Sep 2015 15:17:36 +0100
> From: Pedro Alves <[hidden email]>
>
> On 09/06/2015 09:03 PM, Paul Pluzhnikov wrote:
>
> > index 91bf49e..0624b90 100644
> > --- a/gdb/value.c
> > +++ b/gdb/value.c
> > @@ -2927,7 +2927,13 @@ unpack_pointer (struct type *type, const gdb_byte *valaddr)
> >  {
> >    /* Assume a CORE_ADDR can fit in a LONGEST (for now).  Not sure
> >       whether we want this to be true eventually.  */
> > -  return unpack_long (type, valaddr);
> > +  LONGEST ret = unpack_long (type, valaddr);
> > +  int len = TYPE_LENGTH (type);
> > +  if (sizeof (CORE_ADDR) > len && ret < 0) {
> > +    /* Don't sign-extend 32-bit pointer.  BZ 15121.  */
> > +    return ret & ((1UL << (8 * len)) - 1);
> > +  }
> > +  return ret;
> >  }
>
> Do we need to keep sign-extending on MIPS?  Adding Maciej.

I'm pretty sure you do.
Reply | Threaded
Open this post in threaded view
|

Re: [patch] Fix BZ15121 -- x/a broken for addresses in shared libraries

Paul Pluzhnikov-4
On Thu, Sep 10, 2015 at 7:33 AM, Mark Kettenis <[hidden email]> wrote:

> > From: Pedro Alves <[hidden email]>

> > Do we need to keep sign-extending on MIPS?  Adding Maciej.
>
> I'm pretty sure you do.

What makes MIPS special?

I can't imagine any reason why (upper levels of) 64-bit GDB would need
to be lied to that the 32-bit inferior's 0x80000004 pointer has
CORE_ADDR value of 0xFFFFFFFF80000004.

Thanks,
--
Paul Pluzhnikov
Reply | Threaded
Open this post in threaded view
|

Re: [patch] Fix BZ15121 -- x/a broken for addresses in shared libraries

Maciej W. Rozycki
In reply to this post by Mark Kettenis
On Thu, 10 Sep 2015, Mark Kettenis wrote:

> > > index 91bf49e..0624b90 100644
> > > --- a/gdb/value.c
> > > +++ b/gdb/value.c
> > > @@ -2927,7 +2927,13 @@ unpack_pointer (struct type *type, const gdb_byte *valaddr)
> > >  {
> > >    /* Assume a CORE_ADDR can fit in a LONGEST (for now).  Not sure
> > >       whether we want this to be true eventually.  */
> > > -  return unpack_long (type, valaddr);
> > > +  LONGEST ret = unpack_long (type, valaddr);
> > > +  int len = TYPE_LENGTH (type);
> > > +  if (sizeof (CORE_ADDR) > len && ret < 0) {
> > > +    /* Don't sign-extend 32-bit pointer.  BZ 15121.  */
> > > +    return ret & ((1UL << (8 * len)) - 1);
> > > +  }
> > > +  return ret;
> > >  }
> >
> > Do we need to keep sign-extending on MIPS?  Adding Maciej.

 Thanks for the heads-up!

> I'm pretty sure you do.

 Indeed.  Use `bfd_get_sign_extend_vma' to determine.

  Maciej
Reply | Threaded
Open this post in threaded view
|

Re: [patch] Fix BZ15121 -- x/a broken for addresses in shared libraries

Pedro Alves-7
In reply to this post by Paul Pluzhnikov-4
On 09/10/2015 04:00 PM, Paul Pluzhnikov wrote:

> On Thu, Sep 10, 2015 at 7:33 AM, Mark Kettenis <[hidden email]> wrote:
>
>>> From: Pedro Alves <[hidden email]>
>
>>> Do we need to keep sign-extending on MIPS?  Adding Maciej.
>>
>> I'm pretty sure you do.
>
> What makes MIPS special?
>
> I can't imagine any reason why (upper levels of) 64-bit GDB would need
> to be lied to that the 32-bit inferior's 0x80000004 pointer has
> CORE_ADDR value of 0xFFFFFFFF80000004.

MIPS has signed addresses, at the hardware level.  Thus a 32-bit ABI on
a 64-bit machine ends up seeing with sign-extended addresses.

See e.g.:
 https://www.sourceware.org/ml/gdb/2002-09/msg00084.html

Thanks,
Pedro Alves

Reply | Threaded
Open this post in threaded view
|

Re: [patch] Fix BZ15121 -- x/a broken for addresses in shared libraries

Maciej W. Rozycki
On Thu, 10 Sep 2015, Pedro Alves wrote:

> > I can't imagine any reason why (upper levels of) 64-bit GDB would need
> > to be lied to that the 32-bit inferior's 0x80000004 pointer has
> > CORE_ADDR value of 0xFFFFFFFF80000004.
>
> MIPS has signed addresses, at the hardware level.  Thus a 32-bit ABI on
> a 64-bit machine ends up seeing with sign-extended addresses.

 SH seems to be the same.

  Maciej
Reply | Threaded
Open this post in threaded view
|

Re: [patch] Fix BZ15121 -- x/a broken for addresses in shared libraries

Paul Pluzhnikov-4
In reply to this post by Maciej W. Rozycki
On Thu, Sep 10, 2015 at 8:02 AM, Maciej W. Rozycki <[hidden email]> wrote:

>  Indeed.  Use `bfd_get_sign_extend_vma' to determine.

For the life of me, I can't figure out how I can get the bfd in the
context of do_examine().

Clues?

Thanks,
--
Paul Pluzhnikov
Reply | Threaded
Open this post in threaded view
|

Re: [patch] Fix BZ15121 -- x/a broken for addresses in shared libraries

Maciej W. Rozycki
On Sat, 12 Sep 2015, Paul Pluzhnikov wrote:

> >  Indeed.  Use `bfd_get_sign_extend_vma' to determine.
>
> For the life of me, I can't figure out how I can get the bfd in the
> context of do_examine().
>
> Clues?

 If it's not reachable in this context, then you may have to figure it out
earlier on and store in `gdbarch'.

 HTH,

  Maciej