Generate set_tdesc_osabi for valid OSABI.
[deliverable/binutils-gdb.git] / gdb / target-descriptions.c
1 /* Target description support for GDB.
2
3 Copyright (C) 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
4
5 Contributed by CodeSourcery.
6
7 This file is part of GDB.
8
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.
13
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.
18
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/>. */
21
22 #include "defs.h"
23 #include "arch-utils.h"
24 #include "gdbcmd.h"
25 #include "gdbtypes.h"
26 #include "reggroups.h"
27 #include "target.h"
28 #include "target-descriptions.h"
29 #include "vec.h"
30 #include "xml-support.h"
31 #include "xml-tdesc.h"
32 #include "osabi.h"
33
34 #include "gdb_assert.h"
35 #include "gdb_obstack.h"
36 #include "hashtab.h"
37
38 /* Types. */
39
40 typedef struct property
41 {
42 char *key;
43 char *value;
44 } property_s;
45 DEF_VEC_O(property_s);
46
47 /* An individual register from a target description. */
48
49 typedef struct tdesc_reg
50 {
51 /* The name of this register. In standard features, it may be
52 recognized by the architecture support code, or it may be purely
53 for the user. */
54 char *name;
55
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. */
59 long target_regnum;
60
61 /* If this flag is set, GDB should save and restore this register
62 around calls to an inferior function. */
63 int save_restore;
64
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). */
72 char *group;
73
74 /* The size of the register, in bits. */
75 int bitsize;
76
77 /* The type of the register. This string corresponds to either
78 a named type from the target description or a predefined
79 type from GDB. */
80 char *type;
81
82 /* The target-described type corresponding to TYPE, if found. */
83 struct tdesc_type *tdesc_type;
84 } *tdesc_reg_p;
85 DEF_VEC_P(tdesc_reg_p);
86
87 /* A named type from a target description. */
88
89 typedef struct tdesc_type_field
90 {
91 char *name;
92 struct tdesc_type *type;
93 } tdesc_type_field;
94 DEF_VEC_O(tdesc_type_field);
95
96 typedef struct tdesc_type
97 {
98 /* The name of this type. */
99 char *name;
100
101 /* Identify the kind of this type. */
102 enum
103 {
104 /* Predefined types. */
105 TDESC_TYPE_INT8,
106 TDESC_TYPE_INT16,
107 TDESC_TYPE_INT32,
108 TDESC_TYPE_INT64,
109 TDESC_TYPE_INT128,
110 TDESC_TYPE_UINT8,
111 TDESC_TYPE_UINT16,
112 TDESC_TYPE_UINT32,
113 TDESC_TYPE_UINT64,
114 TDESC_TYPE_UINT128,
115 TDESC_TYPE_CODE_PTR,
116 TDESC_TYPE_DATA_PTR,
117 TDESC_TYPE_IEEE_SINGLE,
118 TDESC_TYPE_IEEE_DOUBLE,
119 TDESC_TYPE_ARM_FPA_EXT,
120
121 /* Types defined by a target feature. */
122 TDESC_TYPE_VECTOR,
123 TDESC_TYPE_UNION
124 } kind;
125
126 /* Kind-specific data. */
127 union
128 {
129 /* Vector type. */
130 struct
131 {
132 struct tdesc_type *type;
133 int count;
134 } v;
135
136 /* Union type. */
137 struct
138 {
139 VEC(tdesc_type_field) *fields;
140 } u;
141 } u;
142 } *tdesc_type_p;
143 DEF_VEC_P(tdesc_type_p);
144
145 /* A feature from a target description. Each feature is a collection
146 of other elements, e.g. registers and types. */
147
148 typedef struct tdesc_feature
149 {
150 /* The name of this feature. It may be recognized by the architecture
151 support code. */
152 char *name;
153
154 /* The registers associated with this feature. */
155 VEC(tdesc_reg_p) *registers;
156
157 /* The types associated with this feature. */
158 VEC(tdesc_type_p) *types;
159 } *tdesc_feature_p;
160 DEF_VEC_P(tdesc_feature_p);
161
162 /* A compatible architecture from a target description. */
163 typedef const struct bfd_arch_info *arch_p;
164 DEF_VEC_P(arch_p);
165
166 /* A target description. */
167
168 struct target_desc
169 {
170 /* The architecture reported by the target, if any. */
171 const struct bfd_arch_info *arch;
172
173 /* The osabi reported by the target, if any; GDB_OSABI_UNKNOWN
174 otherwise. */
175 enum gdb_osabi osabi;
176
177 /* The list of compatible architectures reported by the target. */
178 VEC(arch_p) *compatible;
179
180 /* Any architecture-specific properties specified by the target. */
181 VEC(property_s) *properties;
182
183 /* The features associated with this target. */
184 VEC(tdesc_feature_p) *features;
185 };
186
187 /* Per-architecture data associated with a target description. The
188 target description may be shared by multiple architectures, but
189 this data is private to one gdbarch. */
190
191 typedef struct tdesc_arch_reg
192 {
193 struct tdesc_reg *reg;
194 struct type *type;
195 } tdesc_arch_reg;
196 DEF_VEC_O(tdesc_arch_reg);
197
198 struct tdesc_arch_data
199 {
200 /* A list of register/type pairs, indexed by GDB's internal register number.
201 During initialization of the gdbarch this list is used to store
202 registers which the architecture assigns a fixed register number.
203 Registers which are NULL in this array, or off the end, are
204 treated as zero-sized and nameless (i.e. placeholders in the
205 numbering). */
206 VEC(tdesc_arch_reg) *arch_regs;
207
208 /* Functions which report the register name, type, and reggroups for
209 pseudo-registers. */
210 gdbarch_register_name_ftype *pseudo_register_name;
211 gdbarch_register_type_ftype *pseudo_register_type;
212 gdbarch_register_reggroup_p_ftype *pseudo_register_reggroup_p;
213 };
214
215 /* Global state. These variables are associated with the current
216 target; if GDB adds support for multiple simultaneous targets, then
217 these variables should become target-specific data. */
218
219 /* A flag indicating that a description has already been fetched from
220 the current target, so it should not be queried again. */
221
222 static int target_desc_fetched;
223
224 /* The description fetched from the current target, or NULL if the
225 current target did not supply any description. Only valid when
226 target_desc_fetched is set. Only the description initialization
227 code should access this; normally, the description should be
228 accessed through the gdbarch object. */
229
230 static const struct target_desc *current_target_desc;
231
232 /* Other global variables. */
233
234 /* The filename to read a target description from. */
235
236 static char *target_description_filename;
237
238 /* A handle for architecture-specific data associated with the
239 target description (see struct tdesc_arch_data). */
240
241 static struct gdbarch_data *tdesc_data;
242
243 /* Fetch the current target's description, and switch the current
244 architecture to one which incorporates that description. */
245
246 void
247 target_find_description (void)
248 {
249 /* If we've already fetched a description from the target, don't do
250 it again. This allows a target to fetch the description early,
251 during its to_open or to_create_inferior, if it needs extra
252 information about the target to initialize. */
253 if (target_desc_fetched)
254 return;
255
256 /* The current architecture should not have any target description
257 specified. It should have been cleared, e.g. when we
258 disconnected from the previous target. */
259 gdb_assert (gdbarch_target_desc (target_gdbarch) == NULL);
260
261 /* First try to fetch an XML description from the user-specified
262 file. */
263 current_target_desc = NULL;
264 if (target_description_filename != NULL
265 && *target_description_filename != '\0')
266 current_target_desc
267 = file_read_description_xml (target_description_filename);
268
269 /* Next try to read the description from the current target using
270 target objects. */
271 if (current_target_desc == NULL)
272 current_target_desc = target_read_description_xml (&current_target);
273
274 /* If that failed try a target-specific hook. */
275 if (current_target_desc == NULL)
276 current_target_desc = target_read_description (&current_target);
277
278 /* If a non-NULL description was returned, then update the current
279 architecture. */
280 if (current_target_desc)
281 {
282 struct gdbarch_info info;
283
284 gdbarch_info_init (&info);
285 info.target_desc = current_target_desc;
286 if (!gdbarch_update_p (info))
287 warning (_("Architecture rejected target-supplied description"));
288 else
289 {
290 struct tdesc_arch_data *data;
291
292 data = gdbarch_data (target_gdbarch, tdesc_data);
293 if (tdesc_has_registers (current_target_desc)
294 && data->arch_regs == NULL)
295 warning (_("Target-supplied registers are not supported "
296 "by the current architecture"));
297 }
298 }
299
300 /* Now that we know this description is usable, record that we
301 fetched it. */
302 target_desc_fetched = 1;
303 }
304
305 /* Discard any description fetched from the current target, and switch
306 the current architecture to one with no target description. */
307
308 void
309 target_clear_description (void)
310 {
311 struct gdbarch_info info;
312
313 if (!target_desc_fetched)
314 return;
315
316 target_desc_fetched = 0;
317 current_target_desc = NULL;
318
319 gdbarch_info_init (&info);
320 if (!gdbarch_update_p (info))
321 internal_error (__FILE__, __LINE__,
322 _("Could not remove target-supplied description"));
323 }
324
325 /* Return the global current target description. This should only be
326 used by gdbarch initialization code; most access should be through
327 an existing gdbarch. */
328
329 const struct target_desc *
330 target_current_description (void)
331 {
332 if (target_desc_fetched)
333 return current_target_desc;
334
335 return NULL;
336 }
337
338 /* Return non-zero if this target description is compatible
339 with the given BFD architecture. */
340
341 int
342 tdesc_compatible_p (const struct target_desc *target_desc,
343 const struct bfd_arch_info *arch)
344 {
345 const struct bfd_arch_info *compat;
346 int ix;
347
348 for (ix = 0; VEC_iterate (arch_p, target_desc->compatible, ix, compat);
349 ix++)
350 {
351 if (compat == arch
352 || arch->compatible (arch, compat)
353 || compat->compatible (compat, arch))
354 return 1;
355 }
356
357 return 0;
358 }
359 \f
360
361 /* Direct accessors for target descriptions. */
362
363 /* Return the string value of a property named KEY, or NULL if the
364 property was not specified. */
365
366 const char *
367 tdesc_property (const struct target_desc *target_desc, const char *key)
368 {
369 struct property *prop;
370 int ix;
371
372 for (ix = 0; VEC_iterate (property_s, target_desc->properties, ix, prop);
373 ix++)
374 if (strcmp (prop->key, key) == 0)
375 return prop->value;
376
377 return NULL;
378 }
379
380 /* Return the BFD architecture associated with this target
381 description, or NULL if no architecture was specified. */
382
383 const struct bfd_arch_info *
384 tdesc_architecture (const struct target_desc *target_desc)
385 {
386 return target_desc->arch;
387 }
388
389 /* Return the OSABI associated with this target description, or
390 GDB_OSABI_UNKNOWN if no osabi was specified. */
391
392 enum gdb_osabi
393 tdesc_osabi (const struct target_desc *target_desc)
394 {
395 return target_desc->osabi;
396 }
397
398 \f
399
400 /* Return 1 if this target description includes any registers. */
401
402 int
403 tdesc_has_registers (const struct target_desc *target_desc)
404 {
405 int ix;
406 struct tdesc_feature *feature;
407
408 if (target_desc == NULL)
409 return 0;
410
411 for (ix = 0;
412 VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature);
413 ix++)
414 if (! VEC_empty (tdesc_reg_p, feature->registers))
415 return 1;
416
417 return 0;
418 }
419
420 /* Return the feature with the given name, if present, or NULL if
421 the named feature is not found. */
422
423 const struct tdesc_feature *
424 tdesc_find_feature (const struct target_desc *target_desc,
425 const char *name)
426 {
427 int ix;
428 struct tdesc_feature *feature;
429
430 for (ix = 0;
431 VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature);
432 ix++)
433 if (strcmp (feature->name, name) == 0)
434 return feature;
435
436 return NULL;
437 }
438
439 /* Return the name of FEATURE. */
440
441 const char *
442 tdesc_feature_name (const struct tdesc_feature *feature)
443 {
444 return feature->name;
445 }
446
447 /* Predefined types. */
448 static struct tdesc_type tdesc_predefined_types[] =
449 {
450 { "int8", TDESC_TYPE_INT8 },
451 { "int16", TDESC_TYPE_INT16 },
452 { "int32", TDESC_TYPE_INT32 },
453 { "int64", TDESC_TYPE_INT64 },
454 { "int128", TDESC_TYPE_INT128 },
455 { "uint8", TDESC_TYPE_UINT8 },
456 { "uint16", TDESC_TYPE_UINT16 },
457 { "uint32", TDESC_TYPE_UINT32 },
458 { "uint64", TDESC_TYPE_UINT64 },
459 { "uint128", TDESC_TYPE_UINT128 },
460 { "code_ptr", TDESC_TYPE_CODE_PTR },
461 { "data_ptr", TDESC_TYPE_DATA_PTR },
462 { "ieee_single", TDESC_TYPE_IEEE_SINGLE },
463 { "ieee_double", TDESC_TYPE_IEEE_DOUBLE },
464 { "arm_fpa_ext", TDESC_TYPE_ARM_FPA_EXT }
465 };
466
467 /* Return the type associated with ID in the context of FEATURE, or
468 NULL if none. */
469
470 struct tdesc_type *
471 tdesc_named_type (const struct tdesc_feature *feature, const char *id)
472 {
473 int ix;
474 struct tdesc_type *type;
475
476 /* First try target-defined types. */
477 for (ix = 0; VEC_iterate (tdesc_type_p, feature->types, ix, type); ix++)
478 if (strcmp (type->name, id) == 0)
479 return type;
480
481 /* Next try the predefined types. */
482 for (ix = 0; ix < ARRAY_SIZE (tdesc_predefined_types); ix++)
483 if (strcmp (tdesc_predefined_types[ix].name, id) == 0)
484 return &tdesc_predefined_types[ix];
485
486 return NULL;
487 }
488
489 /* Construct, if necessary, and return the GDB type implementing target
490 type TDESC_TYPE for architecture GDBARCH. */
491
492 static struct type *
493 tdesc_gdb_type (struct gdbarch *gdbarch, struct tdesc_type *tdesc_type)
494 {
495 switch (tdesc_type->kind)
496 {
497 /* Predefined types. */
498 case TDESC_TYPE_INT8:
499 return builtin_type (gdbarch)->builtin_int8;
500
501 case TDESC_TYPE_INT16:
502 return builtin_type (gdbarch)->builtin_int16;
503
504 case TDESC_TYPE_INT32:
505 return builtin_type (gdbarch)->builtin_int32;
506
507 case TDESC_TYPE_INT64:
508 return builtin_type (gdbarch)->builtin_int64;
509
510 case TDESC_TYPE_INT128:
511 return builtin_type (gdbarch)->builtin_int128;
512
513 case TDESC_TYPE_UINT8:
514 return builtin_type (gdbarch)->builtin_uint8;
515
516 case TDESC_TYPE_UINT16:
517 return builtin_type (gdbarch)->builtin_uint16;
518
519 case TDESC_TYPE_UINT32:
520 return builtin_type (gdbarch)->builtin_uint32;
521
522 case TDESC_TYPE_UINT64:
523 return builtin_type (gdbarch)->builtin_uint64;
524
525 case TDESC_TYPE_UINT128:
526 return builtin_type (gdbarch)->builtin_uint128;
527
528 case TDESC_TYPE_CODE_PTR:
529 return builtin_type (gdbarch)->builtin_func_ptr;
530
531 case TDESC_TYPE_DATA_PTR:
532 return builtin_type (gdbarch)->builtin_data_ptr;
533
534 case TDESC_TYPE_IEEE_SINGLE:
535 return arch_float_type (gdbarch, -1, "builtin_type_ieee_single",
536 floatformats_ieee_single);
537
538 case TDESC_TYPE_IEEE_DOUBLE:
539 return arch_float_type (gdbarch, -1, "builtin_type_ieee_double",
540 floatformats_ieee_double);
541
542 case TDESC_TYPE_ARM_FPA_EXT:
543 return arch_float_type (gdbarch, -1, "builtin_type_arm_ext",
544 floatformats_arm_ext);
545
546 /* Types defined by a target feature. */
547 case TDESC_TYPE_VECTOR:
548 {
549 struct type *type, *field_type;
550
551 field_type = tdesc_gdb_type (gdbarch, tdesc_type->u.v.type);
552 type = init_vector_type (field_type, tdesc_type->u.v.count);
553 TYPE_NAME (type) = xstrdup (tdesc_type->name);
554
555 return type;
556 }
557
558 case TDESC_TYPE_UNION:
559 {
560 struct type *type, *field_type;
561 struct tdesc_type_field *f;
562 int ix;
563
564 type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
565 TYPE_NAME (type) = xstrdup (tdesc_type->name);
566
567 for (ix = 0;
568 VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f);
569 ix++)
570 {
571 field_type = tdesc_gdb_type (gdbarch, f->type);
572 append_composite_type_field (type, xstrdup (f->name), field_type);
573
574 /* If any of the children of this union are vectors, flag the
575 union as a vector also. This allows e.g. a union of two
576 vector types to show up automatically in "info vector". */
577 if (TYPE_VECTOR (field_type))
578 TYPE_VECTOR (type) = 1;
579 }
580
581 return type;
582 }
583 }
584
585 internal_error (__FILE__, __LINE__,
586 "Type \"%s\" has an unknown kind %d",
587 tdesc_type->name, tdesc_type->kind);
588 }
589 \f
590
591 /* Support for registers from target descriptions. */
592
593 /* Construct the per-gdbarch data. */
594
595 static void *
596 tdesc_data_init (struct obstack *obstack)
597 {
598 struct tdesc_arch_data *data;
599
600 data = OBSTACK_ZALLOC (obstack, struct tdesc_arch_data);
601 return data;
602 }
603
604 /* Similar, but for the temporary copy used during architecture
605 initialization. */
606
607 struct tdesc_arch_data *
608 tdesc_data_alloc (void)
609 {
610 return XZALLOC (struct tdesc_arch_data);
611 }
612
613 /* Free something allocated by tdesc_data_alloc, if it is not going
614 to be used (for instance if it was unsuitable for the
615 architecture). */
616
617 void
618 tdesc_data_cleanup (void *data_untyped)
619 {
620 struct tdesc_arch_data *data = data_untyped;
621
622 VEC_free (tdesc_arch_reg, data->arch_regs);
623 xfree (data);
624 }
625
626 /* Search FEATURE for a register named NAME. */
627
628 static struct tdesc_reg *
629 tdesc_find_register_early (const struct tdesc_feature *feature,
630 const char *name)
631 {
632 int ixr;
633 struct tdesc_reg *reg;
634
635 for (ixr = 0;
636 VEC_iterate (tdesc_reg_p, feature->registers, ixr, reg);
637 ixr++)
638 if (strcasecmp (reg->name, name) == 0)
639 return reg;
640
641 return NULL;
642 }
643
644 /* Search FEATURE for a register named NAME. Assign REGNO to it. */
645
646 int
647 tdesc_numbered_register (const struct tdesc_feature *feature,
648 struct tdesc_arch_data *data,
649 int regno, const char *name)
650 {
651 struct tdesc_arch_reg arch_reg = { 0 };
652 struct tdesc_reg *reg = tdesc_find_register_early (feature, name);
653
654 if (reg == NULL)
655 return 0;
656
657 /* Make sure the vector includes a REGNO'th element. */
658 while (regno >= VEC_length (tdesc_arch_reg, data->arch_regs))
659 VEC_safe_push (tdesc_arch_reg, data->arch_regs, &arch_reg);
660
661 arch_reg.reg = reg;
662 VEC_replace (tdesc_arch_reg, data->arch_regs, regno, &arch_reg);
663 return 1;
664 }
665
666 /* Search FEATURE for a register named NAME, but do not assign a fixed
667 register number to it. */
668
669 int
670 tdesc_unnumbered_register (const struct tdesc_feature *feature,
671 const char *name)
672 {
673 struct tdesc_reg *reg = tdesc_find_register_early (feature, name);
674
675 if (reg == NULL)
676 return 0;
677
678 return 1;
679 }
680
681 /* Search FEATURE for a register whose name is in NAMES and assign
682 REGNO to it. */
683
684 int
685 tdesc_numbered_register_choices (const struct tdesc_feature *feature,
686 struct tdesc_arch_data *data,
687 int regno, const char *const names[])
688 {
689 int i;
690
691 for (i = 0; names[i] != NULL; i++)
692 if (tdesc_numbered_register (feature, data, regno, names[i]))
693 return 1;
694
695 return 0;
696 }
697
698 /* Search FEATURE for a register named NAME, and return its size in
699 bits. The register must exist. */
700
701 int
702 tdesc_register_size (const struct tdesc_feature *feature,
703 const char *name)
704 {
705 struct tdesc_reg *reg = tdesc_find_register_early (feature, name);
706
707 gdb_assert (reg != NULL);
708 return reg->bitsize;
709 }
710
711 /* Look up a register by its GDB internal register number. */
712
713 static struct tdesc_arch_reg *
714 tdesc_find_arch_register (struct gdbarch *gdbarch, int regno)
715 {
716 struct tdesc_arch_reg *reg;
717 struct tdesc_arch_data *data;
718
719 data = gdbarch_data (gdbarch, tdesc_data);
720 if (regno < VEC_length (tdesc_arch_reg, data->arch_regs))
721 return VEC_index (tdesc_arch_reg, data->arch_regs, regno);
722 else
723 return NULL;
724 }
725
726 static struct tdesc_reg *
727 tdesc_find_register (struct gdbarch *gdbarch, int regno)
728 {
729 struct tdesc_arch_reg *reg = tdesc_find_arch_register (gdbarch, regno);
730 return reg? reg->reg : NULL;
731 }
732
733 /* Return the name of register REGNO, from the target description or
734 from an architecture-provided pseudo_register_name method. */
735
736 const char *
737 tdesc_register_name (struct gdbarch *gdbarch, int regno)
738 {
739 struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno);
740 int num_regs = gdbarch_num_regs (gdbarch);
741 int num_pseudo_regs = gdbarch_num_pseudo_regs (gdbarch);
742
743 if (reg != NULL)
744 return reg->name;
745
746 if (regno >= num_regs && regno < num_regs + num_pseudo_regs)
747 {
748 struct tdesc_arch_data *data = gdbarch_data (gdbarch, tdesc_data);
749 gdb_assert (data->pseudo_register_name != NULL);
750 return data->pseudo_register_name (gdbarch, regno);
751 }
752
753 return "";
754 }
755
756 struct type *
757 tdesc_register_type (struct gdbarch *gdbarch, int regno)
758 {
759 struct tdesc_arch_reg *arch_reg = tdesc_find_arch_register (gdbarch, regno);
760 struct tdesc_reg *reg = arch_reg? arch_reg->reg : NULL;
761 int num_regs = gdbarch_num_regs (gdbarch);
762 int num_pseudo_regs = gdbarch_num_pseudo_regs (gdbarch);
763
764 if (reg == NULL && regno >= num_regs && regno < num_regs + num_pseudo_regs)
765 {
766 struct tdesc_arch_data *data = gdbarch_data (gdbarch, tdesc_data);
767 gdb_assert (data->pseudo_register_type != NULL);
768 return data->pseudo_register_type (gdbarch, regno);
769 }
770
771 if (reg == NULL)
772 /* Return "int0_t", since "void" has a misleading size of one. */
773 return builtin_type (gdbarch)->builtin_int0;
774
775 if (arch_reg->type == NULL)
776 {
777 /* First check for a predefined or target defined type. */
778 if (reg->tdesc_type)
779 arch_reg->type = tdesc_gdb_type (gdbarch, reg->tdesc_type);
780
781 /* Next try size-sensitive type shortcuts. */
782 else if (strcmp (reg->type, "float") == 0)
783 {
784 if (reg->bitsize == gdbarch_float_bit (gdbarch))
785 arch_reg->type = builtin_type (gdbarch)->builtin_float;
786 else if (reg->bitsize == gdbarch_double_bit (gdbarch))
787 arch_reg->type = builtin_type (gdbarch)->builtin_double;
788 else if (reg->bitsize == gdbarch_long_double_bit (gdbarch))
789 arch_reg->type = builtin_type (gdbarch)->builtin_long_double;
790 else
791 {
792 warning (_("Register \"%s\" has an unsupported size (%d bits)"),
793 reg->name, reg->bitsize);
794 arch_reg->type = builtin_type (gdbarch)->builtin_double;
795 }
796 }
797 else if (strcmp (reg->type, "int") == 0)
798 {
799 if (reg->bitsize == gdbarch_long_bit (gdbarch))
800 arch_reg->type = builtin_type (gdbarch)->builtin_long;
801 else if (reg->bitsize == TARGET_CHAR_BIT)
802 arch_reg->type = builtin_type (gdbarch)->builtin_char;
803 else if (reg->bitsize == gdbarch_short_bit (gdbarch))
804 arch_reg->type = builtin_type (gdbarch)->builtin_short;
805 else if (reg->bitsize == gdbarch_int_bit (gdbarch))
806 arch_reg->type = builtin_type (gdbarch)->builtin_int;
807 else if (reg->bitsize == gdbarch_long_long_bit (gdbarch))
808 arch_reg->type = builtin_type (gdbarch)->builtin_long_long;
809 else if (reg->bitsize == gdbarch_ptr_bit (gdbarch))
810 /* A bit desperate by this point... */
811 arch_reg->type = builtin_type (gdbarch)->builtin_data_ptr;
812 else
813 {
814 warning (_("Register \"%s\" has an unsupported size (%d bits)"),
815 reg->name, reg->bitsize);
816 arch_reg->type = builtin_type (gdbarch)->builtin_long;
817 }
818 }
819
820 if (arch_reg->type == NULL)
821 internal_error (__FILE__, __LINE__,
822 "Register \"%s\" has an unknown type \"%s\"",
823 reg->name, reg->type);
824 }
825
826 return arch_reg->type;
827 }
828
829 static int
830 tdesc_remote_register_number (struct gdbarch *gdbarch, int regno)
831 {
832 struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno);
833
834 if (reg != NULL)
835 return reg->target_regnum;
836 else
837 return -1;
838 }
839
840 /* Check whether REGNUM is a member of REGGROUP. Registers from the
841 target description may be classified as general, float, or vector.
842 Unlike a gdbarch register_reggroup_p method, this function will
843 return -1 if it does not know; the caller should handle registers
844 with no specified group.
845
846 Arbitrary strings (other than "general", "float", and "vector")
847 from the description are not used; they cause the register to be
848 displayed in "info all-registers" but excluded from "info
849 registers" et al. The names of containing features are also not
850 used. This might be extended to display registers in some more
851 useful groupings.
852
853 The save-restore flag is also implemented here. */
854
855 int
856 tdesc_register_in_reggroup_p (struct gdbarch *gdbarch, int regno,
857 struct reggroup *reggroup)
858 {
859 struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno);
860
861 if (reg != NULL && reg->group != NULL)
862 {
863 int general_p = 0, float_p = 0, vector_p = 0;
864
865 if (strcmp (reg->group, "general") == 0)
866 general_p = 1;
867 else if (strcmp (reg->group, "float") == 0)
868 float_p = 1;
869 else if (strcmp (reg->group, "vector") == 0)
870 vector_p = 1;
871
872 if (reggroup == float_reggroup)
873 return float_p;
874
875 if (reggroup == vector_reggroup)
876 return vector_p;
877
878 if (reggroup == general_reggroup)
879 return general_p;
880 }
881
882 if (reg != NULL
883 && (reggroup == save_reggroup || reggroup == restore_reggroup))
884 return reg->save_restore;
885
886 return -1;
887 }
888
889 /* Check whether REGNUM is a member of REGGROUP. Registers with no
890 group specified go to the default reggroup function and are handled
891 by type. */
892
893 static int
894 tdesc_register_reggroup_p (struct gdbarch *gdbarch, int regno,
895 struct reggroup *reggroup)
896 {
897 int num_regs = gdbarch_num_regs (gdbarch);
898 int num_pseudo_regs = gdbarch_num_pseudo_regs (gdbarch);
899 int ret;
900
901 if (regno >= num_regs && regno < num_regs + num_pseudo_regs)
902 {
903 struct tdesc_arch_data *data = gdbarch_data (gdbarch, tdesc_data);
904 if (data->pseudo_register_reggroup_p != NULL)
905 return data->pseudo_register_reggroup_p (gdbarch, regno, reggroup);
906 /* Otherwise fall through to the default reggroup_p. */
907 }
908
909 ret = tdesc_register_in_reggroup_p (gdbarch, regno, reggroup);
910 if (ret != -1)
911 return ret;
912
913 return default_register_reggroup_p (gdbarch, regno, reggroup);
914 }
915
916 /* Record architecture-specific functions to call for pseudo-register
917 support. */
918
919 void
920 set_tdesc_pseudo_register_name (struct gdbarch *gdbarch,
921 gdbarch_register_name_ftype *pseudo_name)
922 {
923 struct tdesc_arch_data *data = gdbarch_data (gdbarch, tdesc_data);
924
925 data->pseudo_register_name = pseudo_name;
926 }
927
928 void
929 set_tdesc_pseudo_register_type (struct gdbarch *gdbarch,
930 gdbarch_register_type_ftype *pseudo_type)
931 {
932 struct tdesc_arch_data *data = gdbarch_data (gdbarch, tdesc_data);
933
934 data->pseudo_register_type = pseudo_type;
935 }
936
937 void
938 set_tdesc_pseudo_register_reggroup_p
939 (struct gdbarch *gdbarch,
940 gdbarch_register_reggroup_p_ftype *pseudo_reggroup_p)
941 {
942 struct tdesc_arch_data *data = gdbarch_data (gdbarch, tdesc_data);
943
944 data->pseudo_register_reggroup_p = pseudo_reggroup_p;
945 }
946
947 /* Update GDBARCH to use the target description for registers. */
948
949 void
950 tdesc_use_registers (struct gdbarch *gdbarch,
951 const struct target_desc *target_desc,
952 struct tdesc_arch_data *early_data)
953 {
954 int num_regs = gdbarch_num_regs (gdbarch);
955 int i, ixf, ixr;
956 struct tdesc_feature *feature;
957 struct tdesc_reg *reg;
958 struct tdesc_arch_data *data;
959 struct tdesc_arch_reg *arch_reg, new_arch_reg = { 0 };
960 htab_t reg_hash;
961
962 /* We can't use the description for registers if it doesn't describe
963 any. This function should only be called after validating
964 registers, so the caller should know that registers are
965 included. */
966 gdb_assert (tdesc_has_registers (target_desc));
967
968 data = gdbarch_data (gdbarch, tdesc_data);
969 data->arch_regs = early_data->arch_regs;
970 xfree (early_data);
971
972 /* Build up a set of all registers, so that we can assign register
973 numbers where needed. The hash table expands as necessary, so
974 the initial size is arbitrary. */
975 reg_hash = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
976 for (ixf = 0;
977 VEC_iterate (tdesc_feature_p, target_desc->features, ixf, feature);
978 ixf++)
979 for (ixr = 0;
980 VEC_iterate (tdesc_reg_p, feature->registers, ixr, reg);
981 ixr++)
982 {
983 void **slot = htab_find_slot (reg_hash, reg, INSERT);
984
985 *slot = reg;
986 }
987
988 /* Remove any registers which were assigned numbers by the
989 architecture. */
990 for (ixr = 0;
991 VEC_iterate (tdesc_arch_reg, data->arch_regs, ixr, arch_reg);
992 ixr++)
993 if (arch_reg->reg)
994 htab_remove_elt (reg_hash, arch_reg->reg);
995
996 /* Assign numbers to the remaining registers and add them to the
997 list of registers. The new numbers are always above gdbarch_num_regs.
998 Iterate over the features, not the hash table, so that the order
999 matches that in the target description. */
1000
1001 gdb_assert (VEC_length (tdesc_arch_reg, data->arch_regs) <= num_regs);
1002 while (VEC_length (tdesc_arch_reg, data->arch_regs) < num_regs)
1003 VEC_safe_push (tdesc_arch_reg, data->arch_regs, &new_arch_reg);
1004 for (ixf = 0;
1005 VEC_iterate (tdesc_feature_p, target_desc->features, ixf, feature);
1006 ixf++)
1007 for (ixr = 0;
1008 VEC_iterate (tdesc_reg_p, feature->registers, ixr, reg);
1009 ixr++)
1010 if (htab_find (reg_hash, reg) != NULL)
1011 {
1012 new_arch_reg.reg = reg;
1013 VEC_safe_push (tdesc_arch_reg, data->arch_regs, &new_arch_reg);
1014 num_regs++;
1015 }
1016
1017 htab_delete (reg_hash);
1018
1019 /* Update the architecture. */
1020 set_gdbarch_num_regs (gdbarch, num_regs);
1021 set_gdbarch_register_name (gdbarch, tdesc_register_name);
1022 set_gdbarch_register_type (gdbarch, tdesc_register_type);
1023 set_gdbarch_remote_register_number (gdbarch,
1024 tdesc_remote_register_number);
1025 set_gdbarch_register_reggroup_p (gdbarch, tdesc_register_reggroup_p);
1026 }
1027 \f
1028
1029 /* Methods for constructing a target description. */
1030
1031 static void
1032 tdesc_free_reg (struct tdesc_reg *reg)
1033 {
1034 xfree (reg->name);
1035 xfree (reg->type);
1036 xfree (reg->group);
1037 xfree (reg);
1038 }
1039
1040 void
1041 tdesc_create_reg (struct tdesc_feature *feature, const char *name,
1042 int regnum, int save_restore, const char *group,
1043 int bitsize, const char *type)
1044 {
1045 struct tdesc_reg *reg = XZALLOC (struct tdesc_reg);
1046
1047 reg->name = xstrdup (name);
1048 reg->target_regnum = regnum;
1049 reg->save_restore = save_restore;
1050 reg->group = group ? xstrdup (group) : NULL;
1051 reg->bitsize = bitsize;
1052 reg->type = type ? xstrdup (type) : xstrdup ("<unknown>");
1053
1054 /* If the register's type is target-defined, look it up now. We may not
1055 have easy access to the containing feature when we want it later. */
1056 reg->tdesc_type = tdesc_named_type (feature, reg->type);
1057
1058 VEC_safe_push (tdesc_reg_p, feature->registers, reg);
1059 }
1060
1061 static void
1062 tdesc_free_type (struct tdesc_type *type)
1063 {
1064
1065 switch (type->kind)
1066 {
1067 case TDESC_TYPE_UNION:
1068 {
1069 struct tdesc_type_field *f;
1070 int ix;
1071
1072 for (ix = 0;
1073 VEC_iterate (tdesc_type_field, type->u.u.fields, ix, f);
1074 ix++)
1075 xfree (f->name);
1076
1077 VEC_free (tdesc_type_field, type->u.u.fields);
1078 }
1079 break;
1080
1081 default:
1082 break;
1083 }
1084
1085 xfree (type->name);
1086 xfree (type);
1087 }
1088
1089 struct tdesc_type *
1090 tdesc_create_vector (struct tdesc_feature *feature, const char *name,
1091 struct tdesc_type *field_type, int count)
1092 {
1093 struct tdesc_type *type = XZALLOC (struct tdesc_type);
1094
1095 type->name = xstrdup (name);
1096 type->kind = TDESC_TYPE_VECTOR;
1097 type->u.v.type = field_type;
1098 type->u.v.count = count;
1099
1100 VEC_safe_push (tdesc_type_p, feature->types, type);
1101 return type;
1102 }
1103
1104 struct tdesc_type *
1105 tdesc_create_union (struct tdesc_feature *feature, const char *name)
1106 {
1107 struct tdesc_type *type = XZALLOC (struct tdesc_type);
1108
1109 type->name = xstrdup (name);
1110 type->kind = TDESC_TYPE_UNION;
1111
1112 VEC_safe_push (tdesc_type_p, feature->types, type);
1113 return type;
1114 }
1115
1116 void
1117 tdesc_add_field (struct tdesc_type *type, const char *field_name,
1118 struct tdesc_type *field_type)
1119 {
1120 struct tdesc_type_field f = { 0 };
1121
1122 gdb_assert (type->kind == TDESC_TYPE_UNION);
1123
1124 f.name = xstrdup (field_name);
1125 f.type = field_type;
1126
1127 VEC_safe_push (tdesc_type_field, type->u.u.fields, &f);
1128 }
1129
1130 static void
1131 tdesc_free_feature (struct tdesc_feature *feature)
1132 {
1133 struct tdesc_reg *reg;
1134 struct tdesc_type *type;
1135 int ix;
1136
1137 for (ix = 0; VEC_iterate (tdesc_reg_p, feature->registers, ix, reg); ix++)
1138 tdesc_free_reg (reg);
1139 VEC_free (tdesc_reg_p, feature->registers);
1140
1141 for (ix = 0; VEC_iterate (tdesc_type_p, feature->types, ix, type); ix++)
1142 tdesc_free_type (type);
1143 VEC_free (tdesc_type_p, feature->types);
1144
1145 xfree (feature->name);
1146 xfree (feature);
1147 }
1148
1149 struct tdesc_feature *
1150 tdesc_create_feature (struct target_desc *tdesc, const char *name)
1151 {
1152 struct tdesc_feature *new_feature = XZALLOC (struct tdesc_feature);
1153
1154 new_feature->name = xstrdup (name);
1155
1156 VEC_safe_push (tdesc_feature_p, tdesc->features, new_feature);
1157 return new_feature;
1158 }
1159
1160 struct target_desc *
1161 allocate_target_description (void)
1162 {
1163 return XZALLOC (struct target_desc);
1164 }
1165
1166 static void
1167 free_target_description (void *arg)
1168 {
1169 struct target_desc *target_desc = arg;
1170 struct tdesc_feature *feature;
1171 struct property *prop;
1172 int ix;
1173
1174 for (ix = 0;
1175 VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature);
1176 ix++)
1177 tdesc_free_feature (feature);
1178 VEC_free (tdesc_feature_p, target_desc->features);
1179
1180 for (ix = 0;
1181 VEC_iterate (property_s, target_desc->properties, ix, prop);
1182 ix++)
1183 {
1184 xfree (prop->key);
1185 xfree (prop->value);
1186 }
1187 VEC_free (property_s, target_desc->properties);
1188
1189 VEC_free (arch_p, target_desc->compatible);
1190
1191 xfree (target_desc);
1192 }
1193
1194 struct cleanup *
1195 make_cleanup_free_target_description (struct target_desc *target_desc)
1196 {
1197 return make_cleanup (free_target_description, target_desc);
1198 }
1199
1200 void
1201 tdesc_add_compatible (struct target_desc *target_desc,
1202 const struct bfd_arch_info *compatible)
1203 {
1204 const struct bfd_arch_info *compat;
1205 int ix;
1206
1207 /* If this instance of GDB is compiled without BFD support for the
1208 compatible architecture, simply ignore it -- we would not be able
1209 to handle it anyway. */
1210 if (compatible == NULL)
1211 return;
1212
1213 for (ix = 0; VEC_iterate (arch_p, target_desc->compatible, ix, compat);
1214 ix++)
1215 if (compat == compatible)
1216 internal_error (__FILE__, __LINE__,
1217 _("Attempted to add duplicate "
1218 "compatible architecture \"%s\""),
1219 compatible->printable_name);
1220
1221 VEC_safe_push (arch_p, target_desc->compatible, compatible);
1222 }
1223
1224 void
1225 set_tdesc_property (struct target_desc *target_desc,
1226 const char *key, const char *value)
1227 {
1228 struct property *prop, new_prop;
1229 int ix;
1230
1231 gdb_assert (key != NULL && value != NULL);
1232
1233 for (ix = 0; VEC_iterate (property_s, target_desc->properties, ix, prop);
1234 ix++)
1235 if (strcmp (prop->key, key) == 0)
1236 internal_error (__FILE__, __LINE__,
1237 _("Attempted to add duplicate property \"%s\""), key);
1238
1239 new_prop.key = xstrdup (key);
1240 new_prop.value = xstrdup (value);
1241 VEC_safe_push (property_s, target_desc->properties, &new_prop);
1242 }
1243
1244 void
1245 set_tdesc_architecture (struct target_desc *target_desc,
1246 const struct bfd_arch_info *arch)
1247 {
1248 target_desc->arch = arch;
1249 }
1250
1251 void
1252 set_tdesc_osabi (struct target_desc *target_desc, enum gdb_osabi osabi)
1253 {
1254 target_desc->osabi = osabi;
1255 }
1256 \f
1257
1258 static struct cmd_list_element *tdesc_set_cmdlist, *tdesc_show_cmdlist;
1259 static struct cmd_list_element *tdesc_unset_cmdlist;
1260
1261 /* Helper functions for the CLI commands. */
1262
1263 static void
1264 set_tdesc_cmd (char *args, int from_tty)
1265 {
1266 help_list (tdesc_set_cmdlist, "set tdesc ", -1, gdb_stdout);
1267 }
1268
1269 static void
1270 show_tdesc_cmd (char *args, int from_tty)
1271 {
1272 cmd_show_list (tdesc_show_cmdlist, from_tty, "");
1273 }
1274
1275 static void
1276 unset_tdesc_cmd (char *args, int from_tty)
1277 {
1278 help_list (tdesc_unset_cmdlist, "unset tdesc ", -1, gdb_stdout);
1279 }
1280
1281 static void
1282 set_tdesc_filename_cmd (char *args, int from_tty,
1283 struct cmd_list_element *c)
1284 {
1285 target_clear_description ();
1286 target_find_description ();
1287 }
1288
1289 static void
1290 show_tdesc_filename_cmd (struct ui_file *file, int from_tty,
1291 struct cmd_list_element *c,
1292 const char *value)
1293 {
1294 if (value != NULL && *value != '\0')
1295 printf_filtered (_("\
1296 The target description will be read from \"%s\".\n"),
1297 value);
1298 else
1299 printf_filtered (_("\
1300 The target description will be read from the target.\n"));
1301 }
1302
1303 static void
1304 unset_tdesc_filename_cmd (char *args, int from_tty)
1305 {
1306 xfree (target_description_filename);
1307 target_description_filename = NULL;
1308 target_clear_description ();
1309 target_find_description ();
1310 }
1311
1312 static void
1313 maint_print_c_tdesc_cmd (char *args, int from_tty)
1314 {
1315 const struct target_desc *tdesc;
1316 const struct bfd_arch_info *compatible;
1317 const char *filename, *inp;
1318 char *function, *outp;
1319 struct property *prop;
1320 struct tdesc_feature *feature;
1321 struct tdesc_reg *reg;
1322 struct tdesc_type *type;
1323 struct tdesc_type_field *f;
1324 int ix, ix2, ix3;
1325
1326 /* Use the global target-supplied description, not the current
1327 architecture's. This lets a GDB for one architecture generate C
1328 for another architecture's description, even though the gdbarch
1329 initialization code will reject the new description. */
1330 tdesc = current_target_desc;
1331 if (tdesc == NULL)
1332 error (_("There is no target description to print."));
1333
1334 if (target_description_filename == NULL)
1335 error (_("The current target description did not come from an XML file."));
1336
1337 filename = lbasename (target_description_filename);
1338 function = alloca (strlen (filename) + 1);
1339 for (inp = filename, outp = function; *inp != '\0'; inp++)
1340 if (*inp == '.')
1341 break;
1342 else if (*inp == '-')
1343 *outp++ = '_';
1344 else
1345 *outp++ = *inp;
1346 *outp = '\0';
1347
1348 /* Standard boilerplate. */
1349 printf_unfiltered ("/* THIS FILE IS GENERATED. Original: %s */\n\n",
1350 filename);
1351 printf_unfiltered ("#include \"defs.h\"\n");
1352 printf_unfiltered ("#include \"osabi.h\"\n");
1353 printf_unfiltered ("#include \"target-descriptions.h\"\n");
1354 printf_unfiltered ("\n");
1355
1356 printf_unfiltered ("struct target_desc *tdesc_%s;\n", function);
1357 printf_unfiltered ("static void\n");
1358 printf_unfiltered ("initialize_tdesc_%s (void)\n", function);
1359 printf_unfiltered ("{\n");
1360 printf_unfiltered
1361 (" struct target_desc *result = allocate_target_description ();\n");
1362 printf_unfiltered (" struct tdesc_feature *feature;\n");
1363 printf_unfiltered (" struct tdesc_type *field_type, *type;\n");
1364 printf_unfiltered ("\n");
1365
1366 if (tdesc_architecture (tdesc) != NULL)
1367 {
1368 printf_unfiltered
1369 (" set_tdesc_architecture (result, bfd_scan_arch (\"%s\"));\n",
1370 tdesc_architecture (tdesc)->printable_name);
1371 printf_unfiltered ("\n");
1372 }
1373
1374 if (tdesc_osabi (tdesc) > GDB_OSABI_UNKNOWN
1375 && tdesc_osabi (tdesc) < GDB_OSABI_INVALID)
1376 {
1377 printf_unfiltered
1378 (" set_tdesc_osabi (result, osabi_from_tdesc_string (\"%s\"));\n",
1379 gdbarch_osabi_name (tdesc_osabi (tdesc)));
1380 printf_unfiltered ("\n");
1381 }
1382
1383 for (ix = 0; VEC_iterate (arch_p, tdesc->compatible, ix, compatible);
1384 ix++)
1385 {
1386 printf_unfiltered
1387 (" tdesc_add_compatible (result, bfd_scan_arch (\"%s\"));\n",
1388 compatible->printable_name);
1389 }
1390 if (ix)
1391 printf_unfiltered ("\n");
1392
1393 for (ix = 0; VEC_iterate (property_s, tdesc->properties, ix, prop);
1394 ix++)
1395 {
1396 printf_unfiltered (" set_tdesc_property (result, \"%s\", \"%s\");\n",
1397 prop->key, prop->value);
1398 }
1399
1400 for (ix = 0;
1401 VEC_iterate (tdesc_feature_p, tdesc->features, ix, feature);
1402 ix++)
1403 {
1404 printf_unfiltered (" feature = tdesc_create_feature (result, \"%s\");\n",
1405 feature->name);
1406
1407 for (ix2 = 0;
1408 VEC_iterate (tdesc_type_p, feature->types, ix2, type);
1409 ix2++)
1410 {
1411 switch (type->kind)
1412 {
1413 case TDESC_TYPE_VECTOR:
1414 printf_unfiltered
1415 (" field_type = tdesc_named_type (feature, \"%s\");\n",
1416 type->u.v.type->name);
1417 printf_unfiltered
1418 (" tdesc_create_vector (feature, \"%s\", field_type, %d);\n",
1419 type->name, type->u.v.count);
1420 break;
1421 case TDESC_TYPE_UNION:
1422 printf_unfiltered
1423 (" type = tdesc_create_union (feature, \"%s\");\n",
1424 type->name);
1425 for (ix3 = 0;
1426 VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f);
1427 ix3++)
1428 {
1429 printf_unfiltered
1430 (" field_type = tdesc_named_type (feature, \"%s\");\n",
1431 f->type->name);
1432 printf_unfiltered
1433 (" tdesc_add_field (type, \"%s\", field_type);\n",
1434 f->name);
1435 }
1436 break;
1437 default:
1438 error (_("C output is not supported type \"%s\"."), type->name);
1439 }
1440 printf_unfiltered ("\n");
1441 }
1442
1443 for (ix2 = 0;
1444 VEC_iterate (tdesc_reg_p, feature->registers, ix2, reg);
1445 ix2++)
1446 {
1447 printf_unfiltered (" tdesc_create_reg (feature, \"%s\", %ld, %d, ",
1448 reg->name, reg->target_regnum, reg->save_restore);
1449 if (reg->group)
1450 printf_unfiltered ("\"%s\", ", reg->group);
1451 else
1452 printf_unfiltered ("NULL, ");
1453 printf_unfiltered ("%d, \"%s\");\n", reg->bitsize, reg->type);
1454 }
1455
1456 printf_unfiltered ("\n");
1457 }
1458
1459 printf_unfiltered (" tdesc_%s = result;\n", function);
1460 printf_unfiltered ("}\n");
1461 }
1462
1463 /* Provide a prototype to silence -Wmissing-prototypes. */
1464 extern initialize_file_ftype _initialize_target_descriptions;
1465
1466 void
1467 _initialize_target_descriptions (void)
1468 {
1469 tdesc_data = gdbarch_data_register_pre_init (tdesc_data_init);
1470
1471 add_prefix_cmd ("tdesc", class_maintenance, set_tdesc_cmd, _("\
1472 Set target description specific variables."),
1473 &tdesc_set_cmdlist, "set tdesc ",
1474 0 /* allow-unknown */, &setlist);
1475 add_prefix_cmd ("tdesc", class_maintenance, show_tdesc_cmd, _("\
1476 Show target description specific variables."),
1477 &tdesc_show_cmdlist, "show tdesc ",
1478 0 /* allow-unknown */, &showlist);
1479 add_prefix_cmd ("tdesc", class_maintenance, unset_tdesc_cmd, _("\
1480 Unset target description specific variables."),
1481 &tdesc_unset_cmdlist, "unset tdesc ",
1482 0 /* allow-unknown */, &unsetlist);
1483
1484 add_setshow_filename_cmd ("filename", class_obscure,
1485 &target_description_filename,
1486 _("\
1487 Set the file to read for an XML target description"), _("\
1488 Show the file to read for an XML target description"), _("\
1489 When set, GDB will read the target description from a local\n\
1490 file instead of querying the remote target."),
1491 set_tdesc_filename_cmd,
1492 show_tdesc_filename_cmd,
1493 &tdesc_set_cmdlist, &tdesc_show_cmdlist);
1494
1495 add_cmd ("filename", class_obscure, unset_tdesc_filename_cmd, _("\
1496 Unset the file to read for an XML target description. When unset,\n\
1497 GDB will read the description from the target."),
1498 &tdesc_unset_cmdlist);
1499
1500 add_cmd ("c-tdesc", class_maintenance, maint_print_c_tdesc_cmd, _("\
1501 Print the current target description as a C source file."),
1502 &maintenanceprintlist);
1503 }
This page took 0.085703 seconds and 5 git commands to generate.