This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Casting an object to another type while debugging?


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]