From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22119 invoked by alias); 10 Sep 2010 18:09:35 -0000 Received: (qmail 22110 invoked by uid 22791); 10 Sep 2010 18:09:34 -0000 X-SWARE-Spam-Status: No, hits=-0.7 required=5.0 tests=AWL,BAYES_40,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU X-Spam-Check-By: sourceware.org Received: from caiajhbdcaib.dreamhost.com (HELO homiemail-a67.g.dreamhost.com) (208.97.132.81) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 10 Sep 2010 18:09:30 +0000 Received: from homiemail-a67.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a67.g.dreamhost.com (Postfix) with ESMTP id 0B8586D407A; Fri, 10 Sep 2010 11:09:27 -0700 (PDT) Received: from webmail.kenrose.org (caiajhbdcbef.dreamhost.com [208.97.132.145]) (Authenticated sender: kenrose@kenrose.org) by homiemail-a67.g.dreamhost.com (Postfix) with ESMTPA id C03176D4074; Fri, 10 Sep 2010 11:09:26 -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; Fri, 10 Sep 2010 14:09:27 -0400 Message-ID: <35cb13dde5f183ce57b117e677709dd0.squirrel@webmail.kenrose.org> In-Reply-To: References: <784f56871ebbe612785c8be91771a9a5.squirrel@webmail.kenrose.org> Date: Fri, 10 Sep 2010 18:09:00 -0000 Subject: Re: Cast to result of whatis expression From: "Kenneth Rose" To: "Tom Tromey" Cc: 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/msg00067.txt.bz2 >>>>>> "Kenneth" =3D=3D Kenneth Rose writes: > > Kenneth> I'm writing something similar to gdb-stl-views for some custom > Kenneth> container classes that we have. > > I think that these days it is better to use the Python pretty-printing > infrastructure instead. It has a number of advantages -- it works no > matter how the object is printed (in a stack trace, embedded in some > other structure), and it works with MI. > > Kenneth> I need to explicitly cast foo.m_x to the appropriate type, but > Kenneth> I'm at a loss as to how to get that type from gdb. "whatis > Kenneth> foo" gives me back "Container". Is there anyway of > Kenneth> extracting the "int" part of that result and using that as the > Kenneth> type to cast to? > > You can do this in Python :-) > > You could probably do it (with some difficulty) using a combination of > logging, "shell", and "source". > > Kenneth> I'm using the stock GDB that ships with Mac OS X 10.6 (GNU gdb > Kenneth> 6.3.50-20050815 (Apple version gdb-1461). I know... it's old. > > Ah, Apple's fork. Unfortunately it is Python-free. > > You could try GDB 7.2. It has some known bugs on Mac OS, but I have > also heard reports of it work. > > Tom > Thanks Tom. Unfortunately, this is for a bunch of developers and I can't make everyone upgrade to GDB 7.2. That said, when I was researching how to do this, the Python stuff looked uber sexy (and uber practical). I played around with sending the result of "whatis foo" to a shell command, but couldn't figure out how to actually pass an argument to the inferior shell with gdb. The shell command seems to literally interpret its arguments. I tried playing with 'set environment', but the inferior shell didn't seem to pick up any of the env. variable declarations. Anyways, I've ended up just passing the type to my pvector command. For example, "pvector myContainer int". It's not so bad because I can get gdb to tell me the container's value type with whatis. I just need to manually copy and paste it myself as an argument to pvector. Since I run gdb in emacs, this is pretty easy. Thanks again, -- kenrose