* Casting an object to another type while debugging?
@ 2016-04-15 3:02 Thomas Nyberg
2016-04-15 3:09 ` Yichao Yu
0 siblings, 1 reply; 3+ messages in thread
From: Thomas Nyberg @ 2016-04-15 3:02 UTC (permalink / raw)
To: gdb
Hello,
Please yell and scream if I'm posting this to the wrong list (and then
point me in the right direction :) ).
To make my situation specific, I'm stepping through the cpython
implementation of the python interpreter using gdb. The implementation
tends to pass around all objects as type (PyObject *). I know that a
certain object can be cast to (PyUnicode_Type *) and so I've tried to do
this to print out the structure, but without success. Here are some
examples:
```
(gdb) print name
$10 = (PyObject *) 0x7ffff7ee3298
(gdb) print *name
$11 = {ob_refcnt = 2, ob_type = 0x8a1a00 <PyUnicode_Type>}
(gdb) print name
$12 = (PyObject *) 0x7ffff7ee3298
(gdb) print *name
$13 = {ob_refcnt = 2, ob_type = 0x8a1a00 <PyUnicode_Type>}
(gdb) print (void *) name
$14 = (void *) 0x7ffff7ee3298
(gdb) print * (void *) name
Attempt to dereference a generic pointer.
(gdb) print * (PyUnicode_Type *) name
A syntax error in expression, near `) name'.
(gdb) print * (PyUnicode_Typ *) name
No symbol "PyUnicode_Typ" in current context.
(gdb) print (PyUnicode_Type *) name
A syntax error in expression, near `) name'.
(gdb) print ((PyUnicode_Type *) name)
A syntax error in expression, near `) name)'.
(gdb) print ((PyUnicode_Type *) name);
A syntax error in expression, near `) name);'.
```
So from this it seems to me like it's recognizing the PyUnicode_Type
fine, but I just get this weird syntax error. My google-foo hasn't
worked out that well so far in resolving this. What am I doing wrong? Am
I misunderstanding how casting works?
Thanks for any help!
Cheers,
Thomas
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Casting an object to another type while debugging?
2016-04-15 3:02 Casting an object to another type while debugging? Thomas Nyberg
@ 2016-04-15 3:09 ` Yichao Yu
2016-04-15 3:12 ` Thomas Nyberg
0 siblings, 1 reply; 3+ messages in thread
From: Yichao Yu @ 2016-04-15 3:09 UTC (permalink / raw)
To: Thomas Nyberg; +Cc: gdb
On Thu, Apr 14, 2016 at 11:02 PM, Thomas Nyberg <tomnyberg@gmail.com> wrote:
> Hello,
>
> Please yell and scream if I'm posting this to the wrong list (and then
> point me in the right direction :) ).
>
> To make my situation specific, I'm stepping through the cpython
> implementation of the python interpreter using gdb. The implementation
> tends to pass around all objects as type (PyObject *). I know that a
> certain object can be cast to (PyUnicode_Type *) and so I've tried to do
> this to print out the structure, but without success. Here are some
> examples:
>
> ```
> (gdb) print name
> $10 = (PyObject *) 0x7ffff7ee3298
> (gdb) print *name
> $11 = {ob_refcnt = 2, ob_type = 0x8a1a00 <PyUnicode_Type>}
> (gdb) print name
> $12 = (PyObject *) 0x7ffff7ee3298
> (gdb) print *name
> $13 = {ob_refcnt = 2, ob_type = 0x8a1a00 <PyUnicode_Type>}
> (gdb) print (void *) name
> $14 = (void *) 0x7ffff7ee3298
> (gdb) print * (void *) name
> Attempt to dereference a generic pointer.
> (gdb) print * (PyUnicode_Type *) name
> A syntax error in expression, near `) name'.
> (gdb) print * (PyUnicode_Typ *) name
> No symbol "PyUnicode_Typ" in current context.
> (gdb) print (PyUnicode_Type *) name
> A syntax error in expression, near `) name'.
> (gdb) print ((PyUnicode_Type *) name)
> A syntax error in expression, near `) name)'.
> (gdb) print ((PyUnicode_Type *) name);
> A syntax error in expression, near `) name);'.
PyUnicode_Type is not the name of the C type it's a variable/address
that's holding the python type/vtable. I believe PyUnicodObject is the
C type name.
> ```
>
> So from this it seems to me like it's recognizing the PyUnicode_Type
> fine, but I just get this weird syntax error. My google-foo hasn't
> worked out that well so far in resolving this. What am I doing wrong? Am
> I misunderstanding how casting works?
>
> Thanks for any help!
>
> Cheers,
> Thomas
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Casting an object to another type while debugging?
2016-04-15 3:09 ` Yichao Yu
@ 2016-04-15 3:12 ` Thomas Nyberg
0 siblings, 0 replies; 3+ messages in thread
From: Thomas Nyberg @ 2016-04-15 3:12 UTC (permalink / raw)
To: Yichao Yu; +Cc: gdb
Thank you so much! Should have been obvious when reading (PyObject *)...
Here it is in action:
```
(gdb) print ((PyUnicodeObject *) name)
$15 = (PyUnicodeObject *) 0x7ffff7ee3298
(gdb) print *((PyUnicodeObject *) name)
$16 = {_base = {_base = {ob_base = {ob_refcnt = 2,
ob_type = 0x8a1a00 <PyUnicode_Type>}, length = 4,
hash = -1762387814536268224, state = {interned = 1, kind = 1,
compact = 1, ascii = 1, ready = 1}, wstr = 0x0},
utf8_length = 92360930452852,
utf8 = 0x73 <error: Cannot access memory at address 0x73>,
wstr_length = 9050624}, data = {any = 0x2,
latin1 = 0x2 <error: Cannot access memory at address 0x2>, ucs2 = 0x2,
ucs4 = 0x2}}
```
On 04/14/2016 11:09 PM, Yichao Yu wrote:
> On Thu, Apr 14, 2016 at 11:02 PM, Thomas Nyberg <tomnyberg@gmail.com> wrote:
>> Hello,
>>
>> Please yell and scream if I'm posting this to the wrong list (and then
>> point me in the right direction :) ).
>>
>> To make my situation specific, I'm stepping through the cpython
>> implementation of the python interpreter using gdb. The implementation
>> tends to pass around all objects as type (PyObject *). I know that a
>> certain object can be cast to (PyUnicode_Type *) and so I've tried to do
>> this to print out the structure, but without success. Here are some
>> examples:
>>
>> ```
>> (gdb) print name
>> $10 = (PyObject *) 0x7ffff7ee3298
>> (gdb) print *name
>> $11 = {ob_refcnt = 2, ob_type = 0x8a1a00 <PyUnicode_Type>}
>> (gdb) print name
>> $12 = (PyObject *) 0x7ffff7ee3298
>> (gdb) print *name
>> $13 = {ob_refcnt = 2, ob_type = 0x8a1a00 <PyUnicode_Type>}
>> (gdb) print (void *) name
>> $14 = (void *) 0x7ffff7ee3298
>> (gdb) print * (void *) name
>> Attempt to dereference a generic pointer.
>> (gdb) print * (PyUnicode_Type *) name
>> A syntax error in expression, near `) name'.
>> (gdb) print * (PyUnicode_Typ *) name
>> No symbol "PyUnicode_Typ" in current context.
>> (gdb) print (PyUnicode_Type *) name
>> A syntax error in expression, near `) name'.
>> (gdb) print ((PyUnicode_Type *) name)
>> A syntax error in expression, near `) name)'.
>> (gdb) print ((PyUnicode_Type *) name);
>> A syntax error in expression, near `) name);'.
>
> PyUnicode_Type is not the name of the C type it's a variable/address
> that's holding the python type/vtable. I believe PyUnicodObject is the
> C type name.
>
>
>> ```
>>
>> So from this it seems to me like it's recognizing the PyUnicode_Type
>> fine, but I just get this weird syntax error. My google-foo hasn't
>> worked out that well so far in resolving this. What am I doing wrong? Am
>> I misunderstanding how casting works?
>>
>> Thanks for any help!
>>
>> Cheers,
>> Thomas
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-04-15 3:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-15 3:02 Casting an object to another type while debugging? Thomas Nyberg
2016-04-15 3:09 ` Yichao Yu
2016-04-15 3:12 ` Thomas Nyberg
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox