[rfc] Use LONGEST instead of value for index arithmetic

Ulrich Weigand uweigand@de.ibm.com
Fri Jun 26 15:49:00 GMT 2009


Hello,

this patch implements the change I mentioned recently: use LONGEST instead
of struct value to represent array indexes (and similarly the integer
operands to pointer arithmetic).  This has the advantage that index
computations can be performed in host instead of target arithmetic,
and not just eliminates a bunch of references to global built-in types,
but makes both implementation and users of the value_subscript and
pointer arithmetic routines quite a bit simpler.

In particular, the following routines now take a LONGEST instead of a
struct value to represent the index: 
  gdb_value_subscript
  value_subscript
  value_subscripted_rvalue
  value_bitstring_subscript

Likewise, the value_ptradd routine now takes a LONGEST to represent
the integer operand of pointer arithmetic.  Note that this means the
value_ptrsub routine is now completely redundant, and can be replaced
simply by passing a negative argument to value_ptradd.

Tested on amd64-linux and powerpc64-linux.

Bye,
Ulrich


ChangeLog:

	* value.h (value_subscript, value_subscripted_rvalue,
	value_bitstring_subscript, value_ptradd): Use LONGEST instead
	of value as type of the index argument.
	(value_ptrsub): Remove.
	* valarith.c (value_subscript, value_subscripted_rvalue,
	value_bitstring_subscript, value_ptradd): Use LONGEST instead
	of value as type of the index argument.
	(value_ptrsub): Remove.

	* wrapper.h (gdb_value_subscript): Use LONGEST instead of
	value as type of the index argument.
	* wrapper.c (gdb_value_subscript): Likewise.

	Update calls to gdb_value_subscript, value_subscript,
	value_subscripted_rvalue, value_bitstring_subscript and
	value_ptradd to use LONGEST instead of value as index
	argument type.  Use value_ptradd instead of value_ptrsub.
	* ada-lang.c (ada_value_subscript, ada_value_ptr_subscript,
	ada_tag_name_2): Update.
	* ada-tasks.c (read_atcb): Update.
	* eval.c (evaluate_subexp_standard): Update.
	* valarith.c (value_subscript): Update.
	* gnu-v2-abi.c (gnuv2_virtual_fn_field): Update.
	* gnu-v3-abi.c (gnuv3_get_virtual_fn, gnuv3_baseclass_offset,
	gnuv3_method_ptr_to_value): Update.
	* jv-lang.c (evaluate_subexp_java): Update.
	* m2-lang.c (evaluate_subexp_modula2): Update.
	* python/python-value.c (valpy_getitem, valpy_binop): Update.
	* wrapper.c (gdb_value_subscript): Update.
	* varobj.c (c_describe_child): Update.


Index: gdb-head/gdb/ada-lang.c
===================================================================
--- gdb-head.orig/gdb/ada-lang.c
+++ gdb-head/gdb/ada-lang.c
@@ -2273,7 +2273,7 @@ ada_value_subscript (struct value *arr, 
     {
       if (TYPE_CODE (elt_type) != TYPE_CODE_ARRAY)
         error (_("too many subscripts (%d expected)"), k);
-      elt = value_subscript (elt, value_pos_atr (builtin_type_int32, ind[k]));
+      elt = value_subscript (elt, pos_atr (ind[k]));
     }
   return elt;
 }
