1 /* Target description support for GDB.
3 Copyright (C) 2006-2017 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. If this type is a built-in type, this is
132 a pointer to a constant string. Otherwise, it's a
133 malloc-allocated string (and thus must be freed). */
136 /* Identify the kind of this type. */
137 enum tdesc_type_kind kind;
139 /* Kind-specific data. */
145 struct tdesc_type *type;
149 /* Struct, union, flags, or enum type. */
152 VEC(tdesc_type_field) *fields;
157 DEF_VEC_P(tdesc_type_p);
159 /* A feature from a target description. Each feature is a collection
160 of other elements, e.g. registers and types. */
162 typedef struct tdesc_feature
164 /* The name of this feature. It may be recognized by the architecture
168 /* The registers associated with this feature. */
169 VEC(tdesc_reg_p) *registers;
171 /* The types associated with this feature. */
172 VEC(tdesc_type_p) *types;
174 DEF_VEC_P(tdesc_feature_p);
176 /* A compatible architecture from a target description. */
177 typedef const struct bfd_arch_info *arch_p;
180 /* A target description. */
184 /* The architecture reported by the target, if any. */
185 const struct bfd_arch_info *arch;
187 /* The osabi reported by the target, if any; GDB_OSABI_UNKNOWN
189 enum gdb_osabi osabi;
191 /* The list of compatible architectures reported by the target. */
192 VEC(arch_p) *compatible;
194 /* Any architecture-specific properties specified by the target. */
195 VEC(property_s) *properties;
197 /* The features associated with this target. */
198 VEC(tdesc_feature_p) *features;
201 /* Per-architecture data associated with a target description. The
202 target description may be shared by multiple architectures, but
203 this data is private to one gdbarch. */
205 typedef struct tdesc_arch_reg
207 struct tdesc_reg *reg;
210 DEF_VEC_O(tdesc_arch_reg);
212 struct tdesc_arch_data
214 /* A list of register/type pairs, indexed by GDB's internal register number.
215 During initialization of the gdbarch this list is used to store
216 registers which the architecture assigns a fixed register number.
217 Registers which are NULL in this array, or off the end, are
218 treated as zero-sized and nameless (i.e. placeholders in the
220 VEC(tdesc_arch_reg) *arch_regs;
222 /* Functions which report the register name, type, and reggroups for
224 gdbarch_register_name_ftype *pseudo_register_name;
225 gdbarch_register_type_ftype *pseudo_register_type;
226 gdbarch_register_reggroup_p_ftype *pseudo_register_reggroup_p;
229 /* Info about an inferior's target description. There's one of these
230 for each inferior. */
232 struct target_desc_info
234 /* A flag indicating that a description has already been fetched
235 from the target, so it should not be queried again. */
239 /* The description fetched from the target, or NULL if the target
240 did not supply any description. Only valid when
241 target_desc_fetched is set. Only the description initialization
242 code should access this; normally, the description should be
243 accessed through the gdbarch object. */
245 const struct target_desc *tdesc;
247 /* The filename to read a target description from, as set by "set
248 tdesc filename ..." */
253 /* Get the inferior INF's target description info, allocating one on
254 the stop if necessary. */
256 static struct target_desc_info *
257 get_tdesc_info (struct inferior *inf)
259 if (inf->tdesc_info == NULL)
260 inf->tdesc_info = XCNEW (struct target_desc_info);
261 return inf->tdesc_info;
264 /* A handle for architecture-specific data associated with the
265 target description (see struct tdesc_arch_data). */
267 static struct gdbarch_data *tdesc_data;
269 /* See target-descriptions.h. */
272 target_desc_info_from_user_p (struct target_desc_info *info)
274 return info != NULL && info->filename != NULL;
277 /* See target-descriptions.h. */
280 copy_inferior_target_desc_info (struct inferior *destinf, struct inferior *srcinf)
282 struct target_desc_info *src = get_tdesc_info (srcinf);
283 struct target_desc_info *dest = get_tdesc_info (destinf);
285 dest->fetched = src->fetched;
286 dest->tdesc = src->tdesc;
287 dest->filename = src->filename != NULL ? xstrdup (src->filename) : NULL;
290 /* See target-descriptions.h. */
293 target_desc_info_free (struct target_desc_info *tdesc_info)
295 if (tdesc_info != NULL)
297 xfree (tdesc_info->filename);
302 /* Convenience helper macros. */
304 #define target_desc_fetched \
305 get_tdesc_info (current_inferior ())->fetched
306 #define current_target_desc \
307 get_tdesc_info (current_inferior ())->tdesc
308 #define target_description_filename \
309 get_tdesc_info (current_inferior ())->filename
311 /* The string manipulated by the "set tdesc filename ..." command. */
313 static char *tdesc_filename_cmd_string;
315 /* Fetch the current target's description, and switch the current
316 architecture to one which incorporates that description. */
319 target_find_description (void)
321 /* If we've already fetched a description from the target, don't do
322 it again. This allows a target to fetch the description early,
323 during its to_open or to_create_inferior, if it needs extra
324 information about the target to initialize. */
325 if (target_desc_fetched)
328 /* The current architecture should not have any target description
329 specified. It should have been cleared, e.g. when we
330 disconnected from the previous target. */
331 gdb_assert (gdbarch_target_desc (target_gdbarch ()) == NULL);
333 /* First try to fetch an XML description from the user-specified
335 current_target_desc = NULL;
336 if (target_description_filename != NULL
337 && *target_description_filename != '\0')
339 = file_read_description_xml (target_description_filename);
341 /* Next try to read the description from the current target using
343 if (current_target_desc == NULL)
344 current_target_desc = target_read_description_xml (¤t_target);
346 /* If that failed try a target-specific hook. */
347 if (current_target_desc == NULL)
348 current_target_desc = target_read_description (¤t_target);
350 /* If a non-NULL description was returned, then update the current
352 if (current_target_desc)
354 struct gdbarch_info info;
356 gdbarch_info_init (&info);
357 info.target_desc = current_target_desc;
358 if (!gdbarch_update_p (info))
359 warning (_("Architecture rejected target-supplied description"));
362 struct tdesc_arch_data *data;
364 data = ((struct tdesc_arch_data *)
365 gdbarch_data (target_gdbarch (), tdesc_data));
366 if (tdesc_has_registers (current_target_desc)
367 && data->arch_regs == NULL)
368 warning (_("Target-supplied registers are not supported "
369 "by the current architecture"));
373 /* Now that we know this description is usable, record that we
375 target_desc_fetched = 1;
378 /* Discard any description fetched from the current target, and switch
379 the current architecture to one with no target description. */
382 target_clear_description (void)
384 struct gdbarch_info info;
386 if (!target_desc_fetched)
389 target_desc_fetched = 0;
390 current_target_desc = NULL;
392 gdbarch_info_init (&info);
393 if (!gdbarch_update_p (info))
394 internal_error (__FILE__, __LINE__,
395 _("Could not remove target-supplied description"));
398 /* Return the global current target description. This should only be
399 used by gdbarch initialization code; most access should be through
400 an existing gdbarch. */
402 const struct target_desc *
403 target_current_description (void)
405 if (target_desc_fetched)
406 return current_target_desc;
411 /* Return non-zero if this target description is compatible
412 with the given BFD architecture. */
415 tdesc_compatible_p (const struct target_desc *target_desc,
416 const struct bfd_arch_info *arch)
418 const struct bfd_arch_info *compat;
421 for (ix = 0; VEC_iterate (arch_p, target_desc->compatible, ix, compat);
425 || arch->compatible (arch, compat)
426 || compat->compatible (compat, arch))
434 /* Direct accessors for target descriptions. */
436 /* Return the string value of a property named KEY, or NULL if the
437 property was not specified. */
440 tdesc_property (const struct target_desc *target_desc, const char *key)
442 struct property *prop;
445 for (ix = 0; VEC_iterate (property_s, target_desc->properties, ix, prop);
447 if (strcmp (prop->key, key) == 0)
453 /* Return the BFD architecture associated with this target
454 description, or NULL if no architecture was specified. */
456 const struct bfd_arch_info *
457 tdesc_architecture (const struct target_desc *target_desc)
459 return target_desc->arch;
462 /* Return the OSABI associated with this target description, or
463 GDB_OSABI_UNKNOWN if no osabi was specified. */
466 tdesc_osabi (const struct target_desc *target_desc)
468 return target_desc->osabi;
473 /* Return 1 if this target description includes any registers. */
476 tdesc_has_registers (const struct target_desc *target_desc)
479 struct tdesc_feature *feature;
481 if (target_desc == NULL)
485 VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature);
487 if (! VEC_empty (tdesc_reg_p, feature->registers))
493 /* Return the feature with the given name, if present, or NULL if
494 the named feature is not found. */
496 const struct tdesc_feature *
497 tdesc_find_feature (const struct target_desc *target_desc,
501 struct tdesc_feature *feature;
504 VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature);
506 if (strcmp (feature->name, name) == 0)
512 /* Return the name of FEATURE. */
515 tdesc_feature_name (const struct tdesc_feature *feature)
517 return feature->name;
520 /* Predefined types. */
521 static struct tdesc_type tdesc_predefined_types[] =
523 { "bool", TDESC_TYPE_BOOL },
524 { "int8", TDESC_TYPE_INT8 },
525 { "int16", TDESC_TYPE_INT16 },
526 { "int32", TDESC_TYPE_INT32 },
527 { "int64", TDESC_TYPE_INT64 },
528 { "int128", TDESC_TYPE_INT128 },
529 { "uint8", TDESC_TYPE_UINT8 },
530 { "uint16", TDESC_TYPE_UINT16 },
531 { "uint32", TDESC_TYPE_UINT32 },
532 { "uint64", TDESC_TYPE_UINT64 },
533 { "uint128", TDESC_TYPE_UINT128 },
534 { "code_ptr", TDESC_TYPE_CODE_PTR },
535 { "data_ptr", TDESC_TYPE_DATA_PTR },
536 { "ieee_single", TDESC_TYPE_IEEE_SINGLE },
537 { "ieee_double", TDESC_TYPE_IEEE_DOUBLE },
538 { "arm_fpa_ext", TDESC_TYPE_ARM_FPA_EXT },
539 { "i387_ext", TDESC_TYPE_I387_EXT }
542 /* Lookup a predefined type. */
544 static struct tdesc_type *
545 tdesc_predefined_type (enum tdesc_type_kind kind)
548 struct tdesc_type *type;
550 for (ix = 0; ix < ARRAY_SIZE (tdesc_predefined_types); ix++)
551 if (tdesc_predefined_types[ix].kind == kind)
552 return &tdesc_predefined_types[ix];
554 gdb_assert_not_reached ("bad predefined tdesc type");
557 /* Return the type associated with ID in the context of FEATURE, or
561 tdesc_named_type (const struct tdesc_feature *feature, const char *id)
564 struct tdesc_type *type;
566 /* First try target-defined types. */
567 for (ix = 0; VEC_iterate (tdesc_type_p, feature->types, ix, type); ix++)
568 if (strcmp (type->name, id) == 0)
571 /* Next try the predefined types. */
572 for (ix = 0; ix < ARRAY_SIZE (tdesc_predefined_types); ix++)
573 if (strcmp (tdesc_predefined_types[ix].name, id) == 0)
574 return &tdesc_predefined_types[ix];
579 /* Lookup type associated with ID. */
582 tdesc_find_type (struct gdbarch *gdbarch, const char *id)
584 struct tdesc_arch_reg *reg;
585 struct tdesc_arch_data *data;
588 data = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
589 num_regs = VEC_length (tdesc_arch_reg, data->arch_regs);
590 for (i = 0; i < num_regs; i++)
592 reg = VEC_index (tdesc_arch_reg, data->arch_regs, i);
594 && reg->reg->tdesc_type
596 && strcmp (id, reg->reg->tdesc_type->name) == 0)
603 /* Construct, if necessary, and return the GDB type implementing target
604 type TDESC_TYPE for architecture GDBARCH. */
607 tdesc_gdb_type (struct gdbarch *gdbarch, struct tdesc_type *tdesc_type)
611 switch (tdesc_type->kind)
613 /* Predefined types. */
614 case TDESC_TYPE_BOOL:
615 return builtin_type (gdbarch)->builtin_bool;
617 case TDESC_TYPE_INT8:
618 return builtin_type (gdbarch)->builtin_int8;
620 case TDESC_TYPE_INT16:
621 return builtin_type (gdbarch)->builtin_int16;
623 case TDESC_TYPE_INT32:
624 return builtin_type (gdbarch)->builtin_int32;
626 case TDESC_TYPE_INT64:
627 return builtin_type (gdbarch)->builtin_int64;
629 case TDESC_TYPE_INT128:
630 return builtin_type (gdbarch)->builtin_int128;
632 case TDESC_TYPE_UINT8:
633 return builtin_type (gdbarch)->builtin_uint8;
635 case TDESC_TYPE_UINT16:
636 return builtin_type (gdbarch)->builtin_uint16;
638 case TDESC_TYPE_UINT32:
639 return builtin_type (gdbarch)->builtin_uint32;
641 case TDESC_TYPE_UINT64:
642 return builtin_type (gdbarch)->builtin_uint64;
644 case TDESC_TYPE_UINT128:
645 return builtin_type (gdbarch)->builtin_uint128;
647 case TDESC_TYPE_CODE_PTR:
648 return builtin_type (gdbarch)->builtin_func_ptr;
650 case TDESC_TYPE_DATA_PTR:
651 return builtin_type (gdbarch)->builtin_data_ptr;
657 type = tdesc_find_type (gdbarch, tdesc_type->name);
661 switch (tdesc_type->kind)
663 case TDESC_TYPE_IEEE_SINGLE:
664 return arch_float_type (gdbarch, -1, "builtin_type_ieee_single",
665 floatformats_ieee_single);
667 case TDESC_TYPE_IEEE_DOUBLE:
668 return arch_float_type (gdbarch, -1, "builtin_type_ieee_double",
669 floatformats_ieee_double);
671 case TDESC_TYPE_ARM_FPA_EXT:
672 return arch_float_type (gdbarch, -1, "builtin_type_arm_ext",
673 floatformats_arm_ext);
675 case TDESC_TYPE_I387_EXT:
676 return arch_float_type (gdbarch, -1, "builtin_type_i387_ext",
677 floatformats_i387_ext);
679 /* Types defined by a target feature. */
680 case TDESC_TYPE_VECTOR:
682 struct type *type, *field_type;
684 field_type = tdesc_gdb_type (gdbarch, tdesc_type->u.v.type);
685 type = init_vector_type (field_type, tdesc_type->u.v.count);
686 TYPE_NAME (type) = xstrdup (tdesc_type->name);
691 case TDESC_TYPE_STRUCT:
693 struct type *type, *field_type;
694 struct tdesc_type_field *f;
697 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
698 TYPE_NAME (type) = xstrdup (tdesc_type->name);
699 TYPE_TAG_NAME (type) = TYPE_NAME (type);
702 VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f);
705 if (f->start != -1 && f->end != -1)
709 struct type *field_type;
710 int bitsize, total_size;
712 /* This invariant should be preserved while creating types. */
713 gdb_assert (tdesc_type->u.u.size != 0);
715 field_type = tdesc_gdb_type (gdbarch, f->type);
716 else if (tdesc_type->u.u.size > 4)
717 field_type = builtin_type (gdbarch)->builtin_uint64;
719 field_type = builtin_type (gdbarch)->builtin_uint32;
721 fld = append_composite_type_field_raw (type, xstrdup (f->name),
724 /* For little-endian, BITPOS counts from the LSB of
725 the structure and marks the LSB of the field. For
726 big-endian, BITPOS counts from the MSB of the
727 structure and marks the MSB of the field. Either
728 way, it is the number of bits to the "left" of the
729 field. To calculate this in big-endian, we need
730 the total size of the structure. */
731 bitsize = f->end - f->start + 1;
732 total_size = tdesc_type->u.u.size * TARGET_CHAR_BIT;
733 if (gdbarch_bits_big_endian (gdbarch))
734 SET_FIELD_BITPOS (fld[0], total_size - f->start - bitsize);
736 SET_FIELD_BITPOS (fld[0], f->start);
737 FIELD_BITSIZE (fld[0]) = bitsize;
741 gdb_assert (f->start == -1 && f->end == -1);
742 field_type = tdesc_gdb_type (gdbarch, f->type);
743 append_composite_type_field (type, xstrdup (f->name),
748 if (tdesc_type->u.u.size != 0)
749 TYPE_LENGTH (type) = tdesc_type->u.u.size;
753 case TDESC_TYPE_UNION:
755 struct type *type, *field_type;
756 struct tdesc_type_field *f;
759 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
760 TYPE_NAME (type) = xstrdup (tdesc_type->name);
763 VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f);
766 field_type = tdesc_gdb_type (gdbarch, f->type);
767 append_composite_type_field (type, xstrdup (f->name), field_type);
769 /* If any of the children of a union are vectors, flag the
770 union as a vector also. This allows e.g. a union of two
771 vector types to show up automatically in "info vector". */
772 if (TYPE_VECTOR (field_type))
773 TYPE_VECTOR (type) = 1;
778 case TDESC_TYPE_FLAGS:
780 struct tdesc_type_field *f;
783 type = arch_flags_type (gdbarch, tdesc_type->name,
784 tdesc_type->u.u.size);
786 VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f);
789 struct type *field_type;
790 int bitsize = f->end - f->start + 1;
792 gdb_assert (f->type != NULL);
793 field_type = tdesc_gdb_type (gdbarch, f->type);
794 append_flags_type_field (type, f->start, bitsize,
795 field_type, f->name);
801 case TDESC_TYPE_ENUM:
803 struct tdesc_type_field *f;
806 type = arch_type (gdbarch, TYPE_CODE_ENUM,
807 tdesc_type->u.u.size, tdesc_type->name);
808 TYPE_UNSIGNED (type) = 1;
810 VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f);
814 = append_composite_type_field_raw (type, xstrdup (f->name),
817 SET_FIELD_BITPOS (fld[0], f->start);
824 internal_error (__FILE__, __LINE__,
825 "Type \"%s\" has an unknown kind %d",
826 tdesc_type->name, tdesc_type->kind);
830 /* Support for registers from target descriptions. */
832 /* Construct the per-gdbarch data. */
835 tdesc_data_init (struct obstack *obstack)
837 struct tdesc_arch_data *data;
839 data = OBSTACK_ZALLOC (obstack, struct tdesc_arch_data);
843 /* Similar, but for the temporary copy used during architecture
846 struct tdesc_arch_data *
847 tdesc_data_alloc (void)
849 return XCNEW (struct tdesc_arch_data);
852 /* Free something allocated by tdesc_data_alloc, if it is not going
853 to be used (for instance if it was unsuitable for the
857 tdesc_data_cleanup (void *data_untyped)
859 struct tdesc_arch_data *data = (struct tdesc_arch_data *) data_untyped;
861 VEC_free (tdesc_arch_reg, data->arch_regs);
865 /* Search FEATURE for a register named NAME. */
867 static struct tdesc_reg *
868 tdesc_find_register_early (const struct tdesc_feature *feature,
872 struct tdesc_reg *reg;
875 VEC_iterate (tdesc_reg_p, feature->registers, ixr, reg);
877 if (strcasecmp (reg->name, name) == 0)
883 /* Search FEATURE for a register named NAME. Assign REGNO to it. */
886 tdesc_numbered_register (const struct tdesc_feature *feature,
887 struct tdesc_arch_data *data,
888 int regno, const char *name)
890 struct tdesc_arch_reg arch_reg = { 0 };
891 struct tdesc_reg *reg = tdesc_find_register_early (feature, name);
896 /* Make sure the vector includes a REGNO'th element. */
897 while (regno >= VEC_length (tdesc_arch_reg, data->arch_regs))
898 VEC_safe_push (tdesc_arch_reg, data->arch_regs, &arch_reg);
901 VEC_replace (tdesc_arch_reg, data->arch_regs, regno, &arch_reg);
905 /* Search FEATURE for a register named NAME, but do not assign a fixed
906 register number to it. */
909 tdesc_unnumbered_register (const struct tdesc_feature *feature,
912 struct tdesc_reg *reg = tdesc_find_register_early (feature, name);
920 /* Search FEATURE for a register whose name is in NAMES and assign
924 tdesc_numbered_register_choices (const struct tdesc_feature *feature,
925 struct tdesc_arch_data *data,
926 int regno, const char *const names[])
930 for (i = 0; names[i] != NULL; i++)
931 if (tdesc_numbered_register (feature, data, regno, names[i]))
937 /* Search FEATURE for a register named NAME, and return its size in
938 bits. The register must exist. */
941 tdesc_register_size (const struct tdesc_feature *feature,
944 struct tdesc_reg *reg = tdesc_find_register_early (feature, name);
946 gdb_assert (reg != NULL);
950 /* Look up a register by its GDB internal register number. */
952 static struct tdesc_arch_reg *
953 tdesc_find_arch_register (struct gdbarch *gdbarch, int regno)
955 struct tdesc_arch_data *data;
957 data = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
958 if (regno < VEC_length (tdesc_arch_reg, data->arch_regs))
959 return VEC_index (tdesc_arch_reg, data->arch_regs, regno);
964 static struct tdesc_reg *
965 tdesc_find_register (struct gdbarch *gdbarch, int regno)
967 struct tdesc_arch_reg *reg = tdesc_find_arch_register (gdbarch, regno);
969 return reg? reg->reg : NULL;
972 /* Return the name of register REGNO, from the target description or
973 from an architecture-provided pseudo_register_name method. */
976 tdesc_register_name (struct gdbarch *gdbarch, int regno)
978 struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno);
979 int num_regs = gdbarch_num_regs (gdbarch);
980 int num_pseudo_regs = gdbarch_num_pseudo_regs (gdbarch);
985 if (regno >= num_regs && regno < num_regs + num_pseudo_regs)
987 struct tdesc_arch_data *data
988 = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
990 gdb_assert (data->pseudo_register_name != NULL);
991 return data->pseudo_register_name (gdbarch, regno);
998 tdesc_register_type (struct gdbarch *gdbarch, int regno)
1000 struct tdesc_arch_reg *arch_reg = tdesc_find_arch_register (gdbarch, regno);
1001 struct tdesc_reg *reg = arch_reg? arch_reg->reg : NULL;
1002 int num_regs = gdbarch_num_regs (gdbarch);
1003 int num_pseudo_regs = gdbarch_num_pseudo_regs (gdbarch);
1005 if (reg == NULL && regno >= num_regs && regno < num_regs + num_pseudo_regs)
1007 struct tdesc_arch_data *data
1008 = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
1010 gdb_assert (data->pseudo_register_type != NULL);
1011 return data->pseudo_register_type (gdbarch, regno);
1015 /* Return "int0_t", since "void" has a misleading size of one. */
1016 return builtin_type (gdbarch)->builtin_int0;
1018 if (arch_reg->type == NULL)
1020 /* First check for a predefined or target defined type. */
1021 if (reg->tdesc_type)
1022 arch_reg->type = tdesc_gdb_type (gdbarch, reg->tdesc_type);
1024 /* Next try size-sensitive type shortcuts. */
1025 else if (strcmp (reg->type, "float") == 0)
1027 if (reg->bitsize == gdbarch_float_bit (gdbarch))
1028 arch_reg->type = builtin_type (gdbarch)->builtin_float;
1029 else if (reg->bitsize == gdbarch_double_bit (gdbarch))
1030 arch_reg->type = builtin_type (gdbarch)->builtin_double;
1031 else if (reg->bitsize == gdbarch_long_double_bit (gdbarch))
1032 arch_reg->type = builtin_type (gdbarch)->builtin_long_double;
1035 warning (_("Register \"%s\" has an unsupported size (%d bits)"),
1036 reg->name, reg->bitsize);
1037 arch_reg->type = builtin_type (gdbarch)->builtin_double;
1040 else if (strcmp (reg->type, "int") == 0)
1042 if (reg->bitsize == gdbarch_long_bit (gdbarch))
1043 arch_reg->type = builtin_type (gdbarch)->builtin_long;
1044 else if (reg->bitsize == TARGET_CHAR_BIT)
1045 arch_reg->type = builtin_type (gdbarch)->builtin_char;
1046 else if (reg->bitsize == gdbarch_short_bit (gdbarch))
1047 arch_reg->type = builtin_type (gdbarch)->builtin_short;
1048 else if (reg->bitsize == gdbarch_int_bit (gdbarch))
1049 arch_reg->type = builtin_type (gdbarch)->builtin_int;
1050 else if (reg->bitsize == gdbarch_long_long_bit (gdbarch))
1051 arch_reg->type = builtin_type (gdbarch)->builtin_long_long;
1052 else if (reg->bitsize == gdbarch_ptr_bit (gdbarch))
1053 /* A bit desperate by this point... */
1054 arch_reg->type = builtin_type (gdbarch)->builtin_data_ptr;
1057 warning (_("Register \"%s\" has an unsupported size (%d bits)"),
1058 reg->name, reg->bitsize);
1059 arch_reg->type = builtin_type (gdbarch)->builtin_long;
1063 if (arch_reg->type == NULL)
1064 internal_error (__FILE__, __LINE__,
1065 "Register \"%s\" has an unknown type \"%s\"",
1066 reg->name, reg->type);
1069 return arch_reg->type;
1073 tdesc_remote_register_number (struct gdbarch *gdbarch, int regno)
1075 struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno);
1078 return reg->target_regnum;
1083 /* Check whether REGNUM is a member of REGGROUP. Registers from the
1084 target description may be classified as general, float, or vector.
1085 Unlike a gdbarch register_reggroup_p method, this function will
1086 return -1 if it does not know; the caller should handle registers
1087 with no specified group.
1089 Arbitrary strings (other than "general", "float", and "vector")
1090 from the description are not used; they cause the register to be
1091 displayed in "info all-registers" but excluded from "info
1092 registers" et al. The names of containing features are also not
1093 used. This might be extended to display registers in some more
1096 The save-restore flag is also implemented here. */
1099 tdesc_register_in_reggroup_p (struct gdbarch *gdbarch, int regno,
1100 struct reggroup *reggroup)
1102 struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno);
1104 if (reg != NULL && reg->group != NULL)
1106 int general_p = 0, float_p = 0, vector_p = 0;
1108 if (strcmp (reg->group, "general") == 0)
1110 else if (strcmp (reg->group, "float") == 0)
1112 else if (strcmp (reg->group, "vector") == 0)
1115 if (reggroup == float_reggroup)
1118 if (reggroup == vector_reggroup)
1121 if (reggroup == general_reggroup)
1126 && (reggroup == save_reggroup || reggroup == restore_reggroup))
1127 return reg->save_restore;
1132 /* Check whether REGNUM is a member of REGGROUP. Registers with no
1133 group specified go to the default reggroup function and are handled
1137 tdesc_register_reggroup_p (struct gdbarch *gdbarch, int regno,
1138 struct reggroup *reggroup)
1140 int num_regs = gdbarch_num_regs (gdbarch);
1141 int num_pseudo_regs = gdbarch_num_pseudo_regs (gdbarch);
1144 if (regno >= num_regs && regno < num_regs + num_pseudo_regs)
1146 struct tdesc_arch_data *data
1147 = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
1149 if (data->pseudo_register_reggroup_p != NULL)
1150 return data->pseudo_register_reggroup_p (gdbarch, regno, reggroup);
1151 /* Otherwise fall through to the default reggroup_p. */
1154 ret = tdesc_register_in_reggroup_p (gdbarch, regno, reggroup);
1158 return default_register_reggroup_p (gdbarch, regno, reggroup);
1161 /* Record architecture-specific functions to call for pseudo-register
1165 set_tdesc_pseudo_register_name (struct gdbarch *gdbarch,
1166 gdbarch_register_name_ftype *pseudo_name)
1168 struct tdesc_arch_data *data
1169 = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
1171 data->pseudo_register_name = pseudo_name;
1175 set_tdesc_pseudo_register_type (struct gdbarch *gdbarch,
1176 gdbarch_register_type_ftype *pseudo_type)
1178 struct tdesc_arch_data *data
1179 = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
1181 data->pseudo_register_type = pseudo_type;
1185 set_tdesc_pseudo_register_reggroup_p
1186 (struct gdbarch *gdbarch,
1187 gdbarch_register_reggroup_p_ftype *pseudo_reggroup_p)
1189 struct tdesc_arch_data *data
1190 = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
1192 data->pseudo_register_reggroup_p = pseudo_reggroup_p;
1195 /* Update GDBARCH to use the target description for registers. */
1198 tdesc_use_registers (struct gdbarch *gdbarch,
1199 const struct target_desc *target_desc,
1200 struct tdesc_arch_data *early_data)
1202 int num_regs = gdbarch_num_regs (gdbarch);
1204 struct tdesc_feature *feature;
1205 struct tdesc_reg *reg;
1206 struct tdesc_arch_data *data;
1207 struct tdesc_arch_reg *arch_reg, new_arch_reg = { 0 };
1210 /* We can't use the description for registers if it doesn't describe
1211 any. This function should only be called after validating
1212 registers, so the caller should know that registers are
1214 gdb_assert (tdesc_has_registers (target_desc));
1216 data = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
1217 data->arch_regs = early_data->arch_regs;
1220 /* Build up a set of all registers, so that we can assign register
1221 numbers where needed. The hash table expands as necessary, so
1222 the initial size is arbitrary. */
1223 reg_hash = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
1225 VEC_iterate (tdesc_feature_p, target_desc->features, ixf, feature);
1228 VEC_iterate (tdesc_reg_p, feature->registers, ixr, reg);
1231 void **slot = htab_find_slot (reg_hash, reg, INSERT);
1236 /* Remove any registers which were assigned numbers by the
1239 VEC_iterate (tdesc_arch_reg, data->arch_regs, ixr, arch_reg);
1242 htab_remove_elt (reg_hash, arch_reg->reg);
1244 /* Assign numbers to the remaining registers and add them to the
1245 list of registers. The new numbers are always above gdbarch_num_regs.
1246 Iterate over the features, not the hash table, so that the order
1247 matches that in the target description. */
1249 gdb_assert (VEC_length (tdesc_arch_reg, data->arch_regs) <= num_regs);
1250 while (VEC_length (tdesc_arch_reg, data->arch_regs) < num_regs)
1251 VEC_safe_push (tdesc_arch_reg, data->arch_regs, &new_arch_reg);
1253 VEC_iterate (tdesc_feature_p, target_desc->features, ixf, feature);
1256 VEC_iterate (tdesc_reg_p, feature->registers, ixr, reg);
1258 if (htab_find (reg_hash, reg) != NULL)
1260 new_arch_reg.reg = reg;
1261 VEC_safe_push (tdesc_arch_reg, data->arch_regs, &new_arch_reg);
1265 htab_delete (reg_hash);
1267 /* Update the architecture. */
1268 set_gdbarch_num_regs (gdbarch, num_regs);
1269 set_gdbarch_register_name (gdbarch, tdesc_register_name);
1270 set_gdbarch_register_type (gdbarch, tdesc_register_type);
1271 set_gdbarch_remote_register_number (gdbarch,
1272 tdesc_remote_register_number);
1273 set_gdbarch_register_reggroup_p (gdbarch, tdesc_register_reggroup_p);
1277 /* Methods for constructing a target description. */
1280 tdesc_free_reg (struct tdesc_reg *reg)
1289 tdesc_create_reg (struct tdesc_feature *feature, const char *name,
1290 int regnum, int save_restore, const char *group,
1291 int bitsize, const char *type)
1293 struct tdesc_reg *reg = XCNEW (struct tdesc_reg);
1295 reg->name = xstrdup (name);
1296 reg->target_regnum = regnum;
1297 reg->save_restore = save_restore;
1298 reg->group = group ? xstrdup (group) : NULL;
1299 reg->bitsize = bitsize;
1300 reg->type = type ? xstrdup (type) : xstrdup ("<unknown>");
1302 /* If the register's type is target-defined, look it up now. We may not
1303 have easy access to the containing feature when we want it later. */
1304 reg->tdesc_type = tdesc_named_type (feature, reg->type);
1306 VEC_safe_push (tdesc_reg_p, feature->registers, reg);
1309 /* Subroutine of tdesc_free_feature to simplify it.
1310 Note: We do not want to free any referenced types here (e.g., types of
1311 fields of a struct). All types of a feature are recorded in
1312 feature->types and are freed that way. */
1315 tdesc_free_type (struct tdesc_type *type)
1319 case TDESC_TYPE_STRUCT:
1320 case TDESC_TYPE_UNION:
1321 case TDESC_TYPE_FLAGS:
1322 case TDESC_TYPE_ENUM:
1324 struct tdesc_type_field *f;
1328 VEC_iterate (tdesc_type_field, type->u.u.fields, ix, f);
1332 VEC_free (tdesc_type_field, type->u.u.fields);
1340 xfree ((char *) type->name);
1345 tdesc_create_vector (struct tdesc_feature *feature, const char *name,
1346 struct tdesc_type *field_type, int count)
1348 struct tdesc_type *type = XCNEW (struct tdesc_type);
1350 type->name = xstrdup (name);
1351 type->kind = TDESC_TYPE_VECTOR;
1352 type->u.v.type = field_type;
1353 type->u.v.count = count;
1355 VEC_safe_push (tdesc_type_p, feature->types, type);
1360 tdesc_create_struct (struct tdesc_feature *feature, const char *name)
1362 struct tdesc_type *type = XCNEW (struct tdesc_type);
1364 type->name = xstrdup (name);
1365 type->kind = TDESC_TYPE_STRUCT;
1367 VEC_safe_push (tdesc_type_p, feature->types, type);
1371 /* Set the total length of TYPE. Structs which contain bitfields may
1372 omit the reserved bits, so the end of the last field may not
1376 tdesc_set_struct_size (struct tdesc_type *type, int size)
1378 gdb_assert (type->kind == TDESC_TYPE_STRUCT);
1379 gdb_assert (size > 0);
1380 type->u.u.size = size;
1384 tdesc_create_union (struct tdesc_feature *feature, const char *name)
1386 struct tdesc_type *type = XCNEW (struct tdesc_type);
1388 type->name = xstrdup (name);
1389 type->kind = TDESC_TYPE_UNION;
1391 VEC_safe_push (tdesc_type_p, feature->types, type);
1396 tdesc_create_flags (struct tdesc_feature *feature, const char *name,
1399 struct tdesc_type *type = XCNEW (struct tdesc_type);
1401 gdb_assert (size > 0);
1403 type->name = xstrdup (name);
1404 type->kind = TDESC_TYPE_FLAGS;
1405 type->u.u.size = size;
1407 VEC_safe_push (tdesc_type_p, feature->types, type);
1412 tdesc_create_enum (struct tdesc_feature *feature, const char *name,
1415 struct tdesc_type *type = XCNEW (struct tdesc_type);
1417 gdb_assert (size > 0);
1419 type->name = xstrdup (name);
1420 type->kind = TDESC_TYPE_ENUM;
1421 type->u.u.size = size;
1423 VEC_safe_push (tdesc_type_p, feature->types, type);
1427 /* Add a new field to TYPE. */
1430 tdesc_add_field (struct tdesc_type *type, const char *field_name,
1431 struct tdesc_type *field_type)
1433 struct tdesc_type_field f = { 0 };
1435 gdb_assert (type->kind == TDESC_TYPE_UNION
1436 || type->kind == TDESC_TYPE_STRUCT);
1438 f.name = xstrdup (field_name);
1439 f.type = field_type;
1440 /* Initialize these values so we know this is not a bit-field
1441 when we print-c-tdesc. */
1445 VEC_safe_push (tdesc_type_field, type->u.u.fields, &f);
1448 /* Add a new typed bitfield to TYPE. */
1451 tdesc_add_typed_bitfield (struct tdesc_type *type, const char *field_name,
1452 int start, int end, struct tdesc_type *field_type)
1454 struct tdesc_type_field f = { 0 };
1456 gdb_assert (type->kind == TDESC_TYPE_STRUCT
1457 || type->kind == TDESC_TYPE_FLAGS);
1458 gdb_assert (start >= 0 && end >= start);
1460 f.name = xstrdup (field_name);
1463 f.type = field_type;
1465 VEC_safe_push (tdesc_type_field, type->u.u.fields, &f);
1468 /* Add a new untyped bitfield to TYPE.
1469 Untyped bitfields become either uint32 or uint64 depending on the size
1470 of the underlying type. */
1473 tdesc_add_bitfield (struct tdesc_type *type, const char *field_name,
1476 struct tdesc_type *field_type;
1478 gdb_assert (start >= 0 && end >= start);
1480 if (type->u.u.size > 4)
1481 field_type = tdesc_predefined_type (TDESC_TYPE_UINT64);
1483 field_type = tdesc_predefined_type (TDESC_TYPE_UINT32);
1485 tdesc_add_typed_bitfield (type, field_name, start, end, field_type);
1488 /* A flag is just a typed(bool) single-bit bitfield.
1489 This function is kept to minimize changes in generated files. */
1492 tdesc_add_flag (struct tdesc_type *type, int start,
1493 const char *flag_name)
1495 struct tdesc_type_field f = { 0 };
1497 gdb_assert (type->kind == TDESC_TYPE_FLAGS
1498 || type->kind == TDESC_TYPE_STRUCT);
1500 f.name = xstrdup (flag_name);
1503 f.type = tdesc_predefined_type (TDESC_TYPE_BOOL);
1505 VEC_safe_push (tdesc_type_field, type->u.u.fields, &f);
1509 tdesc_add_enum_value (struct tdesc_type *type, int value,
1512 struct tdesc_type_field f = { 0 };
1514 gdb_assert (type->kind == TDESC_TYPE_ENUM);
1516 f.name = xstrdup (name);
1519 f.type = tdesc_predefined_type (TDESC_TYPE_INT32);
1521 VEC_safe_push (tdesc_type_field, type->u.u.fields, &f);
1525 tdesc_free_feature (struct tdesc_feature *feature)
1527 struct tdesc_reg *reg;
1528 struct tdesc_type *type;
1531 for (ix = 0; VEC_iterate (tdesc_reg_p, feature->registers, ix, reg); ix++)
1532 tdesc_free_reg (reg);
1533 VEC_free (tdesc_reg_p, feature->registers);
1535 for (ix = 0; VEC_iterate (tdesc_type_p, feature->types, ix, type); ix++)
1536 tdesc_free_type (type);
1537 VEC_free (tdesc_type_p, feature->types);
1539 xfree (feature->name);
1543 struct tdesc_feature *
1544 tdesc_create_feature (struct target_desc *tdesc, const char *name)
1546 struct tdesc_feature *new_feature = XCNEW (struct tdesc_feature);
1548 new_feature->name = xstrdup (name);
1550 VEC_safe_push (tdesc_feature_p, tdesc->features, new_feature);
1554 struct target_desc *
1555 allocate_target_description (void)
1557 return XCNEW (struct target_desc);
1561 free_target_description (void *arg)
1563 struct target_desc *target_desc = (struct target_desc *) arg;
1564 struct tdesc_feature *feature;
1565 struct property *prop;
1569 VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature);
1571 tdesc_free_feature (feature);
1572 VEC_free (tdesc_feature_p, target_desc->features);
1575 VEC_iterate (property_s, target_desc->properties, ix, prop);
1579 xfree (prop->value);
1581 VEC_free (property_s, target_desc->properties);
1583 VEC_free (arch_p, target_desc->compatible);
1585 xfree (target_desc);
1589 make_cleanup_free_target_description (struct target_desc *target_desc)
1591 return make_cleanup (free_target_description, target_desc);
1595 tdesc_add_compatible (struct target_desc *target_desc,
1596 const struct bfd_arch_info *compatible)
1598 const struct bfd_arch_info *compat;
1601 /* If this instance of GDB is compiled without BFD support for the
1602 compatible architecture, simply ignore it -- we would not be able
1603 to handle it anyway. */
1604 if (compatible == NULL)
1607 for (ix = 0; VEC_iterate (arch_p, target_desc->compatible, ix, compat);
1609 if (compat == compatible)
1610 internal_error (__FILE__, __LINE__,
1611 _("Attempted to add duplicate "
1612 "compatible architecture \"%s\""),
1613 compatible->printable_name);
1615 VEC_safe_push (arch_p, target_desc->compatible, compatible);
1619 set_tdesc_property (struct target_desc *target_desc,
1620 const char *key, const char *value)
1622 struct property *prop, new_prop;
1625 gdb_assert (key != NULL && value != NULL);
1627 for (ix = 0; VEC_iterate (property_s, target_desc->properties, ix, prop);
1629 if (strcmp (prop->key, key) == 0)
1630 internal_error (__FILE__, __LINE__,
1631 _("Attempted to add duplicate property \"%s\""), key);
1633 new_prop.key = xstrdup (key);
1634 new_prop.value = xstrdup (value);
1635 VEC_safe_push (property_s, target_desc->properties, &new_prop);
1639 set_tdesc_architecture (struct target_desc *target_desc,
1640 const struct bfd_arch_info *arch)
1642 target_desc->arch = arch;
1646 set_tdesc_osabi (struct target_desc *target_desc, enum gdb_osabi osabi)
1648 target_desc->osabi = osabi;
1652 static struct cmd_list_element *tdesc_set_cmdlist, *tdesc_show_cmdlist;
1653 static struct cmd_list_element *tdesc_unset_cmdlist;
1655 /* Helper functions for the CLI commands. */
1658 set_tdesc_cmd (char *args, int from_tty)
1660 help_list (tdesc_set_cmdlist, "set tdesc ", all_commands, gdb_stdout);
1664 show_tdesc_cmd (char *args, int from_tty)
1666 cmd_show_list (tdesc_show_cmdlist, from_tty, "");
1670 unset_tdesc_cmd (char *args, int from_tty)
1672 help_list (tdesc_unset_cmdlist, "unset tdesc ", all_commands, gdb_stdout);
1676 set_tdesc_filename_cmd (char *args, int from_tty,
1677 struct cmd_list_element *c)
1679 xfree (target_description_filename);
1680 target_description_filename = xstrdup (tdesc_filename_cmd_string);
1682 target_clear_description ();
1683 target_find_description ();
1687 show_tdesc_filename_cmd (struct ui_file *file, int from_tty,
1688 struct cmd_list_element *c,
1691 value = target_description_filename;
1693 if (value != NULL && *value != '\0')
1694 printf_filtered (_("The target description will be read from \"%s\".\n"),
1697 printf_filtered (_("The target description will be "
1698 "read from the target.\n"));
1702 unset_tdesc_filename_cmd (char *args, int from_tty)
1704 xfree (target_description_filename);
1705 target_description_filename = NULL;
1706 target_clear_description ();
1707 target_find_description ();
1711 maint_print_c_tdesc_cmd (char *args, int from_tty)
1713 const struct target_desc *tdesc;
1714 const struct bfd_arch_info *compatible;
1715 const char *filename, *inp;
1716 char *function, *outp;
1717 struct property *prop;
1718 struct tdesc_feature *feature;
1719 struct tdesc_reg *reg;
1720 struct tdesc_type *type;
1721 struct tdesc_type_field *f;
1723 int printed_field_type = 0;
1725 /* Use the global target-supplied description, not the current
1726 architecture's. This lets a GDB for one architecture generate C
1727 for another architecture's description, even though the gdbarch
1728 initialization code will reject the new description. */
1729 tdesc = current_target_desc;
1731 error (_("There is no target description to print."));
1733 if (target_description_filename == NULL)
1734 error (_("The current target description did not come from an XML file."));
1736 filename = lbasename (target_description_filename);
1737 function = (char *) alloca (strlen (filename) + 1);
1738 for (inp = filename, outp = function; *inp != '\0'; inp++)
1741 else if (*inp == '-')
1747 /* Standard boilerplate. */
1748 printf_unfiltered ("/* THIS FILE IS GENERATED. "
1749 "-*- buffer-read-only: t -*- vi"
1751 printf_unfiltered (" Original: %s */\n\n", filename);
1752 printf_unfiltered ("#include \"defs.h\"\n");
1753 printf_unfiltered ("#include \"osabi.h\"\n");
1754 printf_unfiltered ("#include \"target-descriptions.h\"\n");
1755 printf_unfiltered ("\n");
1757 printf_unfiltered ("struct target_desc *tdesc_%s;\n", function);
1758 printf_unfiltered ("static void\n");
1759 printf_unfiltered ("initialize_tdesc_%s (void)\n", function);
1760 printf_unfiltered ("{\n");
1762 (" struct target_desc *result = allocate_target_description ();\n");
1763 printf_unfiltered (" struct tdesc_feature *feature;\n");
1765 /* Now we do some "filtering" in order to know which variables to
1766 declare. This is needed because otherwise we would declare unused
1767 variables `field_type' and `type'. */
1769 VEC_iterate (tdesc_feature_p, tdesc->features, ix, feature);
1772 int printed_desc_type = 0;
1775 VEC_iterate (tdesc_type_p, feature->types, ix2, type);
1778 if (!printed_field_type)
1780 printf_unfiltered (" struct tdesc_type *field_type;\n");
1781 printed_field_type = 1;
1784 if ((type->kind == TDESC_TYPE_UNION
1785 || type->kind == TDESC_TYPE_STRUCT
1786 || type->kind == TDESC_TYPE_FLAGS
1787 || type->kind == TDESC_TYPE_ENUM)
1788 && VEC_length (tdesc_type_field, type->u.u.fields) > 0)
1790 printf_unfiltered (" struct tdesc_type *type;\n");
1791 printed_desc_type = 1;
1796 if (printed_desc_type)
1800 printf_unfiltered ("\n");
1802 if (tdesc_architecture (tdesc) != NULL)
1805 (" set_tdesc_architecture (result, bfd_scan_arch (\"%s\"));\n",
1806 tdesc_architecture (tdesc)->printable_name);
1807 printf_unfiltered ("\n");
1810 if (tdesc_osabi (tdesc) > GDB_OSABI_UNKNOWN
1811 && tdesc_osabi (tdesc) < GDB_OSABI_INVALID)
1814 (" set_tdesc_osabi (result, osabi_from_tdesc_string (\"%s\"));\n",
1815 gdbarch_osabi_name (tdesc_osabi (tdesc)));
1816 printf_unfiltered ("\n");
1819 for (ix = 0; VEC_iterate (arch_p, tdesc->compatible, ix, compatible);
1823 (" tdesc_add_compatible (result, bfd_scan_arch (\"%s\"));\n",
1824 compatible->printable_name);
1827 printf_unfiltered ("\n");
1829 for (ix = 0; VEC_iterate (property_s, tdesc->properties, ix, prop);
1832 printf_unfiltered (" set_tdesc_property (result, \"%s\", \"%s\");\n",
1833 prop->key, prop->value);
1837 VEC_iterate (tdesc_feature_p, tdesc->features, ix, feature);
1840 printf_unfiltered (" \
1841 feature = tdesc_create_feature (result, \"%s\");\n",
1845 VEC_iterate (tdesc_type_p, feature->types, ix2, type);
1850 case TDESC_TYPE_VECTOR:
1852 (" field_type = tdesc_named_type (feature, \"%s\");\n",
1853 type->u.v.type->name);
1855 (" tdesc_create_vector (feature, \"%s\", field_type, %d);\n",
1856 type->name, type->u.v.count);
1858 case TDESC_TYPE_STRUCT:
1859 case TDESC_TYPE_FLAGS:
1860 if (type->kind == TDESC_TYPE_STRUCT)
1863 (" type = tdesc_create_struct (feature, \"%s\");\n",
1865 if (type->u.u.size != 0)
1867 (" tdesc_set_struct_size (type, %d);\n",
1873 (" type = tdesc_create_flags (feature, \"%s\", %d);\n",
1874 type->name, type->u.u.size);
1877 VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f);
1880 const char *type_name;
1882 gdb_assert (f->type != NULL);
1883 type_name = f->type->name;
1885 /* To minimize changes to generated files, don't emit type
1886 info for fields that have defaulted types. */
1889 gdb_assert (f->end != -1);
1890 if (f->type->kind == TDESC_TYPE_BOOL)
1892 gdb_assert (f->start == f->end);
1894 (" tdesc_add_flag (type, %d, \"%s\");\n",
1897 else if ((type->u.u.size == 4
1898 && f->type->kind == TDESC_TYPE_UINT32)
1899 || (type->u.u.size == 8
1900 && f->type->kind == TDESC_TYPE_UINT64))
1903 (" tdesc_add_bitfield (type, \"%s\", %d, %d);\n",
1904 f->name, f->start, f->end);
1909 (" field_type = tdesc_named_type (feature,"
1913 (" tdesc_add_typed_bitfield (type, \"%s\","
1914 " %d, %d, field_type);\n",
1915 f->name, f->start, f->end);
1918 else /* Not a bitfield. */
1920 gdb_assert (f->end == -1);
1921 gdb_assert (type->kind == TDESC_TYPE_STRUCT);
1923 (" field_type = tdesc_named_type (feature,"
1927 (" tdesc_add_field (type, \"%s\", field_type);\n",
1932 case TDESC_TYPE_UNION:
1934 (" type = tdesc_create_union (feature, \"%s\");\n",
1937 VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f);
1941 (" field_type = tdesc_named_type (feature, \"%s\");\n",
1944 (" tdesc_add_field (type, \"%s\", field_type);\n",
1948 case TDESC_TYPE_ENUM:
1950 (" type = tdesc_create_enum (feature, \"%s\", %d);\n",
1951 type->name, type->u.u.size);
1953 VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f);
1956 (" tdesc_add_enum_value (type, %d, \"%s\");\n",
1960 error (_("C output is not supported type \"%s\"."), type->name);
1962 printf_unfiltered ("\n");
1966 VEC_iterate (tdesc_reg_p, feature->registers, ix2, reg);
1969 printf_unfiltered (" tdesc_create_reg (feature, \"%s\", %ld, %d, ",
1970 reg->name, reg->target_regnum, reg->save_restore);
1972 printf_unfiltered ("\"%s\", ", reg->group);
1974 printf_unfiltered ("NULL, ");
1975 printf_unfiltered ("%d, \"%s\");\n", reg->bitsize, reg->type);
1978 printf_unfiltered ("\n");
1981 printf_unfiltered (" tdesc_%s = result;\n", function);
1982 printf_unfiltered ("}\n");
1985 /* Provide a prototype to silence -Wmissing-prototypes. */
1986 extern initialize_file_ftype _initialize_target_descriptions;
1989 _initialize_target_descriptions (void)
1991 tdesc_data = gdbarch_data_register_pre_init (tdesc_data_init);
1993 add_prefix_cmd ("tdesc", class_maintenance, set_tdesc_cmd, _("\
1994 Set target description specific variables."),
1995 &tdesc_set_cmdlist, "set tdesc ",
1996 0 /* allow-unknown */, &setlist);
1997 add_prefix_cmd ("tdesc", class_maintenance, show_tdesc_cmd, _("\
1998 Show target description specific variables."),
1999 &tdesc_show_cmdlist, "show tdesc ",
2000 0 /* allow-unknown */, &showlist);
2001 add_prefix_cmd ("tdesc", class_maintenance, unset_tdesc_cmd, _("\
2002 Unset target description specific variables."),
2003 &tdesc_unset_cmdlist, "unset tdesc ",
2004 0 /* allow-unknown */, &unsetlist);
2006 add_setshow_filename_cmd ("filename", class_obscure,
2007 &tdesc_filename_cmd_string,
2009 Set the file to read for an XML target description"), _("\
2010 Show the file to read for an XML target description"), _("\
2011 When set, GDB will read the target description from a local\n\
2012 file instead of querying the remote target."),
2013 set_tdesc_filename_cmd,
2014 show_tdesc_filename_cmd,
2015 &tdesc_set_cmdlist, &tdesc_show_cmdlist);
2017 add_cmd ("filename", class_obscure, unset_tdesc_filename_cmd, _("\
2018 Unset the file to read for an XML target description. When unset,\n\
2019 GDB will read the description from the target."),
2020 &tdesc_unset_cmdlist);
2022 add_cmd ("c-tdesc", class_maintenance, maint_print_c_tdesc_cmd, _("\
2023 Print the current target description as a C source file."),
2024 &maintenanceprintlist);