This is the mail archive of the
mailing list for the GDB project.
Re: Python: fetch value when building gdb.Value object
- From: Paul Koning <paulkoning at comcast dot net>
- To: Tom Tromey <tromey at redhat dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Tue, 4 Oct 2011 11:51:00 -0400
- Subject: Re: Python: fetch value when building gdb.Value object
- References: <36B29E9D-F2B3-446F-AF8A-97254A3AAEE2@comcast.net> <firstname.lastname@example.org>
On Oct 4, 2011, at 11:44 AM, Tom Tromey wrote:
>>>>>> "Paul" == Paul Koning <email@example.com> writes:
> Paul> GDB sometimes lazily evaluates operations on values, and
> Paul> py-value.c wasn't taking that into account. The result was that
> Paul> assigning a Value object to a Python variable could assign a lazy
> Paul> value, so that any errors in accessing the data would occur at a
> Paul> later time, and sometimes would not be handled right. (For
> Paul> example, the "nonzero" operation would fail without a Python
> Paul> traceback.) The attached patch cures this by fetching any lazy
> Paul> values when the gdb.Value object is built, and adds a test in the
> Paul> testcases to verify this.
> Paul> Ok to submit?
> I am not convinced that this is the right approach.
> I think it would probably be better to expose the laziness to the Python
> programmer -- via a new attribute and a new method to un-lazy the
> The reason is that eager fetching can be very expensive. E.g., you may
> construct an intermediate value that is a very large array, but intend
> only to reference a few elements. This can be done efficiently by gdb,
> but eager fetching will defeat that.
I modeled what I did after the way the existing GDB code handles convenience variables. It seemed logical that
set $foo = *ptr
python foo=gdb.eval ("*ptr")
should behave the same. With the patch, they do, because in both case the lazy evaluation is done.