@@ -2291,19 +2291,13 @@ ada_value_ptr_subscript (struct value *a
   for (k = 0; k < arity; k += 1)
     {
       LONGEST lwb, upb;
-      struct value *idx;
 
       if (TYPE_CODE (type) != TYPE_CODE_ARRAY)
         error (_("too many subscripts (%d expected)"), k);
       arr = value_cast (lookup_pointer_type (TYPE_TARGET_TYPE (type)),
                         value_copy (arr));
       get_discrete_bounds (TYPE_INDEX_TYPE (type), &lwb, &upb);
-      idx = value_pos_atr (builtin_type_int32, ind[k]);
-      if (lwb != 0)
-	idx = value_binop (idx, value_from_longest (value_type (idx), lwb),
-			   BINOP_SUB);
-
-      arr = value_ptradd (arr, idx);
+      arr = value_ptradd (arr, pos_atr (ind[k]) - lwb);
       type = TYPE_TARGET_TYPE (type);
     }
 
@@ -5568,8 +5562,7 @@ ada_tag_name_2 (struct tag_args *args)
   valp = value_cast (info_type, args->tag);
   if (valp == NULL)
     return 0;
-  val = value_ind (value_ptradd (valp,
-				 value_from_longest (builtin_type_int8, -1)));
+  val = value_ind (value_ptradd (valp, -1));
   if (val == NULL)
     return 0;
   val = ada_value_struct_elt (val, "expanded_name", 1);
Index: gdb-head/gdb/ada-tasks.c
===================================================================
--- gdb-head.orig/gdb/ada-tasks.c
+++ gdb-head/gdb/ada-tasks.c
@@ -548,7 +548,8 @@ read_atcb (CORE_ADDR task_id, struct ada
         ada_coerce_to_simple_array_ptr (value_field (tcb_value,
                                                      fieldno.entry_calls));
       entry_calls_value_element =
-        value_subscript (entry_calls_value, atc_nesting_level_value);
+        value_subscript (entry_calls_value,
+			 value_as_long (atc_nesting_level_value));
       called_task_fieldno =
         ada_get_field_index (value_type (entry_calls_value_element),
                              "called_task", 0);
Index: gdb-head/gdb/eval.c
===================================================================
--- gdb-head.orig/gdb/eval.c
+++ gdb-head/gdb/eval.c
@@ -1575,7 +1575,7 @@ evaluate_subexp_standard (struct type *e
 	  else
 	    {
 	      arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
-	      return value_subscript (arg1, arg2);
+	      return value_subscript (arg1, value_as_long (arg2));
 	    }
 
 	case TYPE_CODE_PTR:
@@ -1737,10 +1737,12 @@ evaluate_subexp_standard (struct type *e
       op = exp->elts[pc + 1].opcode;
       if (binop_user_defined_p (op, arg1, arg2))
 	return value_x_binop (arg1, arg2, BINOP_ASSIGN_MODIFY, op, noside);
-      else if (op == BINOP_ADD && ptrmath_type_p (value_type (arg1)))
-	arg2 = value_ptradd (arg1, arg2);
-      else if (op == BINOP_SUB && ptrmath_type_p (value_type (arg1)))
-	arg2 = value_ptrsub (arg1, arg2);
+      else if (op == BINOP_ADD && ptrmath_type_p (value_type (arg1))
+	       && is_integral_type (value_type (arg2)))
+	arg2 = value_ptradd (arg1, value_as_long (arg2));
+      else if (op == BINOP_SUB && ptrmath_type_p (value_type (arg1))
+	       && is_integral_type (value_type (arg2)))
+	arg2 = value_ptradd (arg1, - value_as_long (arg2));
       else
 	{
 	  struct value *tmp = arg1;
@@ -1764,10 +1766,12 @@ evaluate_subexp_standard (struct type *e
 	goto nosideret;
       if (binop_user_defined_p (op, arg1, arg2))
 	return value_x_binop (arg1, arg2, op, OP_NULL, noside);
-      else if (ptrmath_type_p (value_type (arg1)))
-	return value_ptradd (arg1, arg2);
-      else if (ptrmath_type_p (value_type (arg2)))
-	return value_ptradd (arg2, arg1);
+      else if (ptrmath_type_p (value_type (arg1))
+	       && is_integral_type (value_type (arg2)))
+	return value_ptradd (arg1, value_as_long (arg2));
+      else if (ptrmath_type_p (value_type (arg2))
+	       && is_integral_type (value_type (arg1)))
+	return value_ptradd (arg2, value_as_long (arg1));
       else
 	{
 	  binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
@@ -1781,17 +1785,16 @@ evaluate_subexp_standard (struct type *e
 	goto nosideret;
       if (binop_user_defined_p (op, arg1, arg2))
 	return value_x_binop (arg1, arg2, op, OP_NULL, noside);
-      else if (ptrmath_type_p (value_type (arg1)))
+      else if (ptrmath_type_p (value_type (arg1))
+	       && ptrmath_type_p (value_type (arg2)))
 	{
-	  if (ptrmath_type_p (value_type (arg2)))
-	    {
-	      /* FIXME -- should be ptrdiff_t */
-	      type = builtin_type (exp->gdbarch)->builtin_long;
-	      return value_from_longest (type, value_ptrdiff (arg1, arg2));
-	    }
-	  else
-	    return value_ptrsub (arg1, arg2);
-	}
+	  /* FIXME -- should be ptrdiff_t */
+	  type = builtin_type (exp->gdbarch)->builtin_long;
+	  return value_from_longest (type, value_ptrdiff (arg1, arg2));
+	}
+      else if (ptrmath_type_p (value_type (arg1))
+	       && is_integral_type (value_type (arg2)))
+	return value_ptradd (arg1, - value_as_long (arg2));
       else
 	{
 	  binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
@@ -1886,7 +1889,7 @@ evaluate_subexp_standard (struct type *e
 	  if (noside == EVAL_AVOID_SIDE_EFFECTS)
 	    return value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (arg1));
 	  else
-	    return value_subscript (arg1, arg2);
+	    return value_subscript (arg1, value_as_long (arg2));
 	}
 
     case BINOP_IN:
@@ -1951,12 +1954,13 @@ evaluate_subexp_standard (struct type *e
 		case TYPE_CODE_PTR:
 		case TYPE_CODE_ARRAY:
 		case TYPE_CODE_STRING:
-		  arg1 = value_subscript (arg1, arg2);
+		  arg1 = value_subscript (arg1, value_as_long (arg2));
 		  break;
 
 		case TYPE_CODE_BITSTRING:
 		  type = language_bool_type (exp->language_defn, exp->gdbarch);
-		  arg1 = value_bitstring_subscript (type, arg1, arg2);
+		  arg1 = value_bitstring_subscript (type, arg1,
+						    value_as_long (arg2));
 		  break;
 
 		default:
@@ -2036,10 +2040,6 @@ evaluate_subexp_standard (struct type *e
 	  offset_item =
 	    array_size_array[i - 1] * offset_item + subscript_array[i - 1];
 
-	/* Construct a value node with the value of the offset */
-
-	arg2 = value_from_longest (builtin_type_int32, offset_item);
-
 	/* Let us now play a dirty trick: we will take arg1 
 	   which is a value node pointing to the topmost level
 	   of the multidimensional array-set and pretend
@@ -2048,7 +2048,7 @@ evaluate_subexp_standard (struct type *e
 	   returns the correct type value */
 
 	deprecated_set_value_type (arg1, tmp_type);
-	return value_subscripted_rvalue (arg1, arg2, 0);
+	return value_subscripted_rvalue (arg1, offset_item, 0);
       }
 
     case BINOP_LOGICAL_AND:
@@ -2387,12 +2387,12 @@ evaluate_subexp_standard (struct type *e
 	}
       else
 	{
-	  arg2 = value_from_longest (builtin_type_uint8, (LONGEST) 1);
 	  if (ptrmath_type_p (value_type (arg1)))
-	    arg2 = value_ptradd (arg1, arg2);
+	    arg2 = value_ptradd (arg1, 1);
 	  else
 	    {
 	      struct value *tmp = arg1;
+	      arg2 = value_one (value_type (arg1), not_lval);
 	      binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
 	      arg2 = value_binop (tmp, arg2, BINOP_ADD);
 	    }
@@ -2410,12 +2410,12 @@ evaluate_subexp_standard (struct type *e
 	}
       else
 	{
-	  arg2 = value_from_longest (builtin_type_uint8, (LONGEST) 1);
 	  if (ptrmath_type_p (value_type (arg1)))
-	    arg2 = value_ptrsub (arg1, arg2);
+	    arg2 = value_ptradd (arg1, -1);
 	  else
 	    {
 	      struct value *tmp = arg1;
+	      arg2 = value_one (value_type (arg1), not_lval);
 	      binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
 	      arg2 = value_binop (tmp, arg2, BINOP_SUB);
 	    }
@@ -2433,12 +2433,12 @@ evaluate_subexp_standard (struct type *e
 	}
       else
 	{
-	  arg2 = value_from_longest (builtin_type_uint8, (LONGEST) 1);
 	  if (ptrmath_type_p (value_type (arg1)))
-	    arg2 = value_ptradd (arg1, arg2);
+	    arg2 = value_ptradd (arg1, 1);
 	  else
 	    {
 	      struct value *tmp = arg1;
+	      arg2 = value_one (value_type (arg1), not_lval);
 	      binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
 	      arg2 = value_binop (tmp, arg2, BINOP_ADD);
 	    }
@@ -2457,12 +2457,12 @@ evaluate_subexp_standard (struct type *e
 	}
       else
 	{
-	  arg2 = value_from_longest (builtin_type_uint8, (LONGEST) 1);
 	  if (ptrmath_type_p (value_type (arg1)))
-	    arg2 = value_ptrsub (arg1, arg2);
+	    arg2 = value_ptradd (arg1, -1);
 	  else
 	    {
 	      struct value *tmp = arg1;
+	      arg2 = value_one (value_type (arg1), not_lval);
 	      binop_promote (exp->language_defn, exp->gdbarch, &tmp, &arg2);
 	      arg2 = value_binop (tmp, arg2, BINOP_SUB);
 	    }
Index: gdb-head/gdb/gnu-v2-abi.c
===================================================================
--- gdb-head.orig/gdb/gnu-v2-abi.c
+++ gdb-head/gdb/gnu-v2-abi.c
@@ -97,8 +97,7 @@ gnuv2_virtual_fn_field (struct value **a
   struct value *entry;
   struct value *vfn;
   struct value *vtbl;
-  struct value *vi = value_from_longest (builtin_type_int32,
-				     (LONGEST) TYPE_FN_FIELD_VOFFSET (f, j));
+  LONGEST vi = (LONGEST) TYPE_FN_FIELD_VOFFSET (f, j);
   struct type *fcontext = TYPE_FN_FIELD_FCONTEXT (f, j);
   struct type *context;
   struct type *context_vptr_basetype;
Index: gdb-head/gdb/gnu-v3-abi.c
===================================================================
--- gdb-head.orig/gdb/gnu-v3-abi.c
+++ gdb-head/gdb/gnu-v3-abi.c
@@ -359,7 +359,7 @@ gnuv3_get_virtual_fn (struct gdbarch *gd
 
   /* Fetch the appropriate function pointer from the vtable.  */
   vfn = value_subscript (value_field (vtable, vtable_field_virtual_functions),
-                         value_from_longest (builtin_type_int32, vtable_index));
+                         vtable_index);
 
   /* If this architecture uses function descriptors directly in the vtable,
      then the address of the vtable entry is actually a "function pointer"
@@ -419,7 +419,7 @@ gnuv3_baseclass_offset (struct type *typ
   struct type *ptr_type;
   struct value *vtable;
   struct type *vbasetype;
-  struct value *offset_val, *vbase_array;
+  struct value *vbase_array;
   CORE_ADDR vtable_address;
   long int cur_base_offset, base_offset;
   int vbasetype_vptr_fieldno;
@@ -471,9 +471,8 @@ gnuv3_baseclass_offset (struct type *typ
   vtable
     = value_at_lazy (vtable_type,
 		     vtable_address - vtable_address_point_offset (gdbarch));
-  offset_val = value_from_longest (builtin_type_int32, cur_base_offset);
   vbase_array = value_field (vtable, vtable_field_vcall_and_vbase_offsets);
-  base_offset = value_as_long (value_subscript (vbase_array, offset_val));
+  base_offset = value_as_long (value_subscript (vbase_array, cur_base_offset));
   return base_offset;
 }
 
@@ -691,7 +690,6 @@ gnuv3_method_ptr_to_value (struct value 
   CORE_ADDR ptr_value;
   struct type *domain_type, *final_type, *method_type;
   LONGEST adjustment;
-  struct value *adjval;
   int vbit;
 
   domain_type = TYPE_DOMAIN_TYPE (check_typedef (value_type (method_ptr)));
@@ -723,9 +721,7 @@ gnuv3_method_ptr_to_value (struct value 
      You can provoke this case by casting a Base::* to a Derived::*, for
      instance.  */
   *this_p = value_cast (builtin_type (gdbarch)->builtin_data_ptr, *this_p);
-  adjval = value_from_longest (builtin_type (gdbarch)->builtin_long,
-			       adjustment);
-  *this_p = value_ptradd (*this_p, adjval);
+  *this_p = value_ptradd (*this_p, adjustment);
   *this_p = value_cast (final_type, *this_p);
 
   if (vbit)
Index: gdb-head/gdb/jv-lang.c
===================================================================
--- gdb-head.orig/gdb/jv-lang.c
+++ gdb-head/gdb/jv-lang.c
@@ -943,7 +943,7 @@ evaluate_subexp_java (struct type *expec
 	  if (noside == EVAL_AVOID_SIDE_EFFECTS)
 	    return value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (arg1));
 	  else
-	    return value_subscript (arg1, arg2);
+	    return value_subscript (arg1, value_as_long (arg2));
 	}
       if (name)
 	error (_("cannot subscript something of type `%s'"), name);
Index: gdb-head/gdb/m2-lang.c
===================================================================
--- gdb-head.orig/gdb/m2-lang.c
+++ gdb-head/gdb/m2-lang.c
@@ -253,7 +253,7 @@ evaluate_subexp_modula2 (struct type *ex
 	    arg1 = value_cast (type, arg1);
 
 	  type = check_typedef (value_type (arg1));
-	  return value_ind (value_ptradd (arg1, arg2));
+	  return value_ind (value_ptradd (arg1, value_as_long (arg2)));
 	}
       else
 	if (TYPE_CODE (type) != TYPE_CODE_ARRAY)
@@ -268,7 +268,7 @@ evaluate_subexp_modula2 (struct type *ex
       if (noside == EVAL_AVOID_SIDE_EFFECTS)
 	return value_zero (TYPE_TARGET_TYPE (type), VALUE_LVAL (arg1));
       else
-	return value_subscript (arg1, arg2);
+	return value_subscript (arg1, value_as_long (arg2));
 
     default:
       return evaluate_subexp_standard (expect_type, exp, pos, noside);
Index: gdb-head/gdb/python/python-value.c
===================================================================
--- gdb-head.orig/gdb/python/python-value.c
+++ gdb-head/gdb/python/python-value.c
@@ -293,7 +293,7 @@ valpy_getitem (PyObject *self, PyObject 
 	  if (idx == NULL)
 	    return NULL;
 
-	  res_val = value_subscript (tmp, idx);
+	  res_val = value_subscript (tmp, value_as_long (idx));
 	}
     }
   if (field)
@@ -413,10 +413,12 @@ valpy_binop (enum valpy_opcode opcode, P
 	    CHECK_TYPEDEF (rtype);
 	    rtype = STRIP_REFERENCE (rtype);
 
-	    if (TYPE_CODE (ltype) == TYPE_CODE_PTR)
-	      res_val = value_ptradd (arg1, arg2);
-	    else if (TYPE_CODE (rtype) == TYPE_CODE_PTR)
-	      res_val = value_ptradd (arg2, arg1);
+	    if (TYPE_CODE (ltype) == TYPE_CODE_PTR
+		&& is_integral_type (rtype))
+	      res_val = value_ptradd (arg1, value_as_long (arg2));
+	    else if (TYPE_CODE (rtype) == TYPE_CODE_PTR
+		     && is_integral_type (ltype))
+	      res_val = value_ptradd (arg2, value_as_long (arg1));
 	    else
 	      res_val = value_binop (arg1, arg2, BINOP_ADD);
 	  }
@@ -431,16 +433,14 @@ valpy_binop (enum valpy_opcode opcode, P
 	    CHECK_TYPEDEF (rtype);
 	    rtype = STRIP_REFERENCE (rtype);
 
-	    if (TYPE_CODE (ltype) == TYPE_CODE_PTR)
-	      {
-		if (TYPE_CODE (rtype) == TYPE_CODE_PTR)
-		    /* A ptrdiff_t for the target would be preferable
-		       here.  */
-		    res_val = value_from_longest (builtin_type_pyint,
-						  value_ptrdiff (arg1, arg2));
-		else
-		  res_val = value_ptrsub (arg1, arg2);
-	      }
+	    if (TYPE_CODE (ltype) == TYPE_CODE_PTR
+		&& TYPE_CODE (rtype) == TYPE_CODE_PTR)
+	      /* A ptrdiff_t for the target would be preferable here.  */
+	      res_val = value_from_longest (builtin_type_pyint,
+					    value_ptrdiff (arg1, arg2));
+	    else if (TYPE_CODE (ltype) == TYPE_CODE_PTR
+		     && is_integral_type (rtype))
+	      res_val = value_ptradd (arg1, - value_as_long (arg2));
 	    else
 	      res_val = value_binop (arg1, arg2, BINOP_SUB);
 	  }
Index: gdb-head/gdb/valarith.c
===================================================================
--- gdb-head.orig/gdb/valarith.c
+++ gdb-head/gdb/valarith.c
@@ -46,7 +46,7 @@ void _initialize_valarith (void);
    If the pointer type is void *, then return 1.
    If the target type is incomplete, then error out.
    This isn't a general purpose function, but just a 
-   helper for value_ptrsub & value_ptradd.
+   helper for value_ptradd.
 */
 
 static LONGEST
@@ -85,7 +85,7 @@ find_size_for_pointer_math (struct type 
    result of C-style pointer arithmetic ARG1 + ARG2.  */
 
 struct value *
-value_ptradd (struct value *arg1, struct value *arg2)
+value_ptradd (struct value *arg1, LONGEST arg2)
 {
   struct type *valptrtype;
   LONGEST sz;
@@ -94,33 +94,8 @@ value_ptradd (struct value *arg1, struct
   valptrtype = check_typedef (value_type (arg1));
   sz = find_size_for_pointer_math (valptrtype);
 
-  if (!is_integral_type (value_type (arg2)))
-    error (_("Argument to arithmetic operation not a number or boolean."));
-
-  return value_from_pointer (valptrtype,
-			     value_as_address (arg1)
-			       + (sz * value_as_long (arg2)));
-}
-
-/* Given a pointer ARG1 and an integral value ARG2, return the
-   result of C-style pointer arithmetic ARG1 - ARG2.  */
-
-struct value *
-value_ptrsub (struct value *arg1, struct value *arg2)
-{
-  struct type *valptrtype;
-  LONGEST sz;
-
-  arg1 = coerce_array (arg1);
-  valptrtype = check_typedef (value_type (arg1));
-  sz = find_size_for_pointer_math (valptrtype);
-
-  if (!is_integral_type (value_type (arg2)))
-    error (_("Argument to arithmetic operation not a number or boolean."));
-
   return value_from_pointer (valptrtype,
-			     value_as_address (arg1)
-			       - (sz * value_as_long (arg2)));
+			     value_as_address (arg1) + sz * arg2);
 }
 
 /* Given two compatible pointer values ARG1 and ARG2, return the
@@ -162,7 +137,7 @@ an integer nor a pointer of the same typ
    verbosity is set, warn about invalid indices (but still use them). */
 
 struct value *
-value_subscript (struct value *array, struct value *idx)
+value_subscript (struct value *array, LONGEST index)
 {
   struct value *bound;
   int c_style = current_language->c_style_arrays;
@@ -179,13 +154,12 @@ value_subscript (struct value *array, st
       get_discrete_bounds (range_type, &lowerbound, &upperbound);
 
       if (VALUE_LVAL (array) != lval_memory)
-	return value_subscripted_rvalue (array, idx, lowerbound);
+	return value_subscripted_rvalue (array, index, lowerbound);
 
       if (c_style == 0)
 	{
-	  LONGEST index = value_as_long (idx);
 	  if (index >= lowerbound && index <= upperbound)
-	    return value_subscripted_rvalue (array, idx, lowerbound);
+	    return value_subscripted_rvalue (array, index, lowerbound);
 	  /* Emit warning unless we have an array of unknown size.
 	     An array of unknown size has lowerbound 0 and upperbound -1.  */
 	  if (upperbound > -1)
@@ -194,17 +168,12 @@ value_subscript (struct value *array, st
 	  c_style = 1;
 	}
 
-      if (lowerbound != 0)
-	{
-	  bound = value_from_longest (value_type (idx), (LONGEST) lowerbound);
-	  idx = value_binop (idx, bound, BINOP_SUB);
-	}
-
+      index -= lowerbound;
       array = value_coerce_array (array);
     }
 
   if (c_style)
-    return value_ind (value_ptradd (array, idx));
+    return value_ind (value_ptradd (array, index));
   else
     error (_("not an array or string"));
 }
@@ -214,12 +183,11 @@ value_subscript (struct value *array, st
    to doubles, but no longer does.  */
 
 struct value *
-value_subscripted_rvalue (struct value *array, struct value *idx, int lowerbound)
+value_subscripted_rvalue (struct value *array, LONGEST index, int lowerbound)
 {
   struct type *array_type = check_typedef (value_type (array));
   struct type *elt_type = check_typedef (TYPE_TARGET_TYPE (array_type));
   unsigned int elt_size = TYPE_LENGTH (elt_type);
-  LONGEST index = value_as_long (idx);
   unsigned int elt_offs = elt_size * longest_to_int (index - lowerbound);
   struct value *v;
 
@@ -244,11 +212,10 @@ value_subscripted_rvalue (struct value *
 
 struct value *
 value_bitstring_subscript (struct type *type,
-			   struct value *bitstring, struct value *idx)
+			   struct value *bitstring, LONGEST index)
 {
 
   struct type *bitstring_type, *range_type;
-  LONGEST index = value_as_long (idx);
   struct value *v;
   int offset, byte, bit_index;
   LONGEST lowerbound, upperbound;
Index: gdb-head/gdb/value.h
===================================================================
--- gdb-head.orig/gdb/value.h
+++ gdb-head/gdb/value.h
@@ -394,9 +394,7 @@ extern struct value *value_concat (struc
 extern struct value *value_binop (struct value *arg1, struct value *arg2,
 				  enum exp_opcode op);
 
-extern struct value *value_ptradd (struct value *arg1, struct value *arg2);
-
-extern struct value *value_ptrsub (struct value *arg1, struct value *arg2);
+extern struct value *value_ptradd (struct value *arg1, LONGEST arg2);
 
 extern LONGEST value_ptrdiff (struct value *arg1, struct value *arg2);
 
@@ -468,11 +466,11 @@ extern struct value *value_one (struct t
 
 extern struct value *value_repeat (struct value *arg1, int count);
 
-extern struct value *value_subscript (struct value *array, struct value *idx);
+extern struct value *value_subscript (struct value *array, LONGEST index);
 
 extern struct value *value_bitstring_subscript (struct type *type,
 						struct value *bitstring,
-						struct value *idx);
+						LONGEST index);
 
 extern struct value *register_value_being_returned (struct type *valtype,
 						    struct regcache *retbuf);
@@ -670,7 +668,8 @@ extern struct value *value_allocate_spac
 
 extern struct value *value_of_local (const char *name, int complain);
 
-extern struct value * value_subscripted_rvalue (struct value *array, struct value *idx, int lowerbound);
+extern struct value *value_subscripted_rvalue (struct value *array,
+					       LONGEST index, int lowerbound);
 
 /* User function handler.  */
 
Index: gdb-head/gdb/wrapper.c
===================================================================
--- gdb-head.orig/gdb/wrapper.c
+++ gdb-head/gdb/wrapper.c
@@ -100,14 +100,14 @@ gdb_value_assign (struct value *val1, st
 }
 
 int
-gdb_value_subscript (struct value *val1, struct value *val2,
+gdb_value_subscript (struct value *val, LONGEST index,
 		     struct value **result)
 {
   volatile struct gdb_exception except;
 
   TRY_CATCH (except, RETURN_MASK_ERROR)
     {
-      *result = value_subscript (val1, val2);
+      *result = value_subscript (val, index);
     }
 
   if (except.reason < 0)
Index: gdb-head/gdb/varobj.c
===================================================================
--- gdb-head.orig/gdb/varobj.c
+++ gdb-head/gdb/varobj.c
@@ -2556,9 +2556,7 @@ c_describe_child (struct varobj *parent,
       if (cvalue && value)
 	{
 	  int real_index = index + TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type));
-	  struct value *indval = 
-	    value_from_longest (builtin_type_int32, (LONGEST) real_index);
-	  gdb_value_subscript (value, indval, cvalue);
+	  gdb_value_subscript (value, real_index, cvalue);
 	}
 
       if (ctype)
Index: gdb-head/gdb/wrapper.h
===================================================================
--- gdb-head.orig/gdb/wrapper.h
+++ gdb-head/gdb/wrapper.h
@@ -36,8 +36,7 @@ extern int gdb_value_equal (struct value
 
 extern int gdb_value_assign (struct value *, struct value *, struct value **);
 
-extern int gdb_value_subscript (struct value *, struct value *,
-				struct value **);
+extern int gdb_value_subscript (struct value *, LONGEST, struct value **);
 
 extern enum gdb_rc gdb_value_struct_elt (struct ui_out *uiout,
 					 struct value **result_ptr,
-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com



More information about the Gdb-patches mailing list