[v2,2/2] Optzd-out ptr: Eliminate -var-create error

Message ID 1459200820-24735-3-git-send-email-donb@codesourcery.com
State New, archived

Commit Message

Don Breazeal March 28, 2016, 9:33 p.m. UTC
  This version of the patch is unchanged from the previous version,
except that the description has been revised to be more concise and
the ChangeLog has been updated to note the formatting change made by
the patch.

Luis reviewed this patch, but it still needs to be OK'd by a maintainer.

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.



2016-03-28  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.  Fix a formatting issue.

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


diff --git a/gdb/value.c b/gdb/value.c
index 738b2b2..50e4f8a 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -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)
 	  && TYPE_CODE (check_typedef (TYPE_TARGET_TYPE (result)))
+	  && !value_optimized_out (value))
           struct type *real_type;