From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13009 invoked by alias); 17 Aug 2011 18:37:13 -0000 Received: (qmail 12840 invoked by uid 22791); 17 Aug 2011 18:37:12 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=BAYES_00 X-Spam-Check-By: sourceware.org Received: from adoakley.name (HELO ado.is-a-geek.net) (46.4.104.242) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 17 Aug 2011 18:36:58 +0000 Received: from ado-gentoo.moore.slainvet.net ([2001:8b0:393:0:223:54ff:fe39:b789] helo=ado-gentoo) by ado.is-a-geek.net with esmtpa (Exim 4.76) (envelope-from ) id 1Qtkwq-0007U0-AT; Wed, 17 Aug 2011 18:34:40 +0000 Date: Wed, 17 Aug 2011 18:37:00 -0000 From: Andrew Oakley To: Cc: , Subject: Re: Some Python ideas, looking for feedback Message-ID: <20110817193710.59945561@ado-gentoo> In-Reply-To: <09787EF419216C41A903FD14EE5506DD0151D585D2@AUSX7MCPC103.AMER.DELL.COM> References: <09787EF419216C41A903FD14EE5506DD0151D583A2@AUSX7MCPC103.AMER.DELL.COM> <201108161345.33448.andre.poenitz@nokia.com> <09787EF419216C41A903FD14EE5506DD0151D585D2@AUSX7MCPC103.AMER.DELL.COM> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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: 2011-08/txt/msg00075.txt.bz2 On Tue, 16 Aug 2011 09:45:35 -0500 wrote: > >On Tuesday 16 August 2011 13:03:42 ext Paul_Koning@Dell.com wrote: > >> [...] > >> And a question: is there a way to get the value corresponding to > >> an enum type's value name? The name comes back in the fields() > >> output but I don't see how I would get the value. Could that be > >> made a value attribute of the field object? > > > >int(...) works, or "%d" % ... > > That works for Value objects, but not for fields of Type. But it > looks like an obvious way to make it work for Type (rather than a > "value" attribute as I suggested earlier). What you are looking for is (for some reason) stored in bitpos. I can't actually find any documentation for this :(. You could use the function that is included with current gdb trunk (not sure if it is any releases) in the module gdb.types. It looks like this: > def make_enum_dict(enum_type): > """Return a dictionary from a program's enum type. > > Arguments: > enum_type: The enum to compute the dictionary for. > > Returns: > The dictionary of the enum. > > Raises: > TypeError: The type is not an enum. > """ > > if enum_type.code != gdb.TYPE_CODE_ENUM: > raise TypeError("not an enum type") > enum_dict = {} > for field in enum_type.fields(): > # The enum's value is stored in "bitpos". > enum_dict[field.name] = field.bitpos > return enum_dict -- Andrew Oakley