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

Tom Tromey
2011-10-04T15:45:20Z

>>>>> "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.

Tom