1 /* Target description support for GDB.
3 Copyright (C) 2006-2015 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
;
95 DEF_VEC_O(tdesc_type_field
);
97 typedef struct tdesc_type_flag
102 DEF_VEC_O(tdesc_type_flag
);
106 /* Predefined types. */
119 TDESC_TYPE_IEEE_SINGLE
,
120 TDESC_TYPE_IEEE_DOUBLE
,
121 TDESC_TYPE_ARM_FPA_EXT
,
124 /* Types defined by a target feature. */
131 typedef struct tdesc_type
133 /* The name of this type. */
136 /* Identify the kind of this type. */
137 enum tdesc_type_kind kind
;
139 /* Kind-specific data. */
145 struct tdesc_type
*type
;
149 /* Struct or union type. */
152 VEC(tdesc_type_field
) *fields
;
159 VEC(tdesc_type_flag
) *flags
;
164 DEF_VEC_P(tdesc_type_p
);
166 /* A feature from a target description. Each feature is a collection
167 of other elements, e.g. registers and types. */
169 typedef struct tdesc_feature
171 /* The name of this feature. It may be recognized by the architecture
175 /* The registers associated with this feature. */
176 VEC(tdesc_reg_p
) *registers
;
178 /* The types associated with this feature. */
179 VEC(tdesc_type_p
) *types
;
181 DEF_VEC_P(tdesc_feature_p
);
183 /* A compatible architecture from a target description. */
184 typedef const struct bfd_arch_info
*arch_p
;
187 /* A target description. */
191 /* The architecture reported by the target, if any. */
192 const struct bfd_arch_info
*arch
;
194 /* The osabi reported by the target, if any; GDB_OSABI_UNKNOWN
196 enum gdb_osabi osabi
;
198 /* The list of compatible architectures reported by the target. */
199 VEC(arch_p
) *compatible
;
201 /* Any architecture-specific properties specified by the target. */
202 VEC(property_s
) *properties
;
204 /* The features associated with this target. */
205 VEC(tdesc_feature_p
) *features
;
208 /* Per-architecture data associated with a target description. The
209 target description may be shared by multiple architectures, but
210 this data is private to one gdbarch. */
212 typedef struct tdesc_arch_reg
214 struct tdesc_reg
*reg
;
217 DEF_VEC_O(tdesc_arch_reg
);
219 struct tdesc_arch_data
221 /* A list of register/type pairs, indexed by GDB's internal register number.
222 During initialization of the gdbarch this list is used to store
223 registers which the architecture assigns a fixed register number.
224 Registers which are NULL in this array, or off the end, are
225 treated as zero-sized and nameless (i.e. placeholders in the
227 VEC(tdesc_arch_reg
) *arch_regs
;
229 /* Functions which report the register name, type, and reggroups for
231 gdbarch_register_name_ftype
*pseudo_register_name
;
232 gdbarch_register_type_ftype
*pseudo_register_type
;
233 gdbarch_register_reggroup_p_ftype
*pseudo_register_reggroup_p
;
236 /* Info about an inferior's target description. There's one of these
237 for each inferior. */
239 struct target_desc_info
241 /* A flag indicating that a description has already been fetched
242 from the target, so it should not be queried again. */
246 /* The description fetched from the target, or NULL if the target
247 did not supply any description. Only valid when
248 target_desc_fetched is set. Only the description initialization
249 code should access this; normally, the description should be
250 accessed through the gdbarch object. */
252 const struct target_desc
*tdesc
;
254 /* The filename to read a target description from, as set by "set
255 tdesc filename ..." */
260 /* Get the inferior INF's target description info, allocating one on
261 the stop if necessary. */
263 static struct target_desc_info
*
264 get_tdesc_info (struct inferior
*inf
)
266 if (inf
->tdesc_info
== NULL
)
267 inf
->tdesc_info
= XCNEW (struct target_desc_info
);
268 return inf
->tdesc_info
;
271 /* A handle for architecture-specific data associated with the
272 target description (see struct tdesc_arch_data). */
274 static struct gdbarch_data
*tdesc_data
;
276 /* See target-descriptions.h. */
279 target_desc_info_from_user_p (struct target_desc_info
*info
)
281 return info
!= NULL
&& info
->filename
!= NULL
;
284 /* See target-descriptions.h. */
287 copy_inferior_target_desc_info (struct inferior
*destinf
, struct inferior
*srcinf
)
289 struct target_desc_info
*src
= get_tdesc_info (srcinf
);
290 struct target_desc_info
*dest
= get_tdesc_info (destinf
);
292 dest
->fetched
= src
->fetched
;
293 dest
->tdesc
= src
->tdesc
;
294 dest
->filename
= src
->filename
!= NULL
? xstrdup (src
->filename
) : NULL
;
297 /* See target-descriptions.h. */
300 target_desc_info_free (struct target_desc_info
*tdesc_info
)
302 if (tdesc_info
!= NULL
)
304 xfree (tdesc_info
->filename
);
309 /* Convenience helper macros. */
311 #define target_desc_fetched \
312 get_tdesc_info (current_inferior ())->fetched
313 #define current_target_desc \
314 get_tdesc_info (current_inferior ())->tdesc
315 #define target_description_filename \
316 get_tdesc_info (current_inferior ())->filename
318 /* The string manipulated by the "set tdesc filename ..." command. */
320 static char *tdesc_filename_cmd_string
;
322 /* Fetch the current target's description, and switch the current
323 architecture to one which incorporates that description. */
326 target_find_description (void)
328 /* If we've already fetched a description from the target, don't do
329 it again. This allows a target to fetch the description early,
330 during its to_open or to_create_inferior, if it needs extra
331 information about the target to initialize. */
332 if (target_desc_fetched
)
335 /* The current architecture should not have any target description
336 specified. It should have been cleared, e.g. when we
337 disconnected from the previous target. */
338 gdb_assert (gdbarch_target_desc (target_gdbarch ()) == NULL
);
340 /* First try to fetch an XML description from the user-specified
342 current_target_desc
= NULL
;
343 if (target_description_filename
!= NULL
344 && *target_description_filename
!= '\0')
346 = file_read_description_xml (target_description_filename
);
348 /* Next try to read the description from the current target using
350 if (current_target_desc
== NULL
)
351 current_target_desc
= target_read_description_xml (¤t_target
);
353 /* If that failed try a target-specific hook. */
354 if (current_target_desc
== NULL
)
355 current_target_desc
= target_read_description (¤t_target
);
357 /* If a non-NULL description was returned, then update the current
359 if (current_target_desc
)
361 struct gdbarch_info info
;
363 gdbarch_info_init (&info
);
364 info
.target_desc
= current_target_desc
;
365 if (!gdbarch_update_p (info
))
366 warning (_("Architecture rejected target-supplied description"));
369 struct tdesc_arch_data
*data
;
371 data
= gdbarch_data (target_gdbarch (), tdesc_data
);
372 if (tdesc_has_registers (current_target_desc
)
373 && data
->arch_regs
== NULL
)
374 warning (_("Target-supplied registers are not supported "
375 "by the current architecture"));
379 /* Now that we know this description is usable, record that we
381 target_desc_fetched
= 1;
384 /* Discard any description fetched from the current target, and switch
385 the current architecture to one with no target description. */
388 target_clear_description (void)
390 struct gdbarch_info info
;
392 if (!target_desc_fetched
)
395 target_desc_fetched
= 0;
396 current_target_desc
= NULL
;
398 gdbarch_info_init (&info
);
399 if (!gdbarch_update_p (info
))
400 internal_error (__FILE__
, __LINE__
,
401 _("Could not remove target-supplied description"));
404 /* Return the global current target description. This should only be
405 used by gdbarch initialization code; most access should be through
406 an existing gdbarch. */
408 const struct target_desc
*
409 target_current_description (void)
411 if (target_desc_fetched
)
412 return current_target_desc
;
417 /* Return non-zero if this target description is compatible
418 with the given BFD architecture. */
421 tdesc_compatible_p (const struct target_desc
*target_desc
,
422 const struct bfd_arch_info
*arch
)
424 const struct bfd_arch_info
*compat
;
427 for (ix
= 0; VEC_iterate (arch_p
, target_desc
->compatible
, ix
, compat
);
431 || arch
->compatible (arch
, compat
)
432 || compat
->compatible (compat
, arch
))
440 /* Direct accessors for target descriptions. */
442 /* Return the string value of a property named KEY, or NULL if the
443 property was not specified. */
446 tdesc_property (const struct target_desc
*target_desc
, const char *key
)
448 struct property
*prop
;
451 for (ix
= 0; VEC_iterate (property_s
, target_desc
->properties
, ix
, prop
);
453 if (strcmp (prop
->key
, key
) == 0)
459 /* Return the BFD architecture associated with this target
460 description, or NULL if no architecture was specified. */
462 const struct bfd_arch_info
*
463 tdesc_architecture (const struct target_desc
*target_desc
)
465 return target_desc
->arch
;
468 /* Return the OSABI associated with this target description, or
469 GDB_OSABI_UNKNOWN if no osabi was specified. */
472 tdesc_osabi (const struct target_desc
*target_desc
)
474 return target_desc
->osabi
;
479 /* Return 1 if this target description includes any registers. */
482 tdesc_has_registers (const struct target_desc
*target_desc
)
485 struct tdesc_feature
*feature
;
487 if (target_desc
== NULL
)
491 VEC_iterate (tdesc_feature_p
, target_desc
->features
, ix
, feature
);
493 if (! VEC_empty (tdesc_reg_p
, feature
->registers
))
499 /* Return the feature with the given name, if present, or NULL if
500 the named feature is not found. */
502 const struct tdesc_feature
*
503 tdesc_find_feature (const struct target_desc
*target_desc
,
507 struct tdesc_feature
*feature
;
510 VEC_iterate (tdesc_feature_p
, target_desc
->features
, ix
, feature
);
512 if (strcmp (feature
->name
, name
) == 0)
518 /* Return the name of FEATURE. */
521 tdesc_feature_name (const struct tdesc_feature
*feature
)
523 return feature
->name
;
526 /* Predefined types. */
527 static struct tdesc_type tdesc_predefined_types
[] =
529 { "int8", TDESC_TYPE_INT8
},
530 { "int16", TDESC_TYPE_INT16
},
531 { "int32", TDESC_TYPE_INT32
},
532 { "int64", TDESC_TYPE_INT64
},
533 { "int128", TDESC_TYPE_INT128
},
534 { "uint8", TDESC_TYPE_UINT8
},
535 { "uint16", TDESC_TYPE_UINT16
},
536 { "uint32", TDESC_TYPE_UINT32
},
537 { "uint64", TDESC_TYPE_UINT64
},
538 { "uint128", TDESC_TYPE_UINT128
},
539 { "code_ptr", TDESC_TYPE_CODE_PTR
},
540 { "data_ptr", TDESC_TYPE_DATA_PTR
},
541 { "ieee_single", TDESC_TYPE_IEEE_SINGLE
},
542 { "ieee_double", TDESC_TYPE_IEEE_DOUBLE
},
543 { "arm_fpa_ext", TDESC_TYPE_ARM_FPA_EXT
},
544 { "i387_ext", TDESC_TYPE_I387_EXT
}
547 /* Return the type associated with ID in the context of FEATURE, or
551 tdesc_named_type (const struct tdesc_feature
*feature
, const char *id
)
554 struct tdesc_type
*type
;
556 /* First try target-defined types. */
557 for (ix
= 0; VEC_iterate (tdesc_type_p
, feature
->types
, ix
, type
); ix
++)
558 if (strcmp (type
->name
, id
) == 0)
561 /* Next try the predefined types. */
562 for (ix
= 0; ix
< ARRAY_SIZE (tdesc_predefined_types
); ix
++)
563 if (strcmp (tdesc_predefined_types
[ix
].name
, id
) == 0)
564 return &tdesc_predefined_types
[ix
];
569 /* Lookup type associated with ID. */
572 tdesc_find_type (struct gdbarch
*gdbarch
, const char *id
)
574 struct tdesc_arch_reg
*reg
;
575 struct tdesc_arch_data
*data
;
578 data
= gdbarch_data (gdbarch
, tdesc_data
);
579 num_regs
= VEC_length (tdesc_arch_reg
, data
->arch_regs
);
580 for (i
= 0; i
< num_regs
; i
++)
582 reg
= VEC_index (tdesc_arch_reg
, data
->arch_regs
, i
);
584 && reg
->reg
->tdesc_type
586 && strcmp (id
, reg
->reg
->tdesc_type
->name
) == 0)
593 /* Construct, if necessary, and return the GDB type implementing target
594 type TDESC_TYPE for architecture GDBARCH. */
597 tdesc_gdb_type (struct gdbarch
*gdbarch
, struct tdesc_type
*tdesc_type
)
601 switch (tdesc_type
->kind
)
603 /* Predefined types. */
604 case TDESC_TYPE_INT8
:
605 return builtin_type (gdbarch
)->builtin_int8
;
607 case TDESC_TYPE_INT16
:
608 return builtin_type (gdbarch
)->builtin_int16
;
610 case TDESC_TYPE_INT32
:
611 return builtin_type (gdbarch
)->builtin_int32
;
613 case TDESC_TYPE_INT64
:
614 return builtin_type (gdbarch
)->builtin_int64
;
616 case TDESC_TYPE_INT128
:
617 return builtin_type (gdbarch
)->builtin_int128
;
619 case TDESC_TYPE_UINT8
:
620 return builtin_type (gdbarch
)->builtin_uint8
;
622 case TDESC_TYPE_UINT16
:
623 return builtin_type (gdbarch
)->builtin_uint16
;
625 case TDESC_TYPE_UINT32
:
626 return builtin_type (gdbarch
)->builtin_uint32
;
628 case TDESC_TYPE_UINT64
:
629 return builtin_type (gdbarch
)->builtin_uint64
;
631 case TDESC_TYPE_UINT128
:
632 return builtin_type (gdbarch
)->builtin_uint128
;
634 case TDESC_TYPE_CODE_PTR
:
635 return builtin_type (gdbarch
)->builtin_func_ptr
;
637 case TDESC_TYPE_DATA_PTR
:
638 return builtin_type (gdbarch
)->builtin_data_ptr
;
644 type
= tdesc_find_type (gdbarch
, tdesc_type
->name
);
648 switch (tdesc_type
->kind
)
650 case TDESC_TYPE_IEEE_SINGLE
:
651 return arch_float_type (gdbarch
, -1, "builtin_type_ieee_single",
652 floatformats_ieee_single
);
654 case TDESC_TYPE_IEEE_DOUBLE
:
655 return arch_float_type (gdbarch
, -1, "builtin_type_ieee_double",
656 floatformats_ieee_double
);
658 case TDESC_TYPE_ARM_FPA_EXT
:
659 return arch_float_type (gdbarch
, -1, "builtin_type_arm_ext",
660 floatformats_arm_ext
);
662 case TDESC_TYPE_I387_EXT
:
663 return arch_float_type (gdbarch
, -1, "builtin_type_i387_ext",
664 floatformats_i387_ext
);
666 /* Types defined by a target feature. */
667 case TDESC_TYPE_VECTOR
:
669 struct type
*type
, *field_type
;
671 field_type
= tdesc_gdb_type (gdbarch
, tdesc_type
->u
.v
.type
);
672 type
= init_vector_type (field_type
, tdesc_type
->u
.v
.count
);
673 TYPE_NAME (type
) = xstrdup (tdesc_type
->name
);
678 case TDESC_TYPE_STRUCT
:
680 struct type
*type
, *field_type
;
681 struct tdesc_type_field
*f
;
684 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
685 TYPE_NAME (type
) = xstrdup (tdesc_type
->name
);
686 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
689 VEC_iterate (tdesc_type_field
, tdesc_type
->u
.u
.fields
, ix
, f
);
696 struct type
*field_type
;
697 int bitsize
, total_size
;
699 /* This invariant should be preserved while creating
701 gdb_assert (tdesc_type
->u
.u
.size
!= 0);
702 if (tdesc_type
->u
.u
.size
> 4)
703 field_type
= builtin_type (gdbarch
)->builtin_uint64
;
705 field_type
= builtin_type (gdbarch
)->builtin_uint32
;
707 fld
= append_composite_type_field_raw (type
, xstrdup (f
->name
),
710 /* For little-endian, BITPOS counts from the LSB of
711 the structure and marks the LSB of the field. For
712 big-endian, BITPOS counts from the MSB of the
713 structure and marks the MSB of the field. Either
714 way, it is the number of bits to the "left" of the
715 field. To calculate this in big-endian, we need
716 the total size of the structure. */
717 bitsize
= f
->end
- f
->start
+ 1;
718 total_size
= tdesc_type
->u
.u
.size
* TARGET_CHAR_BIT
;
719 if (gdbarch_bits_big_endian (gdbarch
))
720 SET_FIELD_BITPOS (fld
[0], total_size
- f
->start
- bitsize
);
722 SET_FIELD_BITPOS (fld
[0], f
->start
);
723 FIELD_BITSIZE (fld
[0]) = bitsize
;
727 field_type
= tdesc_gdb_type (gdbarch
, f
->type
);
728 append_composite_type_field (type
, xstrdup (f
->name
),
733 if (tdesc_type
->u
.u
.size
!= 0)
734 TYPE_LENGTH (type
) = tdesc_type
->u
.u
.size
;
738 case TDESC_TYPE_UNION
:
740 struct type
*type
, *field_type
;
741 struct tdesc_type_field
*f
;
744 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_UNION
);
745 TYPE_NAME (type
) = xstrdup (tdesc_type
->name
);
748 VEC_iterate (tdesc_type_field
, tdesc_type
->u
.u
.fields
, ix
, f
);
751 field_type
= tdesc_gdb_type (gdbarch
, f
->type
);
752 append_composite_type_field (type
, xstrdup (f
->name
), field_type
);
754 /* If any of the children of a union are vectors, flag the
755 union as a vector also. This allows e.g. a union of two
756 vector types to show up automatically in "info vector". */
757 if (TYPE_VECTOR (field_type
))
758 TYPE_VECTOR (type
) = 1;
763 case TDESC_TYPE_FLAGS
:
765 struct tdesc_type_flag
*f
;
768 type
= arch_flags_type (gdbarch
, tdesc_type
->name
,
769 tdesc_type
->u
.f
.size
);
771 VEC_iterate (tdesc_type_flag
, tdesc_type
->u
.f
.flags
, ix
, f
);
773 /* Note that contrary to the function name, this call will
774 just set the properties of an already-allocated
776 append_flags_type_flag (type
, f
->start
,
777 *f
->name
? f
->name
: NULL
);
783 internal_error (__FILE__
, __LINE__
,
784 "Type \"%s\" has an unknown kind %d",
785 tdesc_type
->name
, tdesc_type
->kind
);
789 /* Support for registers from target descriptions. */
791 /* Construct the per-gdbarch data. */
794 tdesc_data_init (struct obstack
*obstack
)
796 struct tdesc_arch_data
*data
;
798 data
= OBSTACK_ZALLOC (obstack
, struct tdesc_arch_data
);
802 /* Similar, but for the temporary copy used during architecture
805 struct tdesc_arch_data
*
806 tdesc_data_alloc (void)
808 return XCNEW (struct tdesc_arch_data
);
811 /* Free something allocated by tdesc_data_alloc, if it is not going
812 to be used (for instance if it was unsuitable for the
816 tdesc_data_cleanup (void *data_untyped
)
818 struct tdesc_arch_data
*data
= data_untyped
;
820 VEC_free (tdesc_arch_reg
, data
->arch_regs
);
824 /* Search FEATURE for a register named NAME. */
826 static struct tdesc_reg
*
827 tdesc_find_register_early (const struct tdesc_feature
*feature
,
831 struct tdesc_reg
*reg
;
834 VEC_iterate (tdesc_reg_p
, feature
->registers
, ixr
, reg
);
836 if (strcasecmp (reg
->name
, name
) == 0)
842 /* Search FEATURE for a register named NAME. Assign REGNO to it. */
845 tdesc_numbered_register (const struct tdesc_feature
*feature
,
846 struct tdesc_arch_data
*data
,
847 int regno
, const char *name
)
849 struct tdesc_arch_reg arch_reg
= { 0 };
850 struct tdesc_reg
*reg
= tdesc_find_register_early (feature
, name
);
855 /* Make sure the vector includes a REGNO'th element. */
856 while (regno
>= VEC_length (tdesc_arch_reg
, data
->arch_regs
))
857 VEC_safe_push (tdesc_arch_reg
, data
->arch_regs
, &arch_reg
);
860 VEC_replace (tdesc_arch_reg
, data
->arch_regs
, regno
, &arch_reg
);
864 /* Search FEATURE for a register named NAME, but do not assign a fixed
865 register number to it. */
868 tdesc_unnumbered_register (const struct tdesc_feature
*feature
,
871 struct tdesc_reg
*reg
= tdesc_find_register_early (feature
, name
);
879 /* Search FEATURE for a register whose name is in NAMES and assign
883 tdesc_numbered_register_choices (const struct tdesc_feature
*feature
,
884 struct tdesc_arch_data
*data
,
885 int regno
, const char *const names
[])
889 for (i
= 0; names
[i
] != NULL
; i
++)
890 if (tdesc_numbered_register (feature
, data
, regno
, names
[i
]))
896 /* Search FEATURE for a register named NAME, and return its size in
897 bits. The register must exist. */
900 tdesc_register_size (const struct tdesc_feature
*feature
,
903 struct tdesc_reg
*reg
= tdesc_find_register_early (feature
, name
);
905 gdb_assert (reg
!= NULL
);
909 /* Look up a register by its GDB internal register number. */
911 static struct tdesc_arch_reg
*
912 tdesc_find_arch_register (struct gdbarch
*gdbarch
, int regno
)
914 struct tdesc_arch_data
*data
;
916 data
= gdbarch_data (gdbarch
, tdesc_data
);
917 if (regno
< VEC_length (tdesc_arch_reg
, data
->arch_regs
))
918 return VEC_index (tdesc_arch_reg
, data
->arch_regs
, regno
);
923 static struct tdesc_reg
*
924 tdesc_find_register (struct gdbarch
*gdbarch
, int regno
)
926 struct tdesc_arch_reg
*reg
= tdesc_find_arch_register (gdbarch
, regno
);
928 return reg
? reg
->reg
: NULL
;
931 /* Return the name of register REGNO, from the target description or
932 from an architecture-provided pseudo_register_name method. */
935 tdesc_register_name (struct gdbarch
*gdbarch
, int regno
)
937 struct tdesc_reg
*reg
= tdesc_find_register (gdbarch
, regno
);
938 int num_regs
= gdbarch_num_regs (gdbarch
);
939 int num_pseudo_regs
= gdbarch_num_pseudo_regs (gdbarch
);
944 if (regno
>= num_regs
&& regno
< num_regs
+ num_pseudo_regs
)
946 struct tdesc_arch_data
*data
= gdbarch_data (gdbarch
, tdesc_data
);
948 gdb_assert (data
->pseudo_register_name
!= NULL
);
949 return data
->pseudo_register_name (gdbarch
, regno
);
956 tdesc_register_type (struct gdbarch
*gdbarch
, int regno
)
958 struct tdesc_arch_reg
*arch_reg
= tdesc_find_arch_register (gdbarch
, regno
);
959 struct tdesc_reg
*reg
= arch_reg
? arch_reg
->reg
: NULL
;
960 int num_regs
= gdbarch_num_regs (gdbarch
);
961 int num_pseudo_regs
= gdbarch_num_pseudo_regs (gdbarch
);
963 if (reg
== NULL
&& regno
>= num_regs
&& regno
< num_regs
+ num_pseudo_regs
)
965 struct tdesc_arch_data
*data
= gdbarch_data (gdbarch
, tdesc_data
);
967 gdb_assert (data
->pseudo_register_type
!= NULL
);
968 return data
->pseudo_register_type (gdbarch
, regno
);
972 /* Return "int0_t", since "void" has a misleading size of one. */
973 return builtin_type (gdbarch
)->builtin_int0
;
975 if (arch_reg
->type
== NULL
)
977 /* First check for a predefined or target defined type. */
979 arch_reg
->type
= tdesc_gdb_type (gdbarch
, reg
->tdesc_type
);
981 /* Next try size-sensitive type shortcuts. */
982 else if (strcmp (reg
->type
, "float") == 0)
984 if (reg
->bitsize
== gdbarch_float_bit (gdbarch
))
985 arch_reg
->type
= builtin_type (gdbarch
)->builtin_float
;
986 else if (reg
->bitsize
== gdbarch_double_bit (gdbarch
))
987 arch_reg
->type
= builtin_type (gdbarch
)->builtin_double
;
988 else if (reg
->bitsize
== gdbarch_long_double_bit (gdbarch
))
989 arch_reg
->type
= builtin_type (gdbarch
)->builtin_long_double
;
992 warning (_("Register \"%s\" has an unsupported size (%d bits)"),
993 reg
->name
, reg
->bitsize
);
994 arch_reg
->type
= builtin_type (gdbarch
)->builtin_double
;
997 else if (strcmp (reg
->type
, "int") == 0)
999 if (reg
->bitsize
== gdbarch_long_bit (gdbarch
))
1000 arch_reg
->type
= builtin_type (gdbarch
)->builtin_long
;
1001 else if (reg
->bitsize
== TARGET_CHAR_BIT
)
1002 arch_reg
->type
= builtin_type (gdbarch
)->builtin_char
;
1003 else if (reg
->bitsize
== gdbarch_short_bit (gdbarch
))
1004 arch_reg
->type
= builtin_type (gdbarch
)->builtin_short
;
1005 else if (reg
->bitsize
== gdbarch_int_bit (gdbarch
))
1006 arch_reg
->type
= builtin_type (gdbarch
)->builtin_int
;
1007 else if (reg
->bitsize
== gdbarch_long_long_bit (gdbarch
))
1008 arch_reg
->type
= builtin_type (gdbarch
)->builtin_long_long
;
1009 else if (reg
->bitsize
== gdbarch_ptr_bit (gdbarch
))
1010 /* A bit desperate by this point... */
1011 arch_reg
->type
= builtin_type (gdbarch
)->builtin_data_ptr
;
1014 warning (_("Register \"%s\" has an unsupported size (%d bits)"),
1015 reg
->name
, reg
->bitsize
);
1016 arch_reg
->type
= builtin_type (gdbarch
)->builtin_long
;
1020 if (arch_reg
->type
== NULL
)
1021 internal_error (__FILE__
, __LINE__
,
1022 "Register \"%s\" has an unknown type \"%s\"",
1023 reg
->name
, reg
->type
);
1026 return arch_reg
->type
;
1030 tdesc_remote_register_number (struct gdbarch
*gdbarch
, int regno
)
1032 struct tdesc_reg
*reg
= tdesc_find_register (gdbarch
, regno
);
1035 return reg
->target_regnum
;
1040 /* Check whether REGNUM is a member of REGGROUP. Registers from the
1041 target description may be classified as general, float, or vector.
1042 Unlike a gdbarch register_reggroup_p method, this function will
1043 return -1 if it does not know; the caller should handle registers
1044 with no specified group.
1046 Arbitrary strings (other than "general", "float", and "vector")
1047 from the description are not used; they cause the register to be
1048 displayed in "info all-registers" but excluded from "info
1049 registers" et al. The names of containing features are also not
1050 used. This might be extended to display registers in some more
1053 The save-restore flag is also implemented here. */
1056 tdesc_register_in_reggroup_p (struct gdbarch
*gdbarch
, int regno
,
1057 struct reggroup
*reggroup
)
1059 struct tdesc_reg
*reg
= tdesc_find_register (gdbarch
, regno
);
1061 if (reg
!= NULL
&& reg
->group
!= NULL
)
1063 int general_p
= 0, float_p
= 0, vector_p
= 0;
1065 if (strcmp (reg
->group
, "general") == 0)
1067 else if (strcmp (reg
->group
, "float") == 0)
1069 else if (strcmp (reg
->group
, "vector") == 0)
1072 if (reggroup
== float_reggroup
)
1075 if (reggroup
== vector_reggroup
)
1078 if (reggroup
== general_reggroup
)
1083 && (reggroup
== save_reggroup
|| reggroup
== restore_reggroup
))
1084 return reg
->save_restore
;
1089 /* Check whether REGNUM is a member of REGGROUP. Registers with no
1090 group specified go to the default reggroup function and are handled
1094 tdesc_register_reggroup_p (struct gdbarch
*gdbarch
, int regno
,
1095 struct reggroup
*reggroup
)
1097 int num_regs
= gdbarch_num_regs (gdbarch
);
1098 int num_pseudo_regs
= gdbarch_num_pseudo_regs (gdbarch
);
1101 if (regno
>= num_regs
&& regno
< num_regs
+ num_pseudo_regs
)
1103 struct tdesc_arch_data
*data
= gdbarch_data (gdbarch
, tdesc_data
);
1105 if (data
->pseudo_register_reggroup_p
!= NULL
)
1106 return data
->pseudo_register_reggroup_p (gdbarch
, regno
, reggroup
);
1107 /* Otherwise fall through to the default reggroup_p. */
1110 ret
= tdesc_register_in_reggroup_p (gdbarch
, regno
, reggroup
);
1114 return default_register_reggroup_p (gdbarch
, regno
, reggroup
);
1117 /* Record architecture-specific functions to call for pseudo-register
1121 set_tdesc_pseudo_register_name (struct gdbarch
*gdbarch
,
1122 gdbarch_register_name_ftype
*pseudo_name
)
1124 struct tdesc_arch_data
*data
= gdbarch_data (gdbarch
, tdesc_data
);
1126 data
->pseudo_register_name
= pseudo_name
;
1130 set_tdesc_pseudo_register_type (struct gdbarch
*gdbarch
,
1131 gdbarch_register_type_ftype
*pseudo_type
)
1133 struct tdesc_arch_data
*data
= gdbarch_data (gdbarch
, tdesc_data
);
1135 data
->pseudo_register_type
= pseudo_type
;
1139 set_tdesc_pseudo_register_reggroup_p
1140 (struct gdbarch
*gdbarch
,
1141 gdbarch_register_reggroup_p_ftype
*pseudo_reggroup_p
)
1143 struct tdesc_arch_data
*data
= gdbarch_data (gdbarch
, tdesc_data
);
1145 data
->pseudo_register_reggroup_p
= pseudo_reggroup_p
;
1148 /* Update GDBARCH to use the target description for registers. */
1151 tdesc_use_registers (struct gdbarch
*gdbarch
,
1152 const struct target_desc
*target_desc
,
1153 struct tdesc_arch_data
*early_data
)
1155 int num_regs
= gdbarch_num_regs (gdbarch
);
1157 struct tdesc_feature
*feature
;
1158 struct tdesc_reg
*reg
;
1159 struct tdesc_arch_data
*data
;
1160 struct tdesc_arch_reg
*arch_reg
, new_arch_reg
= { 0 };
1163 /* We can't use the description for registers if it doesn't describe
1164 any. This function should only be called after validating
1165 registers, so the caller should know that registers are
1167 gdb_assert (tdesc_has_registers (target_desc
));
1169 data
= gdbarch_data (gdbarch
, tdesc_data
);
1170 data
->arch_regs
= early_data
->arch_regs
;
1173 /* Build up a set of all registers, so that we can assign register
1174 numbers where needed. The hash table expands as necessary, so
1175 the initial size is arbitrary. */
1176 reg_hash
= htab_create (37, htab_hash_pointer
, htab_eq_pointer
, NULL
);
1178 VEC_iterate (tdesc_feature_p
, target_desc
->features
, ixf
, feature
);
1181 VEC_iterate (tdesc_reg_p
, feature
->registers
, ixr
, reg
);
1184 void **slot
= htab_find_slot (reg_hash
, reg
, INSERT
);
1189 /* Remove any registers which were assigned numbers by the
1192 VEC_iterate (tdesc_arch_reg
, data
->arch_regs
, ixr
, arch_reg
);
1195 htab_remove_elt (reg_hash
, arch_reg
->reg
);
1197 /* Assign numbers to the remaining registers and add them to the
1198 list of registers. The new numbers are always above gdbarch_num_regs.
1199 Iterate over the features, not the hash table, so that the order
1200 matches that in the target description. */
1202 gdb_assert (VEC_length (tdesc_arch_reg
, data
->arch_regs
) <= num_regs
);
1203 while (VEC_length (tdesc_arch_reg
, data
->arch_regs
) < num_regs
)
1204 VEC_safe_push (tdesc_arch_reg
, data
->arch_regs
, &new_arch_reg
);
1206 VEC_iterate (tdesc_feature_p
, target_desc
->features
, ixf
, feature
);
1209 VEC_iterate (tdesc_reg_p
, feature
->registers
, ixr
, reg
);
1211 if (htab_find (reg_hash
, reg
) != NULL
)
1213 new_arch_reg
.reg
= reg
;
1214 VEC_safe_push (tdesc_arch_reg
, data
->arch_regs
, &new_arch_reg
);
1218 htab_delete (reg_hash
);
1220 /* Update the architecture. */
1221 set_gdbarch_num_regs (gdbarch
, num_regs
);
1222 set_gdbarch_register_name (gdbarch
, tdesc_register_name
);
1223 set_gdbarch_register_type (gdbarch
, tdesc_register_type
);
1224 set_gdbarch_remote_register_number (gdbarch
,
1225 tdesc_remote_register_number
);
1226 set_gdbarch_register_reggroup_p (gdbarch
, tdesc_register_reggroup_p
);
1230 /* Methods for constructing a target description. */
1233 tdesc_free_reg (struct tdesc_reg
*reg
)
1242 tdesc_create_reg (struct tdesc_feature
*feature
, const char *name
,
1243 int regnum
, int save_restore
, const char *group
,
1244 int bitsize
, const char *type
)
1246 struct tdesc_reg
*reg
= XCNEW (struct tdesc_reg
);
1248 reg
->name
= xstrdup (name
);
1249 reg
->target_regnum
= regnum
;
1250 reg
->save_restore
= save_restore
;
1251 reg
->group
= group
? xstrdup (group
) : NULL
;
1252 reg
->bitsize
= bitsize
;
1253 reg
->type
= type
? xstrdup (type
) : xstrdup ("<unknown>");
1255 /* If the register's type is target-defined, look it up now. We may not
1256 have easy access to the containing feature when we want it later. */
1257 reg
->tdesc_type
= tdesc_named_type (feature
, reg
->type
);
1259 VEC_safe_push (tdesc_reg_p
, feature
->registers
, reg
);
1263 tdesc_free_type (struct tdesc_type
*type
)
1267 case TDESC_TYPE_STRUCT
:
1268 case TDESC_TYPE_UNION
:
1270 struct tdesc_type_field
*f
;
1274 VEC_iterate (tdesc_type_field
, type
->u
.u
.fields
, ix
, f
);
1278 VEC_free (tdesc_type_field
, type
->u
.u
.fields
);
1282 case TDESC_TYPE_FLAGS
:
1284 struct tdesc_type_flag
*f
;
1288 VEC_iterate (tdesc_type_flag
, type
->u
.f
.flags
, ix
, f
);
1292 VEC_free (tdesc_type_flag
, type
->u
.f
.flags
);
1305 tdesc_create_vector (struct tdesc_feature
*feature
, const char *name
,
1306 struct tdesc_type
*field_type
, int count
)
1308 struct tdesc_type
*type
= XCNEW (struct tdesc_type
);
1310 type
->name
= xstrdup (name
);
1311 type
->kind
= TDESC_TYPE_VECTOR
;
1312 type
->u
.v
.type
= field_type
;
1313 type
->u
.v
.count
= count
;
1315 VEC_safe_push (tdesc_type_p
, feature
->types
, type
);
1320 tdesc_create_struct (struct tdesc_feature
*feature
, const char *name
)
1322 struct tdesc_type
*type
= XCNEW (struct tdesc_type
);
1324 type
->name
= xstrdup (name
);
1325 type
->kind
= TDESC_TYPE_STRUCT
;
1327 VEC_safe_push (tdesc_type_p
, feature
->types
, type
);
1331 /* Set the total length of TYPE. Structs which contain bitfields may
1332 omit the reserved bits, so the end of the last field may not
1336 tdesc_set_struct_size (struct tdesc_type
*type
, LONGEST size
)
1338 gdb_assert (type
->kind
== TDESC_TYPE_STRUCT
);
1339 type
->u
.u
.size
= size
;
1343 tdesc_create_union (struct tdesc_feature
*feature
, const char *name
)
1345 struct tdesc_type
*type
= XCNEW (struct tdesc_type
);
1347 type
->name
= xstrdup (name
);
1348 type
->kind
= TDESC_TYPE_UNION
;
1350 VEC_safe_push (tdesc_type_p
, feature
->types
, type
);
1355 tdesc_create_flags (struct tdesc_feature
*feature
, const char *name
,
1358 struct tdesc_type
*type
= XCNEW (struct tdesc_type
);
1360 type
->name
= xstrdup (name
);
1361 type
->kind
= TDESC_TYPE_FLAGS
;
1362 type
->u
.f
.size
= size
;
1364 VEC_safe_push (tdesc_type_p
, feature
->types
, type
);
1368 /* Add a new field. Return a temporary pointer to the field, which
1369 is only valid until the next call to tdesc_add_field (the vector
1370 might be reallocated). */
1373 tdesc_add_field (struct tdesc_type
*type
, const char *field_name
,
1374 struct tdesc_type
*field_type
)
1376 struct tdesc_type_field f
= { 0 };
1378 gdb_assert (type
->kind
== TDESC_TYPE_UNION
1379 || type
->kind
== TDESC_TYPE_STRUCT
);
1381 f
.name
= xstrdup (field_name
);
1382 f
.type
= field_type
;
1384 VEC_safe_push (tdesc_type_field
, type
->u
.u
.fields
, &f
);
1387 /* Add a new bitfield. */
1390 tdesc_add_bitfield (struct tdesc_type
*type
, const char *field_name
,
1393 struct tdesc_type_field f
= { 0 };
1395 gdb_assert (type
->kind
== TDESC_TYPE_STRUCT
);
1397 f
.name
= xstrdup (field_name
);
1401 VEC_safe_push (tdesc_type_field
, type
->u
.u
.fields
, &f
);
1405 tdesc_add_flag (struct tdesc_type
*type
, int start
,
1406 const char *flag_name
)
1408 struct tdesc_type_flag f
= { 0 };
1410 gdb_assert (type
->kind
== TDESC_TYPE_FLAGS
);
1412 f
.name
= xstrdup (flag_name
);
1415 VEC_safe_push (tdesc_type_flag
, type
->u
.f
.flags
, &f
);
1419 tdesc_free_feature (struct tdesc_feature
*feature
)
1421 struct tdesc_reg
*reg
;
1422 struct tdesc_type
*type
;
1425 for (ix
= 0; VEC_iterate (tdesc_reg_p
, feature
->registers
, ix
, reg
); ix
++)
1426 tdesc_free_reg (reg
);
1427 VEC_free (tdesc_reg_p
, feature
->registers
);
1429 for (ix
= 0; VEC_iterate (tdesc_type_p
, feature
->types
, ix
, type
); ix
++)
1430 tdesc_free_type (type
);
1431 VEC_free (tdesc_type_p
, feature
->types
);
1433 xfree (feature
->name
);
1437 struct tdesc_feature
*
1438 tdesc_create_feature (struct target_desc
*tdesc
, const char *name
)
1440 struct tdesc_feature
*new_feature
= XCNEW (struct tdesc_feature
);
1442 new_feature
->name
= xstrdup (name
);
1444 VEC_safe_push (tdesc_feature_p
, tdesc
->features
, new_feature
);
1448 struct target_desc
*
1449 allocate_target_description (void)
1451 return XCNEW (struct target_desc
);
1455 free_target_description (void *arg
)
1457 struct target_desc
*target_desc
= arg
;
1458 struct tdesc_feature
*feature
;
1459 struct property
*prop
;
1463 VEC_iterate (tdesc_feature_p
, target_desc
->features
, ix
, feature
);
1465 tdesc_free_feature (feature
);
1466 VEC_free (tdesc_feature_p
, target_desc
->features
);
1469 VEC_iterate (property_s
, target_desc
->properties
, ix
, prop
);
1473 xfree (prop
->value
);
1475 VEC_free (property_s
, target_desc
->properties
);
1477 VEC_free (arch_p
, target_desc
->compatible
);
1479 xfree (target_desc
);
1483 make_cleanup_free_target_description (struct target_desc
*target_desc
)
1485 return make_cleanup (free_target_description
, target_desc
);
1489 tdesc_add_compatible (struct target_desc
*target_desc
,
1490 const struct bfd_arch_info
*compatible
)
1492 const struct bfd_arch_info
*compat
;
1495 /* If this instance of GDB is compiled without BFD support for the
1496 compatible architecture, simply ignore it -- we would not be able
1497 to handle it anyway. */
1498 if (compatible
== NULL
)
1501 for (ix
= 0; VEC_iterate (arch_p
, target_desc
->compatible
, ix
, compat
);
1503 if (compat
== compatible
)
1504 internal_error (__FILE__
, __LINE__
,
1505 _("Attempted to add duplicate "
1506 "compatible architecture \"%s\""),
1507 compatible
->printable_name
);
1509 VEC_safe_push (arch_p
, target_desc
->compatible
, compatible
);
1513 set_tdesc_property (struct target_desc
*target_desc
,
1514 const char *key
, const char *value
)
1516 struct property
*prop
, new_prop
;
1519 gdb_assert (key
!= NULL
&& value
!= NULL
);
1521 for (ix
= 0; VEC_iterate (property_s
, target_desc
->properties
, ix
, prop
);
1523 if (strcmp (prop
->key
, key
) == 0)
1524 internal_error (__FILE__
, __LINE__
,
1525 _("Attempted to add duplicate property \"%s\""), key
);
1527 new_prop
.key
= xstrdup (key
);
1528 new_prop
.value
= xstrdup (value
);
1529 VEC_safe_push (property_s
, target_desc
->properties
, &new_prop
);
1533 set_tdesc_architecture (struct target_desc
*target_desc
,
1534 const struct bfd_arch_info
*arch
)
1536 target_desc
->arch
= arch
;
1540 set_tdesc_osabi (struct target_desc
*target_desc
, enum gdb_osabi osabi
)
1542 target_desc
->osabi
= osabi
;
1546 static struct cmd_list_element
*tdesc_set_cmdlist
, *tdesc_show_cmdlist
;
1547 static struct cmd_list_element
*tdesc_unset_cmdlist
;
1549 /* Helper functions for the CLI commands. */
1552 set_tdesc_cmd (char *args
, int from_tty
)
1554 help_list (tdesc_set_cmdlist
, "set tdesc ", all_commands
, gdb_stdout
);
1558 show_tdesc_cmd (char *args
, int from_tty
)
1560 cmd_show_list (tdesc_show_cmdlist
, from_tty
, "");
1564 unset_tdesc_cmd (char *args
, int from_tty
)
1566 help_list (tdesc_unset_cmdlist
, "unset tdesc ", all_commands
, gdb_stdout
);
1570 set_tdesc_filename_cmd (char *args
, int from_tty
,
1571 struct cmd_list_element
*c
)
1573 xfree (target_description_filename
);
1574 target_description_filename
= xstrdup (tdesc_filename_cmd_string
);
1576 target_clear_description ();
1577 target_find_description ();
1581 show_tdesc_filename_cmd (struct ui_file
*file
, int from_tty
,
1582 struct cmd_list_element
*c
,
1585 value
= target_description_filename
;
1587 if (value
!= NULL
&& *value
!= '\0')
1588 printf_filtered (_("The target description will be read from \"%s\".\n"),
1591 printf_filtered (_("The target description will be "
1592 "read from the target.\n"));
1596 unset_tdesc_filename_cmd (char *args
, int from_tty
)
1598 xfree (target_description_filename
);
1599 target_description_filename
= NULL
;
1600 target_clear_description ();
1601 target_find_description ();
1605 maint_print_c_tdesc_cmd (char *args
, int from_tty
)
1607 const struct target_desc
*tdesc
;
1608 const struct bfd_arch_info
*compatible
;
1609 const char *filename
, *inp
;
1610 char *function
, *outp
;
1611 struct property
*prop
;
1612 struct tdesc_feature
*feature
;
1613 struct tdesc_reg
*reg
;
1614 struct tdesc_type
*type
;
1615 struct tdesc_type_field
*f
;
1616 struct tdesc_type_flag
*flag
;
1618 int printed_field_type
= 0;
1620 /* Use the global target-supplied description, not the current
1621 architecture's. This lets a GDB for one architecture generate C
1622 for another architecture's description, even though the gdbarch
1623 initialization code will reject the new description. */
1624 tdesc
= current_target_desc
;
1626 error (_("There is no target description to print."));
1628 if (target_description_filename
== NULL
)
1629 error (_("The current target description did not come from an XML file."));
1631 filename
= lbasename (target_description_filename
);
1632 function
= alloca (strlen (filename
) + 1);
1633 for (inp
= filename
, outp
= function
; *inp
!= '\0'; inp
++)
1636 else if (*inp
== '-')
1642 /* Standard boilerplate. */
1643 printf_unfiltered ("/* THIS FILE IS GENERATED. "
1644 "-*- buffer-read-only: t -*- vi"
1646 printf_unfiltered (" Original: %s */\n\n", filename
);
1647 printf_unfiltered ("#include \"defs.h\"\n");
1648 printf_unfiltered ("#include \"osabi.h\"\n");
1649 printf_unfiltered ("#include \"target-descriptions.h\"\n");
1650 printf_unfiltered ("\n");
1652 printf_unfiltered ("struct target_desc *tdesc_%s;\n", function
);
1653 printf_unfiltered ("static void\n");
1654 printf_unfiltered ("initialize_tdesc_%s (void)\n", function
);
1655 printf_unfiltered ("{\n");
1657 (" struct target_desc *result = allocate_target_description ();\n");
1658 printf_unfiltered (" struct tdesc_feature *feature;\n");
1660 /* Now we do some "filtering" in order to know which variables to
1661 declare. This is needed because otherwise we would declare unused
1662 variables `field_type' and `type'. */
1664 VEC_iterate (tdesc_feature_p
, tdesc
->features
, ix
, feature
);
1667 int printed_desc_type
= 0;
1670 VEC_iterate (tdesc_type_p
, feature
->types
, ix2
, type
);
1673 if (!printed_field_type
)
1675 printf_unfiltered (" struct tdesc_type *field_type;\n");
1676 printed_field_type
= 1;
1679 if ((type
->kind
== TDESC_TYPE_UNION
1680 || type
->kind
== TDESC_TYPE_STRUCT
)
1681 && VEC_length (tdesc_type_field
, type
->u
.u
.fields
) > 0)
1683 printf_unfiltered (" struct tdesc_type *type;\n");
1684 printed_desc_type
= 1;
1689 if (printed_desc_type
)
1693 printf_unfiltered ("\n");
1695 if (tdesc_architecture (tdesc
) != NULL
)
1698 (" set_tdesc_architecture (result, bfd_scan_arch (\"%s\"));\n",
1699 tdesc_architecture (tdesc
)->printable_name
);
1700 printf_unfiltered ("\n");
1703 if (tdesc_osabi (tdesc
) > GDB_OSABI_UNKNOWN
1704 && tdesc_osabi (tdesc
) < GDB_OSABI_INVALID
)
1707 (" set_tdesc_osabi (result, osabi_from_tdesc_string (\"%s\"));\n",
1708 gdbarch_osabi_name (tdesc_osabi (tdesc
)));
1709 printf_unfiltered ("\n");
1712 for (ix
= 0; VEC_iterate (arch_p
, tdesc
->compatible
, ix
, compatible
);
1716 (" tdesc_add_compatible (result, bfd_scan_arch (\"%s\"));\n",
1717 compatible
->printable_name
);
1720 printf_unfiltered ("\n");
1722 for (ix
= 0; VEC_iterate (property_s
, tdesc
->properties
, ix
, prop
);
1725 printf_unfiltered (" set_tdesc_property (result, \"%s\", \"%s\");\n",
1726 prop
->key
, prop
->value
);
1730 VEC_iterate (tdesc_feature_p
, tdesc
->features
, ix
, feature
);
1733 printf_unfiltered (" \
1734 feature = tdesc_create_feature (result, \"%s\");\n",
1738 VEC_iterate (tdesc_type_p
, feature
->types
, ix2
, type
);
1743 case TDESC_TYPE_VECTOR
:
1745 (" field_type = tdesc_named_type (feature, \"%s\");\n",
1746 type
->u
.v
.type
->name
);
1748 (" tdesc_create_vector (feature, \"%s\", field_type, %d);\n",
1749 type
->name
, type
->u
.v
.count
);
1751 case TDESC_TYPE_STRUCT
:
1753 (" type = tdesc_create_struct (feature, \"%s\");\n",
1755 if (type
->u
.u
.size
!= 0)
1757 (" tdesc_set_struct_size (type, %s);\n",
1758 plongest (type
->u
.u
.size
));
1760 VEC_iterate (tdesc_type_field
, type
->u
.u
.fields
, ix3
, f
);
1763 /* Going first for implicitly sized types, else part handles
1764 bitfields. As reported on xml-tdesc.c implicitly sized types
1765 cannot contain a bitfield. */
1766 if (f
->type
!= NULL
)
1769 (" field_type = tdesc_named_type (feature, \"%s\");\n",
1772 (" tdesc_add_field (type, \"%s\", field_type);\n",
1777 (" tdesc_add_bitfield (type, \"%s\", %d, %d);\n",
1778 f
->name
, f
->start
, f
->end
);
1781 case TDESC_TYPE_UNION
:
1783 (" type = tdesc_create_union (feature, \"%s\");\n",
1786 VEC_iterate (tdesc_type_field
, type
->u
.u
.fields
, ix3
, f
);
1790 (" field_type = tdesc_named_type (feature, \"%s\");\n",
1793 (" tdesc_add_field (type, \"%s\", field_type);\n",
1797 case TDESC_TYPE_FLAGS
:
1799 (" field_type = tdesc_create_flags (feature, \"%s\", %d);\n",
1800 type
->name
, (int) type
->u
.f
.size
);
1802 VEC_iterate (tdesc_type_flag
, type
->u
.f
.flags
, ix3
,
1806 (" tdesc_add_flag (field_type, %d, \"%s\");\n",
1807 flag
->start
, flag
->name
);
1810 error (_("C output is not supported type \"%s\"."), type
->name
);
1812 printf_unfiltered ("\n");
1816 VEC_iterate (tdesc_reg_p
, feature
->registers
, ix2
, reg
);
1819 printf_unfiltered (" tdesc_create_reg (feature, \"%s\", %ld, %d, ",
1820 reg
->name
, reg
->target_regnum
, reg
->save_restore
);
1822 printf_unfiltered ("\"%s\", ", reg
->group
);
1824 printf_unfiltered ("NULL, ");
1825 printf_unfiltered ("%d, \"%s\");\n", reg
->bitsize
, reg
->type
);
1828 printf_unfiltered ("\n");
1831 printf_unfiltered (" tdesc_%s = result;\n", function
);
1832 printf_unfiltered ("}\n");
1835 /* Provide a prototype to silence -Wmissing-prototypes. */
1836 extern initialize_file_ftype _initialize_target_descriptions
;
1839 _initialize_target_descriptions (void)
1841 tdesc_data
= gdbarch_data_register_pre_init (tdesc_data_init
);
1843 add_prefix_cmd ("tdesc", class_maintenance
, set_tdesc_cmd
, _("\
1844 Set target description specific variables."),
1845 &tdesc_set_cmdlist
, "set tdesc ",
1846 0 /* allow-unknown */, &setlist
);
1847 add_prefix_cmd ("tdesc", class_maintenance
, show_tdesc_cmd
, _("\
1848 Show target description specific variables."),
1849 &tdesc_show_cmdlist
, "show tdesc ",
1850 0 /* allow-unknown */, &showlist
);
1851 add_prefix_cmd ("tdesc", class_maintenance
, unset_tdesc_cmd
, _("\
1852 Unset target description specific variables."),
1853 &tdesc_unset_cmdlist
, "unset tdesc ",
1854 0 /* allow-unknown */, &unsetlist
);
1856 add_setshow_filename_cmd ("filename", class_obscure
,
1857 &tdesc_filename_cmd_string
,
1859 Set the file to read for an XML target description"), _("\
1860 Show the file to read for an XML target description"), _("\
1861 When set, GDB will read the target description from a local\n\
1862 file instead of querying the remote target."),
1863 set_tdesc_filename_cmd
,
1864 show_tdesc_filename_cmd
,
1865 &tdesc_set_cmdlist
, &tdesc_show_cmdlist
);
1867 add_cmd ("filename", class_obscure
, unset_tdesc_filename_cmd
, _("\
1868 Unset the file to read for an XML target description. When unset,\n\
1869 GDB will read the description from the target."),
1870 &tdesc_unset_cmdlist
);
1872 add_cmd ("c-tdesc", class_maintenance
, maint_print_c_tdesc_cmd
, _("\
1873 Print the current target description as a C source file."),
1874 &maintenanceprintlist
);