1 /* Target description support for GDB.
3 Copyright (C) 2006, 2007 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 2 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, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
25 #include "arch-utils.h"
28 #include "reggroups.h"
30 #include "target-descriptions.h"
32 #include "xml-support.h"
33 #include "xml-tdesc.h"
35 #include "gdb_assert.h"
36 #include "gdb_obstack.h"
41 typedef struct property
46 DEF_VEC_O(property_s
);
48 /* An individual register from a target description. */
50 typedef struct tdesc_reg
52 /* The name of this register. In standard features, it may be
53 recognized by the architecture support code, or it may be purely
57 /* The register number used by this target to refer to this
58 register. This is used for remote p/P packets and to determine
59 the ordering of registers in the remote g/G packets. */
62 /* If this flag is set, GDB should save and restore this register
63 around calls to an inferior function. */
66 /* The name of the register group containing this register, or NULL
67 if the group should be automatically determined from the
68 register's type. If this is "general", "float", or "vector", the
69 corresponding "info" command should display this register's
70 value. It can be an arbitrary string, but should be limited to
71 alphanumeric characters and internal hyphens. Currently other
72 strings are ignored (treated as NULL). */
75 /* The size of the register, in bits. */
78 /* The type of the register. This string corresponds to either
79 a named type from the target description or a predefined
83 /* The target-described type corresponding to TYPE, if found. */
84 struct type
*gdb_type
;
86 DEF_VEC_P(tdesc_reg_p
);
88 /* A named type from a target description. */
89 typedef struct type
*type_p
;
92 /* A feature from a target description. Each feature is a collection
93 of other elements, e.g. registers and types. */
95 typedef struct tdesc_feature
97 /* The name of this feature. It may be recognized by the architecture
101 /* The registers associated with this feature. */
102 VEC(tdesc_reg_p
) *registers
;
104 /* The types associated with this feature. */
107 DEF_VEC_P(tdesc_feature_p
);
109 /* A target description. */
113 /* The architecture reported by the target, if any. */
114 const struct bfd_arch_info
*arch
;
116 /* Any architecture-specific properties specified by the target. */
117 VEC(property_s
) *properties
;
119 /* The features associated with this target. */
120 VEC(tdesc_feature_p
) *features
;
123 /* Per-architecture data associated with a target description. The
124 target description may be shared by multiple architectures, but
125 this data is private to one gdbarch. */
127 struct tdesc_arch_data
129 /* A list of registers, indexed by GDB's internal register number.
130 During initialization of the gdbarch this list is used to store
131 registers which the architecture assigns a fixed register number.
132 Registers which are NULL in this array, or off the end, are
133 treated as zero-sized and nameless (i.e. placeholders in the
135 VEC(tdesc_reg_p
) *registers
;
137 /* Functions which report the register name, type, and reggroups for
139 gdbarch_register_name_ftype
*pseudo_register_name
;
140 gdbarch_register_type_ftype
*pseudo_register_type
;
141 gdbarch_register_reggroup_p_ftype
*pseudo_register_reggroup_p
;
144 /* Global state. These variables are associated with the current
145 target; if GDB adds support for multiple simultaneous targets, then
146 these variables should become target-specific data. */
148 /* A flag indicating that a description has already been fetched from
149 the current target, so it should not be queried again. */
151 static int target_desc_fetched
;
153 /* The description fetched from the current target, or NULL if the
154 current target did not supply any description. Only valid when
155 target_desc_fetched is set. Only the description initialization
156 code should access this; normally, the description should be
157 accessed through the gdbarch object. */
159 static const struct target_desc
*current_target_desc
;
161 /* Other global variables. */
163 /* The filename to read a target description from. */
165 static char *target_description_filename
;
167 /* A handle for architecture-specific data associated with the
168 target description (see struct tdesc_arch_data). */
170 static struct gdbarch_data
*tdesc_data
;
172 /* Fetch the current target's description, and switch the current
173 architecture to one which incorporates that description. */
176 target_find_description (void)
178 /* If we've already fetched a description from the target, don't do
179 it again. This allows a target to fetch the description early,
180 during its to_open or to_create_inferior, if it needs extra
181 information about the target to initialize. */
182 if (target_desc_fetched
)
185 /* The current architecture should not have any target description
186 specified. It should have been cleared, e.g. when we
187 disconnected from the previous target. */
188 gdb_assert (gdbarch_target_desc (current_gdbarch
) == NULL
);
190 /* First try to fetch an XML description from the user-specified
192 current_target_desc
= NULL
;
193 if (target_description_filename
!= NULL
194 && *target_description_filename
!= '\0')
196 = file_read_description_xml (target_description_filename
);
198 /* Next try to read the description from the current target using
200 if (current_target_desc
== NULL
)
201 current_target_desc
= target_read_description_xml (¤t_target
);
203 /* If that failed try a target-specific hook. */
204 if (current_target_desc
== NULL
)
205 current_target_desc
= target_read_description (¤t_target
);
207 /* If a non-NULL description was returned, then update the current
209 if (current_target_desc
)
211 struct gdbarch_info info
;
213 gdbarch_info_init (&info
);
214 info
.target_desc
= current_target_desc
;
215 if (!gdbarch_update_p (info
))
216 warning (_("Architecture rejected target-supplied description"));
219 struct tdesc_arch_data
*data
;
221 data
= gdbarch_data (current_gdbarch
, tdesc_data
);
222 if (tdesc_has_registers (current_target_desc
)
223 && data
->registers
== NULL
)
224 warning (_("Target-supplied registers are not supported "
225 "by the current architecture"));
229 /* Now that we know this description is usable, record that we
231 target_desc_fetched
= 1;
234 /* Discard any description fetched from the current target, and switch
235 the current architecture to one with no target description. */
238 target_clear_description (void)
240 struct gdbarch_info info
;
242 if (!target_desc_fetched
)
245 target_desc_fetched
= 0;
246 current_target_desc
= NULL
;
248 gdbarch_info_init (&info
);
249 if (!gdbarch_update_p (info
))
250 internal_error (__FILE__
, __LINE__
,
251 _("Could not remove target-supplied description"));
254 /* Return the global current target description. This should only be
255 used by gdbarch initialization code; most access should be through
256 an existing gdbarch. */
258 const struct target_desc
*
259 target_current_description (void)
261 if (target_desc_fetched
)
262 return current_target_desc
;
268 /* Direct accessors for target descriptions. */
270 /* Return the string value of a property named KEY, or NULL if the
271 property was not specified. */
274 tdesc_property (const struct target_desc
*target_desc
, const char *key
)
276 struct property
*prop
;
279 for (ix
= 0; VEC_iterate (property_s
, target_desc
->properties
, ix
, prop
);
281 if (strcmp (prop
->key
, key
) == 0)
287 /* Return the BFD architecture associated with this target
288 description, or NULL if no architecture was specified. */
290 const struct bfd_arch_info
*
291 tdesc_architecture (const struct target_desc
*target_desc
)
293 return target_desc
->arch
;
297 /* Return 1 if this target description includes any registers. */
300 tdesc_has_registers (const struct target_desc
*target_desc
)
303 struct tdesc_feature
*feature
;
305 if (target_desc
== NULL
)
309 VEC_iterate (tdesc_feature_p
, target_desc
->features
, ix
, feature
);
311 if (! VEC_empty (tdesc_reg_p
, feature
->registers
))
317 /* Return the feature with the given name, if present, or NULL if
318 the named feature is not found. */
320 const struct tdesc_feature
*
321 tdesc_find_feature (const struct target_desc
*target_desc
,
325 struct tdesc_feature
*feature
;
328 VEC_iterate (tdesc_feature_p
, target_desc
->features
, ix
, feature
);
330 if (strcmp (feature
->name
, name
) == 0)
336 /* Return the name of FEATURE. */
339 tdesc_feature_name (const struct tdesc_feature
*feature
)
341 return feature
->name
;
344 /* Return the type associated with ID in the context of FEATURE, or
348 tdesc_named_type (const struct tdesc_feature
*feature
, const char *id
)
351 struct type
*gdb_type
;
353 /* First try target-defined types. */
354 for (ix
= 0; VEC_iterate (type_p
, feature
->types
, ix
, gdb_type
); ix
++)
355 if (strcmp (TYPE_NAME (gdb_type
), id
) == 0)
358 /* Next try some predefined types. Note that none of these types
359 depend on the current architecture; some of the builtin_type_foo
360 variables are swapped based on the architecture. */
361 if (strcmp (id
, "int8") == 0)
362 return builtin_type_int8
;
364 if (strcmp (id
, "int16") == 0)
365 return builtin_type_int16
;
367 if (strcmp (id
, "int32") == 0)
368 return builtin_type_int32
;
370 if (strcmp (id
, "int64") == 0)
371 return builtin_type_int64
;
373 if (strcmp (id
, "uint8") == 0)
374 return builtin_type_uint8
;
376 if (strcmp (id
, "uint16") == 0)
377 return builtin_type_uint16
;
379 if (strcmp (id
, "uint32") == 0)
380 return builtin_type_uint32
;
382 if (strcmp (id
, "uint64") == 0)
383 return builtin_type_uint64
;
385 if (strcmp (id
, "ieee_single") == 0)
386 return builtin_type_ieee_single
;
388 if (strcmp (id
, "ieee_double") == 0)
389 return builtin_type_ieee_double
;
391 if (strcmp (id
, "arm_fpa_ext") == 0)
392 return builtin_type_arm_ext
;
398 /* Support for registers from target descriptions. */
400 /* Construct the per-gdbarch data. */
403 tdesc_data_init (struct obstack
*obstack
)
405 struct tdesc_arch_data
*data
;
407 data
= OBSTACK_ZALLOC (obstack
, struct tdesc_arch_data
);
411 /* Similar, but for the temporary copy used during architecture
414 struct tdesc_arch_data
*
415 tdesc_data_alloc (void)
417 return XZALLOC (struct tdesc_arch_data
);
420 /* Free something allocated by tdesc_data_alloc, if it is not going
421 to be used (for instance if it was unsuitable for the
425 tdesc_data_cleanup (void *data_untyped
)
427 struct tdesc_arch_data
*data
= data_untyped
;
429 VEC_free (tdesc_reg_p
, data
->registers
);
433 /* Search FEATURE for a register named NAME. */
436 tdesc_numbered_register (const struct tdesc_feature
*feature
,
437 struct tdesc_arch_data
*data
,
438 int regno
, const char *name
)
441 struct tdesc_reg
*reg
;
444 VEC_iterate (tdesc_reg_p
, feature
->registers
, ixr
, reg
);
446 if (strcasecmp (reg
->name
, name
) == 0)
448 /* Make sure the vector includes a REGNO'th element. */
449 while (regno
>= VEC_length (tdesc_reg_p
, data
->registers
))
450 VEC_safe_push (tdesc_reg_p
, data
->registers
, NULL
);
451 VEC_replace (tdesc_reg_p
, data
->registers
, regno
, reg
);
458 /* Search FEATURE for a register whose name is in NAMES. */
461 tdesc_numbered_register_choices (const struct tdesc_feature
*feature
,
462 struct tdesc_arch_data
*data
,
463 int regno
, const char *const names
[])
467 for (i
= 0; names
[i
] != NULL
; i
++)
468 if (tdesc_numbered_register (feature
, data
, regno
, names
[i
]))
474 /* Look up a register by its GDB internal register number. */
476 static struct tdesc_reg
*
477 tdesc_find_register (struct gdbarch
*gdbarch
, int regno
)
479 struct tdesc_reg
*reg
;
480 struct tdesc_arch_data
*data
;
482 data
= gdbarch_data (gdbarch
, tdesc_data
);
483 if (regno
< VEC_length (tdesc_reg_p
, data
->registers
))
484 return VEC_index (tdesc_reg_p
, data
->registers
, regno
);
490 tdesc_register_name (int regno
)
492 struct tdesc_reg
*reg
= tdesc_find_register (current_gdbarch
, regno
);
493 int num_regs
= gdbarch_num_regs (current_gdbarch
);
494 int num_pseudo_regs
= gdbarch_num_pseudo_regs (current_gdbarch
);
499 if (regno
>= num_regs
&& regno
< num_regs
+ num_pseudo_regs
)
501 struct tdesc_arch_data
*data
= gdbarch_data (current_gdbarch
,
503 gdb_assert (data
->pseudo_register_name
!= NULL
);
504 return data
->pseudo_register_name (regno
);
511 tdesc_register_type (struct gdbarch
*gdbarch
, int regno
)
513 struct tdesc_reg
*reg
= tdesc_find_register (gdbarch
, regno
);
514 int num_regs
= gdbarch_num_regs (gdbarch
);
515 int num_pseudo_regs
= gdbarch_num_pseudo_regs (gdbarch
);
517 if (reg
== NULL
&& regno
>= num_regs
&& regno
< num_regs
+ num_pseudo_regs
)
519 struct tdesc_arch_data
*data
= gdbarch_data (gdbarch
, tdesc_data
);
520 gdb_assert (data
->pseudo_register_type
!= NULL
);
521 return data
->pseudo_register_type (gdbarch
, regno
);
525 /* Return "int0_t", since "void" has a misleading size of one. */
526 return builtin_type_int0
;
528 /* First check for a predefined or target defined type. */
530 return reg
->gdb_type
;
532 /* Next try size-sensitive type shortcuts. */
533 if (strcmp (reg
->type
, "float") == 0)
535 if (reg
->bitsize
== gdbarch_float_bit (gdbarch
))
536 return builtin_type_float
;
537 else if (reg
->bitsize
== gdbarch_double_bit (gdbarch
))
538 return builtin_type_double
;
539 else if (reg
->bitsize
== gdbarch_long_double_bit (gdbarch
))
540 return builtin_type_long_double
;
542 else if (strcmp (reg
->type
, "int") == 0)
544 if (reg
->bitsize
== gdbarch_long_bit (gdbarch
))
545 return builtin_type_long
;
546 else if (reg
->bitsize
== TARGET_CHAR_BIT
)
547 return builtin_type_char
;
548 else if (reg
->bitsize
== gdbarch_short_bit (gdbarch
))
549 return builtin_type_short
;
550 else if (reg
->bitsize
== gdbarch_int_bit (gdbarch
))
551 return builtin_type_int
;
552 else if (reg
->bitsize
== gdbarch_long_long_bit (gdbarch
))
553 return builtin_type_long_long
;
554 else if (reg
->bitsize
== gdbarch_ptr_bit (gdbarch
))
555 /* A bit desperate by this point... */
556 return builtin_type_void_data_ptr
;
558 else if (strcmp (reg
->type
, "code_ptr") == 0)
559 return builtin_type_void_func_ptr
;
560 else if (strcmp (reg
->type
, "data_ptr") == 0)
561 return builtin_type_void_data_ptr
;
563 internal_error (__FILE__
, __LINE__
,
564 "Register \"%s\" has an unknown type \"%s\"",
565 reg
->name
, reg
->type
);
567 warning (_("Register \"%s\" has an unsupported size (%d bits)"),
568 reg
->name
, reg
->bitsize
);
569 return builtin_type_long
;
573 tdesc_remote_register_number (struct gdbarch
*gdbarch
, int regno
)
575 struct tdesc_reg
*reg
= tdesc_find_register (gdbarch
, regno
);
578 return reg
->target_regnum
;
583 /* Check whether REGNUM is a member of REGGROUP. Registers from the
584 target description may be classified as general, float, or vector.
585 Registers with no group specified go to the default reggroup
586 function and are handled by type.
588 Arbitrary strings (other than "general", "float", and "vector")
589 from the description are not used; they cause the register to be
590 displayed in "info all-registers" but excluded from "info
591 registers" et al. The names of containing features are also not
592 used. This might be extended to display registers in some more
595 The save-restore flag is also implemented here. */
598 tdesc_register_reggroup_p (struct gdbarch
*gdbarch
, int regno
,
599 struct reggroup
*reggroup
)
601 int num_regs
= gdbarch_num_regs (gdbarch
);
602 int num_pseudo_regs
= gdbarch_num_pseudo_regs (gdbarch
);
603 struct tdesc_reg
*reg
= tdesc_find_register (gdbarch
, regno
);
605 if (reg
== NULL
&& regno
>= num_regs
&& regno
< num_regs
+ num_pseudo_regs
)
607 struct tdesc_arch_data
*data
= gdbarch_data (gdbarch
, tdesc_data
);
608 gdb_assert (data
->pseudo_register_reggroup_p
!= NULL
);
609 return data
->pseudo_register_reggroup_p (gdbarch
, regno
, reggroup
);
612 if (reg
!= NULL
&& reg
->group
!= NULL
)
614 int general_p
= 0, float_p
= 0, vector_p
= 0;
616 if (strcmp (reg
->group
, "general") == 0)
618 else if (strcmp (reg
->group
, "float") == 0)
620 else if (strcmp (reg
->group
, "vector") == 0)
623 if (reggroup
== float_reggroup
)
626 if (reggroup
== vector_reggroup
)
629 if (reggroup
== general_reggroup
)
634 && (reggroup
== save_reggroup
|| reggroup
== restore_reggroup
))
635 return reg
->save_restore
;
637 return default_register_reggroup_p (gdbarch
, regno
, reggroup
);
640 /* Record architecture-specific functions to call for pseudo-register
644 set_tdesc_pseudo_register_name (struct gdbarch
*gdbarch
,
645 gdbarch_register_name_ftype
*pseudo_name
)
647 struct tdesc_arch_data
*data
= gdbarch_data (gdbarch
, tdesc_data
);
649 data
->pseudo_register_name
= pseudo_name
;
653 set_tdesc_pseudo_register_type (struct gdbarch
*gdbarch
,
654 gdbarch_register_type_ftype
*pseudo_type
)
656 struct tdesc_arch_data
*data
= gdbarch_data (gdbarch
, tdesc_data
);
658 data
->pseudo_register_type
= pseudo_type
;
662 set_tdesc_pseudo_register_reggroup_p
663 (struct gdbarch
*gdbarch
,
664 gdbarch_register_reggroup_p_ftype
*pseudo_reggroup_p
)
666 struct tdesc_arch_data
*data
= gdbarch_data (gdbarch
, tdesc_data
);
668 data
->pseudo_register_reggroup_p
= pseudo_reggroup_p
;
671 /* Update GDBARCH to use the target description for registers. */
674 tdesc_use_registers (struct gdbarch
*gdbarch
,
675 struct tdesc_arch_data
*early_data
)
677 int num_regs
= gdbarch_num_regs (gdbarch
);
679 const struct target_desc
*target_desc
;
680 struct tdesc_feature
*feature
;
681 struct tdesc_reg
*reg
;
682 struct tdesc_arch_data
*data
;
685 target_desc
= gdbarch_target_desc (gdbarch
);
687 /* We can't use the description for registers if it doesn't describe
688 any. This function should only be called after validating
689 registers, so the caller should know that registers are
691 gdb_assert (tdesc_has_registers (target_desc
));
693 data
= gdbarch_data (gdbarch
, tdesc_data
);
694 data
->registers
= early_data
->registers
;
697 /* Build up a set of all registers, so that we can assign register
698 numbers where needed. The hash table expands as necessary, so
699 the initial size is arbitrary. */
700 reg_hash
= htab_create (37, htab_hash_pointer
, htab_eq_pointer
, NULL
);
702 VEC_iterate (tdesc_feature_p
, target_desc
->features
, ixf
, feature
);
705 VEC_iterate (tdesc_reg_p
, feature
->registers
, ixr
, reg
);
708 void **slot
= htab_find_slot (reg_hash
, reg
, INSERT
);
713 /* Remove any registers which were assigned numbers by the
715 for (ixr
= 0; VEC_iterate (tdesc_reg_p
, data
->registers
, ixr
, reg
); ixr
++)
717 htab_remove_elt (reg_hash
, reg
);
719 /* Assign numbers to the remaining registers and add them to the
720 list of registers. The new numbers are always above NUM_REGS.
721 Iterate over the features, not the hash table, so that the order
722 matches that in the target description. */
724 gdb_assert (VEC_length (tdesc_reg_p
, data
->registers
) <= num_regs
);
725 while (VEC_length (tdesc_reg_p
, data
->registers
) < num_regs
)
726 VEC_safe_push (tdesc_reg_p
, data
->registers
, NULL
);
728 VEC_iterate (tdesc_feature_p
, target_desc
->features
, ixf
, feature
);
731 VEC_iterate (tdesc_reg_p
, feature
->registers
, ixr
, reg
);
733 if (htab_find (reg_hash
, reg
) != NULL
)
735 VEC_safe_push (tdesc_reg_p
, data
->registers
, reg
);
739 htab_delete (reg_hash
);
741 /* Update the architecture. */
742 set_gdbarch_num_regs (gdbarch
, num_regs
);
743 set_gdbarch_register_name (gdbarch
, tdesc_register_name
);
744 set_gdbarch_register_type (gdbarch
, tdesc_register_type
);
745 set_gdbarch_remote_register_number (gdbarch
,
746 tdesc_remote_register_number
);
747 set_gdbarch_register_reggroup_p (gdbarch
, tdesc_register_reggroup_p
);
751 /* Methods for constructing a target description. */
754 tdesc_free_reg (struct tdesc_reg
*reg
)
763 tdesc_create_reg (struct tdesc_feature
*feature
, const char *name
,
764 int regnum
, int save_restore
, const char *group
,
765 int bitsize
, const char *type
)
767 struct tdesc_reg
*reg
= XZALLOC (struct tdesc_reg
);
769 reg
->name
= xstrdup (name
);
770 reg
->target_regnum
= regnum
;
771 reg
->save_restore
= save_restore
;
772 reg
->group
= group
? xstrdup (group
) : NULL
;
773 reg
->bitsize
= bitsize
;
774 reg
->type
= type
? xstrdup (type
) : NULL
;
776 /* If the register's type is target-defined, look it up now. We may not
777 have easy access to the containing feature when we want it later. */
778 reg
->gdb_type
= tdesc_named_type (feature
, reg
->type
);
780 VEC_safe_push (tdesc_reg_p
, feature
->registers
, reg
);
784 tdesc_free_feature (struct tdesc_feature
*feature
)
786 struct tdesc_reg
*reg
;
789 for (ix
= 0; VEC_iterate (tdesc_reg_p
, feature
->registers
, ix
, reg
); ix
++)
790 tdesc_free_reg (reg
);
791 VEC_free (tdesc_reg_p
, feature
->registers
);
793 /* There is no easy way to free xmalloc-allocated types, nor is
794 there a way to allocate types on an obstack not associated with
795 an objfile. Therefore we never free types. Since we only ever
796 parse an identical XML document once, this memory leak is mostly
798 VEC_free (type_p
, feature
->types
);
800 xfree (feature
->name
);
804 struct tdesc_feature
*
805 tdesc_create_feature (struct target_desc
*tdesc
, const char *name
)
807 struct tdesc_feature
*new_feature
= XZALLOC (struct tdesc_feature
);
809 new_feature
->name
= xstrdup (name
);
811 VEC_safe_push (tdesc_feature_p
, tdesc
->features
, new_feature
);
816 tdesc_record_type (struct tdesc_feature
*feature
, struct type
*type
)
818 /* The type's ID should be used as its TYPE_NAME. */
819 gdb_assert (TYPE_NAME (type
) != NULL
);
821 VEC_safe_push (type_p
, feature
->types
, type
);
825 allocate_target_description (void)
827 return XZALLOC (struct target_desc
);
831 free_target_description (void *arg
)
833 struct target_desc
*target_desc
= arg
;
834 struct tdesc_feature
*feature
;
835 struct property
*prop
;
839 VEC_iterate (tdesc_feature_p
, target_desc
->features
, ix
, feature
);
841 tdesc_free_feature (feature
);
842 VEC_free (tdesc_feature_p
, target_desc
->features
);
845 VEC_iterate (property_s
, target_desc
->properties
, ix
, prop
);
851 VEC_free (property_s
, target_desc
->properties
);
857 make_cleanup_free_target_description (struct target_desc
*target_desc
)
859 return make_cleanup (free_target_description
, target_desc
);
863 set_tdesc_property (struct target_desc
*target_desc
,
864 const char *key
, const char *value
)
866 struct property
*prop
, new_prop
;
869 gdb_assert (key
!= NULL
&& value
!= NULL
);
871 for (ix
= 0; VEC_iterate (property_s
, target_desc
->properties
, ix
, prop
);
873 if (strcmp (prop
->key
, key
) == 0)
874 internal_error (__FILE__
, __LINE__
,
875 _("Attempted to add duplicate property \"%s\""), key
);
877 new_prop
.key
= xstrdup (key
);
878 new_prop
.value
= xstrdup (value
);
879 VEC_safe_push (property_s
, target_desc
->properties
, &new_prop
);
883 set_tdesc_architecture (struct target_desc
*target_desc
,
884 const struct bfd_arch_info
*arch
)
886 target_desc
->arch
= arch
;
890 static struct cmd_list_element
*tdesc_set_cmdlist
, *tdesc_show_cmdlist
;
891 static struct cmd_list_element
*tdesc_unset_cmdlist
;
893 /* Helper functions for the CLI commands. */
896 set_tdesc_cmd (char *args
, int from_tty
)
898 help_list (tdesc_set_cmdlist
, "set tdesc ", -1, gdb_stdout
);
902 show_tdesc_cmd (char *args
, int from_tty
)
904 cmd_show_list (tdesc_show_cmdlist
, from_tty
, "");
908 unset_tdesc_cmd (char *args
, int from_tty
)
910 help_list (tdesc_unset_cmdlist
, "unset tdesc ", -1, gdb_stdout
);
914 set_tdesc_filename_cmd (char *args
, int from_tty
,
915 struct cmd_list_element
*c
)
917 target_clear_description ();
918 target_find_description ();
922 show_tdesc_filename_cmd (struct ui_file
*file
, int from_tty
,
923 struct cmd_list_element
*c
,
926 if (value
!= NULL
&& *value
!= '\0')
927 printf_filtered (_("\
928 The target description will be read from \"%s\".\n"),
931 printf_filtered (_("\
932 The target description will be read from the target.\n"));
936 unset_tdesc_filename_cmd (char *args
, int from_tty
)
938 xfree (target_description_filename
);
939 target_description_filename
= NULL
;
940 target_clear_description ();
941 target_find_description ();
945 _initialize_target_descriptions (void)
947 tdesc_data
= gdbarch_data_register_pre_init (tdesc_data_init
);
949 add_prefix_cmd ("tdesc", class_maintenance
, set_tdesc_cmd
, _("\
950 Set target description specific variables."),
951 &tdesc_set_cmdlist
, "set tdesc ",
952 0 /* allow-unknown */, &setlist
);
953 add_prefix_cmd ("tdesc", class_maintenance
, show_tdesc_cmd
, _("\
954 Show target description specific variables."),
955 &tdesc_show_cmdlist
, "show tdesc ",
956 0 /* allow-unknown */, &showlist
);
957 add_prefix_cmd ("tdesc", class_maintenance
, unset_tdesc_cmd
, _("\
958 Unset target description specific variables."),
959 &tdesc_unset_cmdlist
, "unset tdesc ",
960 0 /* allow-unknown */, &unsetlist
);
962 add_setshow_filename_cmd ("filename", class_obscure
,
963 &target_description_filename
,
965 Set the file to read for an XML target description"), _("\
966 Show the file to read for an XML target description"), _("\
967 When set, GDB will read the target description from a local\n\
968 file instead of querying the remote target."),
969 set_tdesc_filename_cmd
,
970 show_tdesc_filename_cmd
,
971 &tdesc_set_cmdlist
, &tdesc_show_cmdlist
);
973 add_cmd ("filename", class_obscure
, unset_tdesc_filename_cmd
, _("\
974 Unset the file to read for an XML target description. When unset,\n\
975 GDB will read the description from the target."),
976 &tdesc_unset_cmdlist
);