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 tdesc_reg (struct tdesc_feature
*feature
, const char *name_
,
52 int regnum
, int save_restore_
, const char *group_
,
53 int bitsize_
, const char *type_
)
54 : name (xstrdup (name_
)), target_regnum (regnum
),
55 save_restore (save_restore_
),
56 group (group_
!= NULL
? xstrdup (group_
) : NULL
),
58 type (type_
!= NULL
? xstrdup (type_
) : xstrdup ("<unknown>"))
60 /* If the register's type is target-defined, look it up now. We may not
61 have easy access to the containing feature when we want it later. */
62 tdesc_type
= tdesc_named_type (feature
, type
);
72 /* Disable copying. */
73 tdesc_reg (const tdesc_reg
&) = delete;
74 tdesc_reg
&operator= (const tdesc_reg
&) = delete;
76 /* The name of this register. In standard features, it may be
77 recognized by the architecture support code, or it may be purely
81 /* The register number used by this target to refer to this
82 register. This is used for remote p/P packets and to determine
83 the ordering of registers in the remote g/G packets. */
86 /* If this flag is set, GDB should save and restore this register
87 around calls to an inferior function. */
90 /* The name of the register group containing this register, or NULL
91 if the group should be automatically determined from the
92 register's type. If this is "general", "float", or "vector", the
93 corresponding "info" command should display this register's
94 value. It can be an arbitrary string, but should be limited to
95 alphanumeric characters and internal hyphens. Currently other
96 strings are ignored (treated as NULL). */
99 /* The size of the register, in bits. */
102 /* The type of the register. This string corresponds to either
103 a named type from the target description or a predefined
107 /* The target-described type corresponding to TYPE, if found. */
108 struct tdesc_type
*tdesc_type
;
110 DEF_VEC_P(tdesc_reg_p
);
112 /* A named type from a target description. */
114 typedef struct tdesc_type_field
117 struct tdesc_type
*type
;
118 /* For non-enum-values, either both are -1 (non-bitfield), or both are
119 not -1 (bitfield). For enum values, start is the value (which could be
123 DEF_VEC_O(tdesc_type_field
);
127 /* Predefined types. */
141 TDESC_TYPE_IEEE_SINGLE
,
142 TDESC_TYPE_IEEE_DOUBLE
,
143 TDESC_TYPE_ARM_FPA_EXT
,
146 /* Types defined by a target feature. */
154 typedef struct tdesc_type
156 tdesc_type (const char *name_
, enum tdesc_type_kind kind_
)
157 : name (xstrdup (name_
)), kind (kind_
)
159 memset (&u
, 0, sizeof (u
));
166 case TDESC_TYPE_STRUCT
:
167 case TDESC_TYPE_UNION
:
168 case TDESC_TYPE_FLAGS
:
169 case TDESC_TYPE_ENUM
:
171 struct tdesc_type_field
*f
;
175 VEC_iterate (tdesc_type_field
, u
.u
.fields
, ix
, f
);
179 VEC_free (tdesc_type_field
, u
.u
.fields
);
186 xfree ((char *) name
);
188 /* Disable copying. */
189 tdesc_type (const tdesc_type
&) = delete;
190 tdesc_type
&operator= (const tdesc_type
&) = delete;
192 /* The name of this type. If this type is a built-in type, this is
193 a pointer to a constant string. Otherwise, it's a
194 malloc-allocated string (and thus must be freed). */
197 /* Identify the kind of this type. */
198 enum tdesc_type_kind kind
;
200 /* Kind-specific data. */
206 struct tdesc_type
*type
;
210 /* Struct, union, flags, or enum type. */
213 VEC(tdesc_type_field
) *fields
;
218 DEF_VEC_P(tdesc_type_p
);
220 /* A feature from a target description. Each feature is a collection
221 of other elements, e.g. registers and types. */
223 typedef struct tdesc_feature
225 tdesc_feature (const char *name_
)
226 : name (xstrdup (name_
))
231 struct tdesc_reg
*reg
;
232 struct tdesc_type
*type
;
235 for (ix
= 0; VEC_iterate (tdesc_reg_p
, registers
, ix
, reg
); ix
++)
237 VEC_free (tdesc_reg_p
, registers
);
239 for (ix
= 0; VEC_iterate (tdesc_type_p
, types
, ix
, type
); ix
++)
241 VEC_free (tdesc_type_p
, types
);
246 /* Disable copying. */
247 tdesc_feature (const tdesc_feature
&) = delete;
248 tdesc_feature
&operator= (const tdesc_feature
&) = delete;
250 /* The name of this feature. It may be recognized by the architecture
254 /* The registers associated with this feature. */
255 VEC(tdesc_reg_p
) *registers
= NULL
;
257 /* The types associated with this feature. */
258 VEC(tdesc_type_p
) *types
= NULL
;
260 DEF_VEC_P(tdesc_feature_p
);
262 /* A compatible architecture from a target description. */
263 typedef const struct bfd_arch_info
*arch_p
;
266 /* A target description. */
270 /* The architecture reported by the target, if any. */
271 const struct bfd_arch_info
*arch
;
273 /* The osabi reported by the target, if any; GDB_OSABI_UNKNOWN
275 enum gdb_osabi osabi
;
277 /* The list of compatible architectures reported by the target. */
278 VEC(arch_p
) *compatible
;
280 /* Any architecture-specific properties specified by the target. */
281 VEC(property_s
) *properties
;
283 /* The features associated with this target. */
284 VEC(tdesc_feature_p
) *features
;
287 /* Per-architecture data associated with a target description. The
288 target description may be shared by multiple architectures, but
289 this data is private to one gdbarch. */
291 typedef struct tdesc_arch_reg
293 struct tdesc_reg
*reg
;
296 DEF_VEC_O(tdesc_arch_reg
);
298 struct tdesc_arch_data
300 /* A list of register/type pairs, indexed by GDB's internal register number.
301 During initialization of the gdbarch this list is used to store
302 registers which the architecture assigns a fixed register number.
303 Registers which are NULL in this array, or off the end, are
304 treated as zero-sized and nameless (i.e. placeholders in the
306 VEC(tdesc_arch_reg
) *arch_regs
;
308 /* Functions which report the register name, type, and reggroups for
310 gdbarch_register_name_ftype
*pseudo_register_name
;
311 gdbarch_register_type_ftype
*pseudo_register_type
;
312 gdbarch_register_reggroup_p_ftype
*pseudo_register_reggroup_p
;
315 /* Info about an inferior's target description. There's one of these
316 for each inferior. */
318 struct target_desc_info
320 /* A flag indicating that a description has already been fetched
321 from the target, so it should not be queried again. */
325 /* The description fetched from the target, or NULL if the target
326 did not supply any description. Only valid when
327 target_desc_fetched is set. Only the description initialization
328 code should access this; normally, the description should be
329 accessed through the gdbarch object. */
331 const struct target_desc
*tdesc
;
333 /* The filename to read a target description from, as set by "set
334 tdesc filename ..." */
339 /* Get the inferior INF's target description info, allocating one on
340 the stop if necessary. */
342 static struct target_desc_info
*
343 get_tdesc_info (struct inferior
*inf
)
345 if (inf
->tdesc_info
== NULL
)
346 inf
->tdesc_info
= XCNEW (struct target_desc_info
);
347 return inf
->tdesc_info
;
350 /* A handle for architecture-specific data associated with the
351 target description (see struct tdesc_arch_data). */
353 static struct gdbarch_data
*tdesc_data
;
355 /* See target-descriptions.h. */
358 target_desc_info_from_user_p (struct target_desc_info
*info
)
360 return info
!= NULL
&& info
->filename
!= NULL
;
363 /* See target-descriptions.h. */
366 copy_inferior_target_desc_info (struct inferior
*destinf
, struct inferior
*srcinf
)
368 struct target_desc_info
*src
= get_tdesc_info (srcinf
);
369 struct target_desc_info
*dest
= get_tdesc_info (destinf
);
371 dest
->fetched
= src
->fetched
;
372 dest
->tdesc
= src
->tdesc
;
373 dest
->filename
= src
->filename
!= NULL
? xstrdup (src
->filename
) : NULL
;
376 /* See target-descriptions.h. */
379 target_desc_info_free (struct target_desc_info
*tdesc_info
)
381 if (tdesc_info
!= NULL
)
383 xfree (tdesc_info
->filename
);
388 /* Convenience helper macros. */
390 #define target_desc_fetched \
391 get_tdesc_info (current_inferior ())->fetched
392 #define current_target_desc \
393 get_tdesc_info (current_inferior ())->tdesc
394 #define target_description_filename \
395 get_tdesc_info (current_inferior ())->filename
397 /* The string manipulated by the "set tdesc filename ..." command. */
399 static char *tdesc_filename_cmd_string
;
401 /* Fetch the current target's description, and switch the current
402 architecture to one which incorporates that description. */
405 target_find_description (void)
407 /* If we've already fetched a description from the target, don't do
408 it again. This allows a target to fetch the description early,
409 during its to_open or to_create_inferior, if it needs extra
410 information about the target to initialize. */
411 if (target_desc_fetched
)
414 /* The current architecture should not have any target description
415 specified. It should have been cleared, e.g. when we
416 disconnected from the previous target. */
417 gdb_assert (gdbarch_target_desc (target_gdbarch ()) == NULL
);
419 /* First try to fetch an XML description from the user-specified
421 current_target_desc
= NULL
;
422 if (target_description_filename
!= NULL
423 && *target_description_filename
!= '\0')
425 = file_read_description_xml (target_description_filename
);
427 /* Next try to read the description from the current target using
429 if (current_target_desc
== NULL
)
430 current_target_desc
= target_read_description_xml (¤t_target
);
432 /* If that failed try a target-specific hook. */
433 if (current_target_desc
== NULL
)
434 current_target_desc
= target_read_description (¤t_target
);
436 /* If a non-NULL description was returned, then update the current
438 if (current_target_desc
)
440 struct gdbarch_info info
;
442 gdbarch_info_init (&info
);
443 info
.target_desc
= current_target_desc
;
444 if (!gdbarch_update_p (info
))
445 warning (_("Architecture rejected target-supplied description"));
448 struct tdesc_arch_data
*data
;
450 data
= ((struct tdesc_arch_data
*)
451 gdbarch_data (target_gdbarch (), tdesc_data
));
452 if (tdesc_has_registers (current_target_desc
)
453 && data
->arch_regs
== NULL
)
454 warning (_("Target-supplied registers are not supported "
455 "by the current architecture"));
459 /* Now that we know this description is usable, record that we
461 target_desc_fetched
= 1;
464 /* Discard any description fetched from the current target, and switch
465 the current architecture to one with no target description. */
468 target_clear_description (void)
470 struct gdbarch_info info
;
472 if (!target_desc_fetched
)
475 target_desc_fetched
= 0;
476 current_target_desc
= NULL
;
478 gdbarch_info_init (&info
);
479 if (!gdbarch_update_p (info
))
480 internal_error (__FILE__
, __LINE__
,
481 _("Could not remove target-supplied description"));
484 /* Return the global current target description. This should only be
485 used by gdbarch initialization code; most access should be through
486 an existing gdbarch. */
488 const struct target_desc
*
489 target_current_description (void)
491 if (target_desc_fetched
)
492 return current_target_desc
;
497 /* Return non-zero if this target description is compatible
498 with the given BFD architecture. */
501 tdesc_compatible_p (const struct target_desc
*target_desc
,
502 const struct bfd_arch_info
*arch
)
504 const struct bfd_arch_info
*compat
;
507 for (ix
= 0; VEC_iterate (arch_p
, target_desc
->compatible
, ix
, compat
);
511 || arch
->compatible (arch
, compat
)
512 || compat
->compatible (compat
, arch
))
520 /* Direct accessors for target descriptions. */
522 /* Return the string value of a property named KEY, or NULL if the
523 property was not specified. */
526 tdesc_property (const struct target_desc
*target_desc
, const char *key
)
528 struct property
*prop
;
531 for (ix
= 0; VEC_iterate (property_s
, target_desc
->properties
, ix
, prop
);
533 if (strcmp (prop
->key
, key
) == 0)
539 /* Return the BFD architecture associated with this target
540 description, or NULL if no architecture was specified. */
542 const struct bfd_arch_info
*
543 tdesc_architecture (const struct target_desc
*target_desc
)
545 return target_desc
->arch
;
548 /* Return the OSABI associated with this target description, or
549 GDB_OSABI_UNKNOWN if no osabi was specified. */
552 tdesc_osabi (const struct target_desc
*target_desc
)
554 return target_desc
->osabi
;
559 /* Return 1 if this target description includes any registers. */
562 tdesc_has_registers (const struct target_desc
*target_desc
)
565 struct tdesc_feature
*feature
;
567 if (target_desc
== NULL
)
571 VEC_iterate (tdesc_feature_p
, target_desc
->features
, ix
, feature
);
573 if (! VEC_empty (tdesc_reg_p
, feature
->registers
))
579 /* Return the feature with the given name, if present, or NULL if
580 the named feature is not found. */
582 const struct tdesc_feature
*
583 tdesc_find_feature (const struct target_desc
*target_desc
,
587 struct tdesc_feature
*feature
;
590 VEC_iterate (tdesc_feature_p
, target_desc
->features
, ix
, feature
);
592 if (strcmp (feature
->name
, name
) == 0)
598 /* Return the name of FEATURE. */
601 tdesc_feature_name (const struct tdesc_feature
*feature
)
603 return feature
->name
;
606 /* Predefined types. */
607 static struct tdesc_type tdesc_predefined_types
[] =
609 { "bool", TDESC_TYPE_BOOL
},
610 { "int8", TDESC_TYPE_INT8
},
611 { "int16", TDESC_TYPE_INT16
},
612 { "int32", TDESC_TYPE_INT32
},
613 { "int64", TDESC_TYPE_INT64
},
614 { "int128", TDESC_TYPE_INT128
},
615 { "uint8", TDESC_TYPE_UINT8
},
616 { "uint16", TDESC_TYPE_UINT16
},
617 { "uint32", TDESC_TYPE_UINT32
},
618 { "uint64", TDESC_TYPE_UINT64
},
619 { "uint128", TDESC_TYPE_UINT128
},
620 { "code_ptr", TDESC_TYPE_CODE_PTR
},
621 { "data_ptr", TDESC_TYPE_DATA_PTR
},
622 { "ieee_single", TDESC_TYPE_IEEE_SINGLE
},
623 { "ieee_double", TDESC_TYPE_IEEE_DOUBLE
},
624 { "arm_fpa_ext", TDESC_TYPE_ARM_FPA_EXT
},
625 { "i387_ext", TDESC_TYPE_I387_EXT
}
628 /* Lookup a predefined type. */
630 static struct tdesc_type
*
631 tdesc_predefined_type (enum tdesc_type_kind kind
)
634 struct tdesc_type
*type
;
636 for (ix
= 0; ix
< ARRAY_SIZE (tdesc_predefined_types
); ix
++)
637 if (tdesc_predefined_types
[ix
].kind
== kind
)
638 return &tdesc_predefined_types
[ix
];
640 gdb_assert_not_reached ("bad predefined tdesc type");
643 /* Return the type associated with ID in the context of FEATURE, or
647 tdesc_named_type (const struct tdesc_feature
*feature
, const char *id
)
650 struct tdesc_type
*type
;
652 /* First try target-defined types. */
653 for (ix
= 0; VEC_iterate (tdesc_type_p
, feature
->types
, ix
, type
); ix
++)
654 if (strcmp (type
->name
, id
) == 0)
657 /* Next try the predefined types. */
658 for (ix
= 0; ix
< ARRAY_SIZE (tdesc_predefined_types
); ix
++)
659 if (strcmp (tdesc_predefined_types
[ix
].name
, id
) == 0)
660 return &tdesc_predefined_types
[ix
];
665 /* Lookup type associated with ID. */
668 tdesc_find_type (struct gdbarch
*gdbarch
, const char *id
)
670 struct tdesc_arch_reg
*reg
;
671 struct tdesc_arch_data
*data
;
674 data
= (struct tdesc_arch_data
*) gdbarch_data (gdbarch
, tdesc_data
);
675 num_regs
= VEC_length (tdesc_arch_reg
, data
->arch_regs
);
676 for (i
= 0; i
< num_regs
; i
++)
678 reg
= VEC_index (tdesc_arch_reg
, data
->arch_regs
, i
);
680 && reg
->reg
->tdesc_type
682 && strcmp (id
, reg
->reg
->tdesc_type
->name
) == 0)
689 /* Construct, if necessary, and return the GDB type implementing target
690 type TDESC_TYPE for architecture GDBARCH. */
693 tdesc_gdb_type (struct gdbarch
*gdbarch
, struct tdesc_type
*tdesc_type
)
697 switch (tdesc_type
->kind
)
699 /* Predefined types. */
700 case TDESC_TYPE_BOOL
:
701 return builtin_type (gdbarch
)->builtin_bool
;
703 case TDESC_TYPE_INT8
:
704 return builtin_type (gdbarch
)->builtin_int8
;
706 case TDESC_TYPE_INT16
:
707 return builtin_type (gdbarch
)->builtin_int16
;
709 case TDESC_TYPE_INT32
:
710 return builtin_type (gdbarch
)->builtin_int32
;
712 case TDESC_TYPE_INT64
:
713 return builtin_type (gdbarch
)->builtin_int64
;
715 case TDESC_TYPE_INT128
:
716 return builtin_type (gdbarch
)->builtin_int128
;
718 case TDESC_TYPE_UINT8
:
719 return builtin_type (gdbarch
)->builtin_uint8
;
721 case TDESC_TYPE_UINT16
:
722 return builtin_type (gdbarch
)->builtin_uint16
;
724 case TDESC_TYPE_UINT32
:
725 return builtin_type (gdbarch
)->builtin_uint32
;
727 case TDESC_TYPE_UINT64
:
728 return builtin_type (gdbarch
)->builtin_uint64
;
730 case TDESC_TYPE_UINT128
:
731 return builtin_type (gdbarch
)->builtin_uint128
;
733 case TDESC_TYPE_CODE_PTR
:
734 return builtin_type (gdbarch
)->builtin_func_ptr
;
736 case TDESC_TYPE_DATA_PTR
:
737 return builtin_type (gdbarch
)->builtin_data_ptr
;
743 type
= tdesc_find_type (gdbarch
, tdesc_type
->name
);
747 switch (tdesc_type
->kind
)
749 case TDESC_TYPE_IEEE_SINGLE
:
750 return arch_float_type (gdbarch
, -1, "builtin_type_ieee_single",
751 floatformats_ieee_single
);
753 case TDESC_TYPE_IEEE_DOUBLE
:
754 return arch_float_type (gdbarch
, -1, "builtin_type_ieee_double",
755 floatformats_ieee_double
);
757 case TDESC_TYPE_ARM_FPA_EXT
:
758 return arch_float_type (gdbarch
, -1, "builtin_type_arm_ext",
759 floatformats_arm_ext
);
761 case TDESC_TYPE_I387_EXT
:
762 return arch_float_type (gdbarch
, -1, "builtin_type_i387_ext",
763 floatformats_i387_ext
);
765 /* Types defined by a target feature. */
766 case TDESC_TYPE_VECTOR
:
768 struct type
*type
, *field_type
;
770 field_type
= tdesc_gdb_type (gdbarch
, tdesc_type
->u
.v
.type
);
771 type
= init_vector_type (field_type
, tdesc_type
->u
.v
.count
);
772 TYPE_NAME (type
) = xstrdup (tdesc_type
->name
);
777 case TDESC_TYPE_STRUCT
:
779 struct type
*type
, *field_type
;
780 struct tdesc_type_field
*f
;
783 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_STRUCT
);
784 TYPE_NAME (type
) = xstrdup (tdesc_type
->name
);
785 TYPE_TAG_NAME (type
) = TYPE_NAME (type
);
788 VEC_iterate (tdesc_type_field
, tdesc_type
->u
.u
.fields
, ix
, f
);
791 if (f
->start
!= -1 && f
->end
!= -1)
795 struct type
*field_type
;
796 int bitsize
, total_size
;
798 /* This invariant should be preserved while creating types. */
799 gdb_assert (tdesc_type
->u
.u
.size
!= 0);
801 field_type
= tdesc_gdb_type (gdbarch
, f
->type
);
802 else if (tdesc_type
->u
.u
.size
> 4)
803 field_type
= builtin_type (gdbarch
)->builtin_uint64
;
805 field_type
= builtin_type (gdbarch
)->builtin_uint32
;
807 fld
= append_composite_type_field_raw (type
, xstrdup (f
->name
),
810 /* For little-endian, BITPOS counts from the LSB of
811 the structure and marks the LSB of the field. For
812 big-endian, BITPOS counts from the MSB of the
813 structure and marks the MSB of the field. Either
814 way, it is the number of bits to the "left" of the
815 field. To calculate this in big-endian, we need
816 the total size of the structure. */
817 bitsize
= f
->end
- f
->start
+ 1;
818 total_size
= tdesc_type
->u
.u
.size
* TARGET_CHAR_BIT
;
819 if (gdbarch_bits_big_endian (gdbarch
))
820 SET_FIELD_BITPOS (fld
[0], total_size
- f
->start
- bitsize
);
822 SET_FIELD_BITPOS (fld
[0], f
->start
);
823 FIELD_BITSIZE (fld
[0]) = bitsize
;
827 gdb_assert (f
->start
== -1 && f
->end
== -1);
828 field_type
= tdesc_gdb_type (gdbarch
, f
->type
);
829 append_composite_type_field (type
, xstrdup (f
->name
),
834 if (tdesc_type
->u
.u
.size
!= 0)
835 TYPE_LENGTH (type
) = tdesc_type
->u
.u
.size
;
839 case TDESC_TYPE_UNION
:
841 struct type
*type
, *field_type
;
842 struct tdesc_type_field
*f
;
845 type
= arch_composite_type (gdbarch
, NULL
, TYPE_CODE_UNION
);
846 TYPE_NAME (type
) = xstrdup (tdesc_type
->name
);
849 VEC_iterate (tdesc_type_field
, tdesc_type
->u
.u
.fields
, ix
, f
);
852 field_type
= tdesc_gdb_type (gdbarch
, f
->type
);
853 append_composite_type_field (type
, xstrdup (f
->name
), field_type
);
855 /* If any of the children of a union are vectors, flag the
856 union as a vector also. This allows e.g. a union of two
857 vector types to show up automatically in "info vector". */
858 if (TYPE_VECTOR (field_type
))
859 TYPE_VECTOR (type
) = 1;
864 case TDESC_TYPE_FLAGS
:
866 struct tdesc_type_field
*f
;
869 type
= arch_flags_type (gdbarch
, tdesc_type
->name
,
870 tdesc_type
->u
.u
.size
);
872 VEC_iterate (tdesc_type_field
, tdesc_type
->u
.u
.fields
, ix
, f
);
875 struct type
*field_type
;
876 int bitsize
= f
->end
- f
->start
+ 1;
878 gdb_assert (f
->type
!= NULL
);
879 field_type
= tdesc_gdb_type (gdbarch
, f
->type
);
880 append_flags_type_field (type
, f
->start
, bitsize
,
881 field_type
, f
->name
);
887 case TDESC_TYPE_ENUM
:
889 struct tdesc_type_field
*f
;
892 type
= arch_type (gdbarch
, TYPE_CODE_ENUM
,
893 tdesc_type
->u
.u
.size
, tdesc_type
->name
);
894 TYPE_UNSIGNED (type
) = 1;
896 VEC_iterate (tdesc_type_field
, tdesc_type
->u
.u
.fields
, ix
, f
);
900 = append_composite_type_field_raw (type
, xstrdup (f
->name
),
903 SET_FIELD_BITPOS (fld
[0], f
->start
);
910 internal_error (__FILE__
, __LINE__
,
911 "Type \"%s\" has an unknown kind %d",
912 tdesc_type
->name
, tdesc_type
->kind
);
916 /* Support for registers from target descriptions. */
918 /* Construct the per-gdbarch data. */
921 tdesc_data_init (struct obstack
*obstack
)
923 struct tdesc_arch_data
*data
;
925 data
= OBSTACK_ZALLOC (obstack
, struct tdesc_arch_data
);
929 /* Similar, but for the temporary copy used during architecture
932 struct tdesc_arch_data
*
933 tdesc_data_alloc (void)
935 return XCNEW (struct tdesc_arch_data
);
938 /* Free something allocated by tdesc_data_alloc, if it is not going
939 to be used (for instance if it was unsuitable for the
943 tdesc_data_cleanup (void *data_untyped
)
945 struct tdesc_arch_data
*data
= (struct tdesc_arch_data
*) data_untyped
;
947 VEC_free (tdesc_arch_reg
, data
->arch_regs
);
951 /* Search FEATURE for a register named NAME. */
953 static struct tdesc_reg
*
954 tdesc_find_register_early (const struct tdesc_feature
*feature
,
958 struct tdesc_reg
*reg
;
961 VEC_iterate (tdesc_reg_p
, feature
->registers
, ixr
, reg
);
963 if (strcasecmp (reg
->name
, name
) == 0)
969 /* Search FEATURE for a register named NAME. Assign REGNO to it. */
972 tdesc_numbered_register (const struct tdesc_feature
*feature
,
973 struct tdesc_arch_data
*data
,
974 int regno
, const char *name
)
976 struct tdesc_arch_reg arch_reg
= { 0 };
977 struct tdesc_reg
*reg
= tdesc_find_register_early (feature
, name
);
982 /* Make sure the vector includes a REGNO'th element. */
983 while (regno
>= VEC_length (tdesc_arch_reg
, data
->arch_regs
))
984 VEC_safe_push (tdesc_arch_reg
, data
->arch_regs
, &arch_reg
);
987 VEC_replace (tdesc_arch_reg
, data
->arch_regs
, regno
, &arch_reg
);
991 /* Search FEATURE for a register named NAME, but do not assign a fixed
992 register number to it. */
995 tdesc_unnumbered_register (const struct tdesc_feature
*feature
,
998 struct tdesc_reg
*reg
= tdesc_find_register_early (feature
, name
);
1006 /* Search FEATURE for a register whose name is in NAMES and assign
1010 tdesc_numbered_register_choices (const struct tdesc_feature
*feature
,
1011 struct tdesc_arch_data
*data
,
1012 int regno
, const char *const names
[])
1016 for (i
= 0; names
[i
] != NULL
; i
++)
1017 if (tdesc_numbered_register (feature
, data
, regno
, names
[i
]))
1023 /* Search FEATURE for a register named NAME, and return its size in
1024 bits. The register must exist. */
1027 tdesc_register_size (const struct tdesc_feature
*feature
,
1030 struct tdesc_reg
*reg
= tdesc_find_register_early (feature
, name
);
1032 gdb_assert (reg
!= NULL
);
1033 return reg
->bitsize
;
1036 /* Look up a register by its GDB internal register number. */
1038 static struct tdesc_arch_reg
*
1039 tdesc_find_arch_register (struct gdbarch
*gdbarch
, int regno
)
1041 struct tdesc_arch_data
*data
;
1043 data
= (struct tdesc_arch_data
*) gdbarch_data (gdbarch
, tdesc_data
);
1044 if (regno
< VEC_length (tdesc_arch_reg
, data
->arch_regs
))
1045 return VEC_index (tdesc_arch_reg
, data
->arch_regs
, regno
);
1050 static struct tdesc_reg
*
1051 tdesc_find_register (struct gdbarch
*gdbarch
, int regno
)
1053 struct tdesc_arch_reg
*reg
= tdesc_find_arch_register (gdbarch
, regno
);
1055 return reg
? reg
->reg
: NULL
;
1058 /* Return the name of register REGNO, from the target description or
1059 from an architecture-provided pseudo_register_name method. */
1062 tdesc_register_name (struct gdbarch
*gdbarch
, int regno
)
1064 struct tdesc_reg
*reg
= tdesc_find_register (gdbarch
, regno
);
1065 int num_regs
= gdbarch_num_regs (gdbarch
);
1066 int num_pseudo_regs
= gdbarch_num_pseudo_regs (gdbarch
);
1071 if (regno
>= num_regs
&& regno
< num_regs
+ num_pseudo_regs
)
1073 struct tdesc_arch_data
*data
1074 = (struct tdesc_arch_data
*) gdbarch_data (gdbarch
, tdesc_data
);
1076 gdb_assert (data
->pseudo_register_name
!= NULL
);
1077 return data
->pseudo_register_name (gdbarch
, regno
);
1084 tdesc_register_type (struct gdbarch
*gdbarch
, int regno
)
1086 struct tdesc_arch_reg
*arch_reg
= tdesc_find_arch_register (gdbarch
, regno
);
1087 struct tdesc_reg
*reg
= arch_reg
? arch_reg
->reg
: NULL
;
1088 int num_regs
= gdbarch_num_regs (gdbarch
);
1089 int num_pseudo_regs
= gdbarch_num_pseudo_regs (gdbarch
);
1091 if (reg
== NULL
&& regno
>= num_regs
&& regno
< num_regs
+ num_pseudo_regs
)
1093 struct tdesc_arch_data
*data
1094 = (struct tdesc_arch_data
*) gdbarch_data (gdbarch
, tdesc_data
);
1096 gdb_assert (data
->pseudo_register_type
!= NULL
);
1097 return data
->pseudo_register_type (gdbarch
, regno
);
1101 /* Return "int0_t", since "void" has a misleading size of one. */
1102 return builtin_type (gdbarch
)->builtin_int0
;
1104 if (arch_reg
->type
== NULL
)
1106 /* First check for a predefined or target defined type. */
1107 if (reg
->tdesc_type
)
1108 arch_reg
->type
= tdesc_gdb_type (gdbarch
, reg
->tdesc_type
);
1110 /* Next try size-sensitive type shortcuts. */
1111 else if (strcmp (reg
->type
, "float") == 0)
1113 if (reg
->bitsize
== gdbarch_float_bit (gdbarch
))
1114 arch_reg
->type
= builtin_type (gdbarch
)->builtin_float
;
1115 else if (reg
->bitsize
== gdbarch_double_bit (gdbarch
))
1116 arch_reg
->type
= builtin_type (gdbarch
)->builtin_double
;
1117 else if (reg
->bitsize
== gdbarch_long_double_bit (gdbarch
))
1118 arch_reg
->type
= builtin_type (gdbarch
)->builtin_long_double
;
1121 warning (_("Register \"%s\" has an unsupported size (%d bits)"),
1122 reg
->name
, reg
->bitsize
);
1123 arch_reg
->type
= builtin_type (gdbarch
)->builtin_double
;
1126 else if (strcmp (reg
->type
, "int") == 0)
1128 if (reg
->bitsize
== gdbarch_long_bit (gdbarch
))
1129 arch_reg
->type
= builtin_type (gdbarch
)->builtin_long
;
1130 else if (reg
->bitsize
== TARGET_CHAR_BIT
)
1131 arch_reg
->type
= builtin_type (gdbarch
)->builtin_char
;
1132 else if (reg
->bitsize
== gdbarch_short_bit (gdbarch
))
1133 arch_reg
->type
= builtin_type (gdbarch
)->builtin_short
;
1134 else if (reg
->bitsize
== gdbarch_int_bit (gdbarch
))
1135 arch_reg
->type
= builtin_type (gdbarch
)->builtin_int
;
1136 else if (reg
->bitsize
== gdbarch_long_long_bit (gdbarch
))
1137 arch_reg
->type
= builtin_type (gdbarch
)->builtin_long_long
;
1138 else if (reg
->bitsize
== gdbarch_ptr_bit (gdbarch
))
1139 /* A bit desperate by this point... */
1140 arch_reg
->type
= builtin_type (gdbarch
)->builtin_data_ptr
;
1143 warning (_("Register \"%s\" has an unsupported size (%d bits)"),
1144 reg
->name
, reg
->bitsize
);
1145 arch_reg
->type
= builtin_type (gdbarch
)->builtin_long
;
1149 if (arch_reg
->type
== NULL
)
1150 internal_error (__FILE__
, __LINE__
,
1151 "Register \"%s\" has an unknown type \"%s\"",
1152 reg
->name
, reg
->type
);
1155 return arch_reg
->type
;
1159 tdesc_remote_register_number (struct gdbarch
*gdbarch
, int regno
)
1161 struct tdesc_reg
*reg
= tdesc_find_register (gdbarch
, regno
);
1164 return reg
->target_regnum
;
1169 /* Check whether REGNUM is a member of REGGROUP. Registers from the
1170 target description may be classified as general, float, or vector.
1171 Unlike a gdbarch register_reggroup_p method, this function will
1172 return -1 if it does not know; the caller should handle registers
1173 with no specified group.
1175 Arbitrary strings (other than "general", "float", and "vector")
1176 from the description are not used; they cause the register to be
1177 displayed in "info all-registers" but excluded from "info
1178 registers" et al. The names of containing features are also not
1179 used. This might be extended to display registers in some more
1182 The save-restore flag is also implemented here. */
1185 tdesc_register_in_reggroup_p (struct gdbarch
*gdbarch
, int regno
,
1186 struct reggroup
*reggroup
)
1188 struct tdesc_reg
*reg
= tdesc_find_register (gdbarch
, regno
);
1190 if (reg
!= NULL
&& reg
->group
!= NULL
)
1192 int general_p
= 0, float_p
= 0, vector_p
= 0;
1194 if (strcmp (reg
->group
, "general") == 0)
1196 else if (strcmp (reg
->group
, "float") == 0)
1198 else if (strcmp (reg
->group
, "vector") == 0)
1201 if (reggroup
== float_reggroup
)
1204 if (reggroup
== vector_reggroup
)
1207 if (reggroup
== general_reggroup
)
1212 && (reggroup
== save_reggroup
|| reggroup
== restore_reggroup
))
1213 return reg
->save_restore
;
1218 /* Check whether REGNUM is a member of REGGROUP. Registers with no
1219 group specified go to the default reggroup function and are handled
1223 tdesc_register_reggroup_p (struct gdbarch
*gdbarch
, int regno
,
1224 struct reggroup
*reggroup
)
1226 int num_regs
= gdbarch_num_regs (gdbarch
);
1227 int num_pseudo_regs
= gdbarch_num_pseudo_regs (gdbarch
);
1230 if (regno
>= num_regs
&& regno
< num_regs
+ num_pseudo_regs
)
1232 struct tdesc_arch_data
*data
1233 = (struct tdesc_arch_data
*) gdbarch_data (gdbarch
, tdesc_data
);
1235 if (data
->pseudo_register_reggroup_p
!= NULL
)
1236 return data
->pseudo_register_reggroup_p (gdbarch
, regno
, reggroup
);
1237 /* Otherwise fall through to the default reggroup_p. */
1240 ret
= tdesc_register_in_reggroup_p (gdbarch
, regno
, reggroup
);
1244 return default_register_reggroup_p (gdbarch
, regno
, reggroup
);
1247 /* Record architecture-specific functions to call for pseudo-register
1251 set_tdesc_pseudo_register_name (struct gdbarch
*gdbarch
,
1252 gdbarch_register_name_ftype
*pseudo_name
)
1254 struct tdesc_arch_data
*data
1255 = (struct tdesc_arch_data
*) gdbarch_data (gdbarch
, tdesc_data
);
1257 data
->pseudo_register_name
= pseudo_name
;
1261 set_tdesc_pseudo_register_type (struct gdbarch
*gdbarch
,
1262 gdbarch_register_type_ftype
*pseudo_type
)
1264 struct tdesc_arch_data
*data
1265 = (struct tdesc_arch_data
*) gdbarch_data (gdbarch
, tdesc_data
);
1267 data
->pseudo_register_type
= pseudo_type
;
1271 set_tdesc_pseudo_register_reggroup_p
1272 (struct gdbarch
*gdbarch
,
1273 gdbarch_register_reggroup_p_ftype
*pseudo_reggroup_p
)
1275 struct tdesc_arch_data
*data
1276 = (struct tdesc_arch_data
*) gdbarch_data (gdbarch
, tdesc_data
);
1278 data
->pseudo_register_reggroup_p
= pseudo_reggroup_p
;
1281 /* Update GDBARCH to use the target description for registers. */
1284 tdesc_use_registers (struct gdbarch
*gdbarch
,
1285 const struct target_desc
*target_desc
,
1286 struct tdesc_arch_data
*early_data
)
1288 int num_regs
= gdbarch_num_regs (gdbarch
);
1290 struct tdesc_feature
*feature
;
1291 struct tdesc_reg
*reg
;
1292 struct tdesc_arch_data
*data
;
1293 struct tdesc_arch_reg
*arch_reg
, new_arch_reg
= { 0 };
1296 /* We can't use the description for registers if it doesn't describe
1297 any. This function should only be called after validating
1298 registers, so the caller should know that registers are
1300 gdb_assert (tdesc_has_registers (target_desc
));
1302 data
= (struct tdesc_arch_data
*) gdbarch_data (gdbarch
, tdesc_data
);
1303 data
->arch_regs
= early_data
->arch_regs
;
1306 /* Build up a set of all registers, so that we can assign register
1307 numbers where needed. The hash table expands as necessary, so
1308 the initial size is arbitrary. */
1309 reg_hash
= htab_create (37, htab_hash_pointer
, htab_eq_pointer
, NULL
);
1311 VEC_iterate (tdesc_feature_p
, target_desc
->features
, ixf
, feature
);
1314 VEC_iterate (tdesc_reg_p
, feature
->registers
, ixr
, reg
);
1317 void **slot
= htab_find_slot (reg_hash
, reg
, INSERT
);
1322 /* Remove any registers which were assigned numbers by the
1325 VEC_iterate (tdesc_arch_reg
, data
->arch_regs
, ixr
, arch_reg
);
1328 htab_remove_elt (reg_hash
, arch_reg
->reg
);
1330 /* Assign numbers to the remaining registers and add them to the
1331 list of registers. The new numbers are always above gdbarch_num_regs.
1332 Iterate over the features, not the hash table, so that the order
1333 matches that in the target description. */
1335 gdb_assert (VEC_length (tdesc_arch_reg
, data
->arch_regs
) <= num_regs
);
1336 while (VEC_length (tdesc_arch_reg
, data
->arch_regs
) < num_regs
)
1337 VEC_safe_push (tdesc_arch_reg
, data
->arch_regs
, &new_arch_reg
);
1339 VEC_iterate (tdesc_feature_p
, target_desc
->features
, ixf
, feature
);
1342 VEC_iterate (tdesc_reg_p
, feature
->registers
, ixr
, reg
);
1344 if (htab_find (reg_hash
, reg
) != NULL
)
1346 new_arch_reg
.reg
= reg
;
1347 VEC_safe_push (tdesc_arch_reg
, data
->arch_regs
, &new_arch_reg
);
1351 htab_delete (reg_hash
);
1353 /* Update the architecture. */
1354 set_gdbarch_num_regs (gdbarch
, num_regs
);
1355 set_gdbarch_register_name (gdbarch
, tdesc_register_name
);
1356 set_gdbarch_register_type (gdbarch
, tdesc_register_type
);
1357 set_gdbarch_remote_register_number (gdbarch
,
1358 tdesc_remote_register_number
);
1359 set_gdbarch_register_reggroup_p (gdbarch
, tdesc_register_reggroup_p
);
1364 tdesc_create_reg (struct tdesc_feature
*feature
, const char *name
,
1365 int regnum
, int save_restore
, const char *group
,
1366 int bitsize
, const char *type
)
1368 tdesc_reg
*reg
= new tdesc_reg (feature
, name
, regnum
, save_restore
,
1369 group
, bitsize
, type
);
1371 VEC_safe_push (tdesc_reg_p
, feature
->registers
, reg
);
1375 tdesc_create_vector (struct tdesc_feature
*feature
, const char *name
,
1376 struct tdesc_type
*field_type
, int count
)
1378 struct tdesc_type
*type
= new tdesc_type (name
, TDESC_TYPE_VECTOR
);
1380 type
->u
.v
.type
= field_type
;
1381 type
->u
.v
.count
= count
;
1383 VEC_safe_push (tdesc_type_p
, feature
->types
, type
);
1388 tdesc_create_struct (struct tdesc_feature
*feature
, const char *name
)
1390 struct tdesc_type
*type
= new tdesc_type (name
, TDESC_TYPE_STRUCT
);
1392 VEC_safe_push (tdesc_type_p
, feature
->types
, type
);
1396 /* Set the total length of TYPE. Structs which contain bitfields may
1397 omit the reserved bits, so the end of the last field may not
1401 tdesc_set_struct_size (struct tdesc_type
*type
, int size
)
1403 gdb_assert (type
->kind
== TDESC_TYPE_STRUCT
);
1404 gdb_assert (size
> 0);
1405 type
->u
.u
.size
= size
;
1409 tdesc_create_union (struct tdesc_feature
*feature
, const char *name
)
1411 struct tdesc_type
*type
= new tdesc_type (name
, TDESC_TYPE_UNION
);
1413 VEC_safe_push (tdesc_type_p
, feature
->types
, type
);
1418 tdesc_create_flags (struct tdesc_feature
*feature
, const char *name
,
1421 struct tdesc_type
*type
= new tdesc_type (name
, TDESC_TYPE_FLAGS
);
1423 gdb_assert (size
> 0);
1425 type
->u
.u
.size
= size
;
1427 VEC_safe_push (tdesc_type_p
, feature
->types
, type
);
1432 tdesc_create_enum (struct tdesc_feature
*feature
, const char *name
,
1435 struct tdesc_type
*type
= new tdesc_type (name
, TDESC_TYPE_ENUM
);
1437 gdb_assert (size
> 0);
1439 type
->u
.u
.size
= size
;
1441 VEC_safe_push (tdesc_type_p
, feature
->types
, type
);
1445 /* Add a new field to TYPE. */
1448 tdesc_add_field (struct tdesc_type
*type
, const char *field_name
,
1449 struct tdesc_type
*field_type
)
1451 struct tdesc_type_field f
= { 0 };
1453 gdb_assert (type
->kind
== TDESC_TYPE_UNION
1454 || type
->kind
== TDESC_TYPE_STRUCT
);
1456 f
.name
= xstrdup (field_name
);
1457 f
.type
= field_type
;
1458 /* Initialize these values so we know this is not a bit-field
1459 when we print-c-tdesc. */
1463 VEC_safe_push (tdesc_type_field
, type
->u
.u
.fields
, &f
);
1466 /* Add a new typed bitfield to TYPE. */
1469 tdesc_add_typed_bitfield (struct tdesc_type
*type
, const char *field_name
,
1470 int start
, int end
, struct tdesc_type
*field_type
)
1472 struct tdesc_type_field f
= { 0 };
1474 gdb_assert (type
->kind
== TDESC_TYPE_STRUCT
1475 || type
->kind
== TDESC_TYPE_FLAGS
);
1476 gdb_assert (start
>= 0 && end
>= start
);
1478 f
.name
= xstrdup (field_name
);
1481 f
.type
= field_type
;
1483 VEC_safe_push (tdesc_type_field
, type
->u
.u
.fields
, &f
);
1486 /* Add a new untyped bitfield to TYPE.
1487 Untyped bitfields become either uint32 or uint64 depending on the size
1488 of the underlying type. */
1491 tdesc_add_bitfield (struct tdesc_type
*type
, const char *field_name
,
1494 struct tdesc_type
*field_type
;
1496 gdb_assert (start
>= 0 && end
>= start
);
1498 if (type
->u
.u
.size
> 4)
1499 field_type
= tdesc_predefined_type (TDESC_TYPE_UINT64
);
1501 field_type
= tdesc_predefined_type (TDESC_TYPE_UINT32
);
1503 tdesc_add_typed_bitfield (type
, field_name
, start
, end
, field_type
);
1506 /* A flag is just a typed(bool) single-bit bitfield.
1507 This function is kept to minimize changes in generated files. */
1510 tdesc_add_flag (struct tdesc_type
*type
, int start
,
1511 const char *flag_name
)
1513 struct tdesc_type_field f
= { 0 };
1515 gdb_assert (type
->kind
== TDESC_TYPE_FLAGS
1516 || type
->kind
== TDESC_TYPE_STRUCT
);
1518 f
.name
= xstrdup (flag_name
);
1521 f
.type
= tdesc_predefined_type (TDESC_TYPE_BOOL
);
1523 VEC_safe_push (tdesc_type_field
, type
->u
.u
.fields
, &f
);
1527 tdesc_add_enum_value (struct tdesc_type
*type
, int value
,
1530 struct tdesc_type_field f
= { 0 };
1532 gdb_assert (type
->kind
== TDESC_TYPE_ENUM
);
1534 f
.name
= xstrdup (name
);
1537 f
.type
= tdesc_predefined_type (TDESC_TYPE_INT32
);
1539 VEC_safe_push (tdesc_type_field
, type
->u
.u
.fields
, &f
);
1542 struct tdesc_feature
*
1543 tdesc_create_feature (struct target_desc
*tdesc
, const char *name
)
1545 struct tdesc_feature
*new_feature
= new tdesc_feature (name
);
1547 VEC_safe_push (tdesc_feature_p
, tdesc
->features
, new_feature
);
1551 struct target_desc
*
1552 allocate_target_description (void)
1554 return XCNEW (struct target_desc
);
1558 free_target_description (void *arg
)
1560 struct target_desc
*target_desc
= (struct target_desc
*) arg
;
1561 struct tdesc_feature
*feature
;
1562 struct property
*prop
;
1566 VEC_iterate (tdesc_feature_p
, target_desc
->features
, ix
, feature
);
1569 VEC_free (tdesc_feature_p
, target_desc
->features
);
1572 VEC_iterate (property_s
, target_desc
->properties
, ix
, prop
);
1576 xfree (prop
->value
);
1578 VEC_free (property_s
, target_desc
->properties
);
1580 VEC_free (arch_p
, target_desc
->compatible
);
1582 xfree (target_desc
);
1586 make_cleanup_free_target_description (struct target_desc
*target_desc
)
1588 return make_cleanup (free_target_description
, target_desc
);
1592 tdesc_add_compatible (struct target_desc
*target_desc
,
1593 const struct bfd_arch_info
*compatible
)
1595 const struct bfd_arch_info
*compat
;
1598 /* If this instance of GDB is compiled without BFD support for the
1599 compatible architecture, simply ignore it -- we would not be able
1600 to handle it anyway. */
1601 if (compatible
== NULL
)
1604 for (ix
= 0; VEC_iterate (arch_p
, target_desc
->compatible
, ix
, compat
);
1606 if (compat
== compatible
)
1607 internal_error (__FILE__
, __LINE__
,
1608 _("Attempted to add duplicate "
1609 "compatible architecture \"%s\""),
1610 compatible
->printable_name
);
1612 VEC_safe_push (arch_p
, target_desc
->compatible
, compatible
);
1616 set_tdesc_property (struct target_desc
*target_desc
,
1617 const char *key
, const char *value
)
1619 struct property
*prop
, new_prop
;
1622 gdb_assert (key
!= NULL
&& value
!= NULL
);
1624 for (ix
= 0; VEC_iterate (property_s
, target_desc
->properties
, ix
, prop
);
1626 if (strcmp (prop
->key
, key
) == 0)
1627 internal_error (__FILE__
, __LINE__
,
1628 _("Attempted to add duplicate property \"%s\""), key
);
1630 new_prop
.key
= xstrdup (key
);
1631 new_prop
.value
= xstrdup (value
);
1632 VEC_safe_push (property_s
, target_desc
->properties
, &new_prop
);
1636 set_tdesc_architecture (struct target_desc
*target_desc
,
1637 const struct bfd_arch_info
*arch
)
1639 target_desc
->arch
= arch
;
1643 set_tdesc_osabi (struct target_desc
*target_desc
, enum gdb_osabi osabi
)
1645 target_desc
->osabi
= osabi
;
1649 static struct cmd_list_element
*tdesc_set_cmdlist
, *tdesc_show_cmdlist
;
1650 static struct cmd_list_element
*tdesc_unset_cmdlist
;
1652 /* Helper functions for the CLI commands. */
1655 set_tdesc_cmd (char *args
, int from_tty
)
1657 help_list (tdesc_set_cmdlist
, "set tdesc ", all_commands
, gdb_stdout
);
1661 show_tdesc_cmd (char *args
, int from_tty
)
1663 cmd_show_list (tdesc_show_cmdlist
, from_tty
, "");
1667 unset_tdesc_cmd (char *args
, int from_tty
)
1669 help_list (tdesc_unset_cmdlist
, "unset tdesc ", all_commands
, gdb_stdout
);
1673 set_tdesc_filename_cmd (char *args
, int from_tty
,
1674 struct cmd_list_element
*c
)
1676 xfree (target_description_filename
);
1677 target_description_filename
= xstrdup (tdesc_filename_cmd_string
);
1679 target_clear_description ();
1680 target_find_description ();
1684 show_tdesc_filename_cmd (struct ui_file
*file
, int from_tty
,
1685 struct cmd_list_element
*c
,
1688 value
= target_description_filename
;
1690 if (value
!= NULL
&& *value
!= '\0')
1691 printf_filtered (_("The target description will be read from \"%s\".\n"),
1694 printf_filtered (_("The target description will be "
1695 "read from the target.\n"));
1699 unset_tdesc_filename_cmd (char *args
, int from_tty
)
1701 xfree (target_description_filename
);
1702 target_description_filename
= NULL
;
1703 target_clear_description ();
1704 target_find_description ();
1708 maint_print_c_tdesc_cmd (char *args
, int from_tty
)
1710 const struct target_desc
*tdesc
;
1711 const struct bfd_arch_info
*compatible
;
1712 const char *filename
, *inp
;
1713 char *function
, *outp
;
1714 struct property
*prop
;
1715 struct tdesc_feature
*feature
;
1716 struct tdesc_reg
*reg
;
1717 struct tdesc_type
*type
;
1718 struct tdesc_type_field
*f
;
1720 int printed_field_type
= 0;
1722 /* Use the global target-supplied description, not the current
1723 architecture's. This lets a GDB for one architecture generate C
1724 for another architecture's description, even though the gdbarch
1725 initialization code will reject the new description. */
1726 tdesc
= current_target_desc
;
1728 error (_("There is no target description to print."));
1730 if (target_description_filename
== NULL
)
1731 error (_("The current target description did not come from an XML file."));
1733 filename
= lbasename (target_description_filename
);
1734 function
= (char *) alloca (strlen (filename
) + 1);
1735 for (inp
= filename
, outp
= function
; *inp
!= '\0'; inp
++)
1738 else if (*inp
== '-')
1744 /* Standard boilerplate. */
1745 printf_unfiltered ("/* THIS FILE IS GENERATED. "
1746 "-*- buffer-read-only: t -*- vi"
1748 printf_unfiltered (" Original: %s */\n\n", filename
);
1749 printf_unfiltered ("#include \"defs.h\"\n");
1750 printf_unfiltered ("#include \"osabi.h\"\n");
1751 printf_unfiltered ("#include \"target-descriptions.h\"\n");
1752 printf_unfiltered ("\n");
1754 printf_unfiltered ("struct target_desc *tdesc_%s;\n", function
);
1755 printf_unfiltered ("static void\n");
1756 printf_unfiltered ("initialize_tdesc_%s (void)\n", function
);
1757 printf_unfiltered ("{\n");
1759 (" struct target_desc *result = allocate_target_description ();\n");
1760 printf_unfiltered (" struct tdesc_feature *feature;\n");
1762 /* Now we do some "filtering" in order to know which variables to
1763 declare. This is needed because otherwise we would declare unused
1764 variables `field_type' and `type'. */
1766 VEC_iterate (tdesc_feature_p
, tdesc
->features
, ix
, feature
);
1769 int printed_desc_type
= 0;
1772 VEC_iterate (tdesc_type_p
, feature
->types
, ix2
, type
);
1775 if (!printed_field_type
)
1777 printf_unfiltered (" struct tdesc_type *field_type;\n");
1778 printed_field_type
= 1;
1781 if ((type
->kind
== TDESC_TYPE_UNION
1782 || type
->kind
== TDESC_TYPE_STRUCT
1783 || type
->kind
== TDESC_TYPE_FLAGS
1784 || type
->kind
== TDESC_TYPE_ENUM
)
1785 && VEC_length (tdesc_type_field
, type
->u
.u
.fields
) > 0)
1787 printf_unfiltered (" struct tdesc_type *type;\n");
1788 printed_desc_type
= 1;
1793 if (printed_desc_type
)
1797 printf_unfiltered ("\n");
1799 if (tdesc_architecture (tdesc
) != NULL
)
1802 (" set_tdesc_architecture (result, bfd_scan_arch (\"%s\"));\n",
1803 tdesc_architecture (tdesc
)->printable_name
);
1804 printf_unfiltered ("\n");
1807 if (tdesc_osabi (tdesc
) > GDB_OSABI_UNKNOWN
1808 && tdesc_osabi (tdesc
) < GDB_OSABI_INVALID
)
1811 (" set_tdesc_osabi (result, osabi_from_tdesc_string (\"%s\"));\n",
1812 gdbarch_osabi_name (tdesc_osabi (tdesc
)));
1813 printf_unfiltered ("\n");
1816 for (ix
= 0; VEC_iterate (arch_p
, tdesc
->compatible
, ix
, compatible
);
1820 (" tdesc_add_compatible (result, bfd_scan_arch (\"%s\"));\n",
1821 compatible
->printable_name
);
1824 printf_unfiltered ("\n");
1826 for (ix
= 0; VEC_iterate (property_s
, tdesc
->properties
, ix
, prop
);
1829 printf_unfiltered (" set_tdesc_property (result, \"%s\", \"%s\");\n",
1830 prop
->key
, prop
->value
);
1834 VEC_iterate (tdesc_feature_p
, tdesc
->features
, ix
, feature
);
1837 printf_unfiltered (" \
1838 feature = tdesc_create_feature (result, \"%s\");\n",
1842 VEC_iterate (tdesc_type_p
, feature
->types
, ix2
, type
);
1847 case TDESC_TYPE_VECTOR
:
1849 (" field_type = tdesc_named_type (feature, \"%s\");\n",
1850 type
->u
.v
.type
->name
);
1852 (" tdesc_create_vector (feature, \"%s\", field_type, %d);\n",
1853 type
->name
, type
->u
.v
.count
);
1855 case TDESC_TYPE_STRUCT
:
1856 case TDESC_TYPE_FLAGS
:
1857 if (type
->kind
== TDESC_TYPE_STRUCT
)
1860 (" type = tdesc_create_struct (feature, \"%s\");\n",
1862 if (type
->u
.u
.size
!= 0)
1864 (" tdesc_set_struct_size (type, %d);\n",
1870 (" type = tdesc_create_flags (feature, \"%s\", %d);\n",
1871 type
->name
, type
->u
.u
.size
);
1874 VEC_iterate (tdesc_type_field
, type
->u
.u
.fields
, ix3
, f
);
1877 const char *type_name
;
1879 gdb_assert (f
->type
!= NULL
);
1880 type_name
= f
->type
->name
;
1882 /* To minimize changes to generated files, don't emit type
1883 info for fields that have defaulted types. */
1886 gdb_assert (f
->end
!= -1);
1887 if (f
->type
->kind
== TDESC_TYPE_BOOL
)
1889 gdb_assert (f
->start
== f
->end
);
1891 (" tdesc_add_flag (type, %d, \"%s\");\n",
1894 else if ((type
->u
.u
.size
== 4
1895 && f
->type
->kind
== TDESC_TYPE_UINT32
)
1896 || (type
->u
.u
.size
== 8
1897 && f
->type
->kind
== TDESC_TYPE_UINT64
))
1900 (" tdesc_add_bitfield (type, \"%s\", %d, %d);\n",
1901 f
->name
, f
->start
, f
->end
);
1906 (" field_type = tdesc_named_type (feature,"
1910 (" tdesc_add_typed_bitfield (type, \"%s\","
1911 " %d, %d, field_type);\n",
1912 f
->name
, f
->start
, f
->end
);
1915 else /* Not a bitfield. */
1917 gdb_assert (f
->end
== -1);
1918 gdb_assert (type
->kind
== TDESC_TYPE_STRUCT
);
1920 (" field_type = tdesc_named_type (feature,"
1924 (" tdesc_add_field (type, \"%s\", field_type);\n",
1929 case TDESC_TYPE_UNION
:
1931 (" type = tdesc_create_union (feature, \"%s\");\n",
1934 VEC_iterate (tdesc_type_field
, type
->u
.u
.fields
, ix3
, f
);
1938 (" field_type = tdesc_named_type (feature, \"%s\");\n",
1941 (" tdesc_add_field (type, \"%s\", field_type);\n",
1945 case TDESC_TYPE_ENUM
:
1947 (" type = tdesc_create_enum (feature, \"%s\", %d);\n",
1948 type
->name
, type
->u
.u
.size
);
1950 VEC_iterate (tdesc_type_field
, type
->u
.u
.fields
, ix3
, f
);
1953 (" tdesc_add_enum_value (type, %d, \"%s\");\n",
1957 error (_("C output is not supported type \"%s\"."), type
->name
);
1959 printf_unfiltered ("\n");
1963 VEC_iterate (tdesc_reg_p
, feature
->registers
, ix2
, reg
);
1966 printf_unfiltered (" tdesc_create_reg (feature, \"%s\", %ld, %d, ",
1967 reg
->name
, reg
->target_regnum
, reg
->save_restore
);
1969 printf_unfiltered ("\"%s\", ", reg
->group
);
1971 printf_unfiltered ("NULL, ");
1972 printf_unfiltered ("%d, \"%s\");\n", reg
->bitsize
, reg
->type
);
1975 printf_unfiltered ("\n");
1978 printf_unfiltered (" tdesc_%s = result;\n", function
);
1979 printf_unfiltered ("}\n");
1982 /* Provide a prototype to silence -Wmissing-prototypes. */
1983 extern initialize_file_ftype _initialize_target_descriptions
;
1986 _initialize_target_descriptions (void)
1988 tdesc_data
= gdbarch_data_register_pre_init (tdesc_data_init
);
1990 add_prefix_cmd ("tdesc", class_maintenance
, set_tdesc_cmd
, _("\
1991 Set target description specific variables."),
1992 &tdesc_set_cmdlist
, "set tdesc ",
1993 0 /* allow-unknown */, &setlist
);
1994 add_prefix_cmd ("tdesc", class_maintenance
, show_tdesc_cmd
, _("\
1995 Show target description specific variables."),
1996 &tdesc_show_cmdlist
, "show tdesc ",
1997 0 /* allow-unknown */, &showlist
);
1998 add_prefix_cmd ("tdesc", class_maintenance
, unset_tdesc_cmd
, _("\
1999 Unset target description specific variables."),
2000 &tdesc_unset_cmdlist
, "unset tdesc ",
2001 0 /* allow-unknown */, &unsetlist
);
2003 add_setshow_filename_cmd ("filename", class_obscure
,
2004 &tdesc_filename_cmd_string
,
2006 Set the file to read for an XML target description"), _("\
2007 Show the file to read for an XML target description"), _("\
2008 When set, GDB will read the target description from a local\n\
2009 file instead of querying the remote target."),
2010 set_tdesc_filename_cmd
,
2011 show_tdesc_filename_cmd
,
2012 &tdesc_set_cmdlist
, &tdesc_show_cmdlist
);
2014 add_cmd ("filename", class_obscure
, unset_tdesc_filename_cmd
, _("\
2015 Unset the file to read for an XML target description. When unset,\n\
2016 GDB will read the description from the target."),
2017 &tdesc_unset_cmdlist
);
2019 add_cmd ("c-tdesc", class_maintenance
, maint_print_c_tdesc_cmd
, _("\
2020 Print the current target description as a C source file."),
2021 &maintenanceprintlist
);