return (len1 >= len2 && strcmp (str + len1 - len2, suffix) == 0);
}
-/* Create a value of type TYPE whose contents come from VALADDR, if it
- is non-null, and whose memory address (in the inferior) is
- ADDRESS. */
-
-struct value *
-value_from_contents_and_address (struct type *type,
- const gdb_byte *valaddr,
- CORE_ADDR address)
-{
- struct value *v = allocate_value (type);
- if (valaddr == NULL)
- set_value_lazy (v, 1);
- else
- memcpy (value_contents_raw (v), valaddr, TYPE_LENGTH (type));
- VALUE_ADDRESS (v) = address;
- if (address != 0)
- VALUE_LVAL (v) = lval_memory;
- return v;
-}
-
/* The contents of value VAL, treated as a value of type TYPE. The
result is an lval in memory if VAL is. */
new_type = alloc_type (TYPE_OBJFILE (type));
new_elt_type = packed_array_type (ada_check_typedef (TYPE_TARGET_TYPE (type)),
elt_bits);
- create_array_type (new_type, new_elt_type, TYPE_FIELD_TYPE (type, 0));
+ create_array_type (new_type, new_elt_type, TYPE_INDEX_TYPE (type));
TYPE_FIELD_BITSIZE (new_type, 0) = *elt_bits;
TYPE_NAME (new_type) = ada_type_name (type);
- if (get_discrete_bounds (TYPE_FIELD_TYPE (type, 0),
+ if (get_discrete_bounds (TYPE_INDEX_TYPE (type),
&low_bound, &high_bound) < 0)
low_bound = high_bound = 0;
if (high_bound < low_bound)
}
/* Given that ARRAY_PTR is a pointer or reference to an array of type TYPE (the
- actual type of ARRAY_PTR is ignored), returns a reference to
- the Ada slice of HIGH-LOW+1 elements starting at index LOW. The lower
- bound of this array is LOW, as per Ada rules. */
+ actual type of ARRAY_PTR is ignored), returns the Ada slice of HIGH-LOW+1
+ elements starting at index LOW. The lower bound of this array is LOW, as
+ per Ada rules. */
static struct value *
-ada_value_slice_ptr (struct value *array_ptr, struct type *type,
- int low, int high)
+ada_value_slice_from_ptr (struct value *array_ptr, struct type *type,
+ int low, int high)
{
CORE_ADDR base = value_as_address (array_ptr)
+ ((low - TYPE_LOW_BOUND (TYPE_INDEX_TYPE (type)))
low, high);
struct type *slice_type =
create_array_type (NULL, TYPE_TARGET_TYPE (type), index_type);
- return value_from_pointer (lookup_reference_type (slice_type), base);
+ return value_at_lazy (slice_type, base);
}
for (i = 1; i < n; i += 1)
type = TYPE_TARGET_TYPE (type);
- result_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0));
+ result_type = TYPE_TARGET_TYPE (TYPE_INDEX_TYPE (type));
/* FIXME: The stabs type r(0,0);bound;bound in an array type
has a target type of TYPE_CODE_UNDEF. We compensate here, but
perhaps stabsread.c would make more sense. */
ada_array_bound_from_type (struct type * arr_type, int n, int which,
struct type ** typep)
{
- struct type *type;
- struct type *index_type_desc;
+ struct type *type, *index_type_desc, *index_type;
+ LONGEST retval;
+
+ gdb_assert (which == 0 || which == 1);
if (ada_is_packed_array_type (arr_type))
arr_type = decode_packed_array_type (arr_type);
type = arr_type;
index_type_desc = ada_find_parallel_type (type, "___XA");
- if (index_type_desc == NULL)
+ if (index_type_desc != NULL)
+ index_type = to_fixed_range_type (TYPE_FIELD_NAME (index_type_desc, n - 1),
+ NULL, TYPE_OBJFILE (arr_type));
+ else
{
- struct type *index_type;
-
while (n > 1)
{
type = TYPE_TARGET_TYPE (type);
}
index_type = TYPE_INDEX_TYPE (type);
- if (typep != NULL)
- *typep = index_type;
-
- /* The index type is either a range type or an enumerated type.
- For the range type, we have some macros that allow us to
- extract the value of the low and high bounds. But they
- do now work for enumerated types. The expressions used
- below work for both range and enum types. */
- return
- (LONGEST) (which == 0
- ? TYPE_FIELD_BITPOS (index_type, 0)
- : TYPE_FIELD_BITPOS (index_type,
- TYPE_NFIELDS (index_type) - 1));
}
- else
+
+ switch (TYPE_CODE (index_type))
{
- struct type *index_type =
- to_fixed_range_type (TYPE_FIELD_NAME (index_type_desc, n - 1),
- NULL, TYPE_OBJFILE (arr_type));
+ case TYPE_CODE_RANGE:
+ retval = which == 0 ? TYPE_LOW_BOUND (index_type)
+ : TYPE_HIGH_BOUND (index_type);
+ break;
+ case TYPE_CODE_ENUM:
+ retval = which == 0 ? TYPE_FIELD_BITPOS (index_type, 0)
+ : TYPE_FIELD_BITPOS (index_type,
+ TYPE_NFIELDS (index_type) - 1);
+ break;
+ default:
+ internal_error (__FILE__, __LINE__, _("invalid type code of index type"));
+ }
- if (typep != NULL)
- *typep = index_type;
+ if (typep != NULL)
+ *typep = index_type;
- return
- (LONGEST) (which == 0
- ? TYPE_LOW_BOUND (index_type)
- : TYPE_HIGH_BOUND (index_type));
- }
+ return retval;
}
/* Given that arr is an array value, returns the lower bound of the
/* Given ARG, a value of type (pointer or reference to a)*
structure/union, extract the component named NAME from the ultimate
target structure/union and return it as a value with its
- appropriate type. If ARG is a pointer or reference and the field
- is not packed, returns a reference to the field, otherwise the
- value of the field (an lvalue if ARG is an lvalue).
+ appropriate type.
The routine searches for NAME among all members of the structure itself
and (recursively) among all members of any wrapper members
field_type);
}
else
- v = value_from_pointer (lookup_reference_type (field_type),
- address + byte_offset);
+ v = value_at_lazy (field_type, address + byte_offset);
}
}
struct type *arr_type0 =
to_fixed_array_type (TYPE_TARGET_TYPE (value_type (array)),
NULL, 1);
- return ada_value_slice_ptr (array, arr_type0,
- longest_to_int (low_bound),
- longest_to_int (high_bound));
+ return ada_value_slice_from_ptr (array, arr_type0,
+ longest_to_int (low_bound),
+ longest_to_int (high_bound));
}
}
else if (noside == EVAL_AVOID_SIDE_EFFECTS)
arg1 = ada_coerce_ref (arg1); /* FIXME: What is this for?? */
type = ada_check_typedef (value_type (arg1));
- if (TYPE_CODE (type) == TYPE_CODE_INT && expect_type != NULL)
- /* GDB allows dereferencing an int. We give it the expected
- type (which will be set in the case of a coercion or
- qualification). */
- return ada_value_ind (value_cast (lookup_pointer_type (expect_type),
- arg1));
+ if (TYPE_CODE (type) == TYPE_CODE_INT)
+ /* GDB allows dereferencing an int. If we were given
+ the expect_type, then use that as the target type.
+ Otherwise, assume that the target type is an int. */
+ {
+ if (expect_type != NULL)
+ return ada_value_ind (value_cast (lookup_pointer_type (expect_type),
+ arg1));
+ else
+ return value_at_lazy (builtin_type (exp->gdbarch)->builtin_int,
+ (CORE_ADDR) value_as_address (arg1));
+ }
if (ada_is_array_descriptor_type (type))
/* GDB allows dereferencing GNAT array descriptors. */