struct value **, int, const char *,
struct type *);
-static struct value *ada_coerce_to_simple_array (struct value *);
-
static int ada_is_direct_array_type (struct type *);
static void ada_language_arch_info (struct gdbarch *,
/* Utilities */
+/* If TYPE is a TYPE_CODE_TYPEDEF type, return the target type after
+ all typedef layers have been pealed. Otherwise, return TYPE.
+
+ Normally, we really expect a typedef type to only have 1 typedef layer.
+ In other words, we really expect the target type of a typedef type to be
+ a non-typedef type. This is particularly true for Ada units, because
+ the language does not have a typedef vs not-typedef distinction.
+ In that respect, the Ada compiler has been trying to eliminate as many
+ typedef definitions in the debugging information, since they generally
+ do not bring any extra information (we still use typedef under certain
+ circumstances related mostly to the GNAT encoding).
+
+ Unfortunately, we have seen situations where the debugging information
+ generated by the compiler leads to such multiple typedef layers. For
+ instance, consider the following example with stabs:
+
+ .stabs "pck__float_array___XUP:Tt(0,46)=s16P_ARRAY:(0,47)=[...]"[...]
+ .stabs "pck__float_array___XUP:t(0,36)=(0,46)",128,0,6,0
+
+ This is an error in the debugging information which causes type
+ pck__float_array___XUP to be defined twice, and the second time,
+ it is defined as a typedef of a typedef.
+
+ This is on the fringe of legality as far as debugging information is
+ concerned, and certainly unexpected. But it is easy to handle these
+ situations correctly, so we can afford to be lenient in this case. */
+
+static struct type *
+ada_typedef_target_type (struct type *type)
+{
+ while (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
+ type = TYPE_TARGET_TYPE (type);
+ return type;
+}
+
/* Given DECODED_NAME a string holding a symbol name in its
decoded form (ie using the Ada dotted notation), returns
its unqualified name. */
if (type == NULL)
return NULL;
type = ada_check_typedef (type);
+ if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
+ type = ada_typedef_target_type (type);
+
if (type != NULL
&& (TYPE_CODE (type) == TYPE_CODE_PTR
|| TYPE_CODE (type) == TYPE_CODE_REF))
Otherwise, returns a standard GDB array describing ARR (which may
be ARR itself if it already is in the proper form). */
-static struct value *
+struct value *
ada_coerce_to_simple_array (struct value *arr)
{
if (ada_is_array_descriptor_type (value_type (arr)))
static long
decode_packed_array_bitsize (struct type *type)
{
- char *raw_name = ada_type_name (ada_check_typedef (type));
+ char *raw_name;
char *tail;
long bits;
+ /* Access to arrays implemented as fat pointers are encoded as a typedef
+ of the fat pointer type. We need the name of the fat pointer type
+ to do the decoding, so strip the typedef layer. */
+ if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
+ type = ada_typedef_target_type (type);
+
+ raw_name = ada_type_name (ada_check_typedef (type));
if (!raw_name)
raw_name = ada_type_name (desc_base_type (type));
return 0;
tail = strstr (raw_name, "___XP");
+ gdb_assert (tail != NULL);
if (sscanf (tail + sizeof ("___XP") - 1, "%ld", &bits) != 1)
{
{
struct type *field_type = TYPE_FIELD_TYPE (type, f);
+ /* If our field is a typedef type (most likely a typedef of
+ a fat pointer, encoding an array access), then we need to
+ look at its target type to determine its characteristics.
+ In particular, we would miscompute the field size if we took
+ the size of the typedef (zero), instead of the size of
+ the target type. */
+ if (TYPE_CODE (field_type) == TYPE_CODE_TYPEDEF)
+ field_type = ada_typedef_target_type (field_type);
+
TYPE_FIELD_TYPE (rtype, f) = field_type;
TYPE_FIELD_NAME (rtype, f) = TYPE_FIELD_NAME (type, f);
if (TYPE_FIELD_BITSIZE (type, f) > 0)
because we call check_typedef/ada_check_typedef pretty much everywhere.
*/
if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF
- && (TYPE_MAIN_TYPE (TYPE_TARGET_TYPE (type))
+ && (TYPE_MAIN_TYPE (ada_typedef_target_type (type))
== TYPE_MAIN_TYPE (fixed_type)))
return type;
if (type == NULL)
return NULL;
+ /* If our type is a typedef type of a fat pointer, then we're done.
+ We don't want to strip the TYPE_CODE_TYPDEF layer, because this is
+ what allows us to distinguish between fat pointers that represent
+ array types, and fat pointers that represent array access types
+ (in both cases, the compiler implements them as fat pointers). */
+ if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF
+ && is_thick_pntr (ada_typedef_target_type (type)))
+ return type;
+
CHECK_TYPEDEF (type);
if (type == NULL || TYPE_CODE (type) != TYPE_CODE_ENUM
|| !TYPE_STUB (type)
argvec[0] = value_addr (argvec[0]);
type = ada_check_typedef (value_type (argvec[0]));
+
+ /* Ada allows us to implicitly dereference arrays when subscripting
+ them. So, if this is an typedef (encoding use for array access
+ types encoded as fat pointers), strip it now. */
+ if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
+ type = ada_typedef_target_type (type);
+
if (TYPE_CODE (type) == TYPE_CODE_PTR)
{
switch (TYPE_CODE (ada_check_typedef (TYPE_TARGET_TYPE (type))))
struct value *val;
val = value_from_contents_and_address (type, valaddr, address);
- val = ada_coerce_to_simple_array_ptr (val);
+ if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF) /* array access type. */
+ val = ada_coerce_to_simple_array_ptr (val);
+ else
+ val = ada_coerce_to_simple_array (val);
if (val == NULL)
{
fprintf_filtered (stream, "(null)");
}
else if (ada_is_array_descriptor_type (type))
{
- fprintf_filtered (stream, "(");
- type_print (type, "", stream, -1);
- fprintf_filtered (stream, ") ");
+ /* We do not print the type description unless TYPE is an array
+ access type (this is encoded by the compiler as a typedef to
+ a fat pointer - hence the check against TYPE_CODE_TYPEDEF). */
+ if (TYPE_CODE (type) == TYPE_CODE_TYPEDEF)
+ {
+ fprintf_filtered (stream, "(");
+ type_print (type, "", stream, -1);
+ fprintf_filtered (stream, ") ");
+ }
}
else if (ada_is_bogus_array_descriptor (type))
{