From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3969 invoked by alias); 7 Sep 2010 22:04:24 -0000 Received: (qmail 3956 invoked by uid 22791); 7 Sep 2010 22:04:23 -0000 X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL,BAYES_05,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_DNSWL_NONE X-Spam-Check-By: sourceware.org Received: from mailbigip.dreamhost.com (HELO homiemail-a28.g.dreamhost.com) (208.97.132.5) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 07 Sep 2010 22:03:51 +0000 Received: from homiemail-a28.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a28.g.dreamhost.com (Postfix) with ESMTP id AC3B01B4078 for ; Tue, 7 Sep 2010 15:03:49 -0700 (PDT) Received: from webmail.kenrose.org (caiajhbdcbef.dreamhost.com [208.97.132.145]) (Authenticated sender: kenrose@kenrose.org) by homiemail-a28.g.dreamhost.com (Postfix) with ESMTPA id 9C9841B4014 for ; Tue, 7 Sep 2010 15:03:49 -0700 (PDT) Received: from 207.61.230.154 (proxying for 207.61.230.154) (SquirrelMail authenticated user kenrose@kenrose.org) by webmail.kenrose.org with HTTP; Tue, 7 Sep 2010 18:03:49 -0400 Message-ID: Date: Tue, 07 Sep 2010 22:04:00 -0000 Subject: Cast to result of whatis expression From: "Kenneth Rose" To: gdb@sourceware.org User-Agent: SquirrelMail/1.4.21 MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes 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 X-SW-Source: 2010-09/txt/msg00051.txt.bz2 Hi all, I'm writing something similar to gdb-stl-views for some custom container classes that we have. As opposed to the STL containers though, our containers cast the datatype to void*. A minimalistic example looks like: class ContainerBase { protected: ContainerBase( void *x ) : m_x( x ) {} void *m_x; }; template class Container : public ContainerBase { public: Container() : ContainerBase( new T ) {} T& get() { return *static_cast( m_x ); } }; Say I have the following code somewhere: Container foo; I'd like to be able to have a gdb command like "pcontainer foo" that shows me something like "The value in foo is 0". In terms of implementing such a command, I cannot just call get() because I get the dreaded "Cannot evaluate function -- may be inlined" message. I need to explicitly cast foo.m_x to the appropriate type, but I'm at a loss as to how to get that type from gdb. "whatis foo" gives me back "Container". Is there anyway of extracting the "int" part of that result and using that as the type to cast to? The following is not valid, but this is what I'm going for.... set $type =3D regex 'whatis foo' Container< \1 > set $result =3D *(($type *) foo.m_x) I'm using the stock GDB that ships with Mac OS X 10.6 (GNU gdb 6.3.50-20050815 (Apple version gdb-1461). I know... it's old. Thanks for your help. -- kenrose P.S. - I could have something like "pcontainer foo int", but I'm trying to avoid that since gdb already knows the type of foo (as Container).