Create subobject value in pretty printer
authorYao Qi <yao.qi@linaro.org>
Mon, 21 Nov 2016 14:15:06 +0000 (14:15 +0000)
committerYao Qi <yao.qi@linaro.org>
Mon, 21 Nov 2016 14:15:06 +0000 (14:15 +0000)
Nowadays, we create a value of subobject in pretty printer with 'address'
being used,

  value = value_from_contents_and_address (type, valaddr + embedded_offset,
   address + embedded_offset);

  set_value_component_location (value, val);
  /* set_value_component_location resets the address, so we may
     need to set it again.  */
  if (VALUE_LVAL (value) != lval_internalvar
      && VALUE_LVAL (value) != lval_internalvar_component
      && VALUE_LVAL (value) != lval_computed)
    set_value_address (value, address + embedded_offset);

value_from_contents_and_address creates a value from memory, but the
value we are pretty-printing may not from memory at all.

Instead of using value_from_contents_and_address, we create a value
of subobject with the same location as object's but different offset.
We avoid using address in this way.  As a result, parameter 'address'
in apply_val_pretty_printer is no longer needed, we can remove it in
next step.

We've already had the location of the 'whole' value, so it is safe
to assume we can create a value of 'component' or 'suboject' value
at the same location but with different offset.

gdb:

2016-11-21  Yao Qi  <yao.qi@linaro.org>

* guile/scm-pretty-print.c (gdbscm_apply_val_pretty_printer):
Don't call value_from_contents_and_address and
set_value_address.  Call value_from_component.
* python/py-prettyprint.c (gdbpy_apply_val_pretty_printer):
Likewise.
* value.c (value_from_component): New function.
* value.h (value_from_component): Likewise.
* valarith.c (value_subscripted_rvalue): Call
value_from_component.

gdb/ChangeLog
gdb/guile/scm-pretty-print.c
gdb/python/py-prettyprint.c
gdb/valarith.c
gdb/value.c
gdb/value.h

index 3797e8beddf45f211d05b7df831e1ab75adc9c5a..768a1b33af7cb17377856e17489058435487d75f 100644 (file)
@@ -1,3 +1,15 @@
+2016-11-21  Yao Qi  <yao.qi@linaro.org>
+
+       * guile/scm-pretty-print.c (gdbscm_apply_val_pretty_printer):
+       Don't call value_from_contents_and_address and
+       set_value_address.  Call value_from_component.
+       * python/py-prettyprint.c (gdbpy_apply_val_pretty_printer):
+       Likewise.
+       * value.c (value_from_component): New function.
+       * value.h (value_from_component): Likewise.
+       * valarith.c (value_subscripted_rvalue): Call
+       value_from_component.
+
 2016-11-19  Joel Brobecker  <brobecker@adacore.com>
 
        * contrib/ari/gdb_ari.sh: Add detection of printf_vma and
index 5253defc1eea0049ab1f02e9fcafecc1c02b07f5..648ca53471bd81468bd3644380a5f1dbd8491669 100644 (file)
@@ -985,16 +985,7 @@ gdbscm_apply_val_pretty_printer (const struct extension_language_defn *extlang,
   cleanups = make_cleanup (null_cleanup, NULL);
 
   /* Instantiate the printer.  */
-  value = value_from_contents_and_address (type, valaddr + embedded_offset,
-                                          address + embedded_offset);
-
-  set_value_component_location (value, val);
-  /* set_value_component_location resets the address, so we may
-     need to set it again.  */
-  if (VALUE_LVAL (value) != lval_internalvar
-      && VALUE_LVAL (value) != lval_internalvar_component
-      && VALUE_LVAL (value) != lval_computed)
-    set_value_address (value, address + embedded_offset);
+  value = value_from_component (val, type, embedded_offset);
 
   val_obj = vlscm_scm_from_value (value);
   if (gdbscm_is_exception (val_obj))
index cbc168de4ee85a56fce3f398c309af2dc7c1eb2b..4f5e7f7662db7064289f972bd5a4bd6506cab0c9 100644 (file)
@@ -726,16 +726,7 @@ gdbpy_apply_val_pretty_printer (const struct extension_language_defn *extlang,
   cleanups = ensure_python_env (gdbarch, language);
 
   /* Instantiate the printer.  */
-  value = value_from_contents_and_address (type, valaddr + embedded_offset,
-                                          address + embedded_offset);
-
-  set_value_component_location (value, val);
-  /* set_value_component_location resets the address, so we may
-     need to set it again.  */
-  if (VALUE_LVAL (value) != lval_internalvar
-      && VALUE_LVAL (value) != lval_internalvar_component
-      && VALUE_LVAL (value) != lval_computed)
-    set_value_address (value, address + embedded_offset);
+  value = value_from_component (val, type, embedded_offset);
 
   val_obj = value_to_value_object (value);
   if (! val_obj)
index 2c561107dae38755b40d7cd16bd8242517964733..efa41ed06568b0f5e29926d841fd67371d0c6600 100644 (file)
@@ -194,7 +194,6 @@ value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound)
   struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type));
   ULONGEST elt_size = type_length_units (elt_type);
   ULONGEST elt_offs = elt_size * (index - lowerbound);
