public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [patch] Fix BZ15121 -- x/a broken for addresses in shared libraries
@ 2015-09-06 20:03 Paul Pluzhnikov
  2015-09-10 14:17 ` Pedro Alves
  0 siblings, 1 reply; 9+ messages in thread
From: Paul Pluzhnikov @ 2015-09-06 20:03 UTC (permalink / raw)
  To: gdb-patches ml; +Cc: Paul Pluzhnikov

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

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  <ppluzhnikov@google.com>

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

testsuite/ChangeLog:

2015-09-06  Paul Pluzhnikov  <ppluzhnikov@google.com>

        * gdb.base/long_long.exp: Adjust.

-- 
Paul Pluzhnikov

[-- Attachment #2: gdb-bz15121.20150906.txt --]
[-- Type: text/plain, Size: 2066 bytes --]

diff --git a/gdb/testsuite/gdb.base/long_long.exp b/gdb/testsuite/gdb.base/long_long.exp
index 5eea391..f4f3961 100644
--- a/gdb/testsuite/gdb.base/long_long.exp
+++ b/gdb/testsuite/gdb.base/long_long.exp
@@ -255,7 +255,7 @@ gdb_test "x/2bd b" "1.*-89"
 gdb_test "x/2bu b" "1.*167"
 gdb_test "x/2bo b" "01.*0247"
 gdb_test "x/2bt b" "00000001.*10100111"
-gdb_test_ptr "x/2ba b" "" "" "0x1.*0xffffffa7" "0x1.*0xffffffffffffffa7"
+gdb_test_ptr "x/2ba b" "" "" "0x1.*0xa7" "0x1.*0xa7"
 gdb_test "x/2bc b" "1 '.001'.*-89 '.\[0-9\]*'"
 gdb_test "x/2bf b" "1.*-89"
 
@@ -264,7 +264,7 @@ gdb_test "x/2hd h" "291.*-22738"
 gdb_test "x/2hu h" "291.*42798"
 gdb_test "x/2ho h" "0443.*0123456"
 gdb_test "x/2ht h" "0000000100100011.*1010011100101110"
-gdb_test_ptr "x/2ha h" "" ""  "0x123.*0xffffa72e" "0x123.*0xffffffffffffa72e"
+gdb_test_ptr "x/2ha h" "" ""  "0x123.*0xa72e" "0x123.*0xa72e"
 gdb_test "x/2hc h" "35 '.'.*46 '.'"
 gdb_test "x/2hf h" "291.*-22738"
 
@@ -273,7 +273,7 @@ gdb_test "x/2wd w" "19088743.*-1490098887"
 gdb_test "x/2wu w" "19088743.*2804868409"
 gdb_test "x/2wo w" "0110642547.*024713562471"
 gdb_test "x/2wt w" "00000001001000110100010101100111.*10100111001011101110010100111001"
-gdb_test_ptr "x/2wa w" "" ""  "0x1234567.*0xa72ee539" "0x1234567.*0xffffffffa72ee539"
+gdb_test_ptr "x/2wa w" "" ""  "0x1234567.*0xa72ee539" "0x1234567.*0xa72ee539"
 gdb_test "x/2wc w" "103 'g'.*57 '9'"
 gdb_test "x/2wf w" "2.99881655e-0?38.*-2.42716126e-0?15"
 
diff --git a/gdb/value.c b/gdb/value.c
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;
 }
 
 \f

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

* Re: [patch] Fix BZ15121 -- x/a broken for addresses in shared libraries
  2015-09-06 20:03 [patch] Fix BZ15121 -- x/a broken for addresses in shared libraries Paul Pluzhnikov
@ 2015-09-10 14:17 ` Pedro Alves
  2015-09-10 14:33   ` Mark Kettenis
  0 siblings, 1 reply; 9+ messages in thread
From: Pedro Alves @ 2015-09-10 14:17 UTC (permalink / raw)
  To: Paul Pluzhnikov, gdb-patches ml; +Cc: Paul Pluzhnikov, Maciej W. Rozycki

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

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

* Re: [patch] Fix BZ15121 -- x/a broken for addresses in shared libraries
  2015-09-10 14:17 ` Pedro Alves
@ 2015-09-10 14:33   ` Mark Kettenis
  2015-09-10 15:00     ` Paul Pluzhnikov
  2015-09-10 15:02     ` Maciej W. Rozycki
  0 siblings, 2 replies; 9+ messages in thread
From: Mark Kettenis @ 2015-09-10 14:33 UTC (permalink / raw)
  To: palves; +Cc: ppluzhnikov, gdb-patches, ppluzhnikov, macro

> Date: Thu, 10 Sep 2015 15:17:36 +0100
> From: Pedro Alves <palves@redhat.com>
> 
> 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.

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

* Re: [patch] Fix BZ15121 -- x/a broken for addresses in shared libraries
  2015-09-10 14:33   ` Mark Kettenis
