This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH] ada-lang.c:coerce_unspec_val_to_type: Preserve laziness.
- From: Pedro Alves <palves at redhat dot com>
- To: Joel Brobecker <brobecker at adacore dot com>
- Cc: gdb-patches at sourceware dot org, Andrew Burgess <aburgess at broadcom dot com>
- Date: Fri, 26 Jul 2013 18:00:18 +0100
- Subject: Re: [PATCH] ada-lang.c:coerce_unspec_val_to_type: Preserve laziness.
- References: <20130704182244 dot 16683 dot 55719 dot stgit at brno dot lan> <20130710004434 dot GE8063 at adacore dot com>
On 07/10/2013 01:44 AM, Joel Brobecker wrote:
> Hi Pedro,
>
>> ada-lang.c:coerce_unspec_val_to_type does:
>>
>> if (value_lazy (val)
>> || TYPE_LENGTH (type) > TYPE_LENGTH (value_type (val)))
>> result = allocate_value_lazy (type);
>> else
>> {
>> result = allocate_value (type);
>> memcpy (value_contents_raw (result), value_contents (val),
>> TYPE_LENGTH (type));
>> }
>> set_value_component_location (result, val);
>> set_value_bitsize (result, value_bitsize (val));
>> set_value_bitpos (result, value_bitpos (val));
>> set_value_address (result, value_address (val));
>> set_value_optimized_out (result, value_optimized_out (val));
>>
>> Notice that before value_optimized_out was made to auto-fetch lazy
>> values, VAL would end up still lazy if it was lazy on entry. It's not
>> really a problem here if VAL is lazy, and VAL->optimized_out is 0,
>> because RESULT is also left lazy. IOW, this just wants to copy the
>> VAL->optimized_out flag to RESULT->optimized_out, nothing else.
>>
>> The patch adds the value_optimized_out_const function for that.
>>
>> (I found this out by grepping for set_value_optimized_out and trying
>> to convert the uses I found to instead allocate the value with
>> allocate_optimized_out_value.)
>>
>> Tested on x86_64 Fedora 17.
>
>> gdb/
>> 2013-07-04 Pedro Alves <palves@redhat.com>
>>
>> * ada-lang.c (coerce_unspec_val_to_type): Use
>> value_optimized_out_const.
>> * value.c (value_optimized_out_const): New function.
>> * value.h (value_optimized_out_const): New declaration.
>
> Thanks for the patch!
>
> We can actually demonstrate a regression which your patch fixes.
> Consider:
>
> type Small is range -64 .. 63;
> for Small'Size use 7;
> type Arr is array (1..10) of Small;
> pragma Pack (Arr);
>
> type Arr_Ptr is access Arr;
>
> An_Arr_Ptr : Arr_Ptr := new Arr'(10, 20, 30, 40, 50, 60, 62, 63,
> -23, 42);
>
> Trying to print one element of An_Arr_Ptr yields:
>
> (gdb) p an_arr_ptr(3)
> Cannot access memory at address 0x0
>
> I've updated one of the testcases that deals with array "pointers"
> (we call them access types in Ada) to add this case:
>
> http://www.sourceware.org/ml/gdb-patches/2013-07/msg00254.html
>
> Since your patch looks correct to me, you had answers to Andrew's
> comments, this is a regression, you are away for a while and no one
> else commented on your patch, I've taken the liberty of checking it
> in.
Thanks!
--
Pedro Alves