-  struct value *v;
 
   if (index < lowerbound || (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)
                             && elt_offs >= type_length_units (array_type)))
@@ -215,21 +214,7 @@ value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound)
       elt_type = resolve_dynamic_type (elt_type, NULL, address);
     }
 
-  if (VALUE_LVAL (array) == lval_memory && value_lazy (array))
-    v = allocate_value_lazy (elt_type);
-  else
-    {
-      v = allocate_value (elt_type);
-      value_contents_copy (v, value_embedded_offset (v),
-                          array, value_embedded_offset (array) + elt_offs,
-                          elt_size);
-    }
-
-  set_value_component_location (v, array);
-  VALUE_REGNUM (v) = VALUE_REGNUM (array);
-  VALUE_NEXT_FRAME_ID (v) = VALUE_NEXT_FRAME_ID (array);
-  set_value_offset (v, value_offset (array) + elt_offs);
-  return v;
+  return value_from_component (array, elt_type, elt_offs);
 }
 
 \f
index 0575a550f2161931954a69ac9f19425ff5db2d12..200d61d0cedac40cf009fb7e5a0011f282fb3478 100644 (file)
@@ -3795,6 +3795,31 @@ value_from_history_ref (const char *h, const char **endp)
   return access_value_history (index);
 }
 
+/* Get the component value (offset by OFFSET bytes) of a struct or
+   union WHOLE.  Component's type is TYPE.  */
+
+struct value *
+value_from_component (struct value *whole, struct type *type, LONGEST offset)
+{
+  struct value *v;
+
+  if (VALUE_LVAL (whole) == lval_memory && value_lazy (whole))
+    v = allocate_value_lazy (type);
+  else
+    {
+      v = allocate_value (type);
+      value_contents_copy (v, value_embedded_offset (v),
+                          whole, value_embedded_offset (whole) + offset,
+                          type_length_units (type));
+    }
+  v->offset = value_offset (whole) + offset + value_embedded_offset (whole);
+  set_value_component_location (v, whole);
+  VALUE_REGNUM (v) = VALUE_REGNUM (whole);
+  VALUE_FRAME_ID (v) = VALUE_FRAME_ID (whole);
+
+  return v;
+}
+
 struct value *
 coerce_ref_if_computed (const struct value *arg)
 {
index afcbcaefe71f0908fa40c08934e7d42329ddb98e..281b5a8c8ac6591a8bbf5cf0582799b6f69135fa 100644 (file)
@@ -645,6 +645,8 @@ extern struct value *value_from_double (struct type *type, DOUBLEST num);
 extern struct value *value_from_decfloat (struct type *type,
                                          const gdb_byte *decbytes);
 extern struct value *value_from_history_ref (const char *, const char **);
+extern struct value *value_from_component (struct value *, struct type *,
+                                          LONGEST);
 
 extern struct value *value_at (struct type *type, CORE_ADDR addr);
 extern struct value *value_at_lazy (struct type *type, CORE_ADDR addr);
This page took 0.033074 seconds and 4 git commands to generate.