@ 2015-09-10 15:00     ` Paul Pluzhnikov
  2015-09-10 15:07       ` Pedro Alves
  2015-09-10 15:02     ` Maciej W. Rozycki
  1 sibling, 1 reply; 9+ messages in thread
From: Paul Pluzhnikov @ 2015-09-10 15:00 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: Pedro Alves, gdb-patches ml, macro

On Thu, Sep 10, 2015 at 7:33 AM, Mark Kettenis <mark.kettenis@xs4all.nl> wrote:

> > From: Pedro Alves <palves@redhat.com>

> > 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

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

* Re: [patch] Fix BZ15121 -- x/a broken for addresses in shared libraries
  2015-09-10 14:33   ` Mark Kettenis
  2015-09-10 15:00     ` Paul Pluzhnikov
@ 2015-09-10 15:02     ` Maciej W. Rozycki
  2015-09-12 21:41       ` Paul Pluzhnikov
  1 sibling, 1 reply; 9+ messages in thread
From: Maciej W. Rozycki @ 2015-09-10 15:02 UTC (permalink / raw)
  To: Mark Kettenis; +Cc: Pedro Alves, ppluzhnikov, gdb-patches, ppluzhnikov

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

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

* Re: [patch] Fix BZ15121 -- x/a broken for addresses in shared libraries
  2015-09-10 15:00     ` Paul Pluzhnikov
@ 2015-09-10 15:07       ` Pedro Alves
  2015-09-10 15:19         ` Maciej W. Rozycki
  0 siblings, 1 reply; 9+ messages in thread
From: Pedro Alves @ 2015-09-10 15:07 UTC (permalink / raw)
  To: Paul Pluzhnikov, Mark Kettenis; +Cc: gdb-patches ml, macro

On 09/10/2015 04:00 PM, Paul Pluzhnikov wrote:
> On Thu, Sep 10, 2015 at 7:33 AM, Mark Kettenis <mark.kettenis@xs4all.nl> wrote:
> 
>>> From: Pedro Alves <palves@redhat.com>
> 
>>> 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

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

* Re: [patch] Fix BZ15121 -- x/a broken for addresses in shared libraries
  2015-09-10 15:07       ` Pedro Alves
@ 2015-09-10 15:19         ` Maciej W. Rozycki
  0 siblings, 0 replies; 9+ messages in thread
From: Maciej W. Rozycki @ 2015-09-10 15:19 UTC (permalink / raw)
  To: Pedro Alves; +Cc: Paul Pluzhnikov, Mark Kettenis, gdb-patches ml

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

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

* Re: [patch] Fix BZ15121 -- x/a broken for addresses in shared libraries
  2015-09-10 15:02     ` Maciej W. Rozycki
@ 2015-09-12 21:41       ` Paul Pluzhnikov
  2015-09-12 21:56         ` Maciej W. Rozycki
  0 siblings, 1 reply; 9+ messages in thread
From: Paul Pluzhnikov @ 2015-09-12 21:41 UTC (permalink / raw)
  To: Maciej W. Rozycki; +Cc: Mark Kettenis, Pedro Alves, gdb-patches ml

On Thu, Sep 10, 2015 at 8:02 AM, Maciej W. Rozycki <macro@linux-mips.org> 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

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

* Re: [patch] Fix BZ15121 -- x/a broken for addresses in shared libraries
  2015-09-12 21:41       ` Paul Pluzhnikov
@ 2015-09-12 21:56         ` Maciej W. Rozycki
  0 siblings, 0 replies; 9+ messages in thread
From: Maciej W. Rozycki @ 2015-09-12 21:56 UTC (permalink / raw)
  To: Paul Pluzhnikov; +Cc: Mark Kettenis, Pedro Alves, gdb-patches ml

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

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

end of thread, other threads:[~2015-09-12 21:56 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-06 20:03 [patch] Fix BZ15121 -- x/a broken for addresses in shared libraries Paul Pluzhnikov
2015-09-10 14:17 ` Pedro Alves
2015-09-10 14:33   ` Mark Kettenis
2015-09-10 15:00     ` Paul Pluzhnikov
2015-09-10 15:07       ` Pedro Alves
2015-09-10 15:19         ` Maciej W. Rozycki
2015-09-10 15:02     ` Maciej W. Rozycki
2015-09-12 21:41       ` Paul Pluzhnikov
2015-09-12 21:56         ` Maciej W. Rozycki

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).