public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 00/12] More type macros removal
@ 2020-07-06 13:38 Simon Marchi
  2020-07-06 13:38 ` [PATCH 01/12] gdb: add type::bounds / type::set_bounds Simon Marchi
                   ` (10 more replies)
  0 siblings, 11 replies; 14+ messages in thread
From: Simon Marchi @ 2020-07-06 13:38 UTC (permalink / raw)
  To: gdb-patches

Here is the next installment of removal of type macros, in favor of
getter/setter methods.

I added some assertions in some of these methods, to verify that the
method is called on a type with the expected code (this is one of the
goal of these changes).  It found one case that needed to be fixed,
handled by patch 3.

The rest should be relatively straightforward.

Simon Marchi (12):
  gdb: add type::bounds / type::set_bounds
  gdb: remove TYPE_RANGE_DATA macro
  gdb: make get_discrete_bounds check for non-constant range bounds
  gdb: add accessors to struct dynamic_prop
  gdb: remove TYPE_HIGH_BOUND and TYPE_LOW_BOUND
  gdb: remove TYPE_LOW_BOUND_UNDEFINED and TYPE_HIGH_BOUND_UNDEFINED
  gdb: remove TYPE_LOW_BOUND_KIND and TYPE_HIGH_BOUND_KIND
  gdb: remove TYPE_ARRAY_{UPPER,LOWER}_BOUND_IS_UNDEFINED
  gdb: remove TYPE_ARRAY_{LOWER,UPPER}_BOUND_VALUE
  gdb: remove TYPE_BIT_STRIDE
  gdb: remove TYPE_ARRAY_BIT_STRIDE
  gdb: make type::bounds work for array and string types

 gdb/ada-lang.c                    |  22 ++--
 gdb/ada-tasks.c                   |   7 +-
 gdb/ada-typeprint.c               |   8 +-
 gdb/ada-valprint.c                |   2 +-
 gdb/c-typeprint.c                 |   4 +-
 gdb/c-varobj.c                    |  18 ++-
 gdb/compile/compile-c-symbols.c   |   6 +-
 gdb/compile/compile-c-types.c     |  10 +-
 gdb/compile/compile-cplus-types.c |  10 +-
 gdb/ctfread.c                     |   2 +-
 gdb/dwarf2/loc.c                  |  16 +--
 gdb/dwarf2/read.c                 |  71 +++++-------
 gdb/eval.c                        |   8 +-
 gdb/f-typeprint.c                 |   4 +-
 gdb/f-valprint.c                  |  10 +-
 gdb/gdbtypes.c                    | 186 +++++++++++++-----------------
 gdb/gdbtypes.h                    | 162 +++++++++++++++++++-------
 gdb/gnu-v3-abi.c                  |   3 +-
 gdb/guile/scm-type.c              |   7 +-
 gdb/m2-typeprint.c                |  20 ++--
 gdb/m2-valprint.c                 |   4 +-
 gdb/mdebugread.c                  |   8 +-
 gdb/p-typeprint.c                 |  10 +-
 gdb/p-valprint.c                  |   2 +-
 gdb/printcmd.c                    |   3 +-
 gdb/python/py-type.c              |   7 +-
 gdb/rust-lang.c                   |   8 +-
 gdb/type-stack.c                  |   3 +-
 gdb/valarith.c                    |  11 +-
 gdb/valops.c                      |   2 +-
 gdb/value.c                       |   4 +-
 31 files changed, 337 insertions(+), 301 deletions(-)

-- 
2.27.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 01/12] gdb: add type::bounds / type::set_bounds
  2020-07-06 13:38 [PATCH 00/12] More type macros removal Simon Marchi
@ 2020-07-06 13:38 ` Simon Marchi
  2020-07-06 13:38 ` [PATCH 02/12] gdb: remove TYPE_RANGE_DATA macro Simon Marchi
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Simon Marchi @ 2020-07-06 13:38 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@efficios.com>

Add the `bounds` and `set_bounds` methods on `struct type`, in order to
remove the `TYPE_RANGE_DATA` macro.  In this patch, the
`TYPE_RANGE_DATA` macro is changed to use `type::bounds`, so all the
call sites that are used to set a range type's bounds are changed to use
`type::set_bounds`.  The next patch will remove `TYPE_RANGE_DATA`
completely.

gdb/ChangeLog:

	* gdbtypes.h (struct type) <bounds, set_bounds>: New methods.
	(TYPE_RANGE_DATA): Use type::bounds.  Change all uses that
	are used to set the range type's bounds to use set_bounds.

