1 /* Target description support for GDB.
3 Copyright (C) 2006-2016 Free Software Foundation, Inc.
5 Contributed by CodeSourcery.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "arch-utils.h"
26 #include "reggroups.h"
28 #include "target-descriptions.h"
30 #include "xml-support.h"
31 #include "xml-tdesc.h"
34 #include "gdb_obstack.h"
40 typedef struct property
45 DEF_VEC_O(property_s);
47 /* An individual register from a target description. */
49 typedef struct tdesc_reg
51 /* The name of this register. In standard features, it may be
52 recognized by the architecture support code, or it may be purely
56 /* The register number used by this target to refer to this
57 register. This is used for remote p/P packets and to determine
58 the ordering of registers in the remote g/G packets. */
61 /* If this flag is set, GDB should save and restore this register
62 around calls to an inferior function. */
65 /* The name of the register group containing this register, or NULL
66 if the group should be automatically determined from the
67 register's type. If this is "general", "float", or "vector", the
68 corresponding "info" command should display this register's
69 value. It can be an arbitrary string, but should be limited to
70 alphanumeric characters and internal hyphens. Currently other
71 strings are ignored (treated as NULL). */
74 /* The size of the register, in bits. */
77 /* The type of the register. This string corresponds to either
78 a named type from the target description or a predefined
82 /* The target-described type corresponding to TYPE, if found. */
83 struct tdesc_type *tdesc_type;
85 DEF_VEC_P(tdesc_reg_p);
87 /* A named type from a target description. */
89 typedef struct tdesc_type_field
92 struct tdesc_type *type;
93 /* For non-enum-values, either both are -1 (non-bitfield), or both are
94 not -1 (bitfield). For enum values, start is the value (which could be
98 DEF_VEC_O(tdesc_type_field);
102 /* Predefined types. */
116 TDESC_TYPE_IEEE_SINGLE,
117 TDESC_TYPE_IEEE_DOUBLE,
118 TDESC_TYPE_ARM_FPA_EXT,
121 /* Types defined by a target feature. */
129 typedef struct tdesc_type
131 /* The name of this type. */
134 /* Identify the kind of this type. */
135 enum tdesc_type_kind kind;
137 /* Kind-specific data. */
143 struct tdesc_type *type;
147 /* Struct, union, flags, or enum type. */
150 VEC(tdesc_type_field) *fields;
155 DEF_VEC_P(tdesc_type_p);
157 /* A feature from a target description. Each feature is a collection
158 of other elements, e.g. registers and types. */
160 typedef struct tdesc_feature
162 /* The name of this feature. It may be recognized by the architecture
166 /* The registers associated with this feature. */
167 VEC(tdesc_reg_p) *registers;
169 /* The types associated with this feature. */
170 VEC(tdesc_type_p) *types;
172 DEF_VEC_P(tdesc_feature_p);
174 /* A compatible architecture from a target description. */
175 typedef const struct bfd_arch_info *arch_p;
178 /* A target description. */
182 /* The architecture reported by the target, if any. */
183 const struct bfd_arch_info *arch;
185 /* The osabi reported by the target, if any; GDB_OSABI_UNKNOWN
187 enum gdb_osabi osabi;
189 /* The list of compatible architectures reported by the target. */
190 VEC(arch_p) *compatible;
192 /* Any architecture-specific properties specified by the target. */
193 VEC(property_s) *properties;
195 /* The features associated with this target. */
196 VEC(tdesc_feature_p) *features;
199 /* Per-architecture data associated with a target description. The
200 target description may be shared by multiple architectures, but
201 this data is private to one gdbarch. */
203 typedef struct tdesc_arch_reg
205 struct tdesc_reg *reg;
208 DEF_VEC_O(tdesc_arch_reg);
210 struct tdesc_arch_data
212 /* A list of register/type pairs, indexed by GDB's internal register number.
213 During initialization of the gdbarch this list is used to store
214 registers which the architecture assigns a fixed register number.
215 Registers which are NULL in this array, or off the end, are
216 treated as zero-sized and nameless (i.e. placeholders in the
218 VEC(tdesc_arch_reg) *arch_regs;
220 /* Functions which report the register name, type, and reggroups for
222 gdbarch_register_name_ftype *pseudo_register_name;
223 gdbarch_register_type_ftype *pseudo_register_type;
224 gdbarch_register_reggroup_p_ftype *pseudo_register_reggroup_p;
227 /* Info about an inferior's target description. There's one of these
228 for each inferior. */
230 struct target_desc_info
232 /* A flag indicating that a description has already been fetched
233 from the target, so it should not be queried again. */
237 /* The description fetched from the target, or NULL if the target
238 did not supply any description. Only valid when
239 target_desc_fetched is set. Only the description initialization
240 code should access this; normally, the description should be
241 accessed through the gdbarch object. */
243 const struct target_desc *tdesc;
245 /* The filename to read a target description from, as set by "set
246 tdesc filename ..." */
251 /* Get the inferior INF's target description info, allocating one on
252 the stop if necessary. */
254 static struct target_desc_info *
255 get_tdesc_info (struct inferior *inf)
257 if (inf->tdesc_info == NULL)
258 inf->tdesc_info = XCNEW (struct target_desc_info);
259 return inf->tdesc_info;
262 /* A handle for architecture-specific data associated with the
263 target description (see struct tdesc_arch_data). */
265 static struct gdbarch_data *tdesc_data;
267 /* See target-descriptions.h. */
270 target_desc_info_from_user_p (struct target_desc_info *info)
272 return info != NULL && info->filename != NULL;
275 /* See target-descriptions.h. */
278 copy_inferior_target_desc_info (struct inferior *destinf, struct inferior *srcinf)
280 struct target_desc_info *src = get_tdesc_info (srcinf);
281 struct target_desc_info *dest = get_tdesc_info (destinf);
283 dest->fetched = src->fetched;
284 dest->tdesc = src->tdesc;
285 dest->filename = src->filename != NULL ? xstrdup (src->filename) : NULL;
288 /* See target-descriptions.h. */
291 target_desc_info_free (struct target_desc_info *tdesc_info)
293 if (tdesc_info != NULL)
295 xfree (tdesc_info->filename);
300 /* Convenience helper macros. */
302 #define target_desc_fetched \
303 get_tdesc_info (current_inferior ())->fetched
304 #define current_target_desc \
305 get_tdesc_info (current_inferior ())->tdesc
306 #define target_description_filename \
307 get_tdesc_info (current_inferior ())->filename
309 /* The string manipulated by the "set tdesc filename ..." command. */
311 static char *tdesc_filename_cmd_string;
313 /* Fetch the current target's description, and switch the current
314 architecture to one which incorporates that description. */
317 target_find_description (void)
319 /* If we've already fetched a description from the target, don't do
320 it again. This allows a target to fetch the description early,
321 during its to_open or to_create_inferior, if it needs extra
322 information about the target to initialize. */
323 if (target_desc_fetched)
326 /* The current architecture should not have any target description
327 specified. It should have been cleared, e.g. when we
328 disconnected from the previous target. */
329 gdb_assert (gdbarch_target_desc (target_gdbarch ()) == NULL);
331 /* First try to fetch an XML description from the user-specified
333 current_target_desc = NULL;
334 if (target_description_filename != NULL
335 && *target_description_filename != '\0')
337 = file_read_description_xml (target_description_filename);
339 /* Next try to read the description from the current target using
341 if (current_target_desc == NULL)
342 current_target_desc = target_read_description_xml (¤t_target);
344 /* If that failed try a target-specific hook. */
345 if (current_target_desc == NULL)
346 current_target_desc = target_read_description (¤t_target);
348 /* If a non-NULL description was returned, then update the current
350 if (current_target_desc)
352 struct gdbarch_info info;
354 gdbarch_info_init (&info);
355 info.target_desc = current_target_desc;
356 if (!gdbarch_update_p (info))
357 warning (_("Architecture rejected target-supplied description"));
360 struct tdesc_arch_data *data;
362 data = ((struct tdesc_arch_data *)
363 gdbarch_data (target_gdbarch (), tdesc_data));
364 if (tdesc_has_registers (current_target_desc)
365 && data->arch_regs == NULL)
366 warning (_("Target-supplied registers are not supported "
367 "by the current architecture"));
371 /* Now that we know this description is usable, record that we
373 target_desc_fetched = 1;
376 /* Discard any description fetched from the current target, and switch
377 the current architecture to one with no target description. */
380 target_clear_description (void)
382 struct gdbarch_info info;
384 if (!target_desc_fetched)
387 target_desc_fetched = 0;
388 current_target_desc = NULL;
390 gdbarch_info_init (&info);
391 if (!gdbarch_update_p (info))
392 internal_error (__FILE__, __LINE__,
393 _("Could not remove target-supplied description"));
396 /* Return the global current target description. This should only be
397 used by gdbarch initialization code; most access should be through
398 an existing gdbarch. */
400 const struct target_desc *
401 target_current_description (void)
403 if (target_desc_fetched)
404 return current_target_desc;
409 /* Return non-zero if this target description is compatible
410 with the given BFD architecture. */
413 tdesc_compatible_p (const struct target_desc *target_desc,
414 const struct bfd_arch_info *arch)
416 const struct bfd_arch_info *compat;
419 for (ix = 0; VEC_iterate (arch_p, target_desc->compatible, ix, compat);
423 || arch->compatible (arch, compat)
424 || compat->compatible (compat, arch))
432 /* Direct accessors for target descriptions. */
434 /* Return the string value of a property named KEY, or NULL if the
435 property was not specified. */
438 tdesc_property (const struct target_desc *target_desc, const char *key)
440 struct property *prop;
443 for (ix = 0; VEC_iterate (property_s, target_desc->properties, ix, prop);
445 if (strcmp (prop->key, key) == 0)
451 /* Return the BFD architecture associated with this target
452 description, or NULL if no architecture was specified. */
454 const struct bfd_arch_info *
455 tdesc_architecture (const struct target_desc *target_desc)
457 return target_desc->arch;
460 /* Return the OSABI associated with this target description, or
461 GDB_OSABI_UNKNOWN if no osabi was specified. */
464 tdesc_osabi (const struct target_desc *target_desc)
466 return target_desc->osabi;
471 /* Return 1 if this target description includes any registers. */
474 tdesc_has_registers (const struct target_desc *target_desc)
477 struct tdesc_feature *feature;
479 if (target_desc == NULL)
483 VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature);
485 if (! VEC_empty (tdesc_reg_p, feature->registers))
491 /* Return the feature with the given name, if present, or NULL if
492 the named feature is not found. */
494 const struct tdesc_feature *
495 tdesc_find_feature (const struct target_desc *target_desc,
499 struct tdesc_feature *feature;
502 VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature);
504 if (strcmp (feature->name, name) == 0)
510 /* Return the name of FEATURE. */
513 tdesc_feature_name (const struct tdesc_feature *feature)
515 return feature->name;
518 /* Predefined types. */
519 static struct tdesc_type tdesc_predefined_types[] =
521 { "bool", TDESC_TYPE_BOOL },
522 { "int8", TDESC_TYPE_INT8 },
523 { "int16", TDESC_TYPE_INT16 },
524 { "int32", TDESC_TYPE_INT32 },
525 { "int64", TDESC_TYPE_INT64 },
526 { "int128", TDESC_TYPE_INT128 },
527 { "uint8", TDESC_TYPE_UINT8 },
528 { "uint16", TDESC_TYPE_UINT16 },
529 { "uint32", TDESC_TYPE_UINT32 },
530 { "uint64", TDESC_TYPE_UINT64 },
531 { "uint128", TDESC_TYPE_UINT128 },
532 { "code_ptr", TDESC_TYPE_CODE_PTR },
533 { "data_ptr", TDESC_TYPE_DATA_PTR },
534 { "ieee_single", TDESC_TYPE_IEEE_SINGLE },
535 { "ieee_double", TDESC_TYPE_IEEE_DOUBLE },
536 { "arm_fpa_ext", TDESC_TYPE_ARM_FPA_EXT },
537 { "i387_ext", TDESC_TYPE_I387_EXT }
540 /* Lookup a predefined type. */
542 static struct tdesc_type *
543 tdesc_predefined_type (enum tdesc_type_kind kind)
546 struct tdesc_type *type;
548 for (ix = 0; ix < ARRAY_SIZE (tdesc_predefined_types); ix++)
549 if (tdesc_predefined_types[ix].kind == kind)
550 return &tdesc_predefined_types[ix];
552 gdb_assert_not_reached ("bad predefined tdesc type");
555 /* Return the type associated with ID in the context of FEATURE, or
559 tdesc_named_type (const struct tdesc_feature *feature, const char *id)
562 struct tdesc_type *type;
564 /* First try target-defined types. */
565 for (ix = 0; VEC_iterate (tdesc_type_p, feature->types, ix, type); ix++)
566 if (strcmp (type->name, id) == 0)
569 /* Next try the predefined types. */
570 for (ix = 0; ix < ARRAY_SIZE (tdesc_predefined_types); ix++)
571 if (strcmp (tdesc_predefined_types[ix].name, id) == 0)
572 return &tdesc_predefined_types[ix];
577 /* Lookup type associated with ID. */
580 tdesc_find_type (struct gdbarch *gdbarch, const char *id)
582 struct tdesc_arch_reg *reg;
583 struct tdesc_arch_data *data;
586 data = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
587 num_regs = VEC_length (tdesc_arch_reg, data->arch_regs);
588 for (i = 0; i < num_regs; i++)
590 reg = VEC_index (tdesc_arch_reg, data->arch_regs, i);
592 && reg->reg->tdesc_type
594 && strcmp (id, reg->reg->tdesc_type->name) == 0)
601 /* Construct, if necessary, and return the GDB type implementing target
602 type TDESC_TYPE for architecture GDBARCH. */
605 tdesc_gdb_type (struct gdbarch *gdbarch, struct tdesc_type *tdesc_type)
609 switch (tdesc_type->kind)
611 /* Predefined types. */
612 case TDESC_TYPE_BOOL:
613 return builtin_type (gdbarch)->builtin_bool;
615 case TDESC_TYPE_INT8:
616 return builtin_type (gdbarch)->builtin_int8;
618 case TDESC_TYPE_INT16:
619 return builtin_type (gdbarch)->builtin_int16;
621 case TDESC_TYPE_INT32:
622 return builtin_type (gdbarch)->builtin_int32;
624 case TDESC_TYPE_INT64:
625 return builtin_type (gdbarch)->builtin_int64;
627 case TDESC_TYPE_INT128:
628 return builtin_type (gdbarch)->builtin_int128;
630 case TDESC_TYPE_UINT8:
631 return builtin_type (gdbarch)->builtin_uint8;
633 case TDESC_TYPE_UINT16:
634 return builtin_type (gdbarch)->builtin_uint16;
636 case TDESC_TYPE_UINT32:
637 return builtin_type (gdbarch)->builtin_uint32;
639 case TDESC_TYPE_UINT64:
640 return builtin_type (gdbarch)->builtin_uint64;
642 case TDESC_TYPE_UINT128:
643 return builtin_type (gdbarch)->builtin_uint128;
645 case TDESC_TYPE_CODE_PTR:
646 return builtin_type (gdbarch)->builtin_func_ptr;
648 case TDESC_TYPE_DATA_PTR:
649 return builtin_type (gdbarch)->builtin_data_ptr;
655 type = tdesc_find_type (gdbarch, tdesc_type->name);
659 switch (tdesc_type->kind)
661 case TDESC_TYPE_IEEE_SINGLE:
662 return arch_float_type (gdbarch, -1, "builtin_type_ieee_single",
663 floatformats_ieee_single);
665 case TDESC_TYPE_IEEE_DOUBLE:
666 return arch_float_type (gdbarch, -1, "builtin_type_ieee_double",
667 floatformats_ieee_double);
669 case TDESC_TYPE_ARM_FPA_EXT:
670 return arch_float_type (gdbarch, -1, "builtin_type_arm_ext",
671 floatformats_arm_ext);
673 case TDESC_TYPE_I387_EXT:
674 return arch_float_type (gdbarch, -1, "builtin_type_i387_ext",
675 floatformats_i387_ext);
677 /* Types defined by a target feature. */
678 case TDESC_TYPE_VECTOR:
680 struct type *type, *field_type;
682 field_type = tdesc_gdb_type (gdbarch, tdesc_type->u.v.type);
683 type = init_vector_type (field_type, tdesc_type->u.v.count);
684 TYPE_NAME (type) = xstrdup (tdesc_type->name);
689 case TDESC_TYPE_STRUCT:
691 struct type *type, *field_type;
692 struct tdesc_type_field *f;
695 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
696 TYPE_NAME (type) = xstrdup (tdesc_type->name);
697 TYPE_TAG_NAME (type) = TYPE_NAME (type);
700 VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f);
703 if (f->start != -1 && f->end != -1)
707 struct type *field_type;
708 int bitsize, total_size;
710 /* This invariant should be preserved while creating types. */
711 gdb_assert (tdesc_type->u.u.size != 0);
713 field_type = tdesc_gdb_type (gdbarch, f->type);
714 else if (tdesc_type->u.u.size > 4)
715 field_type = builtin_type (gdbarch)->builtin_uint64;
717 field_type = builtin_type (gdbarch)->builtin_uint32;
719 fld = append_composite_type_field_raw (type, xstrdup (f->name),
722 /* For little-endian, BITPOS counts from the LSB of
723 the structure and marks the LSB of the field. For
724 big-endian, BITPOS counts from the MSB of the
725 structure and marks the MSB of the field. Either
726 way, it is the number of bits to the "left" of the
727 field. To calculate this in big-endian, we need
728 the total size of the structure. */
729 bitsize = f->end - f->start + 1;
730 total_size = tdesc_type->u.u.size * TARGET_CHAR_BIT;
731 if (gdbarch_bits_big_endian (gdbarch))
732 SET_FIELD_BITPOS (fld[0], total_size - f->start - bitsize);
734 SET_FIELD_BITPOS (fld[0], f->start);
735 FIELD_BITSIZE (fld[0]) = bitsize;
739 gdb_assert (f->start == -1 && f->end == -1);
740 field_type = tdesc_gdb_type (gdbarch, f->type);
741 append_composite_type_field (type, xstrdup (f->name),
746 if (tdesc_type->u.u.size != 0)
747 TYPE_LENGTH (type) = tdesc_type->u.u.size;
751 case TDESC_TYPE_UNION:
753 struct type *type, *field_type;
754 struct tdesc_type_field *f;
757 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
758 TYPE_NAME (type) = xstrdup (tdesc_type->name);
761 VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f);
764 field_type = tdesc_gdb_type (gdbarch, f->type);
765 append_composite_type_field (type, xstrdup (f->name), field_type);
767 /* If any of the children of a union are vectors, flag the
768 union as a vector also. This allows e.g. a union of two
769 vector types to show up automatically in "info vector". */
770 if (TYPE_VECTOR (field_type))
771 TYPE_VECTOR (type) = 1;
776 case TDESC_TYPE_FLAGS:
778 struct tdesc_type_field *f;
781 type = arch_flags_type (gdbarch, tdesc_type->name,
782 tdesc_type->u.u.size);
784 VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f);
787 struct type *field_type;
788 int bitsize = f->end - f->start + 1;
790 gdb_assert (f->type != NULL);
791 field_type = tdesc_gdb_type (gdbarch, f->type);
792 append_flags_type_field (type, f->start, bitsize,
793 field_type, f->name);
799 case TDESC_TYPE_ENUM:
801 struct tdesc_type_field *f;
804 type = arch_type (gdbarch, TYPE_CODE_ENUM,
805 tdesc_type->u.u.size, tdesc_type->name);
806 TYPE_UNSIGNED (type) = 1;
808 VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f);
812 = append_composite_type_field_raw (type, xstrdup (f->name),
815 SET_FIELD_BITPOS (fld[0], f->start);
822 internal_error (__FILE__, __LINE__,
823 "Type \"%s\" has an unknown kind %d",
824 tdesc_type->name, tdesc_type->kind);
828 /* Support for registers from target descriptions. */
830 /* Construct the per-gdbarch data. */
833 tdesc_data_init (struct obstack *obstack)
835 struct tdesc_arch_data *data;
837 data = OBSTACK_ZALLOC (obstack, struct tdesc_arch_data);
841 /* Similar, but for the temporary copy used during architecture
844 struct tdesc_arch_data *
845 tdesc_data_alloc (void)
847 return XCNEW (struct tdesc_arch_data);
850 /* Free something allocated by tdesc_data_alloc, if it is not going
851 to be used (for instance if it was unsuitable for the
855 tdesc_data_cleanup (void *data_untyped)
857 struct tdesc_arch_data *data = (struct tdesc_arch_data *) data_untyped;
859 VEC_free (tdesc_arch_reg, data->arch_regs);
863 /* Search FEATURE for a register named NAME. */
865 static struct tdesc_reg *
866 tdesc_find_register_early (const struct tdesc_feature *feature,
870 struct tdesc_reg *reg;
873 VEC_iterate (tdesc_reg_p, feature->registers, ixr, reg);
875 if (strcasecmp (reg->name, name) == 0)
881 /* Search FEATURE for a register named NAME. Assign REGNO to it. */
884 tdesc_numbered_register (const struct tdesc_feature *feature,
885 struct tdesc_arch_data *data,
886 int regno, const char *name)
888 struct tdesc_arch_reg arch_reg = { 0 };
889 struct tdesc_reg *reg = tdesc_find_register_early (feature, name);
894 /* Make sure the vector includes a REGNO'th element. */
895 while (regno >= VEC_length (tdesc_arch_reg, data->arch_regs))
896 VEC_safe_push (tdesc_arch_reg, data->arch_regs, &arch_reg);
899 VEC_replace (tdesc_arch_reg, data->arch_regs, regno, &arch_reg);
903 /* Search FEATURE for a register named NAME, but do not assign a fixed
904 register number to it. */
907 tdesc_unnumbered_register (const struct tdesc_feature *feature,
910 struct tdesc_reg *reg = tdesc_find_register_early (feature, name);
918 /* Search FEATURE for a register whose name is in NAMES and assign
922 tdesc_numbered_register_choices (const struct tdesc_feature *feature,
923 struct tdesc_arch_data *data,
924 int regno, const char *const names[])
928 for (i = 0; names[i] != NULL; i++)
929 if (tdesc_numbered_register (feature, data, regno, names[i]))
935 /* Search FEATURE for a register named NAME, and return its size in
936 bits. The register must exist. */
939 tdesc_register_size (const struct tdesc_feature *feature,
942 struct tdesc_reg *reg = tdesc_find_register_early (feature, name);
944 gdb_assert (reg != NULL);
948 /* Look up a register by its GDB internal register number. */
950 static struct tdesc_arch_reg *
951 tdesc_find_arch_register (struct gdbarch *gdbarch, int regno)
953 struct tdesc_arch_data *data;
955 data = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
956 if (regno < VEC_length (tdesc_arch_reg, data->arch_regs))
957 return VEC_index (tdesc_arch_reg, data->arch_regs, regno);
962 static struct tdesc_reg *
963 tdesc_find_register (struct gdbarch *gdbarch, int regno)
965 struct tdesc_arch_reg *reg = tdesc_find_arch_register (gdbarch, regno);
967 return reg? reg->reg : NULL;
970 /* Return the name of register REGNO, from the target description or
971 from an architecture-provided pseudo_register_name method. */
974 tdesc_register_name (struct gdbarch *gdbarch, int regno)
976 struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno);
977 int num_regs = gdbarch_num_regs (gdbarch);
978 int num_pseudo_regs = gdbarch_num_pseudo_regs (gdbarch);
983 if (regno >= num_regs && regno < num_regs + num_pseudo_regs)
985 struct tdesc_arch_data *data
986 = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
988 gdb_assert (data->pseudo_register_name != NULL);
989 return data->pseudo_register_name (gdbarch, regno);
996 tdesc_register_type (struct gdbarch *gdbarch, int regno)
998 struct tdesc_arch_reg *arch_reg = tdesc_find_arch_register (gdbarch, regno);
999 struct tdesc_reg *reg = arch_reg? arch_reg->reg : NULL;
1000 int num_regs = gdbarch_num_regs (gdbarch);
1001 int num_pseudo_regs = gdbarch_num_pseudo_regs (gdbarch);
1003 if (reg == NULL && regno >= num_regs && regno < num_regs + num_pseudo_regs)
1005 struct tdesc_arch_data *data
1006 = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
1008 gdb_assert (data->pseudo_register_type != NULL);
1009 return data->pseudo_register_type (gdbarch, regno);
1013 /* Return "int0_t", since "void" has a misleading size of one. */
1014 return builtin_type (gdbarch)->builtin_int0;
1016 if (arch_reg->type == NULL)
1018 /* First check for a predefined or target defined type. */
1019 if (reg->tdesc_type)
1020 arch_reg->type = tdesc_gdb_type (gdbarch, reg->tdesc_type);
1022 /* Next try size-sensitive type shortcuts. */
1023 else if (strcmp (reg->type, "float") == 0)
1025 if (reg->bitsize == gdbarch_float_bit (gdbarch))
1026 arch_reg->type = builtin_type (gdbarch)->builtin_float;
1027 else if (reg->bitsize == gdbarch_double_bit (gdbarch))
1028 arch_reg->type = builtin_type (gdbarch)->builtin_double;
1029 else if (reg->bitsize == gdbarch_long_double_bit (gdbarch))
1030 arch_reg->type = builtin_type (gdbarch)->builtin_long_double;
1033 warning (_("Register \"%s\" has an unsupported size (%d bits)"),
1034 reg->name, reg->bitsize);
1035 arch_reg->type = builtin_type (gdbarch)->builtin_double;
1038 else if (strcmp (reg->type, "int") == 0)
1040 if (reg->bitsize == gdbarch_long_bit (gdbarch))
1041 arch_reg->type = builtin_type (gdbarch)->builtin_long;
1042 else if (reg->bitsize == TARGET_CHAR_BIT)
1043 arch_reg->type = builtin_type (gdbarch)->builtin_char;
1044 else if (reg->bitsize == gdbarch_short_bit (gdbarch))
1045 arch_reg->type = builtin_type (gdbarch)->builtin_short;
1046 else if (reg->bitsize == gdbarch_int_bit (gdbarch))
1047 arch_reg->type = builtin_type (gdbarch)->builtin_int;
1048 else if (reg->bitsize == gdbarch_long_long_bit (gdbarch))
1049 arch_reg->type = builtin_type (gdbarch)->builtin_long_long;
1050 else if (reg->bitsize == gdbarch_ptr_bit (gdbarch))
1051 /* A bit desperate by this point... */
1052 arch_reg->type = builtin_type (gdbarch)->builtin_data_ptr;
1055 warning (_("Register \"%s\" has an unsupported size (%d bits)"),
1056 reg->name, reg->bitsize);
1057 arch_reg->type = builtin_type (gdbarch)->builtin_long;
1061 if (arch_reg->type == NULL)
1062 internal_error (__FILE__, __LINE__,
1063 "Register \"%s\" has an unknown type \"%s\"",
1064 reg->name, reg->type);
1067 return arch_reg->type;
1071 tdesc_remote_register_number (struct gdbarch *gdbarch, int regno)
1073 struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno);
1076 return reg->target_regnum;
1081 /* Check whether REGNUM is a member of REGGROUP. Registers from the
1082 target description may be classified as general, float, or vector.
1083 Unlike a gdbarch register_reggroup_p method, this function will
1084 return -1 if it does not know; the caller should handle registers
1085 with no specified group.
1087 Arbitrary strings (other than "general", "float", and "vector")
1088 from the description are not used; they cause the register to be
1089 displayed in "info all-registers" but excluded from "info
1090 registers" et al. The names of containing features are also not
1091 used. This might be extended to display registers in some more
1094 The save-restore flag is also implemented here. */
1097 tdesc_register_in_reggroup_p (struct gdbarch *gdbarch, int regno,
1098 struct reggroup *reggroup)
1100 struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno);
1102 if (reg != NULL && reg->group != NULL)
1104 int general_p = 0, float_p = 0, vector_p = 0;
1106 if (strcmp (reg->group, "general") == 0)
1108 else if (strcmp (reg->group, "float") == 0)
1110 else if (strcmp (reg->group, "vector") == 0)
1113 if (reggroup == float_reggroup)
1116 if (reggroup == vector_reggroup)
1119 if (reggroup == general_reggroup)
1124 && (reggroup == save_reggroup || reggroup == restore_reggroup))
1125 return reg->save_restore;
1130 /* Check whether REGNUM is a member of REGGROUP. Registers with no
1131 group specified go to the default reggroup function and are handled
1135 tdesc_register_reggroup_p (struct gdbarch *gdbarch, int regno,
1136 struct reggroup *reggroup)
1138 int num_regs = gdbarch_num_regs (gdbarch);
1139 int num_pseudo_regs = gdbarch_num_pseudo_regs (gdbarch);
1142 if (regno >= num_regs && regno < num_regs + num_pseudo_regs)
1144 struct tdesc_arch_data *data
1145 = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
1147 if (data->pseudo_register_reggroup_p != NULL)
1148 return data->pseudo_register_reggroup_p (gdbarch, regno, reggroup);
1149 /* Otherwise fall through to the default reggroup_p. */
1152 ret = tdesc_register_in_reggroup_p (gdbarch, regno, reggroup);
1156 return default_register_reggroup_p (gdbarch, regno, reggroup);
1159 /* Record architecture-specific functions to call for pseudo-register
1163 set_tdesc_pseudo_register_name (struct gdbarch *gdbarch,
1164 gdbarch_register_name_ftype *pseudo_name)
1166 struct tdesc_arch_data *data
1167 = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
1169 data->pseudo_register_name = pseudo_name;
1173 set_tdesc_pseudo_register_type (struct gdbarch *gdbarch,
1174 gdbarch_register_type_ftype *pseudo_type)
1176 struct tdesc_arch_data *data
1177 = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
1179 data->pseudo_register_type = pseudo_type;
1183 set_tdesc_pseudo_register_reggroup_p
1184 (struct gdbarch *gdbarch,
1185 gdbarch_register_reggroup_p_ftype *pseudo_reggroup_p)
1187 struct tdesc_arch_data *data
1188 = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
1190 data->pseudo_register_reggroup_p = pseudo_reggroup_p;
1193 /* Update GDBARCH to use the target description for registers. */
1196 tdesc_use_registers (struct gdbarch *gdbarch,
1197 const struct target_desc *target_desc,
1198 struct tdesc_arch_data *early_data)
1200 int num_regs = gdbarch_num_regs (gdbarch);
1202 struct tdesc_feature *feature;
1203 struct tdesc_reg *reg;
1204 struct tdesc_arch_data *data;
1205 struct tdesc_arch_reg *arch_reg, new_arch_reg = { 0 };
1208 /* We can't use the description for registers if it doesn't describe
1209 any. This function should only be called after validating
1210 registers, so the caller should know that registers are
1212 gdb_assert (tdesc_has_registers (target_desc));
1214 data = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
1215 data->arch_regs = early_data->arch_regs;
1218 /* Build up a set of all registers, so that we can assign register
1219 numbers where needed. The hash table expands as necessary, so
1220 the initial size is arbitrary. */
1221 reg_hash = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
1223 VEC_iterate (tdesc_feature_p, target_desc->features, ixf, feature);
1226 VEC_iterate (tdesc_reg_p, feature->registers, ixr, reg);
1229 void **slot = htab_find_slot (reg_hash, reg, INSERT);
1234 /* Remove any registers which were assigned numbers by the
1237 VEC_iterate (tdesc_arch_reg, data->arch_regs, ixr, arch_reg);
1240 htab_remove_elt (reg_hash, arch_reg->reg);
1242 /* Assign numbers to the remaining registers and add them to the
1243 list of registers. The new numbers are always above gdbarch_num_regs.
1244 Iterate over the features, not the hash table, so that the order
1245 matches that in the target description. */
1247 gdb_assert (VEC_length (tdesc_arch_reg, data->arch_regs) <= num_regs);
1248 while (VEC_length (tdesc_arch_reg, data->arch_regs) < num_regs)
1249 VEC_safe_push (tdesc_arch_reg, data->arch_regs, &new_arch_reg);
1251 VEC_iterate (tdesc_feature_p, target_desc->features, ixf, feature);
1254 VEC_iterate (tdesc_reg_p, feature->registers, ixr, reg);
1256 if (htab_find (reg_hash, reg) != NULL)
1258 new_arch_reg.reg = reg;
1259 VEC_safe_push (tdesc_arch_reg, data->arch_regs, &new_arch_reg);
1263 htab_delete (reg_hash);
1265 /* Update the architecture. */
1266 set_gdbarch_num_regs (gdbarch, num_regs);
1267 set_gdbarch_register_name (gdbarch, tdesc_register_name);
1268 set_gdbarch_register_type (gdbarch, tdesc_register_type);
1269 set_gdbarch_remote_register_number (gdbarch,
1270 tdesc_remote_register_number);
1271 set_gdbarch_register_reggroup_p (gdbarch, tdesc_register_reggroup_p);
1275 /* Methods for constructing a target description. */
1278 tdesc_free_reg (struct tdesc_reg *reg)
1287 tdesc_create_reg (struct tdesc_feature *feature, const char *name,
1288 int regnum, int save_restore, const char *group,
1289 int bitsize, const char *type)
1291 struct tdesc_reg *reg = XCNEW (struct tdesc_reg);
1293 reg->name = xstrdup (name);
1294 reg->target_regnum = regnum;
1295 reg->save_restore = save_restore;
1296 reg->group = group ? xstrdup (group) : NULL;
1297 reg->bitsize = bitsize;
1298 reg->type = type ? xstrdup (type) : xstrdup ("<unknown>");
1300 /* If the register's type is target-defined, look it up now. We may not
1301 have easy access to the containing feature when we want it later. */
1302 reg->tdesc_type = tdesc_named_type (feature, reg->type);
1304 VEC_safe_push (tdesc_reg_p, feature->registers, reg);
1307 /* Subroutine of tdesc_free_feature to simplify it.
1308 Note: We do not want to free any referenced types here (e.g., types of
1309 fields of a struct). All types of a feature are recorded in
1310 feature->types and are freed that way. */
1313 tdesc_free_type (struct tdesc_type *type)
1317 case TDESC_TYPE_STRUCT:
1318 case TDESC_TYPE_UNION:
1319 case TDESC_TYPE_FLAGS:
1320 case TDESC_TYPE_ENUM:
1322 struct tdesc_type_field *f;
1326 VEC_iterate (tdesc_type_field, type->u.u.fields, ix, f);
1330 VEC_free (tdesc_type_field, type->u.u.fields);
1343 tdesc_create_vector (struct tdesc_feature *feature, const char *name,
1344 struct tdesc_type *field_type, int count)
1346 struct tdesc_type *type = XCNEW (struct tdesc_type);
1348 type->name = xstrdup (name);
1349 type->kind = TDESC_TYPE_VECTOR;
1350 type->u.v.type = field_type;
1351 type->u.v.count = count;
1353 VEC_safe_push (tdesc_type_p, feature->types, type);
1358 tdesc_create_struct (struct tdesc_feature *feature, const char *name)
1360 struct tdesc_type *type = XCNEW (struct tdesc_type);
1362 type->name = xstrdup (name);
1363 type->kind = TDESC_TYPE_STRUCT;
1365 VEC_safe_push (tdesc_type_p, feature->types, type);
1369 /* Set the total length of TYPE. Structs which contain bitfields may
1370 omit the reserved bits, so the end of the last field may not
1374 tdesc_set_struct_size (struct tdesc_type *type, int size)
1376 gdb_assert (type->kind == TDESC_TYPE_STRUCT);
1377 gdb_assert (size > 0);
1378 type->u.u.size = size;
1382 tdesc_create_union (struct tdesc_feature *feature, const char *name)
1384 struct tdesc_type *type = XCNEW (struct tdesc_type);
1386 type->name = xstrdup (name);
1387 type->kind = TDESC_TYPE_UNION;
1389 VEC_safe_push (tdesc_type_p, feature->types, type);
1394 tdesc_create_flags (struct tdesc_feature *feature, const char *name,
1397 struct tdesc_type *type = XCNEW (struct tdesc_type);
1399 gdb_assert (size > 0);
1401 type->name = xstrdup (name);
1402 type->kind = TDESC_TYPE_FLAGS;
1403 type->u.u.size = size;
1405 VEC_safe_push (tdesc_type_p, feature->types, type);
1410 tdesc_create_enum (struct tdesc_feature *feature, const char *name,
1413 struct tdesc_type *type = XCNEW (struct tdesc_type);
1415 gdb_assert (size > 0);
1417 type->name = xstrdup (name);
1418 type->kind = TDESC_TYPE_ENUM;
1419 type->u.u.size = size;
1421 VEC_safe_push (tdesc_type_p, feature->types, type);
1425 /* Add a new field to TYPE. */
1428 tdesc_add_field (struct tdesc_type *type, const char *field_name,
1429 struct tdesc_type *field_type)
1431 struct tdesc_type_field f = { 0 };
1433 gdb_assert (type->kind == TDESC_TYPE_UNION
1434 || type->kind == TDESC_TYPE_STRUCT);
1436 f.name = xstrdup (field_name);
1437 f.type = field_type;
1438 /* Initialize these values so we know this is not a bit-field
1439 when we print-c-tdesc. */
1443 VEC_safe_push (tdesc_type_field, type->u.u.fields, &f);
1446 /* Add a new typed bitfield to TYPE. */
1449 tdesc_add_typed_bitfield (struct tdesc_type *type, const char *field_name,
1450 int start, int end, struct tdesc_type *field_type)
1452 struct tdesc_type_field f = { 0 };
1454 gdb_assert (type->kind == TDESC_TYPE_STRUCT
1455 || type->kind == TDESC_TYPE_FLAGS);
1456 gdb_assert (start >= 0 && end >= start);
1458 f.name = xstrdup (field_name);
1461 f.type = field_type;
1463 VEC_safe_push (tdesc_type_field, type->u.u.fields, &f);
1466 /* Add a new untyped bitfield to TYPE.
1467 Untyped bitfields become either uint32 or uint64 depending on the size
1468 of the underlying type. */
1471 tdesc_add_bitfield (struct tdesc_type *type, const char *field_name,
1474 struct tdesc_type *field_type;
1476 gdb_assert (start >= 0 && end >= start);
1478 if (type->u.u.size > 4)
1479 field_type = tdesc_predefined_type (TDESC_TYPE_UINT64);
1481 field_type = tdesc_predefined_type (TDESC_TYPE_UINT32);
1483 tdesc_add_typed_bitfield (type, field_name, start, end, field_type);
1486 /* A flag is just a typed(bool) single-bit bitfield.
1487 This function is kept to minimize changes in generated files. */
1490 tdesc_add_flag (struct tdesc_type *type, int start,
1491 const char *flag_name)
1493 struct tdesc_type_field f = { 0 };
1495 gdb_assert (type->kind == TDESC_TYPE_FLAGS
1496 || type->kind == TDESC_TYPE_STRUCT);
1498 f.name = xstrdup (flag_name);
1501 f.type = tdesc_predefined_type (TDESC_TYPE_BOOL);
1503 VEC_safe_push (tdesc_type_field, type->u.u.fields, &f);
1507 tdesc_add_enum_value (struct tdesc_type *type, int value,
1510 struct tdesc_type_field f = { 0 };
1512 gdb_assert (type->kind == TDESC_TYPE_ENUM);
1514 f.name = xstrdup (name);
1517 f.type = tdesc_predefined_type (TDESC_TYPE_INT32);
1519 VEC_safe_push (tdesc_type_field, type->u.u.fields, &f);
1523 tdesc_free_feature (struct tdesc_feature *feature)
1525 struct tdesc_reg *reg;
1526 struct tdesc_type *type;
1529 for (ix = 0; VEC_iterate (tdesc_reg_p, feature->registers, ix, reg); ix++)
1530 tdesc_free_reg (reg);
1531 VEC_free (tdesc_reg_p, feature->registers);
1533 for (ix = 0; VEC_iterate (tdesc_type_p, feature->types, ix, type); ix++)
1534 tdesc_free_type (type);
1535 VEC_free (tdesc_type_p, feature->types);
1537 xfree (feature->name);
1541 struct tdesc_feature *
1542 tdesc_create_feature (struct target_desc *tdesc, const char *name)
1544 struct tdesc_feature *new_feature = XCNEW (struct tdesc_feature);
1546 new_feature->name = xstrdup (name);
1548 VEC_safe_push (tdesc_feature_p, tdesc->features, new_feature);
1552 struct target_desc *
1553 allocate_target_description (void)
1555 return XCNEW (struct target_desc);
1559 free_target_description (void *arg)
1561 struct target_desc *target_desc = (struct target_desc *) arg;
1562 struct tdesc_feature *feature;
1563 struct property *prop;
1567 VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature);
1569 tdesc_free_feature (feature);
1570 VEC_free (tdesc_feature_p, target_desc->features);
1573 VEC_iterate (property_s, target_desc->properties, ix, prop);
1577 xfree (prop->value);
1579 VEC_free (property_s, target_desc->properties);
1581 VEC_free (arch_p, target_desc->compatible);
1583 xfree (target_desc);
1587 make_cleanup_free_target_description (struct target_desc *target_desc)
1589 return make_cleanup (free_target_description, target_desc);
1593 tdesc_add_compatible (struct target_desc *target_desc,
1594 const struct bfd_arch_info *compatible)
1596 const struct bfd_arch_info *compat;
1599 /* If this instance of GDB is compiled without BFD support for the
1600 compatible architecture, simply ignore it -- we would not be able
1601 to handle it anyway. */
1602 if (compatible == NULL)
1605 for (ix = 0; VEC_iterate (arch_p, target_desc->compatible, ix, compat);
1607 if (compat == compatible)
1608 internal_error (__FILE__, __LINE__,
1609 _("Attempted to add duplicate "
1610 "compatible architecture \"%s\""),
1611 compatible->printable_name);
1613 VEC_safe_push (arch_p, target_desc->compatible, compatible);
1617 set_tdesc_property (struct target_desc *target_desc,
1618 const char *key, const char *value)
1620 struct property *prop, new_prop;
1623 gdb_assert (key != NULL && value != NULL);
1625 for (ix = 0; VEC_iterate (property_s, target_desc->properties, ix, prop);
1627 if (strcmp (prop->key, key) == 0)
1628 internal_error (__FILE__, __LINE__,
1629 _("Attempted to add duplicate property \"%s\""), key);
1631 new_prop.key = xstrdup (key);
1632 new_prop.value = xstrdup (value);
1633 VEC_safe_push (property_s, target_desc->properties, &new_prop);
1637 set_tdesc_architecture (struct target_desc *target_desc,
1638 const struct bfd_arch_info *arch)
1640 target_desc->arch = arch;
1644 set_tdesc_osabi (struct target_desc *target_desc, enum gdb_osabi osabi)
1646 target_desc->osabi = osabi;
1650 static struct cmd_list_element *tdesc_set_cmdlist, *tdesc_show_cmdlist;
1651 static struct cmd_list_element *tdesc_unset_cmdlist;
1653 /* Helper functions for the CLI commands. */
1656 set_tdesc_cmd (char *args, int from_tty)
1658 help_list (tdesc_set_cmdlist, "set tdesc ", all_commands, gdb_stdout);
1662 show_tdesc_cmd (char *args, int from_tty)
1664 cmd_show_list (tdesc_show_cmdlist, from_tty, "");
1668 unset_tdesc_cmd (char *args, int from_tty)
1670 help_list (tdesc_unset_cmdlist, "unset tdesc ", all_commands, gdb_stdout);
1674 set_tdesc_filename_cmd (char *args, int from_tty,
1675 struct cmd_list_element *c)
1677 xfree (target_description_filename);
1678 target_description_filename = xstrdup (tdesc_filename_cmd_string);
1680 target_clear_description ();
1681 target_find_description ();
1685 show_tdesc_filename_cmd (struct ui_file *file, int from_tty,
1686 struct cmd_list_element *c,
1689 value = target_description_filename;
1691 if (value != NULL && *value != '\0')
1692 printf_filtered (_("The target description will be read from \"%s\".\n"),
1695 printf_filtered (_("The target description will be "
1696 "read from the target.\n"));
1700 unset_tdesc_filename_cmd (char *args, int from_tty)
1702 xfree (target_description_filename);
1703 target_description_filename = NULL;
1704 target_clear_description ();
1705 target_find_description ();
1709 maint_print_c_tdesc_cmd (char *args, int from_tty)
1711 const struct target_desc *tdesc;
1712 const struct bfd_arch_info *compatible;
1713 const char *filename, *inp;
1714 char *function, *outp;
1715 struct property *prop;
1716 struct tdesc_feature *feature;
1717 struct tdesc_reg *reg;
1718 struct tdesc_type *type;
1719 struct tdesc_type_field *f;
1721 int printed_field_type = 0;
1723 /* Use the global target-supplied description, not the current
1724 architecture's. This lets a GDB for one architecture generate C
1725 for another architecture's description, even though the gdbarch
1726 initialization code will reject the new description. */
1727 tdesc = current_target_desc;
1729 error (_("There is no target description to print."));
1731 if (target_description_filename == NULL)
1732 error (_("The current target description did not come from an XML file."));
1734 filename = lbasename (target_description_filename);
1735 function = (char *) alloca (strlen (filename) + 1);
1736 for (inp = filename, outp = function; *inp != '\0'; inp++)
1739 else if (*inp == '-')
1745 /* Standard boilerplate. */
1746 printf_unfiltered ("/* THIS FILE IS GENERATED. "
1747 "-*- buffer-read-only: t -*- vi"
1749 printf_unfiltered (" Original: %s */\n\n", filename);
1750 printf_unfiltered ("#include \"defs.h\"\n");
1751 printf_unfiltered ("#include \"osabi.h\"\n");
1752 printf_unfiltered ("#include \"target-descriptions.h\"\n");
1753 printf_unfiltered ("\n");
1755 printf_unfiltered ("struct target_desc *tdesc_%s;\n", function);
1756 printf_unfiltered ("static void\n");
1757 printf_unfiltered ("initialize_tdesc_%s (void)\n", function);
1758 printf_unfiltered ("{\n");
1760 (" struct target_desc *result = allocate_target_description ();\n");
1761 printf_unfiltered (" struct tdesc_feature *feature;\n");
1763 /* Now we do some "filtering" in order to know which variables to
1764 declare. This is needed because otherwise we would declare unused
1765 variables `field_type' and `type'. */
1767 VEC_iterate (tdesc_feature_p, tdesc->features, ix, feature);
1770 int printed_desc_type = 0;
1773 VEC_iterate (tdesc_type_p, feature->types, ix2, type);
1776 if (!printed_field_type)
1778 printf_unfiltered (" struct tdesc_type *field_type;\n");
1779 printed_field_type = 1;
1782 if ((type->kind == TDESC_TYPE_UNION
1783 || type->kind == TDESC_TYPE_STRUCT
1784 || type->kind == TDESC_TYPE_FLAGS
1785 || type->kind == TDESC_TYPE_ENUM)
1786 && VEC_length (tdesc_type_field, type->u.u.fields) > 0)
1788 printf_unfiltered (" struct tdesc_type *type;\n");
1789 printed_desc_type = 1;
1794 if (printed_desc_type)
1798 printf_unfiltered ("\n");
1800 if (tdesc_architecture (tdesc) != NULL)
1803 (" set_tdesc_architecture (result, bfd_scan_arch (\"%s\"));\n",
1804 tdesc_architecture (tdesc)->printable_name);
1805 printf_unfiltered ("\n");
1808 if (tdesc_osabi (tdesc) > GDB_OSABI_UNKNOWN
1809 && tdesc_osabi (tdesc) < GDB_OSABI_INVALID)
1812 (" set_tdesc_osabi (result, osabi_from_tdesc_string (\"%s\"));\n",
1813 gdbarch_osabi_name (tdesc_osabi (tdesc)));
1814 printf_unfiltered ("\n");
1817 for (ix = 0; VEC_iterate (arch_p, tdesc->compatible, ix, compatible);
1821 (" tdesc_add_compatible (result, bfd_scan_arch (\"%s\"));\n",
1822 compatible->printable_name);
1825 printf_unfiltered ("\n");
1827 for (ix = 0; VEC_iterate (property_s, tdesc->properties, ix, prop);
1830 printf_unfiltered (" set_tdesc_property (result, \"%s\", \"%s\");\n",
1831 prop->key, prop->value);
1835 VEC_iterate (tdesc_feature_p, tdesc->features, ix, feature);
1838 printf_unfiltered (" \
1839 feature = tdesc_create_feature (result, \"%s\");\n",
1843 VEC_iterate (tdesc_type_p, feature->types, ix2, type);
1848 case TDESC_TYPE_VECTOR:
1850 (" field_type = tdesc_named_type (feature, \"%s\");\n",
1851 type->u.v.type->name);
1853 (" tdesc_create_vector (feature, \"%s\", field_type, %d);\n",
1854 type->name, type->u.v.count);
1856 case TDESC_TYPE_STRUCT:
1857 case TDESC_TYPE_FLAGS:
1858 if (type->kind == TDESC_TYPE_STRUCT)
1861 (" type = tdesc_create_struct (feature, \"%s\");\n",
1863 if (type->u.u.size != 0)
1865 (" tdesc_set_struct_size (type, %d);\n",
1871 (" type = tdesc_create_flags (feature, \"%s\", %d);\n",
1872 type->name, type->u.u.size);
1875 VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f);
1878 const char *type_name;
1880 gdb_assert (f->type != NULL);
1881 type_name = f->type->name;
1883 /* To minimize changes to generated files, don't emit type
1884 info for fields that have defaulted types. */
1887 gdb_assert (f->end != -1);
1888 if (f->type->kind == TDESC_TYPE_BOOL)
1890 gdb_assert (f->start == f->end);
1892 (" tdesc_add_flag (type, %d, \"%s\");\n",
1895 else if ((type->u.u.size == 4
1896 && f->type->kind == TDESC_TYPE_UINT32)
1897 || (type->u.u.size == 8
1898 && f->type->kind == TDESC_TYPE_UINT64))
1901 (" tdesc_add_bitfield (type, \"%s\", %d, %d);\n",
1902 f->name, f->start, f->end);
1907 (" field_type = tdesc_named_type (feature,"
1911 (" tdesc_add_typed_bitfield (type, \"%s\","
1912 " %d, %d, field_type);\n",
1913 f->name, f->start, f->end);
1916 else /* Not a bitfield. */
1918 gdb_assert (f->end == -1);
1919 gdb_assert (type->kind == TDESC_TYPE_STRUCT);
1921 (" field_type = tdesc_named_type (feature,"
1925 (" tdesc_add_field (type, \"%s\", field_type);\n",
1930 case TDESC_TYPE_UNION:
1932 (" type = tdesc_create_union (feature, \"%s\");\n",
1935 VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f);
1939 (" field_type = tdesc_named_type (feature, \"%s\");\n",
1942 (" tdesc_add_field (type, \"%s\", field_type);\n",
1946 case TDESC_TYPE_ENUM:
1948 (" type = tdesc_create_enum (feature, \"%s\", %d);\n",
1949 type->name, type->u.u.size);
1951 VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f);
1954 (" tdesc_add_enum_value (type, %d, \"%s\");\n",
1958 error (_("C output is not supported type \"%s\"."), type->name);
1960 printf_unfiltered ("\n");
1964 VEC_iterate (tdesc_reg_p, feature->registers, ix2, reg);
1967 printf_unfiltered (" tdesc_create_reg (feature, \"%s\", %ld, %d, ",
1968 reg->name, reg->target_regnum, reg->save_restore);
1970 printf_unfiltered ("\"%s\", ", reg->group);
1972 printf_unfiltered ("NULL, ");
1973 printf_unfiltered ("%d, \"%s\");\n", reg->bitsize, reg->type);
1976 printf_unfiltered ("\n");
1979 printf_unfiltered (" tdesc_%s = result;\n", function);
1980 printf_unfiltered ("}\n");
1983 /* Provide a prototype to silence -Wmissing-prototypes. */
1984 extern initialize_file_ftype _initialize_target_descriptions;
1987 _initialize_target_descriptions (void)
1989 tdesc_data = gdbarch_data_register_pre_init (tdesc_data_init);
1991 add_prefix_cmd ("tdesc", class_maintenance, set_tdesc_cmd, _("\
1992 Set target description specific variables."),
1993 &tdesc_set_cmdlist, "set tdesc ",
1994 0 /* allow-unknown */, &setlist);
1995 add_prefix_cmd ("tdesc", class_maintenance, show_tdesc_cmd, _("\
1996 Show target description specific variables."),
1997 &tdesc_show_cmdlist, "show tdesc ",
1998 0 /* allow-unknown */, &showlist);
1999 add_prefix_cmd ("tdesc", class_maintenance, unset_tdesc_cmd, _("\
2000 Unset target description specific variables."),
2001 &tdesc_unset_cmdlist, "unset tdesc ",
2002 0 /* allow-unknown */, &unsetlist);
2004 add_setshow_filename_cmd ("filename", class_obscure,
2005 &tdesc_filename_cmd_string,
2007 Set the file to read for an XML target description"), _("\
2008 Show the file to read for an XML target description"), _("\
2009 When set, GDB will read the target description from a local\n\
2010 file instead of querying the remote target."),
2011 set_tdesc_filename_cmd,
2012 show_tdesc_filename_cmd,
2013 &tdesc_set_cmdlist, &tdesc_show_cmdlist);
2015 add_cmd ("filename", class_obscure, unset_tdesc_filename_cmd, _("\
2016 Unset the file to read for an XML target description. When unset,\n\
2017 GDB will read the description from the target."),
2018 &tdesc_unset_cmdlist);
2020 add_cmd ("c-tdesc", class_maintenance, maint_print_c_tdesc_cmd, _("\
2021 Print the current target description as a C source file."),
2022 &maintenanceprintlist);