This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [python] acessing struct elements
- From: Daniel Jacobowitz <drow at false dot org>
- To: Thiago Jung Bauermann <bauerman at br dot ibm dot com>
- Cc: gdb-patches at sources dot redhat dot com
- Date: Wed, 13 Aug 2008 08:37:33 -0400
- Subject: Re: [python] acessing struct elements
- References: <20080429155212.444237503@br.ibm.com> <20080429155304.466637516@br.ibm.com> <20080528212451.GB2969@caradoc.them.org> <m3k5h78j64.fsf@fleche.redhat.com> <1215410598.1795.58.camel@localhost.localdomain> <g7tvla$lck$2@ger.gmane.org>
On Wed, Aug 13, 2008 at 01:46:53AM -0300, Thiago Jung Bauermann wrote:
> There's one unexpected consequence of this: to enable the syntax above, all
> gdb.Value objects need to implement the map methods, and Python considers
> empty maps to be False in contexts which expect a boolean. Because of this,
> the following will not generally work:
>
> val = frame.read_var_value (sym)
> if val:
> print "Variable value is: " + str (val)
> else:
> print "Variable not found."
It took me a while to find it, but I knew there was an operator for
this. Take a look at __nonzero__:
http://docs.python.org/ref/customization.html
--
Daniel Jacobowitz
CodeSourcery