public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
* Extending GDB: Python: Wrong handling of 64-bit pointers
@ 2012-10-09 17:15 chandan r
  2012-10-10 22:48 ` Andrew Pinski
  0 siblings, 1 reply; 6+ messages in thread
From: chandan r @ 2012-10-09 17:15 UTC (permalink / raw)
  To: gdb

Hi all,

As the following CLI interactions show, GDB's python support code seems to be
mishandling 64-bit pointers (GNU/Linux on x86-64):

NOTE: "p" is a pointer of type "struct task_struct *"

(gdb) python print gdb.parse_and_eval("p")
0xffff88001f5f7600
(gdb) python print long(gdb.parse_and_eval("p"))
-131940868983296
(gdb) show version
show version
GNU gdb (GDB) 7.5
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.

Is it GDB or am I messing up something here?

--
Chandan

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

* Re: Extending GDB: Python: Wrong handling of 64-bit pointers
  2012-10-09 17:15 Extending GDB: Python: Wrong handling of 64-bit pointers chandan r
@ 2012-10-10 22:48 ` Andrew Pinski
  2012-10-12  2:07   ` chandan r
  0 siblings, 1 reply; 6+ messages in thread
From: Andrew Pinski @ 2012-10-10 22:48 UTC (permalink / raw)
  To: chandan r; +Cc: gdb

On Tue, Oct 9, 2012 at 10:30 AM, chandan r <chandanrmail@gmail.com> wrote:
> Hi all,
>
> As the following CLI interactions show, GDB's python support code seems to be
> mishandling 64-bit pointers (GNU/Linux on x86-64):
>
> NOTE: "p" is a pointer of type "struct task_struct *"
>
> (gdb) python print gdb.parse_and_eval("p")
> 0xffff88001f5f7600
> (gdb) python print long(gdb.parse_and_eval("p"))
> -131940868983296
> (gdb) show version
> show version
> GNU gdb (GDB) 7.5
> Copyright (C) 2012 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
> This is free software: you are free to change and redistribute it.
> There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
> and "show warranty" for details.
> This GDB was configured as "x86_64-unknown-linux-gnu".
> For bug reporting instructions, please see:
> <http://www.gnu.org/software/gdb/bugs/>.
>
> Is it GDB or am I messing up something here?

Nothing looks wrong as -131940868983296 is the same as
0xffff88001f5f7600 in signed integer.
(gdb) p/x -131940868983296
$1 = 0xffff88001f5f7600

Thanks,
Andrew Pinski

>
> --
> Chandan

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

* Re: Extending GDB: Python: Wrong handling of 64-bit pointers
  2012-10-10 22:48 ` Andrew Pinski
@ 2012-10-12  2:07   ` chandan r
  2012-10-12  5:52     ` Bjoern Doebel
  2012-10-12  5:59     ` Andrew Pinski
  0 siblings, 2 replies; 6+ messages in thread
From: chandan r @ 2012-10-12  2:07 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: gdb


Andrew Pinski <pinskia@gmail.com> writes:

> On Tue, Oct 9, 2012 at 10:30 AM, chandan r <chandanrmail@gmail.com> wrote:
>> Hi all,
>>
>> As the following CLI interactions show, GDB's python support code seems to be
>> mishandling 64-bit pointers (GNU/Linux on x86-64):
>>
>> NOTE: "p" is a pointer of type "struct task_struct *"
>>
>> (gdb) python print gdb.parse_and_eval("p")
>> 0xffff88001f5f7600
>> (gdb) python print long(gdb.parse_and_eval("p"))
>> -131940868983296
>> (gdb) show version
>> show version
>> GNU gdb (GDB) 7.5
>> Copyright (C) 2012 Free Software Foundation, Inc.
>> License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
>> This is free software: you are free to change and redistribute it.
>> There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
>> and "show warranty" for details.
>> This GDB was configured as "x86_64-unknown-linux-gnu".
>> For bug reporting instructions, please see:
>> <http://www.gnu.org/software/gdb/bugs/>.
>>
>> Is it GDB or am I messing up something here?
>
> Nothing looks wrong as -131940868983296 is the same as
> 0xffff88001f5f7600 in signed integer.
> (gdb) p/x -131940868983296
> $1 = 0xffff88001f5f7600
>
> Thanks,
> Andrew Pinski
>
>>
>> --
>> Chandan

But shouldn't pointer values be read/printed without interpretting the sign
bit?.

Right now I have to do 'long(str(gdb.parse_and_eval('p')), 16)' to obtain the
correct value.

--
chandan

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

* Re: Extending GDB: Python: Wrong handling of 64-bit pointers
  2012-10-12  2:07   ` chandan r
