Mirror of the gdb mailing list
 help / color / mirror / Atom feed
From: Yichao Yu <yyc1992@gmail.com>
To: Thomas Nyberg <tomnyberg@gmail.com>
Cc: gdb@sourceware.org
Subject: Re: Casting an object to another type while debugging?
Date: Fri, 15 Apr 2016 03:09:00 -0000	[thread overview]
Message-ID: <CAMvDr+T9bEOn5D01FFpkr0v5EGXy9ys2KUwmbBVdunL1g9hL-g@mail.gmail.com> (raw)
In-Reply-To: <571059D1.3010308@gmail.com>

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


  reply	other threads:[~2016-04-15  3:09 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-15  3:02 Thomas Nyberg
2016-04-15  3:09 ` Yichao Yu [this message]
2016-04-15  3:12   ` Thomas Nyberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMvDr+T9bEOn5D01FFpkr0v5EGXy9ys2KUwmbBVdunL1g9hL-g@mail.gmail.com \
    --to=yyc1992@gmail.com \
    --cc=gdb@sourceware.org \
    --cc=tomnyberg@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox