This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=ecf2e90cd6a862ea5492cb31555a0c33e345b3e7

commit ecf2e90cd6a862ea5492cb31555a0c33e345b3e7
Author: Don Breazeal <donb@codesourcery.com>
Date:   Wed Apr 6 14:18:31 2016 -0700

    Eliminate -var-create error for optzd ptr to struct
    
    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.
    
    To implement the fix, value_optimized_out was modified so that it
    no longer throws an error when it fails to fetch the specified
    value.  Instead, it just checks value->optimized_out.  If we can't
    definitively say that the value is optimized out, then we assume
    it is not.
    
    gdb/ChangeLog:
    2016-04-06  Don Breazeal  <donb@codesourcery.com>
    
    	* value.c (value_actual_type): Don't try to get rtti type
    	of the value if it has been optimized out.
    	(value_optimized_out): If a memory access error occurs,
    	just check vaue->optimized_out.

Diff:
---
 gdb/ChangeLog |  7 +++++++
 gdb/value.c   | 15 +++++++++++++--
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 0af0c79..6b9d342 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,10 @@
+2016-04-06  Don Breazeal  <donb@codesourcery.com>
+
+	* value.c (value_actual_type): Don't try to get rtti type
+	of the value if it has been optimized out.
+	(value_optimized_out): If a memory access error occurs,
+	just check vaue->optimized_out.
+
 2016-04-06  Jan Kratochvil  <jan.kratochvil@redhat.com>
 
 	Revert the previous commit adding unknown_v_replies_ok.
diff --git a/gdb/value.c b/gdb/value.c
index 8268b08..3b66946 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;
 
@@ -1433,7 +1434,17 @@ value_optimized_out (struct value *value)
   /* We can only know if a value is optimized out once we have tried to
      fetch it.  */
   if (VEC_empty (range_s, value->optimized_out) && value->lazy)
-    value_fetch_lazy (value);
+    {
+      TRY
+	{
+	  value_fetch_lazy (value);
+	}
+      CATCH (ex, RETURN_MASK_ERROR)
+	{
+	  /* Fall back to checking value->optimized_out.  */
+	}
+      END_CATCH
+    }
 
   return !VEC_empty (range_s, value->optimized_out);
 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]