@ 2012-10-12  5:52     ` Bjoern Doebel
  2012-10-12  5:59     ` Andrew Pinski
  1 sibling, 0 replies; 6+ messages in thread
From: Bjoern Doebel @ 2012-10-12  5:52 UTC (permalink / raw)
  To: gdb

You are explicitly casting the pointer to a "signed long", hence the
interpreter won't know about this being a pointer anymore.

Bjoern

2012/10/12 chandan r <chandanrmail@gmail.com>:
>
> Andrew Pinski <pinskia@gmail.com> writes:
>
>> On Tue, Oct 9, 2012 at 10:30 AM, chandan r <chandanrmail@gmail.com> wrote:
>>> Hi all,
>>>
>>> As the following CLI interactions show, GDB's python support code seems to be
>>> mishandling 64-bit pointers (GNU/Linux on x86-64):
>>>
>>> NOTE: "p" is a pointer of type "struct task_struct *"
>>>
>>> (gdb) python print gdb.parse_and_eval("p")
>>> 0xffff88001f5f7600
>>> (gdb) python print long(gdb.parse_and_eval("p"))
>>> -131940868983296
>>> (gdb) show version
>>> show version
>>> GNU gdb (GDB) 7.5
>>> Copyright (C) 2012 Free Software Foundation, Inc.
>>> License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
>>> This is free software: you are free to change and redistribute it.
>>> There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
>>> and "show warranty" for details.
>>> This GDB was configured as "x86_64-unknown-linux-gnu".
>>> For bug reporting instructions, please see:
>>> <http://www.gnu.org/software/gdb/bugs/>.
>>>
>>> Is it GDB or am I messing up something here?
>>
>> Nothing looks wrong as -131940868983296 is the same as
>> 0xffff88001f5f7600 in signed integer.
>> (gdb) p/x -131940868983296
>> $1 = 0xffff88001f5f7600
>>
>> Thanks,
>> Andrew Pinski
>>
>>>
>>> --
>>> Chandan
>
> But shouldn't pointer values be read/printed without interpretting the sign
> bit?.
>
> Right now I have to do 'long(str(gdb.parse_and_eval('p')), 16)' to obtain the
> correct value.
>
> --
> chandan

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

* Re: Extending GDB: Python: Wrong handling of 64-bit pointers
  2012-10-12  2:07   ` chandan r
  2012-10-12  5:52     ` Bjoern Doebel
@ 2012-10-12  5:59     ` Andrew Pinski
  2012-10-12 13:08       ` chandan r
  1 sibling, 1 reply; 6+ messages in thread
From: Andrew Pinski @ 2012-10-12  5:59 UTC (permalink / raw)
  To: chandan r; +Cc: gdb

On Thu, Oct 11, 2012 at 7:23 PM, chandan r <chandanrmail@gmail.com> wrote:
>
> Andrew Pinski <pinskia@gmail.com> writes:
>
>> On Tue, Oct 9, 2012 at 10:30 AM, chandan r <chandanrmail@gmail.com> wrote:
>>> Hi all,
>>>
>>> As the following CLI interactions show, GDB's python support code seems to be
>>> mishandling 64-bit pointers (GNU/Linux on x86-64):
>>>
>>> NOTE: "p" is a pointer of type "struct task_struct *"
>>>
>>> (gdb) python print gdb.parse_and_eval("p")
>>> 0xffff88001f5f7600
>>> (gdb) python print long(gdb.parse_and_eval("p"))
>>> -131940868983296
>>> (gdb) show version
>>> show version
>>> GNU gdb (GDB) 7.5
>>> Copyright (C) 2012 Free Software Foundation, Inc.
>>> License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
>>> This is free software: you are free to change and redistribute it.
>>> There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
>>> and "show warranty" for details.
>>> This GDB was configured as "x86_64-unknown-linux-gnu".
>>> For bug reporting instructions, please see:
>>> <http://www.gnu.org/software/gdb/bugs/>.
>>>
>>> Is it GDB or am I messing up something here?
>>
>> Nothing looks wrong as -131940868983296 is the same as
>> 0xffff88001f5f7600 in signed integer.
>> (gdb) p/x -131940868983296
>> $1 = 0xffff88001f5f7600
>>
>> Thanks,
>> Andrew Pinski
>>
>>>
>>> --
>>> Chandan
>
> But shouldn't pointer values be read/printed without interpretting the sign
> bit?.
>
> Right now I have to do 'long(str(gdb.parse_and_eval('p')), 16)' to obtain the
> correct value.


