From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29726 invoked by alias); 1 Jul 2009 20:52:03 -0000 Mailing-List: contact archer-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: List-Id: Received: (qmail 29716 invoked by uid 22791); 1 Jul 2009 20:52:02 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org Message-ID: <4A4BCC63.5020407@googlemail.com> Date: Wed, 01 Jul 2009 20:52:00 -0000 From: Richard Ward User-Agent: Thunderbird 2.0.0.22 (X11/20090608) MIME-Version: 1.0 To: Paul Pluzhnikov CC: archer@sourceware.org Subject: Re: How to distinguish inheritance from containment? References: <20090701203842.32FE076BC0@localhost> In-Reply-To: <20090701203842.32FE076BC0@localhost> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-SW-Source: 2009-q3/txt/msg00002.txt.bz2 Paul Pluzhnikov wrote: > Greetings, > > Consider this source: > > --- cut --- > struct foo { > int x; > }; > > struct is_a_foo : public foo { > int y; > }; > > struct has_a_foo { > foo f; > int z; > }; > > int main() > { > is_a_foo a; > has_a_foo b; > > return a.x + b.f.x; > } > --- cut --- > > Suppose I want to define a pretty printer for anything that "is a foo", > but which should not apply to things which "contain a foo" as the first > field. > > The only way I figured out how to do this currently feels very "hacky": > (assume gdb.Value('a') is bound to python variable a). > > field0 = a.type.fields()[0] > if "foo" == field0.name and "foo" == str(field0.type): > print "is a foo" > > In addition, above test is not fool-proof: if I rename 'f' member of > has_a_foo to 'foo': > > struct has_a_foo { > struct foo foo; > int z; > }; > > then above test answers 'is a foo' for 'b' as well. > > Would adding an 'inherited' pre-defined attribute to gdb.Field be a bad idea? > It would make 'is a foo' determination straightforward: > > if "foo" == str(field0.type) and field0.inherited: > print "is a foo" > > > I'll send a patch if y'all think this is reasonable. > > Thanks, > -- > Paul Pluzhnikov I sent a patch to archer that did just that about two weeks ago, if you want it (not that it take that long to write one yourself). It had "Info about base class in gdb.Type" in the subject line.