[PATCH] Eliminate -var-create error for optzd ptr to struct

Don Breazeal donb@codesourcery.com
Tue Mar 29 17:14:00 GMT 2016


On 3/29/2016 5:01 AM, Yao Qi wrote:
> Don Breazeal <donb@codesourcery.com> writes:
> 
>>>> @@ -1203,9 +1203,10 @@ value_actual_type (struct value *value, int resolve_simple_types,
>>>>         /* If result's target type is TYPE_CODE_STRUCT, proceed to
>>>>   	 fetch its rtti type.  */
>>>>         if ((TYPE_CODE (result) == TYPE_CODE_PTR
>>>> -	  || TYPE_CODE (result) == TYPE_CODE_REF)
>>>> +	   || TYPE_CODE (result) == TYPE_CODE_REF)
>>>
>>> Is this just a formatting change?
>>
>> Yes.  I should have documented that in the ChangeLog.
> 
> If it is just a format change, you can move it to a separate patch, and
> commit it as obvious.  Don't mix format change with your bug fix patch.
> 

Hi Yao,
Here is the patch with the formatting change removed, and with the more
concise patch description posted most recent patchset.
Thanks,
--Don

----
This patch eliminates an error thrown when accessing the value of a
pointer to a structure where the pointer has been optimized out and
'set print object' is 'on'.  The error shows up as the rather ugly
value of the pointer variable in Eclipse.

If 'set print object' is 'on', GDB tries to determine the actual
(derived) type of the object rather than the declared type, which
requires dereferencing the pointer, which in this cases throws an
error because the pointer has been optimized out.

The fix is to simply ignore the 'print object on' setting for
pointers or references to structures when they have been optimized
out.  This means we just get the declared type instead of the actual
type, because in this case that's the best that we can do.

I'm working on setting things in motion for a patch to Eclipse that
recognizes optimized-out pointer-to-struct in this scenario and
prevents any subsequent attempt to dereference it from that end.

Tested on bare-metal powerpc board with Linux x86 host.

gdb/ChangeLog:
2016-03-29  Don Breazeal  <donb@codesourcery.com>

	* gdb/value.c (value_actual_type): Ignore the 'print object
	  on' setting if the object is a pointer to or reference to
	  a structure.

---
 gdb/value.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gdb/value.c b/gdb/value.c
index 738b2b2..95bfdb2 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -1205,7 +1205,8 @@ value_actual_type (struct value *value, int
resolve_simple_types,
       if ((TYPE_CODE (result) == TYPE_CODE_PTR
 	  || TYPE_CODE (result) == TYPE_CODE_REF)
 	  && TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (result)))
-	     == TYPE_CODE_STRUCT)
+	     == TYPE_CODE_STRUCT
+	  && !value_optimized_out (value))
         {
           struct type *real_type;

-- 
1.8.1.1



More information about the Gdb-patches mailing list