Re: Python: fetch value when building gdb.Value object

Paul Koning
2011-10-04T15:51:29Z

On Oct 4, 2011, at 11:44 AM, Tom Tromey wrote:

>>>>>> "Paul" == Paul Koning <paulkoning@comcast.net> 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
> object.
>
> 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

and
python foo=gdb.eval ("*ptr")

should behave the same. With the patch, they do, because in both case the lazy evaluation is done.

paul