+static struct type *
+resolve_dynamic_union (struct type *type,
+ struct property_addr_info *addr_stack)
+{
+ struct type *resolved_type;
+ int i;
+ unsigned int max_len = 0;
+
+ gdb_assert (TYPE_CODE (type) == TYPE_CODE_UNION);
+
+ resolved_type = copy_type (type);
+ TYPE_FIELDS (resolved_type)
+ = (struct field *) TYPE_ALLOC (resolved_type,
+ TYPE_NFIELDS (resolved_type)
+ * sizeof (struct field));
+ memcpy (TYPE_FIELDS (resolved_type),
+ TYPE_FIELDS (type),
+ TYPE_NFIELDS (resolved_type) * sizeof (struct field));
+ for (i = 0; i < TYPE_NFIELDS (resolved_type); ++i)
+ {
+ struct type *t;
+
+ if (field_is_static (&TYPE_FIELD (type, i)))
+ continue;
+
+ t = resolve_dynamic_type_internal (TYPE_FIELD_TYPE (resolved_type, i),
+ addr_stack, 0);
+ TYPE_FIELD_TYPE (resolved_type, i) = t;
+ if (TYPE_LENGTH (t) > max_len)
+ max_len = TYPE_LENGTH (t);
+ }
+
+ TYPE_LENGTH (resolved_type) = max_len;
+ return resolved_type;
+}
+
+/* Resolve dynamic bounds of members of the struct TYPE to static
+ bounds. ADDR_STACK is a stack of struct property_addr_info to
+ be used if needed during the dynamic resolution. */
+
+static struct type *
+resolve_dynamic_struct (struct type *type,
+ struct property_addr_info *addr_stack)
+{
+ struct type *resolved_type;
+ int i;
+ unsigned resolved_type_bit_length = 0;
+
+ gdb_assert (TYPE_CODE (type) == TYPE_CODE_STRUCT);
+ gdb_assert (TYPE_NFIELDS (type) > 0);
+
+ resolved_type = copy_type (type);
+ TYPE_FIELDS (resolved_type)
+ = (struct field *) TYPE_ALLOC (resolved_type,
+ TYPE_NFIELDS (resolved_type)
+ * sizeof (struct field));
+ memcpy (TYPE_FIELDS (resolved_type),
+ TYPE_FIELDS (type),
+ TYPE_NFIELDS (resolved_type) * sizeof (struct field));
+ for (i = 0; i < TYPE_NFIELDS (resolved_type); ++i)
+ {
+ unsigned new_bit_length;
+ struct property_addr_info pinfo;
+
+ if (field_is_static (&TYPE_FIELD (type, i)))
+ continue;
+
+ /* As we know this field is not a static field, the field's
+ field_loc_kind should be FIELD_LOC_KIND_BITPOS. Verify
+ this is the case, but only trigger a simple error rather
+ than an internal error if that fails. While failing
+ that verification indicates a bug in our code, the error
+ is not severe enough to suggest to the user he stops
+ his debugging session because of it. */
+ if (TYPE_FIELD_LOC_KIND (type, i) != FIELD_LOC_KIND_BITPOS)
+ error (_("Cannot determine struct field location"
+ " (invalid location kind)"));
+
+ pinfo.type = check_typedef (TYPE_FIELD_TYPE (type, i));
+ pinfo.valaddr = addr_stack->valaddr;
+ pinfo.addr = addr_stack->addr;
+ pinfo.next = addr_stack;
+
+ TYPE_FIELD_TYPE (resolved_type, i)
+ = resolve_dynamic_type_internal (TYPE_FIELD_TYPE (resolved_type, i),
+ &pinfo, 0);
+ gdb_assert (TYPE_FIELD_LOC_KIND (resolved_type, i)
+ == FIELD_LOC_KIND_BITPOS);
+
+ new_bit_length = TYPE_FIELD_BITPOS (resolved_type, i);
+ if (TYPE_FIELD_BITSIZE (resolved_type, i) != 0)
+ new_bit_length += TYPE_FIELD_BITSIZE (resolved_type, i);
+ else
+ new_bit_length += (TYPE_LENGTH (TYPE_FIELD_TYPE (resolved_type, i))
+ * TARGET_CHAR_BIT);
+
+ /* Normally, we would use the position and size of the last field
+ to determine the size of the enclosing structure. But GCC seems
+ to be encoding the position of some fields incorrectly when
+ the struct contains a dynamic field that is not placed last.
+ So we compute the struct size based on the field that has
+ the highest position + size - probably the best we can do. */
+ if (new_bit_length > resolved_type_bit_length)
+ resolved_type_bit_length = new_bit_length;
+ }
+
+ TYPE_LENGTH (resolved_type)
+ = (resolved_type_bit_length + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
+
+ /* The Ada language uses this field as a cache for static fixed types: reset
+ it as RESOLVED_TYPE must have its own static fixed type. */
+ TYPE_TARGET_TYPE (resolved_type) = NULL;
+
+ return resolved_type;
+}
+
+/* Worker for resolved_dynamic_type. */
+
+static struct type *
+resolve_dynamic_type_internal (struct type *type,
+ struct property_addr_info *addr_stack,
+ int top_level)