From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 71232 invoked by alias); 15 Apr 2016 03:09:52 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 71218 invoked by uid 89); 15 Apr 2016 03:09:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-qk0-f178.google.com Received: from mail-qk0-f178.google.com (HELO mail-qk0-f178.google.com) (209.85.220.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 15 Apr 2016 03:09:50 +0000 Received: by mail-qk0-f178.google.com with SMTP id n63so23898183qkf.0 for ; Thu, 14 Apr 2016 20:09:50 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=tRIPlPy/iTp81h8Vywd2h85ZhHExYtdW7ewyqDongQs=; b=hhVlpNdDWuJ7hYMnV1cV5VSaQpSR+n8ra3N7c90KtL+1aej2Zyip8MqWNQtApbYzA1 RB/Gq2Z1Kg9+33SUHr7/FZyEsvjZ0io3wfww8aKuiECJnmuhgkIX2RSHdWv9tJsbWx1+ b3Akcg2OHk1ICkieut6oCUMp3JJC9dwrLONRnwOKqLiyPaulsSIoGggYOG4dDDXDP+3/ 7pNFxtaxvIcbkVCG6BCpBmZjwuu5v8gfPwjHJFftmmxdOwUoKc+isoqmuHpV33WJCF05 tENAn5H3iA3JZNDsQL4fneuVIu0sPP+Xlqg/71jdwfXTkSH4OOdAGXQxz8lxzyI/2fpK sXkw== X-Gm-Message-State: AOPr4FUJkv4oPB40Zbh7/Dar0GS6UKv/H4nXf/wD6EXFOoIVgHWk+MWuX4WVBTosagrtFV2OhFPg443cHjZwog== X-Received: by 10.55.73.74 with SMTP id w71mr23098407qka.60.1460689788661; Thu, 14 Apr 2016 20:09:48 -0700 (PDT) MIME-Version: 1.0 Received: by 10.55.189.130 with HTTP; Thu, 14 Apr 2016 20:09:29 -0700 (PDT) In-Reply-To: <571059D1.3010308@gmail.com> References: <571059D1.3010308@gmail.com> From: Yichao Yu Date: Fri, 15 Apr 2016 03:09:00 -0000 Message-ID: Subject: Re: Casting an object to another type while debugging? To: Thomas Nyberg Cc: gdb@sourceware.org Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2016-04/txt/msg00020.txt.bz2 On Thu, Apr 14, 2016 at 11:02 PM, Thomas Nyberg 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 } > (gdb) print name > $12 = (PyObject *) 0x7ffff7ee3298 > (gdb) print *name > $13 = {ob_refcnt = 2, ob_type = 0x8a1a00 } > (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