From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27587 invoked by alias); 1 Mar 2014 20:36:04 -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 27576 invoked by uid 89); 1 Mar 2014 20:36:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.9 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,RP_MATCHES_RCVD,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-vc0-f173.google.com Received: from mail-vc0-f173.google.com (HELO mail-vc0-f173.google.com) (209.85.220.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Sat, 01 Mar 2014 20:36:02 +0000 Received: by mail-vc0-f173.google.com with SMTP id ld13so2176458vcb.32 for ; Sat, 01 Mar 2014 12:36:00 -0800 (PST) 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:date :message-id:subject:from:to:cc:content-type; bh=a3v3VmyISzOm5J9CXEhE3sOUhO12SyUnn3zJoL1ocWA=; b=LL0sTlPTM4eLs4UnBhrNYDuGfXl6uErOogi+ED4hyEsNE2mqWN5sdLT7zdLoYlxGF+ 6rcQ6eul/vkShFij2PrWHmGhxioOnfDcaSOiZ0rPaxnMGKIL0crqtb4Oa5Gouh2HtNxl /WPrWdoxRc/CLrYriRi89mA9wV8y90O/vSchmxbk80oUkAgdbP8D4yiROJt8KVO+cNc0 wL2PJr1pOu9NIl3yDonhG2PphFiLh2n6I8XTh9br7W/F89mBtQ471sfIVAF2ZSW2P9Ok oksXrb4GcsEUhnoVQHgI6TjXoyn4Bkb1CIxdJisyuUzSt0+pfSarKEEBjtowD2lpMoBX GzxQ== X-Gm-Message-State: ALoCoQkerAbF1Mu7IwDdNxjC2bWd1M/UEGgn1LPLuYg0j64CE3y/cMA7kz2dOP2zwOKskgHO6ngG/ikpKaV4Q42xidgEOiAlsDwB8Uy033qFY9h/KflDVlGNRi26z6+fdOszPK0cSN/Ky8FfE+lz0RVrvcM2OsDXU+rPHsj7+vyNySbXDu5UkTjoY8c3JAX9Mj+BV3dcMBjf MIME-Version: 1.0 X-Received: by 10.58.59.100 with SMTP id y4mr9222621veq.4.1393706160569; Sat, 01 Mar 2014 12:36:00 -0800 (PST) Received: by 10.52.51.234 with HTTP; Sat, 1 Mar 2014 12:36:00 -0800 (PST) In-Reply-To: <5310C3FC.6000006@elis.ugent.be> References: <5310C3FC.6000006@elis.ugent.be> Date: Sat, 01 Mar 2014 20:36:00 -0000 Message-ID: Subject: Re: Accessing struct fields without casting From: Doug Evans To: Tim Besard Cc: gdb , Siva Reddy Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2014-03/txt/msg00001.txt.bz2 On Fri, Feb 28, 2014 at 9:14 AM, Tim Besard wrote: > Hi list, > > I'm working with some code base which expresses most internally > used values in terms of some struct "value_t" only containing a single > field, "kind". This field is used as an discriminator, and based on its > value the object is cast after which its available fields can be > accessed (see attached test case). > > Since this is pretty hard to work with from within GDB, especially > because the "kind" field doesn't contain human readable text but rather > raw memory (a pointer to a globally defined object), I wrote a pretty > printer which detects the actual type of "value_t" objects, casts them, > and displays the actual typename when called with to_string() and > returns the casted value its fields when called with children(). > > However, this doesn't ease debugging much, because despite implementing > a children() method which lists all available fields GDB doesn't allow > to access those without an explicit cast (see attached sample). >> (gdb) print value->foo >> There is no member named foo. >> (gdb) print ((example_t*)value)->foo >> $1 = 42 > This is even worse in the actual code, where value_t "subtypes" often > contain pointers to other value_t "subtypes", but since those pointers > are always of type "value_t*" I need to pretty print them in order to > know the type and then cast them in before I can finally access its fields. > > Is it possible to teach GDB about the "actual" type of these objects, or > work around this problem in some other way so that I can access subtype > fields without having to cast each object manually? Hmmm, Siva's original "debug methods" patch would let you handle this nicely (I think). It let one hook python implementations into the expression parser. Seems like we can make good use of *both* flavors (one that hooks into the parser, and one that hooks into method lookup).