The main purpose of this patch would be to allow a clean-up in ada-lang.c, making it a little bit "closer" to the other language supports. This implements lazy allocation of value content. That is to say: the actual content part of the struct value would not be allocated by default for lazy values; it would only be allocated at "fetch" time. Let me give some context. In Ada, passing a big array or record in parameter of a function is a quite common programming idiom; this big object is passed by referenced, its passing mode is typically "in out". If GDB tries to allocate a struct value for such a beast, the allocation may fail. If the user would not expect to debugger to print the whole object, he would at least think that printing a slice of his array (or some components of his record) should be possible. For now, here is what ada-lang does: it never dereferences such objects, and builds references to slices (or references to fields). This solution is not completely satisfactory; it is quite different than what the other language supports do. And we end up manipulating refs in a lot of places where they should not appear. For example, consider the formatted-ref test in the GDB testsuite, and suppose that you ask GDB to evaluate the Ada expression "s.x = 13" (equality test between "s.x" and "13", "s" being a record passed by reference); to compare a ref to "x" to the scalar 13, GDB would try to cast "13" to the type "ref to integer". This would return an error: as "13" is not in memory, making it a ref does not make much sense. In AdaCore's GDB, we have changed ada_value_cast to use the target type when a reference type is given in parameter. This fixes this problem, but makes the semantics of ada_value_cast quite different than value_cast; not very satisfactory... Here, an elegant solution would be to manipulate lazy values instead of references; but, the way it is currently implemented, whenever GDB creates a value, lazy or not, it allocates sufficient space to hold that value when it is eventually read. So this does not protect us against the allocation failure I described. This patch would fix this issue: the raw content spaces is not allocated in the lazy value by default, it is only done if this raw content is fetched from the target. Interestingly, a side effect of this change is that it makes value_change_enclosing_type much simpler. Comments? I have tested it on x86-linux, with a C++/Ada compiler, no regression. 2008-11-24 Jerome Guitton * value.h (allocate_value_lazy): New function declaration. (value_free): Remove macro, make it a function. * value.c (value_aligner): New union, extracted from struct value. (value): Move actual content outside of the struct; add a pointer to this actual content. (allocate_value_lazy, allocate_value_content): New function. (allocate_value): Reimplement using these two new functions. (value_contents_raw, value_contents_all_raw): If no memory has been allocated yet for the actual content, allocate it. (value_contents_all): Resync with struct value's changes. (value_free): New function. (value_copy, value_primitive_field): Use new function allocate_value_lazy to allocate lazy values. (value_change_enclosing_type): Resync with struct value's changes. As the value is not reallocated, remove the special handling for the value chain (now obsolete). * valops.c (value_at_lazy): Use new function allocate_value_lazy. (value_fetch_lazy): Allocate value content. Use allocate_value_lazy to allocate lazy values. (value_slice): Use allocate_value_lazy to allocate lazy values.