What is the correct value for pointers cast to an long?  I don't see
the issue here as you have a pointer which is 64bits and you cast
directly to a signed long.

Thanks,
Andrew Pinski

>
> --
> chandan

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

* Re: Extending GDB: Python: Wrong handling of 64-bit pointers
  2012-10-12  5:59     ` Andrew Pinski
@ 2012-10-12 13:08       ` chandan r
  0 siblings, 0 replies; 6+ messages in thread
From: chandan r @ 2012-10-12 13:08 UTC (permalink / raw)
  To: Andrew Pinski; +Cc: gdb


Andrew Pinski <pinskia@gmail.com> writes:

> On Thu, Oct 11, 2012 at 7:23 PM, chandan r <chandanrmail@gmail.com> wrote:
>>
>> Andrew Pinski <pinskia@gmail.com> writes:
>>
>>> On Tue, Oct 9, 2012 at 10:30 AM, chandan r <chandanrmail@gmail.com> wrote:
>>>> Hi all,
>>>>
>>>> As the following CLI interactions show, GDB's python support code seems to be
>>>> mishandling 64-bit pointers (GNU/Linux on x86-64):
>>>>
>>>> NOTE: "p" is a pointer of type "struct task_struct *"
>>>>
>>>> (gdb) python print gdb.parse_and_eval("p")
>>>> 0xffff88001f5f7600
>>>> (gdb) python print long(gdb.parse_and_eval("p"))
>>>> -131940868983296
>>>> (gdb) show version
>>>> show version
>>>> GNU gdb (GDB) 7.5
>>>> Copyright (C) 2012 Free Software Foundation, Inc.
>>>> License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
>>>> This is free software: you are free to change and redistribute it.
>>>> There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
>>>> and "show warranty" for details.
>>>> This GDB was configured as "x86_64-unknown-linux-gnu".
>>>> For bug reporting instructions, please see:
>>>> <http://www.gnu.org/software/gdb/bugs/>.
>>>>
>>>> Is it GDB or am I messing up something here?
>>>
>>> Nothing looks wrong as -131940868983296 is the same as
>>> 0xffff88001f5f7600 in signed integer.
>>> (gdb) p/x -131940868983296
>>> $1 = 0xffff88001f5f7600
>>>
>>> Thanks,
>>> Andrew Pinski
>>>
>>>>
>>>> --
>>>> Chandan
>>
>> But shouldn't pointer values be read/printed without interpretting the sign
>> bit?.
>>
>> Right now I have to do 'long(str(gdb.parse_and_eval('p')), 16)' to obtain the
>> correct value.
>
>
> What is the correct value for pointers cast to an long?  I don't see
> the issue here as you have a pointer which is 64bits and you cast
> directly to a signed long.
>
> Thanks,
> Andrew Pinski
>
>>
>> --
>> chandan

I used long() based on the instructions given in
http://dmalcolm.fedorapeople.org/presentations/PyCon-US-2011/GdbPythonPresentation/GdbPython.html#11 

Any suggestions for the correct way to convert the pointer into a Python
value?

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

end of thread, other threads:[~2012-10-12 13:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-09 17:15 Extending GDB: Python: Wrong handling of 64-bit pointers chandan r
2012-10-10 22:48 ` Andrew Pinski
2012-10-12  2:07   ` chandan r
2012-10-12  5:52     ` Bjoern Doebel
2012-10-12  5:59     ` Andrew Pinski
2012-10-12 13:08       ` chandan r

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