Change-Id: I62e15506239b98404e62bbea8120db184ed87847
---
 gdb/gdbtypes.c   | 23 ++++++++++++++---------
 gdb/gdbtypes.h   | 18 +++++++++++++++++-
 gdb/mdebugread.c |  4 ++--
 3 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index cdf88a4a7d15..66f094328991 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -935,15 +935,17 @@ create_range_type (struct type *result_type, struct type *index_type,
   else
     TYPE_LENGTH (result_type) = TYPE_LENGTH (check_typedef (index_type));
 
-  TYPE_RANGE_DATA (result_type) = (struct range_bounds *)
-    TYPE_ZALLOC (result_type, sizeof (struct range_bounds));
-  TYPE_RANGE_DATA (result_type)->low = *low_bound;
-  TYPE_RANGE_DATA (result_type)->high = *high_bound;
-  TYPE_RANGE_DATA (result_type)->bias = bias;
+  range_bounds *bounds
+    = (struct range_bounds *) TYPE_ZALLOC (result_type, sizeof (range_bounds));
+  bounds->low = *low_bound;
+  bounds->high = *high_bound;
+  bounds->bias = bias;
 
   /* Initialize the stride to be a constant, the value will already be zero
      thanks to the use of TYPE_ZALLOC above.  */
-  TYPE_RANGE_DATA (result_type)->stride.kind = PROP_CONST;
+  bounds->stride.kind = PROP_CONST;
+
+  result_type->set_bounds (bounds);
 
   if (low_bound->kind == PROP_CONST && low_bound->data.const_val >= 0)
     TYPE_UNSIGNED (result_type) = 1;
@@ -5363,9 +5365,12 @@ copy_type_recursive (struct objfile *objfile,
   /* For range types, copy the bounds information.  */
   if (type->code () == TYPE_CODE_RANGE)
     {
-      TYPE_RANGE_DATA (new_type) = (struct range_bounds *)
-        TYPE_ALLOC (new_type, sizeof (struct range_bounds));
-      *TYPE_RANGE_DATA (new_type) = *TYPE_RANGE_DATA (type);
+      range_bounds *bounds
+        = ((struct range_bounds *) TYPE_ALLOC
+	   (new_type, sizeof (struct range_bounds)));
+
+      *bounds = *type->bounds ();
+      new_type->set_bounds (bounds);
     }
 
   if (type->main_type->dyn_prop_list != NULL)
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 28d42efb7285..236d37b1ce2a 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -953,6 +953,22 @@ struct type
     this->field (0).set_type (index_type);
   }
 
+  /* Get the bounds bounds of this type.  The type must be a range type.  */
+  range_bounds *bounds () const
+  {
+    gdb_assert (this->code () == TYPE_CODE_RANGE);
+
+    return this->main_type->flds_bnds.bounds;
+  }
+
+  /* Set the bounds of this type.  The type must be a range type.  */
+  void set_bounds (range_bounds *bounds)
+  {
+    gdb_assert (this->code () == TYPE_CODE_RANGE);
+
+    this->main_type->flds_bnds.bounds = bounds;
+  }
+
   /* * Return the dynamic property of the requested KIND from this type's
      list of dynamic properties.  */
   dynamic_prop *dyn_prop (dynamic_prop_node_kind kind) const;
@@ -1502,7 +1518,7 @@ extern unsigned type_align (struct type *);
    space in struct type.  */
 extern bool set_type_align (struct type *, ULONGEST);
 
-#define TYPE_RANGE_DATA(thistype) TYPE_MAIN_TYPE(thistype)->flds_bnds.bounds
+#define TYPE_RANGE_DATA(thistype) ((thistype)->bounds ())
 #define TYPE_LOW_BOUND(range_type) \
   TYPE_RANGE_DATA(range_type)->low.data.const_val
 #define TYPE_HIGH_BOUND(range_type) \
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 6f76bc6a84e2..aa0c715b054a 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -1734,8 +1734,8 @@ parse_type (int fd, union aux_ext *ax, unsigned int aux_index, int *bs,
   if (t->bt == btRange)
     {
       tp->set_num_fields (0);
-      TYPE_RANGE_DATA (tp) = ((struct range_bounds *)
-			  TYPE_ZALLOC (tp, sizeof (struct range_bounds)));
+      tp->set_bounds (((struct range_bounds *)
+			TYPE_ZALLOC (tp, sizeof (struct range_bounds))));
       TYPE_LOW_BOUND (tp) = AUX_GET_DNLOW (bigend, ax);
       ax++;
       TYPE_HIGH_BOUND (tp) = AUX_GET_DNHIGH (bigend, ax);
-- 
2.27.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 02/12] gdb: remove TYPE_RANGE_DATA macro
  2020-07-06 13:38 [PATCH 00/12] More type macros removal Simon Marchi
  2020-07-06 13:38 ` [PATCH 01/12] gdb: add type::bounds / type::set_bounds Simon Marchi
@ 2020-07-06 13:38 ` Simon Marchi
  2020-07-06 13:38 ` [PATCH 03/12] gdb: make get_discrete_bounds check for non-constant range bounds Simon Marchi
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Simon Marchi @ 2020-07-06 13:38 UTC (permalink / raw)
  To: gdb-patches

Remove it in favor of using type::bounds directly.

gdb/ChangeLog:

	* gdbtypes.h (TYPE_RANGE_DATA): Remove.  Update callers to use
	the type::bounds method directly.

Change-Id: Id4fab22af0a94cbf505f78b01b3ee5b3d682fba2
---
 gdb/ada-lang.c                    |  2 +-
 gdb/compile/compile-c-symbols.c   |  2 +-
 gdb/compile/compile-c-types.c     |  2 +-
 gdb/compile/compile-cplus-types.c |  2 +-
 gdb/dwarf2/read.c                 |  2 +-
 gdb/eval.c                        |  2 +-
 gdb/gdbtypes.c                    | 25 ++++++++++++-------------
 gdb/gdbtypes.h                    | 17 ++++++++---------
 gdb/printcmd.c                    |  3 +--
 gdb/value.c                       |  4 ++--
 10 files changed, 29 insertions(+), 32 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 98508c168bc1..b89725b7397a 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -2250,7 +2250,7 @@ has_negatives (struct type *type)
     case TYPE_CODE_INT:
       return !TYPE_UNSIGNED (type);
     case TYPE_CODE_RANGE:
-      return TYPE_LOW_BOUND (type) - TYPE_RANGE_DATA (type)->bias < 0;
+      return TYPE_LOW_BOUND (type) - type->bounds ()->bias < 0;
     }
 }
 
diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c
index 4ff757acc6ae..be2ca35dead9 100644
--- a/gdb/compile/compile-c-symbols.c
+++ b/gdb/compile/compile-c-symbols.c
@@ -504,7 +504,7 @@ generate_vla_size (compile_instance *compiler,
 	if (TYPE_HIGH_BOUND_KIND (type) == PROP_LOCEXPR
 	    || TYPE_HIGH_BOUND_KIND (type) == PROP_LOCLIST)
 	  {
-	    const struct dynamic_prop *prop = &TYPE_RANGE_DATA (type)->high;
+	    const struct dynamic_prop *prop = &type->bounds ()->high;
 	    std::string name = c_get_range_decl_name (prop);
 
 	    dwarf2_compile_property_to_c (stream, name.c_str (),
diff --git a/gdb/compile/compile-c-types.c b/gdb/compile/compile-c-types.c
index aad358876668..e5050da03b86 100644
--- a/gdb/compile/compile-c-types.c
+++ b/gdb/compile/compile-c-types.c
@@ -61,7 +61,7 @@ convert_array (compile_c_instance *context, struct type *type)
 					   " is not supported"));
 
       std::string upper_bound
-	= c_get_range_decl_name (&TYPE_RANGE_DATA (range)->high);
+	= c_get_range_decl_name (&range->bounds ()->high);
       result = context->plugin ().build_vla_array_type (element_type,
 							upper_bound.c_str ());
       return result;
diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c
index b04d6c6e4eaa..d07036020cf3 100644
--- a/gdb/compile/compile-cplus-types.c
+++ b/gdb/compile/compile-cplus-types.c
@@ -483,7 +483,7 @@ compile_cplus_convert_array (compile_cplus_instance *instance,
 	}
 
       std::string upper_bound
-	= c_get_range_decl_name (&TYPE_RANGE_DATA (range)->high);
+	= c_get_range_decl_name (&range->bounds ()->high);
       return instance->plugin ().build_vla_array_type (element_type,
 					     upper_bound.c_str ());
     }
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 405b5fb3348c..bc8f4a106d1d 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -17958,7 +17958,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
     range_type = create_range_type (NULL, orig_base_type, &low, &high, bias);
 
   if (high_bound_is_count)
-    TYPE_RANGE_DATA (range_type)->flag_upper_bound_is_count = 1;
+    range_type->bounds ()->flag_upper_bound_is_count = 1;
 
   /* Ada expects an empty array on no boundary attributes.  */
   if (attr == NULL && cu->language != language_ada)
diff --git a/gdb/eval.c b/gdb/eval.c
index f97508162163..e28bfcbbd813 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -3255,7 +3255,7 @@ evaluate_subexp_for_sizeof (struct expression *exp, int *pos,
 		  type = type->index_type ();
 		  /* Only re-evaluate the right hand side if the resulting type
 		     is a variable length type.  */
-		  if (TYPE_RANGE_DATA (type)->flag_bound_evaluated)
+		  if (type->bounds ()->flag_bound_evaluated)
 		    {
 		      val = evaluate_subexp (NULL_TYPE, exp, pos, EVAL_NORMAL);
 		      return value_from_longest
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 66f094328991..957307ec6120 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -978,8 +978,8 @@ create_range_type_with_stride (struct type *result_type,
 				   high_bound, bias);
 
   gdb_assert (stride != nullptr);
-  TYPE_RANGE_DATA (result_type)->stride = *stride;
-  TYPE_RANGE_DATA (result_type)->flag_is_byte_stride = byte_stride_p;
+  result_type->bounds ()->stride = *stride;
+  result_type->bounds ()->flag_is_byte_stride = byte_stride_p;
 
   return result_type;
 }
@@ -1200,7 +1200,7 @@ update_static_array_size (struct type *type)
   struct type *range_type = type->index_type ();
 
   if (type->dyn_prop (DYN_PROP_BYTE_STRIDE) == nullptr
-      && has_static_range (TYPE_RANGE_DATA (range_type))
+      && has_static_range (range_type->bounds ())
       && (!type_not_associated (type)
 	  && !type_not_allocated (type)))
     {
@@ -2017,7 +2017,7 @@ is_dynamic_type_internal (struct type *type, int top_level)
 	   dynamic when its subtype is dynamic, even if the bounds
 	   of the range type are static.  It allows us to assume that
 	   the subtype of a static range type is also static.  */
-	return (!has_static_range (TYPE_RANGE_DATA (type))
+	return (!has_static_range (type->bounds ())
 		|| is_dynamic_type_internal (TYPE_TARGET_TYPE (type), 0));
       }
 
@@ -2094,12 +2094,11 @@ resolve_dynamic_range (struct type *dyn_range_type,
 {
   CORE_ADDR value;
   struct type *static_range_type, *static_target_type;
-  const struct dynamic_prop *prop;
   struct dynamic_prop low_bound, high_bound, stride;
 
   gdb_assert (dyn_range_type->code () == TYPE_CODE_RANGE);
 
-  prop = &TYPE_RANGE_DATA (dyn_range_type)->low;
+  const struct dynamic_prop *prop = &dyn_range_type->bounds ()->low;
   if (dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
     {
       low_bound.kind = PROP_CONST;
@@ -2111,13 +2110,13 @@ resolve_dynamic_range (struct type *dyn_range_type,
       low_bound.data.const_val = 0;
     }
 
-  prop = &TYPE_RANGE_DATA (dyn_range_type)->high;
+  prop = &dyn_range_type->bounds ()->high;
   if (dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
     {
       high_bound.kind = PROP_CONST;
       high_bound.data.const_val = value;
 
-      if (TYPE_RANGE_DATA (dyn_range_type)->flag_upper_bound_is_count)
+      if (dyn_range_type->bounds ()->flag_upper_bound_is_count)
 	high_bound.data.const_val
 	  = low_bound.data.const_val + high_bound.data.const_val - 1;
     }
@@ -2127,8 +2126,8 @@ resolve_dynamic_range (struct type *dyn_range_type,
       high_bound.data.const_val = 0;
     }
 
-  bool byte_stride_p = TYPE_RANGE_DATA (dyn_range_type)->flag_is_byte_stride;
-  prop = &TYPE_RANGE_DATA (dyn_range_type)->stride;
+  bool byte_stride_p = dyn_range_type->bounds ()->flag_is_byte_stride;
+  prop = &dyn_range_type->bounds ()->stride;
   if (dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
     {
       stride.kind = PROP_CONST;
@@ -2154,11 +2153,11 @@ resolve_dynamic_range (struct type *dyn_range_type,
   static_target_type
     = resolve_dynamic_type_internal (TYPE_TARGET_TYPE (dyn_range_type),
 				     addr_stack, 0);
-  LONGEST bias = TYPE_RANGE_DATA (dyn_range_type)->bias;
+  LONGEST bias = dyn_range_type->bounds ()->bias;
   static_range_type = create_range_type_with_stride
     (copy_type (dyn_range_type), static_target_type,
      &low_bound, &high_bound, bias, &stride, byte_stride_p);
-  TYPE_RANGE_DATA (static_range_type)->flag_bound_evaluated = 1;
+  static_range_type->bounds ()->flag_bound_evaluated = 1;
   return static_range_type;
 }
 
@@ -4036,7 +4035,7 @@ check_types_equal (struct type *type1, struct type *type2,
 
   if (type1->code () == TYPE_CODE_RANGE)
     {
-      if (*TYPE_RANGE_DATA (type1) != *TYPE_RANGE_DATA (type2))
+      if (*type1->bounds () != *type2->bounds ())
 	return false;
     }
   else
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 236d37b1ce2a..2a1e6931b7fe 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1518,22 +1518,21 @@ extern unsigned type_align (struct type *);
    space in struct type.  */
 extern bool set_type_align (struct type *, ULONGEST);
 
-#define TYPE_RANGE_DATA(thistype) ((thistype)->bounds ())
 #define TYPE_LOW_BOUND(range_type) \
-  TYPE_RANGE_DATA(range_type)->low.data.const_val
+  ((range_type)->bounds ()->low.data.const_val)
 #define TYPE_HIGH_BOUND(range_type) \
-  TYPE_RANGE_DATA(range_type)->high.data.const_val
+  ((range_type)->bounds ()->high.data.const_val)
 #define TYPE_LOW_BOUND_UNDEFINED(range_type) \
-  (TYPE_RANGE_DATA(range_type)->low.kind == PROP_UNDEFINED)
+  (TYPE_LOW_BOUND_KIND(range_type) == PROP_UNDEFINED)
 #define TYPE_HIGH_BOUND_UNDEFINED(range_type) \
-  (TYPE_RANGE_DATA(range_type)->high.kind == PROP_UNDEFINED)
+  (TYPE_HIGH_BOUND_KIND(range_type) == PROP_UNDEFINED)
 #define TYPE_HIGH_BOUND_KIND(range_type) \
-  TYPE_RANGE_DATA(range_type)->high.kind
+  ((range_type)->bounds ()->high.kind)
 #define TYPE_LOW_BOUND_KIND(range_type) \
-  TYPE_RANGE_DATA(range_type)->low.kind
+  ((range_type)->bounds ()->low.kind)
 #define TYPE_BIT_STRIDE(range_type) \
-  (TYPE_RANGE_DATA(range_type)->stride.data.const_val \
-   * (TYPE_RANGE_DATA(range_type)->flag_is_byte_stride ? 8 : 1))
+  ((range_type)->bounds ()->stride.data.const_val \
+   * ((range_type)->bounds ()->flag_is_byte_stride ? 8 : 1))
 
 /* Property accessors for the type data location.  */
 #define TYPE_DATA_LOCATION(thistype) \
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 388a0b2c6d41..309d2cabfff4 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -418,8 +418,7 @@ print_scalar_formatted (const gdb_byte *valaddr, struct type *type,
 	   || options->format == 'z'
 	   || options->format == 'd'
 	   || options->format == 'u'))
-      || (type->code () == TYPE_CODE_RANGE
-	  && TYPE_RANGE_DATA (type)->bias != 0))
+      || (type->code () == TYPE_CODE_RANGE && type->bounds ()->bias != 0))
     {
       val_long.emplace (unpack_long (type, valaddr));
       converted_bytes.resize (TYPE_LENGTH (type));
diff --git a/gdb/value.c b/gdb/value.c
index 97a099ddbd3e..7d4b30e20ef7 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -2770,7 +2770,7 @@ unpack_long (struct type *type, const gdb_byte *valaddr)
 	else
 	  result = extract_signed_integer (valaddr, len, byte_order);
 	if (code == TYPE_CODE_RANGE)
-	  result += TYPE_RANGE_DATA (type)->bias;
+	  result += type->bounds ()->bias;
 	return result;
       }
 
@@ -3320,7 +3320,7 @@ pack_long (gdb_byte *buf, struct type *type, LONGEST num)
   switch (type->code ())
     {
     case TYPE_CODE_RANGE:
-      num -= TYPE_RANGE_DATA (type)->bias;
+      num -= type->bounds ()->bias;
       /* Fall through.  */
     case TYPE_CODE_INT:
     case TYPE_CODE_CHAR:
-- 
2.27.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 03/12] gdb: make get_discrete_bounds check for non-constant range bounds
  2020-07-06 13:38 [PATCH 00/12] More type macros removal Simon Marchi
  2020-07-06 13:38 ` [PATCH 01/12] gdb: add type::bounds / type::set_bounds Simon Marchi
  2020-07-06 13:38 ` [PATCH 02/12] gdb: remove TYPE_RANGE_DATA macro Simon Marchi
@ 2020-07-06 13:38 ` Simon Marchi
  2020-07-06 13:38 ` [PATCH 04/12] gdb: add accessors to struct dynamic_prop Simon Marchi
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Simon Marchi @ 2020-07-06 13:38 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@efficios.com>

The next patch adds getters to the `dynamic_prop` structure.  These
getters validate that the accessed data matches the property kind (for
example, to access the `const_val` field, the property must be of kind
`PROP_CONST`).  It found one instance where we are accessing the
`const_val` data of a property that has the undefined kind.

This happens in function `get_discrete_bounds`, and is exposed by test
gdb.base/ptype.exp, amongst others.  Without this patch, we would get:

    $ ./gdb -q -nx --data-directory=data-directory testsuite/outputs/gdb.base/ptype/ptype -ex "ptype t_char_array"
    Reading symbols from testsuite/outputs/gdb.base/ptype/ptype...
    type = char [
    /home/smarchi/src/binutils-gdb/gdb/gdbtypes.h:526: internal-error: LONGEST dynamic_prop::const_val() const: Assertion `m_kind == PROP_CONST' failed.
    A problem internal to GDB has been detected,
    further debugging may prove unreliable.
    Quit this debugging session? (y or n)

The `get_discrete_bounds` function returns the bounds of a type (not
only range types).  For range types, it naturally uses the bound
properties that are intrinsic to the range type.  It accesses these
properties using TYPE_LOW_BOUND and TYPE_HIGH_BOUND, which assume the
properties are defined and have constant values.  This is sometimes not
the case, and the passed range type (as in the example above) has an
undefined high/upper bound.

Given its current interface (returning two LONGEST values for low and
high), `get_discrete_bounds` can't really work if the range type's
bounds are not both defined and both constant values.

This patch changes the function to return -1 (failure to get the bounds)
if any of the range type's bounds is not a constant value.  It is
sufficient to fix the issue and it seems to keep the callers happy, at
least according to the testsuite.

A bit in `get_array_bounds` could be removed, since
`get_discrete_bounds` no longer returns 1 if a bound is undefined.

gdb/ChangeLog:

	* gdbtypes.c (get_discrete_bounds): Return failure if
	the range type's bounds are not both defined and constant
	values.
	(get_array_bounds): Update comment.  Remove undefined bound check.

Change-Id: I047a3beee2c1e275f888cfc4778228339922bde9
---
 gdb/gdbtypes.c | 29 +++++++++++++----------------
 1 file changed, 13 insertions(+), 16 deletions(-)

diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 957307ec6120..40165563b91a 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1028,8 +1028,11 @@ has_static_range (const struct range_bounds *bounds)
 
 
 /* Set *LOWP and *HIGHP to the lower and upper bounds of discrete type
-   TYPE.  Return 1 if type is a range type, 0 if it is discrete (and
-   bounds will fit in LONGEST), or -1 otherwise.  */
+   TYPE.
+
+   Return 1 if type is a range type with two defined, constant bounds.
+   Else, return 0 if it is discrete (and bounds will fit in LONGEST).
+   Else, return -1.  */
 
 int
 get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
@@ -1038,8 +1041,15 @@ get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
   switch (type->code ())
     {
     case TYPE_CODE_RANGE:
+      /* This function currently only works for ranges with two defined,
+         constant bounds.  */
+      if (type->bounds ()->low.kind () != PROP_CONST
+	  || type->bounds ()->high.kind () != PROP_CONST)
+	return -1;
+
       *lowp = TYPE_LOW_BOUND (type);
       *highp = TYPE_HIGH_BOUND (type);
+
       if (TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_ENUM)
 	{
 	  if (!discrete_position (TYPE_TARGET_TYPE (type), *lowp, lowp)
@@ -1107,14 +1117,7 @@ get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
    Save the high bound into HIGH_BOUND if not NULL.
 
    Return 1 if the operation was successful.  Return zero otherwise,
-   in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified.
-
-   We now simply use get_discrete_bounds call to get the values
-   of the low and high bounds.
-   get_discrete_bounds can return three values:
-   1, meaning that index is a range,
-   0, meaning that index is a discrete type,
-   or -1 for failure.  */
+   in which case the values of LOW_BOUND and HIGH_BOUNDS are unmodified.  */
 
 int
 get_array_bounds (struct type *type, LONGEST *low_bound, LONGEST *high_bound)
@@ -1131,12 +1134,6 @@ get_array_bounds (struct type *type, LONGEST *low_bound, LONGEST *high_bound)
   if (res == -1)
     return 0;
 
-  /* Check if the array bounds are undefined.  */
-  if (res == 1
-      && ((low_bound && TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type))
-	  || (high_bound && TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))))
-    return 0;
-
   if (low_bound)
     *low_bound = low;
 
-- 
2.27.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 04/12] gdb: add accessors to struct dynamic_prop
  2020-07-06 13:38 [PATCH 00/12] More type macros removal Simon Marchi
                   ` (2 preceding siblings ...)
  2020-07-06 13:38 ` [PATCH 03/12] gdb: make get_discrete_bounds check for non-constant range bounds Simon Marchi
@ 2020-07-06 13:38 ` Simon Marchi
  2020-07-06 13:38 ` [PATCH 05/12] gdb: remove TYPE_HIGH_BOUND and TYPE_LOW_BOUND Simon Marchi
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Simon Marchi @ 2020-07-06 13:38 UTC (permalink / raw)
  To: gdb-patches

Add setters, to ensure that the kind and value of the property are
always kept in sync (a caller can't forget one or the other).  Add
getters, such that we can assert that when a caller accesses a data bit
of the property, the property is indeed of the corresponding kind.

Note that because of the way `struct dynamic_prop` is allocated
currently, we can't make the `m_kind` and `m_data` fields private.  That
would make the type non-default-constructible, and we would have to call
the constructor when allocating them.  However, I still prefixed them
with `m_` to indicate that they should not be accessed from outside the
class (and also to be able to use the name `kind` for the method).

gdb/ChangeLog:

	* gdbtypes.h (struct dynamic_prop) <kind, set_undefined,
	const_val, set_const_val, baton, set_locexpr, set_loclist,
	set_addr_offset, variant_parts, set_variant_parts,
	original_type, set_original_type>: New methods.
	<kind>: Rename to...
	<m_kind>: ... this.  Update all users to use the new methods
	instead.
	<data>: Rename to...
	<m_data>: ... this.  Update all users to use the new methods
	instead.

Change-Id: Ib72a8eb440dfeb1a5421d0933334230d7f2478f9
---
 gdb/ada-typeprint.c |  8 ++--
 gdb/ctfread.c       |  2 +-
 gdb/dwarf2/loc.c    | 16 ++++----
 gdb/dwarf2/read.c   | 69 ++++++++++++++-----------------
 gdb/gdbtypes.c      | 96 ++++++++++++++++----------------------------
 gdb/gdbtypes.h      | 98 ++++++++++++++++++++++++++++++++++++++++-----
 gdb/gnu-v3-abi.c    |  3 +-
 gdb/mdebugread.c    |  4 +-
 gdb/p-valprint.c    |  2 +-
 gdb/rust-lang.c     |  4 +-
 gdb/type-stack.c    |  3 +-
 11 files changed, 170 insertions(+), 135 deletions(-)

diff --git a/gdb/ada-typeprint.c b/gdb/ada-typeprint.c
index 165ea0ee4aa8..062b9d8a21f7 100644
--- a/gdb/ada-typeprint.c
+++ b/gdb/ada-typeprint.c
@@ -779,13 +779,13 @@ print_record_field_types (struct type *type, struct type *outer_type,
   struct dynamic_prop *prop = type->dyn_prop (DYN_PROP_VARIANT_PARTS);
   if (prop != nullptr)
     {
-      if (prop->kind == PROP_TYPE)
+      if (prop->kind () == PROP_TYPE)
 	{
-	  type = prop->data.original_type;
+	  type = prop->original_type ();
 	  prop = type->dyn_prop (DYN_PROP_VARIANT_PARTS);
 	}
-      gdb_assert (prop->kind == PROP_VARIANT_PARTS);
-      print_record_field_types_dynamic (*prop->data.variant_parts,
+      gdb_assert (prop->kind () == PROP_VARIANT_PARTS);
+      print_record_field_types_dynamic (*prop->variant_parts (),
 					0, type->num_fields (),
 					type, stream, show, level, flags);
       return type->num_fields ();
diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index f44cbecba09a..5b6d731479a1 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -774,7 +774,7 @@ read_array_type (struct ctf_context *ccp, ctf_id_t tid)
   type = create_array_type (NULL, element_type, range_type);
   if (ar.ctr_nelems <= 1)	/* Check if undefined upper bound.  */
     {
-      TYPE_HIGH_BOUND_KIND (range_type) = PROP_UNDEFINED;
+      range_type->bounds ()->high.set_undefined ();
       TYPE_LENGTH (type) = 0;
       TYPE_TARGET_STUB (type) = 1;
     }
diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c
index 445d71a5ef16..866417eb1b10 100644
--- a/gdb/dwarf2/loc.c
+++ b/gdb/dwarf2/loc.c
@@ -2589,12 +2589,12 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
   if (frame == NULL && has_stack_frames ())
     frame = get_selected_frame (NULL);
 
-  switch (prop->kind)
+  switch (prop->kind ())
     {
     case PROP_LOCEXPR:
       {
 	const struct dwarf2_property_baton *baton
-	  = (const struct dwarf2_property_baton *) prop->data.baton;
+	  = (const struct dwarf2_property_baton *) prop->baton ();
 	gdb_assert (baton->property_type != NULL);
 
 	if (dwarf2_locexpr_baton_eval (&baton->locexpr, frame, addr_stack,
@@ -2636,7 +2636,7 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
     case PROP_LOCLIST:
       {
 	struct dwarf2_property_baton *baton
-	  = (struct dwarf2_property_baton *) prop->data.baton;
+	  = (struct dwarf2_property_baton *) prop->baton ();
 	CORE_ADDR pc;
 	const gdb_byte *data;
 	struct value *val;
@@ -2662,13 +2662,13 @@ dwarf2_evaluate_property (const struct dynamic_prop *prop,
       break;
 
     case PROP_CONST:
-      *value = prop->data.const_val;
+      *value = prop->const_val ();
       return true;
 
     case PROP_ADDR_OFFSET:
       {
 	struct dwarf2_property_baton *baton
-	  = (struct dwarf2_property_baton *) prop->data.baton;
+	  = (struct dwarf2_property_baton *) prop->baton ();
 	const struct property_addr_info *pinfo;
 	struct value *val;
 
@@ -2708,13 +2708,13 @@ dwarf2_compile_property_to_c (string_file *stream,
 			      struct symbol *sym)
 {
   struct dwarf2_property_baton *baton
-    = (struct dwarf2_property_baton *) prop->data.baton;
+    = (struct dwarf2_property_baton *) prop->baton ();
   const gdb_byte *data;
   size_t size;
   dwarf2_per_cu_data *per_cu;
   dwarf2_per_objfile *per_objfile;
 
-  if (prop->kind == PROP_LOCEXPR)
+  if (prop->kind () == PROP_LOCEXPR)
     {
       data = baton->locexpr.data;
       size = baton->locexpr.size;
@@ -2723,7 +2723,7 @@ dwarf2_compile_property_to_c (string_file *stream,
     }
   else
     {
-      gdb_assert (prop->kind == PROP_LOCLIST);
+      gdb_assert (prop->kind () == PROP_LOCLIST);
 
       data = dwarf2_find_location_expression (&baton->loclist, &size, pc);
       per_cu = baton->loclist.per_cu;
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index bc8f4a106d1d..558fad74f804 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -9464,8 +9464,7 @@ alloc_rust_variant (struct obstack *obstack, struct type *type,
     = new (storage) gdb::array_view<variant_part> (part, 1);
 
   struct dynamic_prop prop;
-  prop.kind = PROP_VARIANT_PARTS;
-  prop.data.variant_parts = prop_value;
+  prop.set_variant_parts (prop_value);
 
   type->add_dyn_prop (DYN_PROP_VARIANT_PARTS, prop);
 }
@@ -14959,10 +14958,9 @@ add_variant_property (struct field_info *fip, struct type *type,
 			    fip->variant_parts);
 
   struct dynamic_prop prop;
-  prop.kind = PROP_VARIANT_PARTS;
-  prop.data.variant_parts
-    = ((gdb::array_view<variant_part> *)
-       obstack_copy (&objfile->objfile_obstack, &parts, sizeof (parts)));
+  prop.set_variant_parts ((gdb::array_view<variant_part> *)
+			  obstack_copy (&objfile->objfile_obstack, &parts,
+					sizeof (parts)));
 
   type->add_dyn_prop (DYN_PROP_VARIANT_PARTS, prop);
 }
@@ -17138,8 +17136,7 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
     {
       struct dynamic_prop low_bound;
 
-      low_bound.kind = PROP_CONST;
-      low_bound.data.const_val = 1;
+      low_bound.set_const_val (1);
       range_type = create_range_type (NULL, index_type, &low_bound, &prop, 0);
     }
   char_type = language_string_char_type (cu->language_defn, gdbarch);
@@ -17646,9 +17643,9 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
 	  baton->locexpr.is_reference = false;
 	  break;
 	}
-      prop->data.baton = baton;
-      prop->kind = PROP_LOCEXPR;
-      gdb_assert (prop->data.baton != NULL);
+
+      prop->set_locexpr (baton);
+      gdb_assert (prop->baton () != NULL);
     }
   else if (attr->form_is_ref ())
     {
@@ -17672,9 +17669,8 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
 		baton = XOBNEW (obstack, struct dwarf2_property_baton);
 		baton->property_type = die_type (target_die, target_cu);
 		fill_in_loclist_baton (cu, &baton->loclist, target_attr);
-		prop->data.baton = baton;
-		prop->kind = PROP_LOCLIST;
-		gdb_assert (prop->data.baton != NULL);
+		prop->set_loclist (baton);
+		gdb_assert (prop->baton () != NULL);
 	      }
 	    else if (target_attr->form_is_block ())
 	      {
@@ -17685,9 +17681,8 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
 		baton->locexpr.size = DW_BLOCK (target_attr)->size;
 		baton->locexpr.data = DW_BLOCK (target_attr)->data;
 		baton->locexpr.is_reference = true;
-		prop->data.baton = baton;
-		prop->kind = PROP_LOCEXPR;
-		gdb_assert (prop->data.baton != NULL);
+		prop->set_locexpr (baton);
+		gdb_assert (prop->baton () != NULL);
 	      }
 	    else
 	      {
@@ -17709,17 +17704,13 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die,
 						      target_cu);
 	      baton->offset_info.offset = offset;
 	      baton->offset_info.type = die_type (target_die, target_cu);
-	      prop->data.baton = baton;
-	      prop->kind = PROP_ADDR_OFFSET;
+	      prop->set_addr_offset (baton);
 	      break;
 	    }
 	}
     }
   else if (attr->form_is_constant ())
-    {
-      prop->data.const_val = attr->constant_value (0);
-      prop->kind = PROP_CONST;
-    }
+    prop->set_const_val (attr->constant_value (0));
   else
     {
       dwarf2_invalid_attrib_class_complaint (dwarf_form_name (attr->form),
@@ -17819,9 +17810,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
   if (range_type)
     return range_type;
 
-  low.kind = PROP_CONST;
-  high.kind = PROP_CONST;
-  high.data.const_val = 0;
+  high.set_const_val (0);
 
   /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow
      omitting DW_AT_lower_bound.  */
@@ -17829,27 +17818,27 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
     {
     case language_c:
     case language_cplus:
-      low.data.const_val = 0;
+      low.set_const_val (0);
       low_default_is_valid = 1;
       break;
     case language_fortran:
-      low.data.const_val = 1;
+      low.set_const_val (1);
       low_default_is_valid = 1;
       break;
     case language_d:
     case language_objc:
     case language_rust:
-      low.data.const_val = 0;
+      low.set_const_val (0);
       low_default_is_valid = (cu->header.version >= 4);
       break;
     case language_ada:
     case language_m2:
     case language_pascal:
-      low.data.const_val = 1;
+      low.set_const_val (1);
       low_default_is_valid = (cu->header.version >= 4);
       break;
     default:
-      low.data.const_val = 0;
+      low.set_const_val (0);
       low_default_is_valid = 0;
       break;
     }
@@ -17871,8 +17860,8 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
       if (attr_to_dynamic_prop (attr, die, cu, &high, base_type))
 	{
 	  /* If bounds are constant do the final calculation here.  */
-	  if (low.kind == PROP_CONST && high.kind == PROP_CONST)
-	    high.data.const_val = low.data.const_val + high.data.const_val - 1;
+	  if (low.kind () == PROP_CONST && high.kind () == PROP_CONST)
+	    high.set_const_val (low.const_val () + high.const_val () - 1);
 	  else
 	    high_bound_is_count = 1;
 	}
@@ -17905,12 +17894,12 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
      the base type is signed.  */
   negative_mask =
     -((ULONGEST) 1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1));
-  if (low.kind == PROP_CONST
-      && !TYPE_UNSIGNED (base_type) && (low.data.const_val & negative_mask))
-    low.data.const_val |= negative_mask;
-  if (high.kind == PROP_CONST
-      && !TYPE_UNSIGNED (base_type) && (high.data.const_val & negative_mask))
-    high.data.const_val |= negative_mask;
+  if (low.kind () == PROP_CONST
+      && !TYPE_UNSIGNED (base_type) && (low.const_val () & negative_mask))
+    low.set_const_val (low.const_val () | negative_mask);
+  if (high.kind () == PROP_CONST
+      && !TYPE_UNSIGNED (base_type) && (high.const_val () & negative_mask))
+    high.set_const_val (high.const_val () | negative_mask);
 
   /* Check for bit and byte strides.  */
   struct dynamic_prop byte_stride_prop;
@@ -17962,7 +17951,7 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu)
 
   /* Ada expects an empty array on no boundary attributes.  */
   if (attr == NULL && cu->language != language_ada)
-    TYPE_HIGH_BOUND_KIND (range_type) = PROP_UNDEFINED;
+    range_type->bounds ()->high.set_undefined ();
 
   name = dwarf2_name (die, cu);
   if (name)
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 40165563b91a..709574545928 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -874,23 +874,23 @@ allocate_stub_method (struct type *type)
 bool
 operator== (const dynamic_prop &l, const dynamic_prop &r)
 {
-  if (l.kind != r.kind)
+  if (l.kind () != r.kind ())
     return false;
 
-  switch (l.kind)
+  switch (l.kind ())
     {
     case PROP_UNDEFINED:
       return true;
     case PROP_CONST:
-      return l.data.const_val == r.data.const_val;
+      return l.const_val () == r.const_val ();
     case PROP_ADDR_OFFSET:
     case PROP_LOCEXPR:
     case PROP_LOCLIST:
-      return l.data.baton == r.data.baton;
+      return l.baton () == r.baton ();
     case PROP_VARIANT_PARTS:
-      return l.data.variant_parts == r.data.variant_parts;
+      return l.variant_parts () == r.variant_parts ();
     case PROP_TYPE:
-      return l.data.original_type == r.data.original_type;
+      return l.original_type () == r.original_type ();
     }
 
   gdb_assert_not_reached ("unhandled dynamic_prop kind");
@@ -940,21 +940,18 @@ create_range_type (struct type *result_type, struct type *index_type,
   bounds->low = *low_bound;
   bounds->high = *high_bound;
   bounds->bias = bias;
-
-  /* Initialize the stride to be a constant, the value will already be zero
-     thanks to the use of TYPE_ZALLOC above.  */
-  bounds->stride.kind = PROP_CONST;
+  bounds->stride.set_const_val (0);
 
   result_type->set_bounds (bounds);
 
-  if (low_bound->kind == PROP_CONST && low_bound->data.const_val >= 0)
+  if (low_bound->kind () == PROP_CONST && low_bound->const_val () >= 0)
     TYPE_UNSIGNED (result_type) = 1;
 
   /* Ada allows the declaration of range types whose upper bound is
      less than the lower bound, so checking the lower bound is not
      enough.  Make sure we do not mark a range type whose upper bound
      is negative as unsigned.  */
-  if (high_bound->kind == PROP_CONST && high_bound->data.const_val < 0)
+  if (high_bound->kind () == PROP_CONST && high_bound->const_val () < 0)
     TYPE_UNSIGNED (result_type) = 0;
 
   TYPE_ENDIANITY_NOT_DEFAULT (result_type)
@@ -1002,11 +999,8 @@ create_static_range_type (struct type *result_type, struct type *index_type,
 {
   struct dynamic_prop low, high;
 
-  low.kind = PROP_CONST;
-  low.data.const_val = low_bound;
-
-  high.kind = PROP_CONST;
-  high.data.const_val = high_bound;
+  low.set_const_val (low_bound);
+  high.set_const_val (high_bound);
 
   result_type = create_range_type (result_type, index_type, &low, &high, 0);
 
@@ -1021,9 +1015,9 @@ has_static_range (const struct range_bounds *bounds)
 {
   /* If the range doesn't have a defined stride then its stride field will
      be initialized to the constant 0.  */
-  return (bounds->low.kind == PROP_CONST
-	  && bounds->high.kind == PROP_CONST
-	  && bounds->stride.kind == PROP_CONST);
+  return (bounds->low.kind () == PROP_CONST
+	  && bounds->high.kind () == PROP_CONST
+	  && bounds->stride.kind () == PROP_CONST);
 }
 
 
@@ -1273,13 +1267,13 @@ create_array_type_with_stride (struct type *result_type,
 			       unsigned int bit_stride)
 {
   if (byte_stride_prop != NULL
-      && byte_stride_prop->kind == PROP_CONST)
+      && byte_stride_prop->kind () == PROP_CONST)
     {
       /* The byte stride is actually not dynamic.  Pretend we were
 	 called with bit_stride set instead of byte_stride_prop.
 	 This will give us the same result type, while avoiding
 	 the need to handle this as a special case.  */
-      bit_stride = byte_stride_prop->data.const_val * 8;
+      bit_stride = byte_stride_prop->const_val () * 8;
       byte_stride_prop = NULL;
     }
 
@@ -1967,7 +1961,7 @@ array_type_has_dynamic_stride (struct type *type)
 {
   struct dynamic_prop *prop = type->dyn_prop (DYN_PROP_BYTE_STRIDE);
 
-  return (prop != NULL && prop->kind != PROP_CONST);
+  return (prop != NULL && prop->kind () != PROP_CONST);
 }
 
 /* Worker for is_dynamic_type.  */
@@ -1999,7 +1993,7 @@ is_dynamic_type_internal (struct type *type, int top_level)
     return 1;
 
   struct dynamic_prop *prop = type->dyn_prop (DYN_PROP_VARIANT_PARTS);
-  if (prop != nullptr && prop->kind != PROP_TYPE)
+  if (prop != nullptr && prop->kind () != PROP_TYPE)
     return 1;
 
   if (TYPE_HAS_DYNAMIC_LENGTH (type))
@@ -2097,38 +2091,27 @@ resolve_dynamic_range (struct type *dyn_range_type,
 
   const struct dynamic_prop *prop = &dyn_range_type->bounds ()->low;
   if (dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
-    {
-      low_bound.kind = PROP_CONST;
-      low_bound.data.const_val = value;
-    }
+    low_bound.set_const_val (value);
   else
-    {
-      low_bound.kind = PROP_UNDEFINED;
-      low_bound.data.const_val = 0;
-    }
+    low_bound.set_undefined ();
 
   prop = &dyn_range_type->bounds ()->high;
   if (dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
     {
-      high_bound.kind = PROP_CONST;
-      high_bound.data.const_val = value;
+      high_bound.set_const_val (value);
 
       if (dyn_range_type->bounds ()->flag_upper_bound_is_count)
-	high_bound.data.const_val
-	  = low_bound.data.const_val + high_bound.data.const_val - 1;
+	high_bound.set_const_val
+	  (low_bound.const_val () + high_bound.const_val () - 1);
     }
   else
-    {
-      high_bound.kind = PROP_UNDEFINED;
-      high_bound.data.const_val = 0;
-    }
+    high_bound.set_undefined ();
 
   bool byte_stride_p = dyn_range_type->bounds ()->flag_is_byte_stride;
   prop = &dyn_range_type->bounds ()->stride;
   if (dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
     {
-      stride.kind = PROP_CONST;
-      stride.data.const_val = value;
+      stride.set_const_val (value);
 
       /* If we have a bit stride that is not an exact number of bytes then
 	 I really don't think this is going to work with current GDB, the
@@ -2142,8 +2125,7 @@ resolve_dynamic_range (struct type *dyn_range_type,
     }
   else
     {
-      stride.kind = PROP_UNDEFINED;
-      stride.data.const_val = 0;
+      stride.set_undefined ();
       byte_stride_p = true;
     }
 
@@ -2188,16 +2170,11 @@ resolve_dynamic_array_or_string (struct type *type,
      will update the length of the array accordingly.  */
   prop = TYPE_ALLOCATED_PROP (type);
   if (prop != NULL && dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
-    {
-      TYPE_DYN_PROP_ADDR (prop) = value;
-      TYPE_DYN_PROP_KIND (prop) = PROP_CONST;
-    }
+    prop->set_const_val (value);
+
   prop = TYPE_ASSOCIATED_PROP (type);
   if (prop != NULL && dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
-    {
-      TYPE_DYN_PROP_ADDR (prop) = value;
-      TYPE_DYN_PROP_KIND (prop) = PROP_CONST;
-    }
+    prop->set_const_val (value);
 
   ary_dim = check_typedef (TYPE_TARGET_TYPE (elt_type));
 
@@ -2447,14 +2424,13 @@ resolve_dynamic_struct (struct type *type,
   resolved_type = copy_type (type);
 
   dynamic_prop *variant_prop = resolved_type->dyn_prop (DYN_PROP_VARIANT_PARTS);
-  if (variant_prop != nullptr && variant_prop->kind == PROP_VARIANT_PARTS)
+  if (variant_prop != nullptr && variant_prop->kind () == PROP_VARIANT_PARTS)
     {
       compute_variant_fields (type, resolved_type, addr_stack,
-			      *variant_prop->data.variant_parts);
+			      *variant_prop->variant_parts ());
       /* We want to leave the property attached, so that the Rust code
 	 can tell whether the type was originally an enum.  */
-      variant_prop->kind = PROP_TYPE;
-      variant_prop->data.original_type = type;
+      variant_prop->set_original_type (type);
     }
   else
     {
@@ -2483,8 +2459,7 @@ resolve_dynamic_struct (struct type *type,
 	  baton.locexpr = *TYPE_FIELD_DWARF_BLOCK (resolved_type, i);
 
 	  struct dynamic_prop prop;
-	  prop.kind = PROP_LOCEXPR;
-	  prop.data.baton = &baton;
+	  prop.set_locexpr (&baton);
 
 	  CORE_ADDR addr;
 	  if (dwarf2_evaluate_property (&prop, nullptr, addr_stack, &addr,
@@ -2642,10 +2617,7 @@ resolve_dynamic_type_internal (struct type *type,
   prop = TYPE_DATA_LOCATION (resolved_type);
   if (prop != NULL
       && dwarf2_evaluate_property (prop, NULL, addr_stack, &value))
-    {
-      TYPE_DYN_PROP_ADDR (prop) = value;
-      TYPE_DYN_PROP_KIND (prop) = PROP_CONST;
-    }
+    prop->set_const_val (value);
 
   return resolved_type;
 }
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 2a1e6931b7fe..5d9ed3972ff1 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -511,11 +511,87 @@ union dynamic_prop_data
 
 struct dynamic_prop
 {
+  dynamic_prop_kind kind () const
+  {
+    return m_kind;
+  }
+
+  void set_undefined ()
+  {
+    m_kind = PROP_UNDEFINED;
+  }
+
+  LONGEST const_val () const
+  {
+    gdb_assert (m_kind == PROP_CONST);
+
+    return m_data.const_val;
+  }
+
+  void set_const_val (LONGEST const_val)
+  {
+    m_kind = PROP_CONST;
+    m_data.const_val = const_val;
+  }
+
+  void *baton () const
+  {
+    gdb_assert (m_kind == PROP_LOCEXPR
+		|| m_kind == PROP_LOCLIST
+		|| m_kind == PROP_ADDR_OFFSET);
+
+    return m_data.baton;
+  }
+
+  void set_locexpr (void *baton)
+  {
+    m_kind = PROP_LOCEXPR;
+    m_data.baton = baton;
+  }
+
+  void set_loclist (void *baton)
+  {
+    m_kind = PROP_LOCLIST;
+    m_data.baton = baton;
+  }
+
+  void set_addr_offset (void *baton)
+  {
+    m_kind = PROP_ADDR_OFFSET;
+    m_data.baton = baton;
+  }
+
+  const gdb::array_view<variant_part> *variant_parts () const
+  {
+    gdb_assert (m_kind == PROP_VARIANT_PARTS);
+
+    return m_data.variant_parts;
+  }
+
+  void set_variant_parts (gdb::array_view<variant_part> *variant_parts)
+  {
+    m_kind = PROP_VARIANT_PARTS;
+    m_data.variant_parts = variant_parts;
+  }
+
+  struct type *original_type () const
+  {
+    gdb_assert (m_kind == PROP_TYPE);
+
+    return m_data.original_type;
+  }
+
+  void set_original_type (struct type *original_type)
+  {
+    m_kind = PROP_TYPE;
+    m_data.original_type = original_type;
+  }
+
   /* Determine which field of the union dynamic_prop.data is used.  */
-  enum dynamic_prop_kind kind;
+  enum dynamic_prop_kind m_kind;
 
   /* Storage for dynamic or static value.  */
-  union dynamic_prop_data data;
+  union dynamic_prop_data m_data;
 };
 
 /* Compare two dynamic_prop objects for equality.  dynamic_prop
@@ -1519,19 +1595,19 @@ extern unsigned type_align (struct type *);
 extern bool set_type_align (struct type *, ULONGEST);
 
 #define TYPE_LOW_BOUND(range_type) \
-  ((range_type)->bounds ()->low.data.const_val)
+  ((range_type)->bounds ()->low.const_val ())
 #define TYPE_HIGH_BOUND(range_type) \
-  ((range_type)->bounds ()->high.data.const_val)
+  ((range_type)->bounds ()->high.const_val ())
 #define TYPE_LOW_BOUND_UNDEFINED(range_type) \
   (TYPE_LOW_BOUND_KIND(range_type) == PROP_UNDEFINED)
 #define TYPE_HIGH_BOUND_UNDEFINED(range_type) \
   (TYPE_HIGH_BOUND_KIND(range_type) == PROP_UNDEFINED)
 #define TYPE_HIGH_BOUND_KIND(range_type) \
-  ((range_type)->bounds ()->high.kind)
+  ((range_type)->bounds ()->high.kind ())
 #define TYPE_LOW_BOUND_KIND(range_type) \
-  ((range_type)->bounds ()->low.kind)
+  ((range_type)->bounds ()->low.kind ())
 #define TYPE_BIT_STRIDE(range_type) \
-  ((range_type)->bounds ()->stride.data.const_val \
+  ((range_type)->bounds ()->stride.const_val () \
    * ((range_type)->bounds ()->flag_is_byte_stride ? 8 : 1))
 
 /* Property accessors for the type data location.  */
@@ -1540,9 +1616,9 @@ extern bool set_type_align (struct type *, ULONGEST);
 #define TYPE_DATA_LOCATION_BATON(thistype) \
   TYPE_DATA_LOCATION (thistype)->data.baton
 #define TYPE_DATA_LOCATION_ADDR(thistype) \
-  TYPE_DATA_LOCATION (thistype)->data.const_val
+  (TYPE_DATA_LOCATION (thistype)->const_val ())
 #define TYPE_DATA_LOCATION_KIND(thistype) \
-  TYPE_DATA_LOCATION (thistype)->kind
+  (TYPE_DATA_LOCATION (thistype)->kind ())
 #define TYPE_DYNAMIC_LENGTH(thistype) \
   ((thistype)->dyn_prop (DYN_PROP_BYTE_SIZE))
 
@@ -1556,9 +1632,9 @@ extern bool set_type_align (struct type *, ULONGEST);
 #define TYPE_DYN_PROP_BATON(dynprop) \
   dynprop->data.baton
 #define TYPE_DYN_PROP_ADDR(dynprop) \
-  dynprop->data.const_val
+  (dynprop->const_val ())
 #define TYPE_DYN_PROP_KIND(dynprop) \
-  dynprop->kind
+  (dynprop->kind ())
 
 
 /* Accessors for struct range_bounds data attached to an array type's
diff --git a/gdb/gnu-v3-abi.c b/gdb/gnu-v3-abi.c
index 23c9c940ca3b..beff8b1ebde6 100644
--- a/gdb/gnu-v3-abi.c
+++ b/gdb/gnu-v3-abi.c
@@ -471,8 +471,7 @@ gnuv3_baseclass_offset (struct type *type, int index,
       baton.locexpr = *TYPE_FIELD_DWARF_BLOCK (type, index);
 
       struct dynamic_prop prop;
-      prop.kind = PROP_LOCEXPR;
-      prop.data.baton = &baton;
+      prop.set_locexpr (&baton);
 
       struct property_addr_info addr_stack;
       addr_stack.type = type;
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index aa0c715b054a..d38372041d75 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -1736,9 +1736,9 @@ parse_type (int fd, union aux_ext *ax, unsigned int aux_index, int *bs,
       tp->set_num_fields (0);
       tp->set_bounds (((struct range_bounds *)
 			TYPE_ZALLOC (tp, sizeof (struct range_bounds))));
-      TYPE_LOW_BOUND (tp) = AUX_GET_DNLOW (bigend, ax);
+      tp->bounds ()->low.set_const_val (AUX_GET_DNLOW (bigend, ax));
       ax++;
-      TYPE_HIGH_BOUND (tp) = AUX_GET_DNHIGH (bigend, ax);
+      tp->bounds ()->high.set_const_val (AUX_GET_DNHIGH (bigend, ax));
       ax++;
     }
 
diff --git a/gdb/p-valprint.c b/gdb/p-valprint.c
index 3b1303d12488..c98f3c5bf735 100644
--- a/gdb/p-valprint.c
+++ b/gdb/p-valprint.c
@@ -350,7 +350,7 @@ pascal_value_print_inner (struct value *val, struct ui_file *stream,
 	      maximum value.  */
 	      bound_info = 0;
 	      high_bound = TYPE_LENGTH (type) * TARGET_CHAR_BIT - 1;
-	      TYPE_HIGH_BOUND (range) = high_bound;
+	      range->bounds ()->high.set_const_val (high_bound);
 	    }
 	maybe_bad_bstring:
 	  if (bound_info < 0)
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index d1efea19e918..31126a24b153 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -653,8 +653,8 @@ rust_print_struct_def (struct type *type, const char *varstring,
 	{
 	  fputs_filtered ("enum ", stream);
 	  dynamic_prop *prop = type->dyn_prop (DYN_PROP_VARIANT_PARTS);
-	  if (prop != nullptr && prop->kind == PROP_TYPE)
-	    type = prop->data.original_type;
+	  if (prop != nullptr && prop->kind () == PROP_TYPE)
+	    type = prop->original_type ();
 	}
       else if (type->code () == TYPE_CODE_STRUCT)
 	fputs_filtered ("struct ", stream);
diff --git a/gdb/type-stack.c b/gdb/type-stack.c
index 2d5c88f8d4d6..fae3216ba65c 100644
--- a/gdb/type-stack.c
+++ b/gdb/type-stack.c
@@ -172,8 +172,7 @@ type_stack::follow_types (struct type *follow_type)
 	  lookup_array_range_type (follow_type,
 				   0, array_size >= 0 ? array_size - 1 : 0);
 	if (array_size < 0)
-	  TYPE_HIGH_BOUND_KIND (follow_type->index_type ())
-	    = PROP_UNDEFINED;
+	  follow_type->index_type ()->bounds ()->high.set_undefined ();
 	break;
       case tp_function:
 	/* FIXME-type-allocation: need a way to free this type when we are
-- 
2.27.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 05/12] gdb: remove TYPE_HIGH_BOUND and TYPE_LOW_BOUND
  2020-07-06 13:38 [PATCH 00/12] More type macros removal Simon Marchi
                   ` (3 preceding siblings ...)
  2020-07-06 13:38 ` [PATCH 04/12] gdb: add accessors to struct dynamic_prop Simon Marchi
@ 2020-07-06 13:38 ` Simon Marchi
  2020-07-06 13:38 ` [PATCH 06/12] gdb: remove TYPE_LOW_BOUND_UNDEFINED and TYPE_HIGH_BOUND_UNDEFINED Simon Marchi
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Simon Marchi @ 2020-07-06 13:38 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@efficios.com>

Remove the macros, use the getters of `struct dynamic_prop` instead.

gdb/ChangeLog:

	* gdbtypes.h (TYPE_LOW_BOUND, TYPE_HIGH_BOUND): Remove.  Update
	all callers to use type::range_bounds followed by
	dynamic_prop::{low,high}.

Change-Id: I31beeed65d94d81ac4f999244a8b859e2ee961d1
---
 gdb/ada-lang.c                    | 18 ++++++++++--------
 gdb/ada-tasks.c                   |  3 ++-
 gdb/ada-valprint.c                |  2 +-
 gdb/c-varobj.c                    | 15 +++++++--------
 gdb/compile/compile-c-types.c     |  2 +-
 gdb/compile/compile-cplus-types.c |  2 +-
 gdb/eval.c                        |  4 ++--
 gdb/gdbtypes.c                    |  8 ++++----
 gdb/gdbtypes.h                    |  8 ++------
 gdb/guile/scm-type.c              |  8 ++++----
 gdb/m2-typeprint.c                | 18 +++++++++---------
 gdb/m2-valprint.c                 |  5 +++--
 gdb/p-typeprint.c                 |  4 ++--
 gdb/python/py-type.c              |  8 ++++----
 14 files changed, 52 insertions(+), 53 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index b89725b7397a..823d339912a9 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -725,7 +725,7 @@ ada_discrete_type_high_bound (struct type *type)
   switch (type->code ())
     {
     case TYPE_CODE_RANGE:
-      return TYPE_HIGH_BOUND (type);
+      return type->bounds ()->high.const_val ();
     case TYPE_CODE_ENUM:
       return TYPE_FIELD_ENUMVAL (type, type->num_fields () - 1);
     case TYPE_CODE_BOOL:
@@ -746,7 +746,7 @@ ada_discrete_type_low_bound (struct type *type)
   switch (type->code ())
     {
     case TYPE_CODE_RANGE:
-      return TYPE_LOW_BOUND (type);
+      return type->bounds ()->low.const_val ();
     case TYPE_CODE_ENUM:
       return TYPE_FIELD_ENUMVAL (type, 0);
     case TYPE_CODE_BOOL:
@@ -2250,7 +2250,7 @@ has_negatives (struct type *type)
     case TYPE_CODE_INT:
       return !TYPE_UNSIGNED (type);
     case TYPE_CODE_RANGE:
-      return TYPE_LOW_BOUND (type) - type->bounds ()->bias < 0;
+      return type->bounds ()->low.const_val () - type->bounds ()->bias < 0;
     }
 }
 
@@ -8283,13 +8283,13 @@ ada_is_redundant_range_encoding (struct type *range_type,
   n = 8; /* Skip "___XDLU_".  */
   if (!ada_scan_number (bounds_str, n, &lo, &n))
     return 0;
-  if (TYPE_LOW_BOUND (range_type) != lo)
+  if (range_type->bounds ()->low.const_val () != lo)
     return 0;
 
   n += 2; /* Skip the "__" separator between the two bounds.  */
   if (!ada_scan_number (bounds_str, n, &hi, &n))
     return 0;
-  if (TYPE_HIGH_BOUND (range_type) != hi)
+  if (range_type->bounds ()->high.const_val () != hi)
     return 0;
 
   return 1;
@@ -10604,8 +10604,10 @@ ada_evaluate_subexp (struct type *expect_type, struct expression *exp,
 	  return value_from_longest (type, (LONGEST) 1);
 
         case TYPE_CODE_RANGE:
-	  arg2 = value_from_longest (type, TYPE_LOW_BOUND (type));
-	  arg3 = value_from_longest (type, TYPE_HIGH_BOUND (type));
+	  arg2 = value_from_longest (type,
+				     type->bounds ()->low.const_val ());
+	  arg3 = value_from_longest (type,
+				     type->bounds ()->high.const_val ());
 	  binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
 	  binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg3);
 	  type = language_bool_type (exp->language_defn, exp->gdbarch);
@@ -11422,7 +11424,7 @@ ada_is_modular_type (struct type *type)
 ULONGEST
 ada_modulus (struct type *type)
 {
-  return (ULONGEST) TYPE_HIGH_BOUND (type) + 1;
+  return (ULONGEST) type->bounds ()->high.const_val () + 1;
 }
 \f
 
diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c
index 785a91c6ed0b..7870a7847ad6 100644
--- a/gdb/ada-tasks.c
+++ b/gdb/ada-tasks.c
@@ -901,7 +901,8 @@ ada_tasks_inferior_data_sniffer (struct ada_tasks_inferior_data *data)
 	    {
 	      data->known_tasks_element = eltype;
 	      data->known_tasks_length =
-		TYPE_HIGH_BOUND (idxtype) - TYPE_LOW_BOUND (idxtype) + 1;
+		(idxtype->bounds ()->high.const_val ()
+		 - idxtype->bounds ()->low.const_val () + 1);
 	      return;
 	    }
 	}
diff --git a/gdb/ada-valprint.c b/gdb/ada-valprint.c
index 61893d5cad3f..6a5b7d3f37aa 100644
--- a/gdb/ada-valprint.c
+++ b/gdb/ada-valprint.c
@@ -42,7 +42,7 @@ static void
 adjust_type_signedness (struct type *type)
 {
   if (type != NULL && type->code () == TYPE_CODE_RANGE
-      && TYPE_LOW_BOUND (type) >= 0)
+      && type->bounds ()->low.const_val () >= 0)
     TYPE_UNSIGNED (type) = 1;
 }
 
diff --git a/gdb/c-varobj.c b/gdb/c-varobj.c
index 6cc76a1e7ac6..a0b84936b023 100644
--- a/gdb/c-varobj.c
+++ b/gdb/c-varobj.c
@@ -307,12 +307,13 @@ c_describe_child (const struct varobj *parent, int index,
     case TYPE_CODE_ARRAY:
       if (cname)
 	*cname = int_string (index
-			     + TYPE_LOW_BOUND (type->index_type ()),
+			     + type->index_type ()->bounds ()->low.const_val (),
 			     10, 1, 0, 0);
 
       if (cvalue && value)
 	{
-	  int real_index = index + TYPE_LOW_BOUND (type->index_type ());
+	  int real_index
+	    = index + type->index_type ()->bounds ()->low.const_val ();
 
 	  try
 	    {
@@ -327,12 +328,10 @@ c_describe_child (const struct varobj *parent, int index,
 	*ctype = get_target_type (type);
 
       if (cfull_expression)
-	*cfull_expression = 
-	  string_printf ("(%s)[%s]", parent_expression.c_str (),
-			 int_string (index
-				     + TYPE_LOW_BOUND (type->index_type ()),
-				     10, 1, 0, 0));
-
+	*cfull_expression = string_printf
+	  ("(%s)[%s]", parent_expression.c_str (),
+	   int_string (index + type->index_type ()->bounds ()->low.const_val (),
+		       10, 1, 0, 0));
 
       break;
 
diff --git a/gdb/compile/compile-c-types.c b/gdb/compile/compile-c-types.c
index e5050da03b86..3c900a24a3a6 100644
--- a/gdb/compile/compile-c-types.c
+++ b/gdb/compile/compile-c-types.c
@@ -47,7 +47,7 @@ convert_array (compile_c_instance *context, struct type *type)
   if (TYPE_LOW_BOUND_KIND (range) != PROP_CONST)
     return context->plugin ().error (_("array type with non-constant"
 				       " lower bound is not supported"));
-  if (TYPE_LOW_BOUND (range) != 0)
+  if (range->bounds ()->low.const_val () != 0)
     return context->plugin ().error (_("cannot convert array type with "
 				       "non-zero lower bound to C"));
 
diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c
index d07036020cf3..4084f87e5a35 100644
--- a/gdb/compile/compile-cplus-types.c
+++ b/gdb/compile/compile-cplus-types.c
@@ -464,7 +464,7 @@ compile_cplus_convert_array (compile_cplus_instance *instance,
       return instance->plugin ().error (s);
     }
 
-  if (TYPE_LOW_BOUND (range) != 0)
+  if (range->bounds ()->low.const_val () != 0)
     {
       const char *s = _("cannot convert array type with "
 			"non-zero lower bound to C");
diff --git a/gdb/eval.c b/gdb/eval.c
index e28bfcbbd813..2191e190927e 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -384,12 +384,12 @@ value_f90_subarray (struct value *array,
   *pos += 3;
 
   if (range_type == LOW_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
-    low_bound = TYPE_LOW_BOUND (range);
+    low_bound = range->bounds ()->low.const_val ();
   else
     low_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
 
   if (range_type == HIGH_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
-    high_bound = TYPE_HIGH_BOUND (range);
+    high_bound = range->bounds ()->high.const_val ();
   else
     high_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
 
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 709574545928..507d2f6dacbe 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -1041,8 +1041,8 @@ get_discrete_bounds (struct type *type, LONGEST *lowp, LONGEST *highp)
 	  || type->bounds ()->high.kind () != PROP_CONST)
 	return -1;
 
-      *lowp = TYPE_LOW_BOUND (type);
-      *highp = TYPE_HIGH_BOUND (type);
+      *lowp = type->bounds ()->low.const_val ();
+      *highp = type->bounds ()->high.const_val ();
 
       if (TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_ENUM)
 	{
@@ -5116,9 +5116,9 @@ recursive_dump_type (struct type *type, int spaces)
   if (type->code () == TYPE_CODE_RANGE)
     {
       printfi_filtered (spaces, "low %s%s  high %s%s\n",
-			plongest (TYPE_LOW_BOUND (type)), 
+			plongest (type->bounds ()->low.const_val ()),
 			TYPE_LOW_BOUND_UNDEFINED (type) ? " (undefined)" : "",
-			plongest (TYPE_HIGH_BOUND (type)),
+			plongest (type->bounds ()->high.const_val ()),
 			TYPE_HIGH_BOUND_UNDEFINED (type) 
 			? " (undefined)" : "");
     }
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 5d9ed3972ff1..044af479727f 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1594,10 +1594,6 @@ extern unsigned type_align (struct type *);
    space in struct type.  */
 extern bool set_type_align (struct type *, ULONGEST);
 
-#define TYPE_LOW_BOUND(range_type) \
-  ((range_type)->bounds ()->low.const_val ())
-#define TYPE_HIGH_BOUND(range_type) \
-  ((range_type)->bounds ()->high.const_val ())
 #define TYPE_LOW_BOUND_UNDEFINED(range_type) \
   (TYPE_LOW_BOUND_KIND(range_type) == PROP_UNDEFINED)
 #define TYPE_HIGH_BOUND_UNDEFINED(range_type) \
@@ -1646,10 +1642,10 @@ extern bool set_type_align (struct type *, ULONGEST);
    TYPE_LOW_BOUND_UNDEFINED((arraytype)->index_type ())
 
 #define TYPE_ARRAY_UPPER_BOUND_VALUE(arraytype) \
-   (TYPE_HIGH_BOUND((arraytype)->index_type ()))
+   ((arraytype)->index_type ()->bounds ()->high.const_val ())
 
 #define TYPE_ARRAY_LOWER_BOUND_VALUE(arraytype) \
-   (TYPE_LOW_BOUND((arraytype)->index_type ()))
+   ((arraytype)->index_type ()->bounds ()->low.const_val ())
 
 #define TYPE_ARRAY_BIT_STRIDE(arraytype) \
   (TYPE_BIT_STRIDE(((arraytype)->index_type ())))
diff --git a/gdb/guile/scm-type.c b/gdb/guile/scm-type.c
index a36f0ba71cf4..fe6f493aa7f5 100644
--- a/gdb/guile/scm-type.c
+++ b/gdb/guile/scm-type.c
@@ -826,12 +826,12 @@ gdbscm_type_range (SCM self)
     {
     case TYPE_CODE_ARRAY:
     case TYPE_CODE_STRING:
-      low = TYPE_LOW_BOUND (type->index_type ());
-      high = TYPE_HIGH_BOUND (type->index_type ());
+      low = type->index_type ()->bounds ()->low.const_val ();
+      high = type->index_type ()->bounds ()->high.const_val ();
       break;
     case TYPE_CODE_RANGE:
-      low = TYPE_LOW_BOUND (type);
-      high = TYPE_HIGH_BOUND (type);
+      low = type->bounds ()->low.const_val ();
+      high = type->bounds ()->high.const_val ();
       break;
     }
 
diff --git a/gdb/m2-typeprint.c b/gdb/m2-typeprint.c
index fe041b48c53d..39f0e8e29610 100644
--- a/gdb/m2-typeprint.c
+++ b/gdb/m2-typeprint.c
@@ -188,7 +188,7 @@ void
 m2_range (struct type *type, struct ui_file *stream, int show,
 	  int level, const struct type_print_options *flags)
 {
-  if (TYPE_HIGH_BOUND (type) == TYPE_LOW_BOUND (type))
+  if (type->bounds ()->high.const_val () == type->bounds ()->low.const_val ())
     {
       /* FIXME: TYPE_TARGET_TYPE used to be TYPE_DOMAIN_TYPE but that was
 	 wrong.  Not sure if TYPE_TARGET_TYPE is correct though.  */
@@ -200,9 +200,9 @@ m2_range (struct type *type, struct ui_file *stream, int show,
       struct type *target = TYPE_TARGET_TYPE (type);
 
       fprintf_filtered (stream, "[");
-      print_type_scalar (target, TYPE_LOW_BOUND (type), stream);
+      print_type_scalar (target, type->bounds ()->low.const_val (), stream);
       fprintf_filtered (stream, "..");
-      print_type_scalar (target, TYPE_HIGH_BOUND (type), stream);
+      print_type_scalar (target, type->bounds ()->high.const_val (), stream);
       fprintf_filtered (stream, "]");
     }
 }
@@ -315,9 +315,9 @@ m2_print_bounds (struct type *type,
     return;
 
   if (print_high)
-    print_type_scalar (target, TYPE_HIGH_BOUND (type), stream);
+    print_type_scalar (target, type->bounds ()->high.const_val (), stream);
   else
-    print_type_scalar (target, TYPE_LOW_BOUND (type), stream);
+    print_type_scalar (target, type->bounds ()->low.const_val (), stream);
 }
 
 static void
@@ -358,9 +358,9 @@ m2_is_long_set (struct type *type)
 	    return 0;
 	  range = type->field (i).type ()->index_type ();
 	  if ((i > TYPE_N_BASECLASSES (type))
-	      && previous_high + 1 != TYPE_LOW_BOUND (range))
+	      && previous_high + 1 != range->bounds ()->low.const_val ())
 	    return 0;
-	  previous_high = TYPE_HIGH_BOUND (range);
+	  previous_high = range->bounds ()->high.const_val ();
 	}
       return len>0;
     }
@@ -416,8 +416,8 @@ m2_is_long_set_of_type (struct type *type, struct type **of_type)
       range = type->field (i).type ()->index_type ();
       target = TYPE_TARGET_TYPE (range);
 
-      l1 = TYPE_LOW_BOUND (type->field (i).type ()->index_type ());
-      h1 = TYPE_HIGH_BOUND (type->field (len - 1).type ()->index_type ());
+      l1 = type->field (i).type ()->index_type ()->bounds ()->low.const_val ();
+      h1 = type->field (len - 1).type ()->index_type ()->bounds ()->high.const_val ();
       *of_type = target;
       if (m2_get_discrete_bounds (target, &l2, &h2) >= 0)
 	return (l1 == l2 && h1 == h2);
diff --git a/gdb/m2-valprint.c b/gdb/m2-valprint.c
index 041bc18d3fd8..175c53adacfa 100644
--- a/gdb/m2-valprint.c
+++ b/gdb/m2-valprint.c
@@ -55,8 +55,9 @@ get_long_set_bounds (struct type *type, LONGEST *low, LONGEST *high)
       i = TYPE_N_BASECLASSES (type);
       if (len == 0)
 	return 0;
-      *low = TYPE_LOW_BOUND (type->field (i).type ()->index_type ());
-      *high = TYPE_HIGH_BOUND (type->field (len - 1).type ()->index_type ());
+      *low = type->field (i).type ()->index_type ()->bounds ()->low.const_val ();
+      *high = (type->field (len - 1).type ()->index_type ()->bounds ()
+	       ->high.const_val ());
       return 1;
     }
   error (_("expecting long_set"));
diff --git a/gdb/p-typeprint.c b/gdb/p-typeprint.c
index 75c1e25f5faa..c453df4b003c 100644
--- a/gdb/p-typeprint.c
+++ b/gdb/p-typeprint.c
@@ -797,9 +797,9 @@ pascal_type_print_base (struct type *type, struct ui_file *stream, int show,
       {
 	struct type *target = TYPE_TARGET_TYPE (type);
 
-	print_type_scalar (target, TYPE_LOW_BOUND (type), stream);
+	print_type_scalar (target, type->bounds ()->low.const_val (), stream);
 	fputs_filtered ("..", stream);
-	print_type_scalar (target, TYPE_HIGH_BOUND (type), stream);
+	print_type_scalar (target, type->bounds ()->high.const_val (), stream);
       }
       break;
 
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 34cb849937cc..e99ee415e2f9 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -592,12 +592,12 @@ typy_range (PyObject *self, PyObject *args)
     {
     case TYPE_CODE_ARRAY:
     case TYPE_CODE_STRING:
-      low = TYPE_LOW_BOUND (type->index_type ());
-      high = TYPE_HIGH_BOUND (type->index_type ());
+      low = type->index_type ()->bounds ()->low.const_val ();
+      high = type->index_type ()->bounds ()->high.const_val ();
       break;
     case TYPE_CODE_RANGE:
-      low = TYPE_LOW_BOUND (type);
-      high = TYPE_HIGH_BOUND (type);
+      low = type->bounds ()->low.const_val ();
+      high = type->bounds ()->high.const_val ();;
       break;
     }
 
-- 
2.27.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 06/12] gdb: remove TYPE_LOW_BOUND_UNDEFINED and TYPE_HIGH_BOUND_UNDEFINED
  2020-07-06 13:38 [PATCH 00/12] More type macros removal Simon Marchi
                   ` (4 preceding siblings ...)
  2020-07-06 13:38 ` [PATCH 05/12] gdb: remove TYPE_HIGH_BOUND and TYPE_LOW_BOUND Simon Marchi
@ 2020-07-06 13:38 ` Simon Marchi
  2020-07-06 13:38 ` [PATCH 07/12] gdb: remove TYPE_LOW_BOUND_KIND and TYPE_HIGH_BOUND_KIND Simon Marchi
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Simon Marchi @ 2020-07-06 13:38 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@efficios.com>

Remove the macros, use the getters of `struct dynamic_prop` instead.

gdb/ChangeLog:

	* gdbtypes.h (TYPE_LOW_BOUND_UNDEFINED,
	TYPE_HIGH_BOUND_UNDEFINED): Remove.  Update all callers
	to get the bound property's kind and check against
	PROP_UNDEFINED.

Change-Id: I6a7641ac1aa3fa7fca0c21f00556f185f2e2d68c
---
 gdb/ada-tasks.c | 4 ++--
 gdb/eval.c      | 3 ++-
 gdb/gdbtypes.c  | 7 ++++---
 gdb/gdbtypes.h  | 8 ++------
 4 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/gdb/ada-tasks.c b/gdb/ada-tasks.c
index 7870a7847ad6..27b458767a79 100644
--- a/gdb/ada-tasks.c
+++ b/gdb/ada-tasks.c
@@ -896,8 +896,8 @@ ada_tasks_inferior_data_sniffer (struct ada_tasks_inferior_data *data)
 	      && eltype->code () == TYPE_CODE_PTR)
 	    idxtype = check_typedef (type->index_type ());
 	  if (idxtype != NULL
-	      && !TYPE_LOW_BOUND_UNDEFINED (idxtype)
-	      && !TYPE_HIGH_BOUND_UNDEFINED (idxtype))
+	      && idxtype->bounds ()->low.kind () != PROP_UNDEFINED
+	      && idxtype->bounds ()->high.kind () != PROP_UNDEFINED)
 	    {
 	      data->known_tasks_element = eltype;
 	      data->known_tasks_length =
diff --git a/gdb/eval.c b/gdb/eval.c
index 2191e190927e..dacd46da44fa 100644
--- a/gdb/eval.c
+++ b/gdb/eval.c
@@ -3212,7 +3212,8 @@ evaluate_subexp_for_sizeof (struct expression *exp, int *pos,
 	  type = value_type (val);
 	  if (type->code () == TYPE_CODE_ARRAY
               && is_dynamic_type (type->index_type ())
-              && TYPE_HIGH_BOUND_UNDEFINED (type->index_type ()))
+              && (type->index_type ()->bounds ()->high.kind ()
+		  == PROP_UNDEFINED))
 	    return allocate_optimized_out_value (size_type);
 	}
       else
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 507d2f6dacbe..227f696b7363 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -5117,10 +5117,11 @@ recursive_dump_type (struct type *type, int spaces)
     {
       printfi_filtered (spaces, "low %s%s  high %s%s\n",
 			plongest (type->bounds ()->low.const_val ()),
-			TYPE_LOW_BOUND_UNDEFINED (type) ? " (undefined)" : "",
+			(type->bounds ()->low.kind () == PROP_UNDEFINED
+			 ? " (undefined)" : ""),
 			plongest (type->bounds ()->high.const_val ()),
-			TYPE_HIGH_BOUND_UNDEFINED (type) 
-			? " (undefined)" : "");
+			(type->bounds ()->high.kind () == PROP_UNDEFINED
+			 ? " (undefined)" : ""));
     }
 
   switch (TYPE_SPECIFIC_FIELD (type))
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 044af479727f..2d277ac688d0 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1594,10 +1594,6 @@ extern unsigned type_align (struct type *);
    space in struct type.  */
 extern bool set_type_align (struct type *, ULONGEST);
 
-#define TYPE_LOW_BOUND_UNDEFINED(range_type) \
-  (TYPE_LOW_BOUND_KIND(range_type) == PROP_UNDEFINED)
-#define TYPE_HIGH_BOUND_UNDEFINED(range_type) \
-  (TYPE_HIGH_BOUND_KIND(range_type) == PROP_UNDEFINED)
 #define TYPE_HIGH_BOUND_KIND(range_type) \
   ((range_type)->bounds ()->high.kind ())
 #define TYPE_LOW_BOUND_KIND(range_type) \
@@ -1637,9 +1633,9 @@ extern bool set_type_align (struct type *, ULONGEST);
    index type.  */
 
 #define TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED(arraytype) \
-   TYPE_HIGH_BOUND_UNDEFINED((arraytype)->index_type ())
+   ((arraytype)->index_type ()->bounds ()->high.kind () == PROP_UNDEFINED)
 #define TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED(arraytype) \
-   TYPE_LOW_BOUND_UNDEFINED((arraytype)->index_type ())
+   ((arraytype)->index_type ()->bounds ()->low.kind () == PROP_UNDEFINED)
 
 #define TYPE_ARRAY_UPPER_BOUND_VALUE(arraytype) \
    ((arraytype)->index_type ()->bounds ()->high.const_val ())
-- 
2.27.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 07/12] gdb: remove TYPE_LOW_BOUND_KIND and TYPE_HIGH_BOUND_KIND
  2020-07-06 13:38 [PATCH 00/12] More type macros removal Simon Marchi
                   ` (5 preceding siblings ...)
  2020-07-06 13:38 ` [PATCH 06/12] gdb: remove TYPE_LOW_BOUND_UNDEFINED and TYPE_HIGH_BOUND_UNDEFINED Simon Marchi
@ 2020-07-06 13:38 ` Simon Marchi
  2020-07-06 13:38 ` [PATCH 08/12] gdb: remove TYPE_ARRAY_{UPPER, LOWER}_BOUND_IS_UNDEFINED Simon Marchi
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Simon Marchi @ 2020-07-06 13:38 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@efficios.com>

Remove the macros, use the getters of `struct dynamic_prop` instead.

gdb/ChangeLog:

	* gdbtypes.h (TYPE_LOW_BOUND_KIND,
	TYPE_HIGH_BOUND_KIND): Remove.  Update all callers
	to use dynamic_prop::kind.

Change-Id: Icb1fc761f675bfac934209f8102392504d905c44
---
 gdb/c-typeprint.c                 | 4 ++--
 gdb/compile/compile-c-symbols.c   | 4 ++--
 gdb/compile/compile-c-types.c     | 6 +++---
 gdb/compile/compile-cplus-types.c | 6 +++---
 gdb/gdbtypes.h                    | 4 ----
 gdb/rust-lang.c                   | 4 ++--
 6 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/gdb/c-typeprint.c b/gdb/c-typeprint.c
index e10a4858a03c..9e408e15a1e2 100644
--- a/gdb/c-typeprint.c
+++ b/gdb/c-typeprint.c
@@ -780,8 +780,8 @@ c_type_print_varspec_suffix (struct type *type,
 	fprintf_filtered (stream, (is_vector ?
 				   " __attribute__ ((vector_size(" : "["));
 	/* Bounds are not yet resolved, print a bounds placeholder instead.  */
-	if (TYPE_HIGH_BOUND_KIND (type->index_type ()) == PROP_LOCEXPR
-	    || TYPE_HIGH_BOUND_KIND (type->index_type ()) == PROP_LOCLIST)
+	if (type->index_type ()->bounds ()->high.kind () == PROP_LOCEXPR
+	    || type->index_type ()->bounds ()->high.kind () == PROP_LOCLIST)
 	  fprintf_filtered (stream, "variable length");
 	else if (get_array_bounds (type, &low_bound, &high_bound))
 	  fprintf_filtered (stream, "%s", 
diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c
index be2ca35dead9..f4e0783d4b89 100644
--- a/gdb/compile/compile-c-symbols.c
+++ b/gdb/compile/compile-c-symbols.c
@@ -501,8 +501,8 @@ generate_vla_size (compile_instance *compiler,
     {
     case TYPE_CODE_RANGE:
       {
-	if (TYPE_HIGH_BOUND_KIND (type) == PROP_LOCEXPR
-	    || TYPE_HIGH_BOUND_KIND (type) == PROP_LOCLIST)
+	if (type->bounds ()->high.kind () == PROP_LOCEXPR
+	    || type->bounds ()->high.kind () == PROP_LOCLIST)
 	  {
 	    const struct dynamic_prop *prop = &type->bounds ()->high;
 	    std::string name = c_get_range_decl_name (prop);
diff --git a/gdb/compile/compile-c-types.c b/gdb/compile/compile-c-types.c
index 3c900a24a3a6..2b25783bb00c 100644
--- a/gdb/compile/compile-c-types.c
+++ b/gdb/compile/compile-c-types.c
@@ -44,15 +44,15 @@ convert_array (compile_c_instance *context, struct type *type)
 
   element_type = context->convert_type (TYPE_TARGET_TYPE (type));
 
-  if (TYPE_LOW_BOUND_KIND (range) != PROP_CONST)
+  if (range->bounds ()->low.kind () != PROP_CONST)
     return context->plugin ().error (_("array type with non-constant"
 				       " lower bound is not supported"));
   if (range->bounds ()->low.const_val () != 0)
     return context->plugin ().error (_("cannot convert array type with "
 				       "non-zero lower bound to C"));
 
-  if (TYPE_HIGH_BOUND_KIND (range) == PROP_LOCEXPR
-      || TYPE_HIGH_BOUND_KIND (range) == PROP_LOCLIST)
+  if (range->bounds ()->high.kind () == PROP_LOCEXPR
+      || range->bounds ()->high.kind () == PROP_LOCLIST)
     {
       gcc_type result;
 
diff --git a/gdb/compile/compile-cplus-types.c b/gdb/compile/compile-cplus-types.c
index 4084f87e5a35..02df7ab90e6e 100644
--- a/gdb/compile/compile-cplus-types.c
+++ b/gdb/compile/compile-cplus-types.c
@@ -456,7 +456,7 @@ compile_cplus_convert_array (compile_cplus_instance *instance,
   struct type *range = type->index_type ();
   gcc_type element_type = instance->convert_type (TYPE_TARGET_TYPE (type));
 
-  if (TYPE_LOW_BOUND_KIND (range) != PROP_CONST)
+  if (range->bounds ()->low.kind () != PROP_CONST)
     {
       const char *s = _("array type with non-constant"
 			" lower bound is not supported");
@@ -472,8 +472,8 @@ compile_cplus_convert_array (compile_cplus_instance *instance,
       return instance->plugin ().error (s);
     }
 
-  if (TYPE_HIGH_BOUND_KIND (range) == PROP_LOCEXPR
-      || TYPE_HIGH_BOUND_KIND (range) == PROP_LOCLIST)
+  if (range->bounds ()->high.kind () == PROP_LOCEXPR
+      || range->bounds ()->high.kind () == PROP_LOCLIST)
     {
       if (TYPE_VECTOR (type))
 	{
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 2d277ac688d0..9be97054cfa5 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1594,10 +1594,6 @@ extern unsigned type_align (struct type *);
    space in struct type.  */
 extern bool set_type_align (struct type *, ULONGEST);
 
-#define TYPE_HIGH_BOUND_KIND(range_type) \
-  ((range_type)->bounds ()->high.kind ())
-#define TYPE_LOW_BOUND_KIND(range_type) \
-  ((range_type)->bounds ()->low.kind ())
 #define TYPE_BIT_STRIDE(range_type) \
   ((range_type)->bounds ()->stride.const_val () \
    * ((range_type)->bounds ()->flag_is_byte_stride ? 8 : 1))
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c
index 31126a24b153..cedb15f555d3 100644
--- a/gdb/rust-lang.c
+++ b/gdb/rust-lang.c
@@ -813,8 +813,8 @@ rust_internal_print_type (struct type *type, const char *varstring,
 				  stream, show - 1, level, flags, false,
 				  podata);
 
-	if (TYPE_HIGH_BOUND_KIND (type->index_type ()) == PROP_LOCEXPR
-	    || TYPE_HIGH_BOUND_KIND (type->index_type ()) == PROP_LOCLIST)
+	if (type->index_type ()->bounds ()->high.kind () == PROP_LOCEXPR
+	    || type->index_type ()->bounds ()->high.kind () == PROP_LOCLIST)
 	  fprintf_filtered (stream, "; variable length");
 	else if (get_array_bounds (type, &low_bound, &high_bound))
 	  fprintf_filtered (stream, "; %s",
-- 
2.27.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 08/12] gdb: remove TYPE_ARRAY_{UPPER, LOWER}_BOUND_IS_UNDEFINED
  2020-07-06 13:38 [PATCH 00/12] More type macros removal Simon Marchi
                   ` (6 preceding siblings ...)
  2020-07-06 13:38 ` [PATCH 07/12] gdb: remove TYPE_LOW_BOUND_KIND and TYPE_HIGH_BOUND_KIND Simon Marchi
@ 2020-07-06 13:38 ` Simon Marchi
  2020-07-06 13:38 ` [PATCH 09/12] gdb: remove TYPE_ARRAY_{LOWER,UPPER}_BOUND_VALUE Simon Marchi
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 14+ messages in thread
From: Simon Marchi @ 2020-07-06 13:38 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@efficios.com>

Remove the macros, use the various equivalent getters instead.

gdb/ChangeLog:

	* gdbtypes.h (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED,
	TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED): Remove.  Update all
	callers to use the equivalent accessor methods instead.

Change-Id: Ifb4c36f440b82533bde5d15a5cbb2fc91f467292
---
 gdb/c-varobj.c     | 2 +-
 gdb/f-typeprint.c  | 4 ++--
 gdb/f-valprint.c   | 4 ++--
 gdb/gdbtypes.h     | 5 -----
 gdb/m2-typeprint.c | 2 +-
 gdb/p-typeprint.c  | 2 +-
 gdb/valarith.c     | 9 +++++----
 gdb/valops.c       | 3 ++-
 8 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/gdb/c-varobj.c b/gdb/c-varobj.c
index a0b84936b023..2bcfe8672eb7 100644
--- a/gdb/c-varobj.c
+++ b/gdb/c-varobj.c
@@ -192,7 +192,7 @@ c_number_of_children (const struct varobj *var)
     {
     case TYPE_CODE_ARRAY:
       if (TYPE_LENGTH (type) > 0 && TYPE_LENGTH (target) > 0
-	  && !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
+	  && (type->index_type ()->bounds ()->high.kind () != PROP_UNDEFINED))
 	children = TYPE_LENGTH (type) / TYPE_LENGTH (target);
       else
 	/* If we don't know how many elements there are, don't display
diff --git a/gdb/f-typeprint.c b/gdb/f-typeprint.c
index f09a4b1f21bf..df83a481386a 100644
--- a/gdb/f-typeprint.c
+++ b/gdb/f-typeprint.c
@@ -223,7 +223,7 @@ f_type_print_varspec_suffix (struct type *type, struct ui_file *stream,
 	  /* Make sure that, if we have an assumed size array, we
 	       print out a warning and print the upperbound as '*'.  */
 
-	  if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
+	  if (type->index_type ()->bounds ()->high.kind () == PROP_UNDEFINED)
 	    fprintf_filtered (stream, "*");
 	  else
 	    {
@@ -408,7 +408,7 @@ f_type_print_base (struct type *type, struct ui_file *stream, int show,
     case TYPE_CODE_STRING:
       /* Strings may have dynamic upperbounds (lengths) like arrays.  */
 
-      if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
+      if (type->index_type ()->bounds ()->high.kind () == PROP_UNDEFINED)
 	fprintfi_filtered (level, stream, "character*(*)");
       else
 	{
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
index 6ed1c340c760..05f98bc35052 100644
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
@@ -46,7 +46,7 @@ int f77_array_offset_tbl[MAX_FORTRAN_DIMS + 1][2];
 LONGEST
 f77_get_lowerbound (struct type *type)
 {
-  if (TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED (type))
+  if (type->index_type ()->bounds ()->low.kind () == PROP_UNDEFINED)
     error (_("Lower bound may not be '*' in F77"));
 
   return TYPE_ARRAY_LOWER_BOUND_VALUE (type);
@@ -55,7 +55,7 @@ f77_get_lowerbound (struct type *type)
 LONGEST
 f77_get_upperbound (struct type *type)
 {
-  if (TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
+  if (type->index_type ()->bounds ()->high.kind () == PROP_UNDEFINED)
     {
       /* We have an assumed size array on our hands.  Assume that
 	 upper_bound == lower_bound so that we show at least 1 element.
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 9be97054cfa5..83432b6fc778 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1628,11 +1628,6 @@ extern bool set_type_align (struct type *, ULONGEST);
 /* Accessors for struct range_bounds data attached to an array type's
    index type.  */
 
-#define TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED(arraytype) \
-   ((arraytype)->index_type ()->bounds ()->high.kind () == PROP_UNDEFINED)
-#define TYPE_ARRAY_LOWER_BOUND_IS_UNDEFINED(arraytype) \
-   ((arraytype)->index_type ()->bounds ()->low.kind () == PROP_UNDEFINED)
-
 #define TYPE_ARRAY_UPPER_BOUND_VALUE(arraytype) \
    ((arraytype)->index_type ()->bounds ()->high.const_val ())
 
diff --git a/gdb/m2-typeprint.c b/gdb/m2-typeprint.c
index 39f0e8e29610..474e58725c7f 100644
--- a/gdb/m2-typeprint.c
+++ b/gdb/m2-typeprint.c
@@ -226,7 +226,7 @@ static void m2_array (struct type *type, struct ui_file *stream,
 {
   fprintf_filtered (stream, "ARRAY [");
   if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
-      && !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
+      && type->index_type ()->bounds ()->high.kind () != PROP_UNDEFINED)
     {
       if (type->index_type () != 0)
 	{
diff --git a/gdb/p-typeprint.c b/gdb/p-typeprint.c
index c453df4b003c..5a32667603b7 100644
--- a/gdb/p-typeprint.c
+++ b/gdb/p-typeprint.c
@@ -274,7 +274,7 @@ pascal_type_print_varspec_prefix (struct type *type, struct ui_file *stream,
 	fprintf_filtered (stream, "(");
       fprintf_filtered (stream, "array ");
       if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
-	&& !TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
+	  && type->index_type ()->bounds ()->high.kind () != PROP_UNDEFINED)
 	fprintf_filtered (stream, "[%s..%s] ",
 			  plongest (TYPE_ARRAY_LOWER_BOUND_VALUE (type)),
 			  plongest (TYPE_ARRAY_UPPER_BOUND_VALUE (type)));
diff --git a/gdb/valarith.c b/gdb/valarith.c
index a5779a3aff97..0b1f43f2e009 100644
--- a/gdb/valarith.c
+++ b/gdb/valarith.c
@@ -200,12 +200,13 @@ value_subscripted_rvalue (struct value *array, LONGEST index, LONGEST lowerbound
     }
 
   LONGEST elt_offs = elt_size * (index - lowerbound);
+  bool array_upper_bound_undefined
+    = array_type->index_type ()->bounds ()->high.kind () == PROP_UNDEFINED;
 
   if (index < lowerbound
-      || (!TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)
-          && elt_offs >= type_length_units (array_type))
-      || (VALUE_LVAL (array) != lval_memory
-          && TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (array_type)))
+      || (!array_upper_bound_undefined
+	  && elt_offs >= type_length_units (array_type))
+      || (VALUE_LVAL (array) != lval_memory && array_upper_bound_undefined))
     {
       if (type_not_associated (array_type))
         error (_("no such vector element (vector not associated)"));
diff --git a/gdb/valops.c b/gdb/valops.c
index afdb429dc377..cfa0f5415d2e 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -388,7 +388,8 @@ value_cast (struct type *type, struct value *arg2)
       struct type *element_type = TYPE_TARGET_TYPE (type);
       unsigned element_length = TYPE_LENGTH (check_typedef (element_type));
 
-      if (element_length > 0 && TYPE_ARRAY_UPPER_BOUND_IS_UNDEFINED (type))
+      if (element_length > 0
+	  && type->index_type ()->bounds ()->high.kind () == PROP_UNDEFINED)
 	{
 	  struct type *range_type = type->index_type ();
 	  int val_length = TYPE_LENGTH (type2);
-- 
2.27.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 09/12] gdb: remove TYPE_ARRAY_{LOWER,UPPER}_BOUND_VALUE
  2020-07-06 13:38 [PATCH 00/12] More type macros removal Simon Marchi
                   ` (7 preceding siblings ...)
  2020-07-06 13:38 ` [PATCH 08/12] gdb: remove TYPE_ARRAY_{UPPER, LOWER}_BOUND_IS_UNDEFINED Simon Marchi
@ 2020-07-06 13:38 ` Simon Marchi
  2020-07-06 13:50 ` [PATCH 00/12] More type macros removal Simon Marchi
  2020-07-13  3:15 ` Simon Marchi
  10 siblings, 0 replies; 14+ messages in thread
From: Simon Marchi @ 2020-07-06 13:38 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

From: Simon Marchi <simon.marchi@efficios.com>

Remove the macros, use the various equivalent getters instead.

gdb/ChangeLog:

	* gdbtypes.h (TYPE_ARRAY_LOWER_BOUND_VALUE,
	TYPE_ARRAY_UPPER_BOUND_VALUE): Remove.  Update all
	callers to use the equivalent accessor methods instead.

Change-Id: I7f96d988f872170e7a2f58095832710e62b85cfd
---
 gdb/ada-lang.c    | 4 ++--
 gdb/f-valprint.c  | 4 ++--
 gdb/gdbtypes.h    | 6 ------
 gdb/p-typeprint.c | 4 ++--
 4 files changed, 6 insertions(+), 12 deletions(-)

diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c
index 823d339912a9..2fc5fc1fdc2c 100644
--- a/gdb/ada-lang.c
+++ b/gdb/ada-lang.c
@@ -9492,8 +9492,8 @@ assign_aggregate (struct value *container,
     {
       lhs = ada_coerce_to_simple_array (lhs);
       lhs_type = check_typedef (value_type (lhs));
-      low_index = TYPE_ARRAY_LOWER_BOUND_VALUE (lhs_type);
-      high_index = TYPE_ARRAY_UPPER_BOUND_VALUE (lhs_type);
+      low_index = lhs_type->index_type ()->bounds ()->low.const_val ();
+      high_index = lhs_type->index_type ()->bounds ()->high.const_val ();
     }
   else if (lhs_type->code () == TYPE_CODE_STRUCT)
     {
diff --git a/gdb/f-valprint.c b/gdb/f-valprint.c
index 05f98bc35052..bda480376510 100644
--- a/gdb/f-valprint.c
+++ b/gdb/f-valprint.c
@@ -49,7 +49,7 @@ f77_get_lowerbound (struct type *type)
   if (type->index_type ()->bounds ()->low.kind () == PROP_UNDEFINED)
     error (_("Lower bound may not be '*' in F77"));
 
-  return TYPE_ARRAY_LOWER_BOUND_VALUE (type);
+  return type->index_type ()->bounds ()->low.const_val ();
 }
 
 LONGEST
@@ -65,7 +65,7 @@ f77_get_upperbound (struct type *type)
       return f77_get_lowerbound (type);
     }
 
-  return TYPE_ARRAY_UPPER_BOUND_VALUE (type);
+  return type->index_type ()->bounds ()->high.const_val ();
 }
 
 /* Obtain F77 adjustable array dimensions.  */
diff --git a/gdb/gdbtypes.h b/gdb/gdbtypes.h
index 83432b6fc778..26db7935f265 100644
--- a/gdb/gdbtypes.h
+++ b/gdb/gdbtypes.h
@@ -1628,12 +1628,6 @@ extern bool set_type_align (struct type *, ULONGEST);
 /* Accessors for struct range_bounds data attached to an array type's
    index type.  */
 
-#define TYPE_ARRAY_UPPER_BOUND_VALUE(arraytype) \
-   ((arraytype)->index_type ()->bounds ()->high.const_val ())
-
-#define TYPE_ARRAY_LOWER_BOUND_VALUE(arraytype) \
-   ((arraytype)->index_type ()->bounds ()->low.const_val ())
-
 #define TYPE_ARRAY_BIT_STRIDE(arraytype) \
   (TYPE_BIT_STRIDE(((arraytype)->index_type ())))
 
diff --git a/gdb/p-typeprint.c b/gdb/p-typeprint.c
index 5a32667603b7..d52358aa4bb4 100644
--- a/gdb/p-typeprint.c
+++ b/gdb/p-typeprint.c
@@ -276,8 +276,8 @@ pascal_type_print_varspec_prefix (struct type *type, struct ui_file *stream,
       if (TYPE_LENGTH (TYPE_TARGET_TYPE (type)) > 0
 	  && type->index_type ()->bounds ()->high.kind () != PROP_UNDEFINED)
 	fprintf_filtered (stream, "[%s..%s] ",
-			  plongest (TYPE_ARRAY_LOWER_BOUND_VALUE (type)),
-			  plongest (TYPE_ARRAY_UPPER_BOUND_VALUE (type)));
+			  plongest (type->index_type ()->bounds ()->low.const_val ()),
+			  plongest (type->index_type ()->bounds ()->high.const_val ()));
       fprintf_filtered (stream, "of ");
       break;
 
-- 
2.27.0


^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 00/12] More type macros removal
  2020-07-06 13:38 [PATCH 00/12] More type macros removal Simon Marchi
                   ` (8 preceding siblings ...)
  2020-07-06 13:38 ` [PATCH 09/12] gdb: remove TYPE_ARRAY_{LOWER,UPPER}_BOUND_VALUE Simon Marchi
@ 2020-07-06 13:50 ` Simon Marchi
  2020-07-11 22:27   ` Tom Tromey
  2020-07-13  3:15 ` Simon Marchi
  10 siblings, 1 reply; 14+ messages in thread
From: Simon Marchi @ 2020-07-06 13:50 UTC (permalink / raw)
  To: gdb-patches

On 2020-07-06 9:38 a.m., Simon Marchi wrote:
> Here is the next installment of removal of type macros, in favor of
> getter/setter methods.
> 
> I added some assertions in some of these methods, to verify that the
> method is called on a type with the expected code (this is one of the
> goal of these changes).  It found one case that needed to be fixed,
> handled by patch 3.
> 
> The rest should be relatively straightforward.
> 
> Simon Marchi (12):
>   gdb: add type::bounds / type::set_bounds
>   gdb: remove TYPE_RANGE_DATA macro
>   gdb: make get_discrete_bounds check for non-constant range bounds
>   gdb: add accessors to struct dynamic_prop
>   gdb: remove TYPE_HIGH_BOUND and TYPE_LOW_BOUND
>   gdb: remove TYPE_LOW_BOUND_UNDEFINED and TYPE_HIGH_BOUND_UNDEFINED
>   gdb: remove TYPE_LOW_BOUND_KIND and TYPE_HIGH_BOUND_KIND
>   gdb: remove TYPE_ARRAY_{UPPER,LOWER}_BOUND_IS_UNDEFINED
>   gdb: remove TYPE_ARRAY_{LOWER,UPPER}_BOUND_VALUE
>   gdb: remove TYPE_BIT_STRIDE
>   gdb: remove TYPE_ARRAY_BIT_STRIDE
>   gdb: make type::bounds work for array and string types

Arf, I had to send this series in two shots, because my SMTP doesn't allow
sending more than 10 messages in one go.  And I forgot to link the second
batch with the first one using the Message-Id.  Here they are, just in case:

10: https://sourceware.org/pipermail/gdb-patches/2020-July/170191.html
11: https://sourceware.org/pipermail/gdb-patches/2020-July/170190.html
12: https://sourceware.org/pipermail/gdb-patches/2020-July/170192.html

Simon

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 00/12] More type macros removal
  2020-07-06 13:50 ` [PATCH 00/12] More type macros removal Simon Marchi
@ 2020-07-11 22:27   ` Tom Tromey
  2020-07-11 23:05     ` Simon Marchi
  0 siblings, 1 reply; 14+ messages in thread
From: Tom Tromey @ 2020-07-11 22:27 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches

>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:

Simon> Arf, I had to send this series in two shots, because my SMTP doesn't allow
Simon> sending more than 10 messages in one go.  And I forgot to link the second
Simon> batch with the first one using the Message-Id.

FWIW I have this problem and I use git send-email --batch-size to work
around it.

Tom

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 00/12] More type macros removal
  2020-07-11 22:27   ` Tom Tromey
@ 2020-07-11 23:05     ` Simon Marchi
  0 siblings, 0 replies; 14+ messages in thread
From: Simon Marchi @ 2020-07-11 23:05 UTC (permalink / raw)
  To: Tom Tromey, Simon Marchi via Gdb-patches

On 2020-07-11 6:27 p.m., Tom Tromey wrote:
>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
> 
> Simon> Arf, I had to send this series in two shots, because my SMTP doesn't allow
> Simon> sending more than 10 messages in one go.  And I forgot to link the second
> Simon> batch with the first one using the Message-Id.
> 
> FWIW I have this problem and I use git send-email --batch-size to work
> around it.
> 
> Tom
> 

Awesome, thanks for the tip!

Simon

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 00/12] More type macros removal
  2020-07-06 13:38 [PATCH 00/12] More type macros removal Simon Marchi
                   ` (9 preceding siblings ...)
  2020-07-06 13:50 ` [PATCH 00/12] More type macros removal Simon Marchi
@ 2020-07-13  3:15 ` Simon Marchi
  10 siblings, 0 replies; 14+ messages in thread
From: Simon Marchi @ 2020-07-13  3:15 UTC (permalink / raw)
  To: gdb-patches

On 2020-07-06 9:38 a.m., Simon Marchi wrote:
> Here is the next installment of removal of type macros, in favor of
> getter/setter methods.
> 
> I added some assertions in some of these methods, to verify that the
> method is called on a type with the expected code (this is one of the
> goal of these changes).  It found one case that needed to be fixed,
> handled by patch 3.
> 
> The rest should be relatively straightforward.
> 
> Simon Marchi (12):
>   gdb: add type::bounds / type::set_bounds
>   gdb: remove TYPE_RANGE_DATA macro
>   gdb: make get_discrete_bounds check for non-constant range bounds
>   gdb: add accessors to struct dynamic_prop
>   gdb: remove TYPE_HIGH_BOUND and TYPE_LOW_BOUND
>   gdb: remove TYPE_LOW_BOUND_UNDEFINED and TYPE_HIGH_BOUND_UNDEFINED
>   gdb: remove TYPE_LOW_BOUND_KIND and TYPE_HIGH_BOUND_KIND
>   gdb: remove TYPE_ARRAY_{UPPER,LOWER}_BOUND_IS_UNDEFINED
>   gdb: remove TYPE_ARRAY_{LOWER,UPPER}_BOUND_VALUE
>   gdb: remove TYPE_BIT_STRIDE
>   gdb: remove TYPE_ARRAY_BIT_STRIDE
>   gdb: make type::bounds work for array and string types
> 
>  gdb/ada-lang.c                    |  22 ++--
>  gdb/ada-tasks.c                   |   7 +-
>  gdb/ada-typeprint.c               |   8 +-
>  gdb/ada-valprint.c                |   2 +-
>  gdb/c-typeprint.c                 |   4 +-
>  gdb/c-varobj.c                    |  18 ++-
>  gdb/compile/compile-c-symbols.c   |   6 +-
>  gdb/compile/compile-c-types.c     |  10 +-
>  gdb/compile/compile-cplus-types.c |  10 +-
>  gdb/ctfread.c                     |   2 +-
>  gdb/dwarf2/loc.c                  |  16 +--
>  gdb/dwarf2/read.c                 |  71 +++++-------
>  gdb/eval.c                        |   8 +-
>  gdb/f-typeprint.c                 |   4 +-
>  gdb/f-valprint.c                  |  10 +-
>  gdb/gdbtypes.c                    | 186 +++++++++++++-----------------
>  gdb/gdbtypes.h                    | 162 +++++++++++++++++++-------
>  gdb/gnu-v3-abi.c                  |   3 +-
>  gdb/guile/scm-type.c              |   7 +-
>  gdb/m2-typeprint.c                |  20 ++--
>  gdb/m2-valprint.c                 |   4 +-
>  gdb/mdebugread.c                  |   8 +-
>  gdb/p-typeprint.c                 |  10 +-
>  gdb/p-valprint.c                  |   2 +-
>  gdb/printcmd.c                    |   3 +-
>  gdb/python/py-type.c              |   7 +-
>  gdb/rust-lang.c                   |   8 +-
>  gdb/type-stack.c                  |   3 +-
>  gdb/valarith.c                    |  11 +-
>  gdb/valops.c                      |   2 +-
>  gdb/value.c                       |   4 +-
>  31 files changed, 337 insertions(+), 301 deletions(-)
> 
> -- 
> 2.27.0
> 

I pushed this.

Simon

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2020-07-13  3:15 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-06 13:38 [PATCH 00/12] More type macros removal Simon Marchi
2020-07-06 13:38 ` [PATCH 01/12] gdb: add type::bounds / type::set_bounds Simon Marchi
2020-07-06 13:38 ` [PATCH 02/12] gdb: remove TYPE_RANGE_DATA macro Simon Marchi
2020-07-06 13:38 ` [PATCH 03/12] gdb: make get_discrete_bounds check for non-constant range bounds Simon Marchi
2020-07-06 13:38 ` [PATCH 04/12] gdb: add accessors to struct dynamic_prop Simon Marchi
2020-07-06 13:38 ` [PATCH 05/12] gdb: remove TYPE_HIGH_BOUND and TYPE_LOW_BOUND Simon Marchi
2020-07-06 13:38 ` [PATCH 06/12] gdb: remove TYPE_LOW_BOUND_UNDEFINED and TYPE_HIGH_BOUND_UNDEFINED Simon Marchi
2020-07-06 13:38 ` [PATCH 07/12] gdb: remove TYPE_LOW_BOUND_KIND and TYPE_HIGH_BOUND_KIND Simon Marchi
2020-07-06 13:38 ` [PATCH 08/12] gdb: remove TYPE_ARRAY_{UPPER, LOWER}_BOUND_IS_UNDEFINED Simon Marchi
2020-07-06 13:38 ` [PATCH 09/12] gdb: remove TYPE_ARRAY_{LOWER,UPPER}_BOUND_VALUE Simon Marchi
2020-07-06 13:50 ` [PATCH 00/12] More type macros removal Simon Marchi
2020-07-11 22:27   ` Tom Tromey
2020-07-11 23:05     ` Simon Marchi
2020-07-13  3:15 ` Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).