+ attr = xml_find_attribute (attributes, "end");
+ if (attr != NULL)
+ {
+ ULONGEST ul_end = * (ULONGEST *) attr->value.get ();
+
+ if (ul_end > MAX_FIELD_BITSIZE)
+ {
+ gdb_xml_error (parser,
+ _("Field end %s is larger than maximum (%d)"),
+ pulongest (ul_end), MAX_FIELD_BITSIZE);
+ }
+ end = ul_end;
+ }
+ else
+ end = -1;
+
+ if (start != -1)
+ {
+ tdesc_type_with_fields *t = data->current_type;
+
+ /* Older versions of gdb can't handle elided end values.
+ Stick with that for now, to help ensure backward compatibility.
+ E.g., If a newer gdbserver is talking to an older gdb. */
+ if (end == -1)
+ gdb_xml_error (parser, _("Missing end value"));
+
+ if (data->current_type_size == 0)
+ gdb_xml_error (parser,
+ _("Bitfields must live in explicitly sized types"));
+
+ if (field_type_id != NULL
+ && strcmp (field_type_id, "bool") == 0
+ && start != end)
+ {
+ gdb_xml_error (parser,
+ _("Boolean fields must be one bit in size"));
+ }
+
+ if (end >= 64)
+ gdb_xml_error (parser,
+ _("Bitfield \"%s\" goes past "
+ "64 bits (unsupported)"),
+ field_name);
+
+ /* Assume that the bit numbering in XML is "lsb-zero". Most
+ architectures other than PowerPC use this ordering. In the
+ future, we can add an XML tag to indicate "msb-zero" numbering. */
+ if (start > end)
+ gdb_xml_error (parser, _("Bitfield \"%s\" has start after end"),
+ field_name);
+ if (end >= data->current_type_size * TARGET_CHAR_BIT)
+ gdb_xml_error (parser, _("Bitfield \"%s\" does not fit in struct"),
+ field_name);
+
+ if (field_type != NULL)
+ tdesc_add_typed_bitfield (t, field_name, start, end, field_type);
+ else if (start == end)
+ tdesc_add_flag (t, start, field_name);
+ else
+ tdesc_add_bitfield (t, field_name, start, end);
+ }
+ else if (start == -1 && end != -1)
+ gdb_xml_error (parser, _("End specified but not start"));
+ else if (field_type_id != NULL)
+ {
+ /* TDESC_TYPE_FLAGS values are explicitly sized, so the following test
+ catches adding non-bitfield types to flags as well. */
+ if (data->current_type_size != 0)
+ gdb_xml_error (parser,
+ _("Explicitly sized type cannot "
+ "contain non-bitfield \"%s\""),
+ field_name);
+
+ if (field_type == NULL)
+ gdb_xml_error (parser, _("Field \"%s\" references undefined "
+ "type \"%s\""),
+ field_name, field_type_id);
+
+ tdesc_add_field (data->current_type, field_name, field_type);
+ }
+ else
+ gdb_xml_error (parser, _("Field \"%s\" has neither type nor bit position"),
+ field_name);
+}
+
+/* Handle the start of an <evalue> element. Attach the value to the
+ current enum. */
+
+static void
+tdesc_start_enum_value (struct gdb_xml_parser *parser,
+ const struct gdb_xml_element *element,
+ void *user_data, std::vector<gdb_xml_value> &attributes)
+{
+ struct tdesc_parsing_data *data = (struct tdesc_parsing_data *) user_data;
+ struct gdb_xml_value *attr;
+ char *field_name;
+ ULONGEST ul_value;
+ int value;
+
+ field_name = (char *) xml_find_attribute (attributes, "name")->value.get ();
+
+ attr = xml_find_attribute (attributes, "value");
+ ul_value = * (ULONGEST *) attr->value.get ();
+ if (ul_value > INT_MAX)
+ {
+ gdb_xml_error (parser,
+ _("Enum value %s is larger than maximum (%d)"),
+ pulongest (ul_value), INT_MAX);
+ }
+ value = ul_value;
+
+ tdesc_add_enum_value (data->current_type, value, field_name);