gdb/
[deliverable/binutils-gdb.git] / gdb / value.c
index 087cdfd5c25ce81b7efed97918470a0f30d0d2e8..e72670b6a29f40cb6e3682863d489bd8e89b18ba 100644 (file)
@@ -1063,9 +1063,9 @@ set_value_pointed_to_offset (struct value *value, int val)
 }
 
 const struct lval_funcs *
-value_computed_funcs (struct value *v)
+value_computed_funcs (const struct value *v)
 {
-  gdb_assert (VALUE_LVAL (v) == lval_computed);
+  gdb_assert (value_lval_const (v) == lval_computed);
 
   return v->location.computed.funcs;
 }
@@ -1084,6 +1084,12 @@ deprecated_value_lval_hack (struct value *value)
   return &value->lval;
 }
 
+enum lval_type
+value_lval_const (const struct value *value)
+{
+  return value->lval;
+}
+
 CORE_ADDR
 value_address (const struct value *value)
 {
@@ -3082,16 +3088,40 @@ value_from_history_ref (char *h, char **endp)
   return access_value_history (index);
 }
 
+struct value *
+coerce_ref_if_computed (const struct value *arg)
+{
+  const struct lval_funcs *funcs;
+
+  if (TYPE_CODE (check_typedef (value_type (arg))) != TYPE_CODE_REF)
+    return NULL;
+
+  if (value_lval_const (arg) != lval_computed)
+    return NULL;
+
+  funcs = value_computed_funcs (arg);
+  if (funcs->coerce_ref == NULL)
+    return NULL;
+
+  return funcs->coerce_ref (arg);
+}
+
 struct value *
 coerce_ref (struct value *arg)
 {
   struct type *value_type_arg_tmp = check_typedef (value_type (arg));
+  struct value *retval;
 
-  if (TYPE_CODE (value_type_arg_tmp) == TYPE_CODE_REF)
-    arg = value_at_lazy (TYPE_TARGET_TYPE (value_type_arg_tmp),
-                        unpack_pointer (value_type (arg),              
-                                        value_contents (arg)));
-  return arg;
+  retval = coerce_ref_if_computed (arg);
+  if (retval)
+    return retval;
+
+  if (TYPE_CODE (value_type_arg_tmp) != TYPE_CODE_REF)
+    return arg;
+
+  return value_at_lazy (TYPE_TARGET_TYPE (value_type_arg_tmp),
+                       unpack_pointer (value_type (arg),
+                                       value_contents (arg)));
 }
 
 struct value *
This page took 0.025225 seconds and 4 git commands to generate.