target-descriptions.c revision 1.6 1 1.1 christos /* Target description support for GDB.
2 1.1 christos
3 1.6 christos Copyright (C) 2006-2016 Free Software Foundation, Inc.
4 1.1 christos
5 1.1 christos Contributed by CodeSourcery.
6 1.1 christos
7 1.1 christos This file is part of GDB.
8 1.1 christos
9 1.1 christos This program is free software; you can redistribute it and/or modify
10 1.1 christos it under the terms of the GNU General Public License as published by
11 1.1 christos the Free Software Foundation; either version 3 of the License, or
12 1.1 christos (at your option) any later version.
13 1.1 christos
14 1.1 christos This program is distributed in the hope that it will be useful,
15 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
16 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 1.1 christos GNU General Public License for more details.
18 1.1 christos
19 1.1 christos You should have received a copy of the GNU General Public License
20 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 1.1 christos
22 1.1 christos #include "defs.h"
23 1.1 christos #include "arch-utils.h"
24 1.1 christos #include "gdbcmd.h"
25 1.1 christos #include "gdbtypes.h"
26 1.1 christos #include "reggroups.h"
27 1.1 christos #include "target.h"
28 1.1 christos #include "target-descriptions.h"
29 1.1 christos #include "vec.h"
30 1.1 christos #include "xml-support.h"
31 1.1 christos #include "xml-tdesc.h"
32 1.1 christos #include "osabi.h"
33 1.1 christos
34 1.1 christos #include "gdb_obstack.h"
35 1.1 christos #include "hashtab.h"
36 1.1 christos #include "inferior.h"
37 1.1 christos
38 1.1 christos /* Types. */
39 1.1 christos
40 1.1 christos typedef struct property
41 1.1 christos {
42 1.1 christos char *key;
43 1.1 christos char *value;
44 1.1 christos } property_s;
45 1.1 christos DEF_VEC_O(property_s);
46 1.1 christos
47 1.1 christos /* An individual register from a target description. */
48 1.1 christos
49 1.1 christos typedef struct tdesc_reg
50 1.1 christos {
51 1.1 christos /* The name of this register. In standard features, it may be
52 1.1 christos recognized by the architecture support code, or it may be purely
53 1.1 christos for the user. */
54 1.1 christos char *name;
55 1.1 christos
56 1.1 christos /* The register number used by this target to refer to this
57 1.1 christos register. This is used for remote p/P packets and to determine
58 1.1 christos the ordering of registers in the remote g/G packets. */
59 1.1 christos long target_regnum;
60 1.1 christos
61 1.1 christos /* If this flag is set, GDB should save and restore this register
62 1.1 christos around calls to an inferior function. */
63 1.1 christos int save_restore;
64 1.1 christos
65 1.1 christos /* The name of the register group containing this register, or NULL
66 1.1 christos if the group should be automatically determined from the
67 1.1 christos register's type. If this is "general", "float", or "vector", the
68 1.1 christos corresponding "info" command should display this register's
69 1.1 christos value. It can be an arbitrary string, but should be limited to
70 1.1 christos alphanumeric characters and internal hyphens. Currently other
71 1.1 christos strings are ignored (treated as NULL). */
72 1.1 christos char *group;
73 1.1 christos
74 1.1 christos /* The size of the register, in bits. */
75 1.1 christos int bitsize;
76 1.1 christos
77 1.1 christos /* The type of the register. This string corresponds to either
78 1.1 christos a named type from the target description or a predefined
79 1.1 christos type from GDB. */
80 1.1 christos char *type;
81 1.1 christos
82 1.1 christos /* The target-described type corresponding to TYPE, if found. */
83 1.1 christos struct tdesc_type *tdesc_type;
84 1.1 christos } *tdesc_reg_p;
85 1.1 christos DEF_VEC_P(tdesc_reg_p);
86 1.1 christos
87 1.1 christos /* A named type from a target description. */
88 1.1 christos
89 1.1 christos typedef struct tdesc_type_field
90 1.1 christos {
91 1.1 christos char *name;
92 1.1 christos struct tdesc_type *type;
93 1.6 christos /* For non-enum-values, either both are -1 (non-bitfield), or both are
94 1.6 christos not -1 (bitfield). For enum values, start is the value (which could be
95 1.6 christos -1), end is -1. */
96 1.1 christos int start, end;
97 1.1 christos } tdesc_type_field;
98 1.1 christos DEF_VEC_O(tdesc_type_field);
99 1.1 christos
100 1.5 christos enum tdesc_type_kind
101 1.5 christos {
102 1.5 christos /* Predefined types. */
103 1.6 christos TDESC_TYPE_BOOL,
104 1.5 christos TDESC_TYPE_INT8,
105 1.5 christos TDESC_TYPE_INT16,
106 1.5 christos TDESC_TYPE_INT32,
107 1.5 christos TDESC_TYPE_INT64,
108 1.5 christos TDESC_TYPE_INT128,
109 1.5 christos TDESC_TYPE_UINT8,
110 1.5 christos TDESC_TYPE_UINT16,
111 1.5 christos TDESC_TYPE_UINT32,
112 1.5 christos TDESC_TYPE_UINT64,
113 1.5 christos TDESC_TYPE_UINT128,
114 1.5 christos TDESC_TYPE_CODE_PTR,
115 1.5 christos TDESC_TYPE_DATA_PTR,
116 1.5 christos TDESC_TYPE_IEEE_SINGLE,
117 1.5 christos TDESC_TYPE_IEEE_DOUBLE,
118 1.5 christos TDESC_TYPE_ARM_FPA_EXT,
119 1.5 christos TDESC_TYPE_I387_EXT,
120 1.5 christos
121 1.5 christos /* Types defined by a target feature. */
122 1.5 christos TDESC_TYPE_VECTOR,
123 1.5 christos TDESC_TYPE_STRUCT,
124 1.5 christos TDESC_TYPE_UNION,
125 1.6 christos TDESC_TYPE_FLAGS,
126 1.6 christos TDESC_TYPE_ENUM
127 1.5 christos };
128 1.5 christos
129 1.1 christos typedef struct tdesc_type
130 1.1 christos {
131 1.1 christos /* The name of this type. */
132 1.1 christos char *name;
133 1.1 christos
134 1.1 christos /* Identify the kind of this type. */
135 1.5 christos enum tdesc_type_kind kind;
136 1.1 christos
137 1.1 christos /* Kind-specific data. */
138 1.1 christos union
139 1.1 christos {
140 1.1 christos /* Vector type. */
141 1.1 christos struct
142 1.1 christos {
143 1.1 christos struct tdesc_type *type;
144 1.1 christos int count;
145 1.1 christos } v;
146 1.1 christos
147 1.6 christos /* Struct, union, flags, or enum type. */
148 1.1 christos struct
149 1.1 christos {
150 1.1 christos VEC(tdesc_type_field) *fields;
151 1.6 christos int size;
152 1.1 christos } u;
153 1.1 christos } u;
154 1.1 christos } *tdesc_type_p;
155 1.1 christos DEF_VEC_P(tdesc_type_p);
156 1.1 christos
157 1.1 christos /* A feature from a target description. Each feature is a collection
158 1.1 christos of other elements, e.g. registers and types. */
159 1.1 christos
160 1.1 christos typedef struct tdesc_feature
161 1.1 christos {
162 1.1 christos /* The name of this feature. It may be recognized by the architecture
163 1.1 christos support code. */
164 1.1 christos char *name;
165 1.1 christos
166 1.1 christos /* The registers associated with this feature. */
167 1.1 christos VEC(tdesc_reg_p) *registers;
168 1.1 christos
169 1.1 christos /* The types associated with this feature. */
170 1.1 christos VEC(tdesc_type_p) *types;
171 1.1 christos } *tdesc_feature_p;
172 1.1 christos DEF_VEC_P(tdesc_feature_p);
173 1.1 christos
174 1.1 christos /* A compatible architecture from a target description. */
175 1.1 christos typedef const struct bfd_arch_info *arch_p;
176 1.1 christos DEF_VEC_P(arch_p);
177 1.1 christos
178 1.1 christos /* A target description. */
179 1.1 christos
180 1.1 christos struct target_desc
181 1.1 christos {
182 1.1 christos /* The architecture reported by the target, if any. */
183 1.1 christos const struct bfd_arch_info *arch;
184 1.1 christos
185 1.1 christos /* The osabi reported by the target, if any; GDB_OSABI_UNKNOWN
186 1.1 christos otherwise. */
187 1.1 christos enum gdb_osabi osabi;
188 1.1 christos
189 1.1 christos /* The list of compatible architectures reported by the target. */
190 1.1 christos VEC(arch_p) *compatible;
191 1.1 christos
192 1.1 christos /* Any architecture-specific properties specified by the target. */
193 1.1 christos VEC(property_s) *properties;
194 1.1 christos
195 1.1 christos /* The features associated with this target. */
196 1.1 christos VEC(tdesc_feature_p) *features;
197 1.1 christos };
198 1.1 christos
199 1.1 christos /* Per-architecture data associated with a target description. The
200 1.1 christos target description may be shared by multiple architectures, but
201 1.1 christos this data is private to one gdbarch. */
202 1.1 christos
203 1.1 christos typedef struct tdesc_arch_reg
204 1.1 christos {
205 1.1 christos struct tdesc_reg *reg;
206 1.1 christos struct type *type;
207 1.1 christos } tdesc_arch_reg;
208 1.1 christos DEF_VEC_O(tdesc_arch_reg);
209 1.1 christos
210 1.1 christos struct tdesc_arch_data
211 1.1 christos {
212 1.1 christos /* A list of register/type pairs, indexed by GDB's internal register number.
213 1.1 christos During initialization of the gdbarch this list is used to store
214 1.1 christos registers which the architecture assigns a fixed register number.
215 1.1 christos Registers which are NULL in this array, or off the end, are
216 1.1 christos treated as zero-sized and nameless (i.e. placeholders in the
217 1.1 christos numbering). */
218 1.1 christos VEC(tdesc_arch_reg) *arch_regs;
219 1.1 christos
220 1.1 christos /* Functions which report the register name, type, and reggroups for
221 1.1 christos pseudo-registers. */
222 1.1 christos gdbarch_register_name_ftype *pseudo_register_name;
223 1.1 christos gdbarch_register_type_ftype *pseudo_register_type;
224 1.1 christos gdbarch_register_reggroup_p_ftype *pseudo_register_reggroup_p;
225 1.1 christos };
226 1.1 christos
227 1.1 christos /* Info about an inferior's target description. There's one of these
228 1.1 christos for each inferior. */
229 1.1 christos
230 1.1 christos struct target_desc_info
231 1.1 christos {
232 1.1 christos /* A flag indicating that a description has already been fetched
233 1.1 christos from the target, so it should not be queried again. */
234 1.1 christos
235 1.1 christos int fetched;
236 1.1 christos
237 1.1 christos /* The description fetched from the target, or NULL if the target
238 1.1 christos did not supply any description. Only valid when
239 1.1 christos target_desc_fetched is set. Only the description initialization
240 1.1 christos code should access this; normally, the description should be
241 1.1 christos accessed through the gdbarch object. */
242 1.1 christos
243 1.1 christos const struct target_desc *tdesc;
244 1.1 christos
245 1.1 christos /* The filename to read a target description from, as set by "set
246 1.1 christos tdesc filename ..." */
247 1.1 christos
248 1.1 christos char *filename;
249 1.1 christos };
250 1.1 christos
251 1.1 christos /* Get the inferior INF's target description info, allocating one on
252 1.1 christos the stop if necessary. */
253 1.1 christos
254 1.1 christos static struct target_desc_info *
255 1.1 christos get_tdesc_info (struct inferior *inf)
256 1.1 christos {
257 1.1 christos if (inf->tdesc_info == NULL)
258 1.1 christos inf->tdesc_info = XCNEW (struct target_desc_info);
259 1.1 christos return inf->tdesc_info;
260 1.1 christos }
261 1.1 christos
262 1.1 christos /* A handle for architecture-specific data associated with the
263 1.1 christos target description (see struct tdesc_arch_data). */
264 1.1 christos
265 1.1 christos static struct gdbarch_data *tdesc_data;
266 1.1 christos
267 1.1 christos /* See target-descriptions.h. */
268 1.1 christos
269 1.1 christos int
270 1.1 christos target_desc_info_from_user_p (struct target_desc_info *info)
271 1.1 christos {
272 1.1 christos return info != NULL && info->filename != NULL;
273 1.1 christos }
274 1.1 christos
275 1.1 christos /* See target-descriptions.h. */
276 1.1 christos
277 1.1 christos void
278 1.1 christos copy_inferior_target_desc_info (struct inferior *destinf, struct inferior *srcinf)
279 1.1 christos {
280 1.1 christos struct target_desc_info *src = get_tdesc_info (srcinf);
281 1.1 christos struct target_desc_info *dest = get_tdesc_info (destinf);
282 1.1 christos
283 1.1 christos dest->fetched = src->fetched;
284 1.1 christos dest->tdesc = src->tdesc;
285 1.1 christos dest->filename = src->filename != NULL ? xstrdup (src->filename) : NULL;
286 1.1 christos }
287 1.1 christos
288 1.1 christos /* See target-descriptions.h. */
289 1.1 christos
290 1.1 christos void
291 1.1 christos target_desc_info_free (struct target_desc_info *tdesc_info)
292 1.1 christos {
293 1.1 christos if (tdesc_info != NULL)
294 1.1 christos {
295 1.1 christos xfree (tdesc_info->filename);
296 1.1 christos xfree (tdesc_info);
297 1.1 christos }
298 1.1 christos }
299 1.1 christos
300 1.1 christos /* Convenience helper macros. */
301 1.1 christos
302 1.1 christos #define target_desc_fetched \
303 1.1 christos get_tdesc_info (current_inferior ())->fetched
304 1.1 christos #define current_target_desc \
305 1.1 christos get_tdesc_info (current_inferior ())->tdesc
306 1.1 christos #define target_description_filename \
307 1.1 christos get_tdesc_info (current_inferior ())->filename
308 1.1 christos
309 1.1 christos /* The string manipulated by the "set tdesc filename ..." command. */
310 1.1 christos
311 1.1 christos static char *tdesc_filename_cmd_string;
312 1.1 christos
313 1.1 christos /* Fetch the current target's description, and switch the current
314 1.1 christos architecture to one which incorporates that description. */
315 1.1 christos
316 1.1 christos void
317 1.1 christos target_find_description (void)
318 1.1 christos {
319 1.1 christos /* If we've already fetched a description from the target, don't do
320 1.1 christos it again. This allows a target to fetch the description early,
321 1.1 christos during its to_open or to_create_inferior, if it needs extra
322 1.1 christos information about the target to initialize. */
323 1.1 christos if (target_desc_fetched)
324 1.1 christos return;
325 1.1 christos
326 1.1 christos /* The current architecture should not have any target description
327 1.1 christos specified. It should have been cleared, e.g. when we
328 1.1 christos disconnected from the previous target. */
329 1.1 christos gdb_assert (gdbarch_target_desc (target_gdbarch ()) == NULL);
330 1.1 christos
331 1.1 christos /* First try to fetch an XML description from the user-specified
332 1.1 christos file. */
333 1.1 christos current_target_desc = NULL;
334 1.1 christos if (target_description_filename != NULL
335 1.1 christos && *target_description_filename != '\0')
336 1.1 christos current_target_desc
337 1.1 christos = file_read_description_xml (target_description_filename);
338 1.1 christos
339 1.1 christos /* Next try to read the description from the current target using
340 1.1 christos target objects. */
341 1.1 christos if (current_target_desc == NULL)
342 1.1 christos current_target_desc = target_read_description_xml (¤t_target);
343 1.1 christos
344 1.1 christos /* If that failed try a target-specific hook. */
345 1.1 christos if (current_target_desc == NULL)
346 1.1 christos current_target_desc = target_read_description (¤t_target);
347 1.1 christos
348 1.1 christos /* If a non-NULL description was returned, then update the current
349 1.1 christos architecture. */
350 1.1 christos if (current_target_desc)
351 1.1 christos {
352 1.1 christos struct gdbarch_info info;
353 1.1 christos
354 1.1 christos gdbarch_info_init (&info);
355 1.1 christos info.target_desc = current_target_desc;
356 1.1 christos if (!gdbarch_update_p (info))
357 1.1 christos warning (_("Architecture rejected target-supplied description"));
358 1.1 christos else
359 1.1 christos {
360 1.1 christos struct tdesc_arch_data *data;
361 1.1 christos
362 1.6 christos data = ((struct tdesc_arch_data *)
363 1.6 christos gdbarch_data (target_gdbarch (), tdesc_data));
364 1.1 christos if (tdesc_has_registers (current_target_desc)
365 1.1 christos && data->arch_regs == NULL)
366 1.1 christos warning (_("Target-supplied registers are not supported "
367 1.1 christos "by the current architecture"));
368 1.1 christos }
369 1.1 christos }
370 1.1 christos
371 1.1 christos /* Now that we know this description is usable, record that we
372 1.1 christos fetched it. */
373 1.1 christos target_desc_fetched = 1;
374 1.1 christos }
375 1.1 christos
376 1.1 christos /* Discard any description fetched from the current target, and switch
377 1.1 christos the current architecture to one with no target description. */
378 1.1 christos
379 1.1 christos void
380 1.1 christos target_clear_description (void)
381 1.1 christos {
382 1.1 christos struct gdbarch_info info;
383 1.1 christos
384 1.1 christos if (!target_desc_fetched)
385 1.1 christos return;
386 1.1 christos
387 1.1 christos target_desc_fetched = 0;
388 1.1 christos current_target_desc = NULL;
389 1.1 christos
390 1.1 christos gdbarch_info_init (&info);
391 1.1 christos if (!gdbarch_update_p (info))
392 1.1 christos internal_error (__FILE__, __LINE__,
393 1.1 christos _("Could not remove target-supplied description"));
394 1.1 christos }
395 1.1 christos
396 1.1 christos /* Return the global current target description. This should only be
397 1.1 christos used by gdbarch initialization code; most access should be through
398 1.1 christos an existing gdbarch. */
399 1.1 christos
400 1.1 christos const struct target_desc *
401 1.1 christos target_current_description (void)
402 1.1 christos {
403 1.1 christos if (target_desc_fetched)
404 1.1 christos return current_target_desc;
405 1.1 christos
406 1.1 christos return NULL;
407 1.1 christos }
408 1.1 christos
409 1.1 christos /* Return non-zero if this target description is compatible
410 1.1 christos with the given BFD architecture. */
411 1.1 christos
412 1.1 christos int
413 1.1 christos tdesc_compatible_p (const struct target_desc *target_desc,
414 1.1 christos const struct bfd_arch_info *arch)
415 1.1 christos {
416 1.1 christos const struct bfd_arch_info *compat;
417 1.1 christos int ix;
418 1.1 christos
419 1.1 christos for (ix = 0; VEC_iterate (arch_p, target_desc->compatible, ix, compat);
420 1.1 christos ix++)
421 1.1 christos {
422 1.1 christos if (compat == arch
423 1.1 christos || arch->compatible (arch, compat)
424 1.1 christos || compat->compatible (compat, arch))
425 1.1 christos return 1;
426 1.1 christos }
427 1.1 christos
428 1.1 christos return 0;
429 1.1 christos }
430 1.1 christos
431 1.1 christos
433 1.1 christos /* Direct accessors for target descriptions. */
434 1.1 christos
435 1.1 christos /* Return the string value of a property named KEY, or NULL if the
436 1.1 christos property was not specified. */
437 1.1 christos
438 1.1 christos const char *
439 1.1 christos tdesc_property (const struct target_desc *target_desc, const char *key)
440 1.1 christos {
441 1.1 christos struct property *prop;
442 1.1 christos int ix;
443 1.1 christos
444 1.1 christos for (ix = 0; VEC_iterate (property_s, target_desc->properties, ix, prop);
445 1.1 christos ix++)
446 1.1 christos if (strcmp (prop->key, key) == 0)
447 1.1 christos return prop->value;
448 1.1 christos
449 1.1 christos return NULL;
450 1.1 christos }
451 1.1 christos
452 1.1 christos /* Return the BFD architecture associated with this target
453 1.1 christos description, or NULL if no architecture was specified. */
454 1.1 christos
455 1.1 christos const struct bfd_arch_info *
456 1.1 christos tdesc_architecture (const struct target_desc *target_desc)
457 1.1 christos {
458 1.1 christos return target_desc->arch;
459 1.1 christos }
460 1.1 christos
461 1.1 christos /* Return the OSABI associated with this target description, or
462 1.1 christos GDB_OSABI_UNKNOWN if no osabi was specified. */
463 1.1 christos
464 1.1 christos enum gdb_osabi
465 1.1 christos tdesc_osabi (const struct target_desc *target_desc)
466 1.1 christos {
467 1.1 christos return target_desc->osabi;
468 1.1 christos }
469 1.1 christos
470 1.1 christos
471 1.1 christos
473 1.1 christos /* Return 1 if this target description includes any registers. */
474 1.1 christos
475 1.1 christos int
476 1.1 christos tdesc_has_registers (const struct target_desc *target_desc)
477 1.1 christos {
478 1.1 christos int ix;
479 1.1 christos struct tdesc_feature *feature;
480 1.1 christos
481 1.1 christos if (target_desc == NULL)
482 1.1 christos return 0;
483 1.1 christos
484 1.1 christos for (ix = 0;
485 1.1 christos VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature);
486 1.1 christos ix++)
487 1.1 christos if (! VEC_empty (tdesc_reg_p, feature->registers))
488 1.1 christos return 1;
489 1.1 christos
490 1.1 christos return 0;
491 1.1 christos }
492 1.1 christos
493 1.1 christos /* Return the feature with the given name, if present, or NULL if
494 1.1 christos the named feature is not found. */
495 1.1 christos
496 1.1 christos const struct tdesc_feature *
497 1.1 christos tdesc_find_feature (const struct target_desc *target_desc,
498 1.1 christos const char *name)
499 1.1 christos {
500 1.1 christos int ix;
501 1.1 christos struct tdesc_feature *feature;
502 1.1 christos
503 1.1 christos for (ix = 0;
504 1.1 christos VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature);
505 1.1 christos ix++)
506 1.1 christos if (strcmp (feature->name, name) == 0)
507 1.1 christos return feature;
508 1.1 christos
509 1.1 christos return NULL;
510 1.1 christos }
511 1.1 christos
512 1.1 christos /* Return the name of FEATURE. */
513 1.1 christos
514 1.1 christos const char *
515 1.1 christos tdesc_feature_name (const struct tdesc_feature *feature)
516 1.1 christos {
517 1.1 christos return feature->name;
518 1.1 christos }
519 1.1 christos
520 1.1 christos /* Predefined types. */
521 1.6 christos static struct tdesc_type tdesc_predefined_types[] =
522 1.1 christos {
523 1.1 christos { "bool", TDESC_TYPE_BOOL },
524 1.1 christos { "int8", TDESC_TYPE_INT8 },
525 1.1 christos { "int16", TDESC_TYPE_INT16 },
526 1.1 christos { "int32", TDESC_TYPE_INT32 },
527 1.1 christos { "int64", TDESC_TYPE_INT64 },
528 1.1 christos { "int128", TDESC_TYPE_INT128 },
529 1.1 christos { "uint8", TDESC_TYPE_UINT8 },
530 1.1 christos { "uint16", TDESC_TYPE_UINT16 },
531 1.1 christos { "uint32", TDESC_TYPE_UINT32 },
532 1.1 christos { "uint64", TDESC_TYPE_UINT64 },
533 1.1 christos { "uint128", TDESC_TYPE_UINT128 },
534 1.1 christos { "code_ptr", TDESC_TYPE_CODE_PTR },
535 1.1 christos { "data_ptr", TDESC_TYPE_DATA_PTR },
536 1.1 christos { "ieee_single", TDESC_TYPE_IEEE_SINGLE },
537 1.1 christos { "ieee_double", TDESC_TYPE_IEEE_DOUBLE },
538 1.1 christos { "arm_fpa_ext", TDESC_TYPE_ARM_FPA_EXT },
539 1.1 christos { "i387_ext", TDESC_TYPE_I387_EXT }
540 1.6 christos };
541 1.6 christos
542 1.6 christos /* Lookup a predefined type. */
543 1.6 christos
544 1.6 christos static struct tdesc_type *
545 1.6 christos tdesc_predefined_type (enum tdesc_type_kind kind)
546 1.6 christos {
547 1.6 christos int ix;
548 1.6 christos struct tdesc_type *type;
549 1.6 christos
550 1.6 christos for (ix = 0; ix < ARRAY_SIZE (tdesc_predefined_types); ix++)
551 1.6 christos if (tdesc_predefined_types[ix].kind == kind)
552 1.6 christos return &tdesc_predefined_types[ix];
553 1.6 christos
554 1.6 christos gdb_assert_not_reached ("bad predefined tdesc type");
555 1.1 christos }
556 1.1 christos
557 1.1 christos /* Return the type associated with ID in the context of FEATURE, or
558 1.1 christos NULL if none. */
559 1.1 christos
560 1.1 christos struct tdesc_type *
561 1.1 christos tdesc_named_type (const struct tdesc_feature *feature, const char *id)
562 1.1 christos {
563 1.1 christos int ix;
564 1.1 christos struct tdesc_type *type;
565 1.1 christos
566 1.1 christos /* First try target-defined types. */
567 1.1 christos for (ix = 0; VEC_iterate (tdesc_type_p, feature->types, ix, type); ix++)
568 1.1 christos if (strcmp (type->name, id) == 0)
569 1.1 christos return type;
570 1.1 christos
571 1.1 christos /* Next try the predefined types. */
572 1.1 christos for (ix = 0; ix < ARRAY_SIZE (tdesc_predefined_types); ix++)
573 1.1 christos if (strcmp (tdesc_predefined_types[ix].name, id) == 0)
574 1.1 christos return &tdesc_predefined_types[ix];
575 1.1 christos
576 1.1 christos return NULL;
577 1.1 christos }
578 1.1 christos
579 1.1 christos /* Lookup type associated with ID. */
580 1.1 christos
581 1.1 christos struct type *
582 1.1 christos tdesc_find_type (struct gdbarch *gdbarch, const char *id)
583 1.1 christos {
584 1.1 christos struct tdesc_arch_reg *reg;
585 1.1 christos struct tdesc_arch_data *data;
586 1.6 christos int i, num_regs;
587 1.1 christos
588 1.1 christos data = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
589 1.1 christos num_regs = VEC_length (tdesc_arch_reg, data->arch_regs);
590 1.1 christos for (i = 0; i < num_regs; i++)
591 1.1 christos {
592 1.1 christos reg = VEC_index (tdesc_arch_reg, data->arch_regs, i);
593 1.1 christos if (reg->reg
594 1.1 christos && reg->reg->tdesc_type
595 1.1 christos && reg->type
596 1.1 christos && strcmp (id, reg->reg->tdesc_type->name) == 0)
597 1.1 christos return reg->type;
598 1.1 christos }
599 1.1 christos
600 1.1 christos return NULL;
601 1.1 christos }
602 1.1 christos
603 1.1 christos /* Construct, if necessary, and return the GDB type implementing target
604 1.1 christos type TDESC_TYPE for architecture GDBARCH. */
605 1.1 christos
606 1.1 christos static struct type *
607 1.1 christos tdesc_gdb_type (struct gdbarch *gdbarch, struct tdesc_type *tdesc_type)
608 1.1 christos {
609 1.1 christos struct type *type;
610 1.1 christos
611 1.1 christos switch (tdesc_type->kind)
612 1.6 christos {
613 1.6 christos /* Predefined types. */
614 1.6 christos case TDESC_TYPE_BOOL:
615 1.1 christos return builtin_type (gdbarch)->builtin_bool;
616 1.1 christos
617 1.1 christos case TDESC_TYPE_INT8:
618 1.1 christos return builtin_type (gdbarch)->builtin_int8;
619 1.1 christos
620 1.1 christos case TDESC_TYPE_INT16:
621 1.1 christos return builtin_type (gdbarch)->builtin_int16;
622 1.1 christos
623 1.1 christos case TDESC_TYPE_INT32:
624 1.1 christos return builtin_type (gdbarch)->builtin_int32;
625 1.1 christos
626 1.1 christos case TDESC_TYPE_INT64:
627 1.1 christos return builtin_type (gdbarch)->builtin_int64;
628 1.1 christos
629 1.1 christos case TDESC_TYPE_INT128:
630 1.1 christos return builtin_type (gdbarch)->builtin_int128;
631 1.1 christos
632 1.1 christos case TDESC_TYPE_UINT8:
633 1.1 christos return builtin_type (gdbarch)->builtin_uint8;
634 1.1 christos
635 1.1 christos case TDESC_TYPE_UINT16:
636 1.1 christos return builtin_type (gdbarch)->builtin_uint16;
637 1.1 christos
638 1.1 christos case TDESC_TYPE_UINT32:
639 1.1 christos return builtin_type (gdbarch)->builtin_uint32;
640 1.1 christos
641 1.1 christos case TDESC_TYPE_UINT64:
642 1.1 christos return builtin_type (gdbarch)->builtin_uint64;
643 1.1 christos
644 1.1 christos case TDESC_TYPE_UINT128:
645 1.1 christos return builtin_type (gdbarch)->builtin_uint128;
646 1.1 christos
647 1.1 christos case TDESC_TYPE_CODE_PTR:
648 1.1 christos return builtin_type (gdbarch)->builtin_func_ptr;
649 1.1 christos
650 1.1 christos case TDESC_TYPE_DATA_PTR:
651 1.1 christos return builtin_type (gdbarch)->builtin_data_ptr;
652 1.1 christos
653 1.1 christos default:
654 1.1 christos break;
655 1.1 christos }
656 1.1 christos
657 1.1 christos type = tdesc_find_type (gdbarch, tdesc_type->name);
658 1.1 christos if (type)
659 1.1 christos return type;
660 1.1 christos
661 1.1 christos switch (tdesc_type->kind)
662 1.1 christos {
663 1.1 christos case TDESC_TYPE_IEEE_SINGLE:
664 1.1 christos return arch_float_type (gdbarch, -1, "builtin_type_ieee_single",
665 1.1 christos floatformats_ieee_single);
666 1.1 christos
667 1.1 christos case TDESC_TYPE_IEEE_DOUBLE:
668 1.1 christos return arch_float_type (gdbarch, -1, "builtin_type_ieee_double",
669 1.1 christos floatformats_ieee_double);
670 1.1 christos
671 1.1 christos case TDESC_TYPE_ARM_FPA_EXT:
672 1.1 christos return arch_float_type (gdbarch, -1, "builtin_type_arm_ext",
673 1.1 christos floatformats_arm_ext);
674 1.1 christos
675 1.1 christos case TDESC_TYPE_I387_EXT:
676 1.1 christos return arch_float_type (gdbarch, -1, "builtin_type_i387_ext",
677 1.1 christos floatformats_i387_ext);
678 1.1 christos
679 1.1 christos /* Types defined by a target feature. */
680 1.1 christos case TDESC_TYPE_VECTOR:
681 1.1 christos {
682 1.1 christos struct type *type, *field_type;
683 1.1 christos
684 1.1 christos field_type = tdesc_gdb_type (gdbarch, tdesc_type->u.v.type);
685 1.1 christos type = init_vector_type (field_type, tdesc_type->u.v.count);
686 1.1 christos TYPE_NAME (type) = xstrdup (tdesc_type->name);
687 1.1 christos
688 1.1 christos return type;
689 1.1 christos }
690 1.1 christos
691 1.1 christos case TDESC_TYPE_STRUCT:
692 1.1 christos {
693 1.1 christos struct type *type, *field_type;
694 1.1 christos struct tdesc_type_field *f;
695 1.1 christos int ix;
696 1.1 christos
697 1.1 christos type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
698 1.1 christos TYPE_NAME (type) = xstrdup (tdesc_type->name);
699 1.1 christos TYPE_TAG_NAME (type) = TYPE_NAME (type);
700 1.1 christos
701 1.1 christos for (ix = 0;
702 1.1 christos VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f);
703 1.6 christos ix++)
704 1.1 christos {
705 1.1 christos if (f->start != -1 && f->end != -1)
706 1.1 christos {
707 1.1 christos /* Bitfield. */
708 1.1 christos struct field *fld;
709 1.1 christos struct type *field_type;
710 1.6 christos int bitsize, total_size;
711 1.1 christos
712 1.6 christos /* This invariant should be preserved while creating types. */
713 1.6 christos gdb_assert (tdesc_type->u.u.size != 0);
714 1.6 christos if (f->type != NULL)
715 1.1 christos field_type = tdesc_gdb_type (gdbarch, f->type);
716 1.1 christos else if (tdesc_type->u.u.size > 4)
717 1.1 christos field_type = builtin_type (gdbarch)->builtin_uint64;
718 1.1 christos else
719 1.1 christos field_type = builtin_type (gdbarch)->builtin_uint32;
720 1.1 christos
721 1.1 christos fld = append_composite_type_field_raw (type, xstrdup (f->name),
722 1.1 christos field_type);
723 1.1 christos
724 1.1 christos /* For little-endian, BITPOS counts from the LSB of
725 1.1 christos the structure and marks the LSB of the field. For
726 1.1 christos big-endian, BITPOS counts from the MSB of the
727 1.1 christos structure and marks the MSB of the field. Either
728 1.1 christos way, it is the number of bits to the "left" of the
729 1.1 christos field. To calculate this in big-endian, we need
730 1.1 christos the total size of the structure. */
731 1.1 christos bitsize = f->end - f->start + 1;
732 1.1 christos total_size = tdesc_type->u.u.size * TARGET_CHAR_BIT;
733 1.1 christos if (gdbarch_bits_big_endian (gdbarch))
734 1.1 christos SET_FIELD_BITPOS (fld[0], total_size - f->start - bitsize);
735 1.1 christos else
736 1.1 christos SET_FIELD_BITPOS (fld[0], f->start);
737 1.1 christos FIELD_BITSIZE (fld[0]) = bitsize;
738 1.1 christos }
739 1.6 christos else
740 1.1 christos {
741 1.1 christos gdb_assert (f->start == -1 && f->end == -1);
742 1.1 christos field_type = tdesc_gdb_type (gdbarch, f->type);
743 1.1 christos append_composite_type_field (type, xstrdup (f->name),
744 1.1 christos field_type);
745 1.1 christos }
746 1.1 christos }
747 1.1 christos
748 1.1 christos if (tdesc_type->u.u.size != 0)
749 1.1 christos TYPE_LENGTH (type) = tdesc_type->u.u.size;
750 1.1 christos return type;
751 1.1 christos }
752 1.1 christos
753 1.1 christos case TDESC_TYPE_UNION:
754 1.1 christos {
755 1.1 christos struct type *type, *field_type;
756 1.1 christos struct tdesc_type_field *f;
757 1.1 christos int ix;
758 1.1 christos
759 1.1 christos type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
760 1.1 christos TYPE_NAME (type) = xstrdup (tdesc_type->name);
761 1.1 christos
762 1.1 christos for (ix = 0;
763 1.1 christos VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f);
764 1.1 christos ix++)
765 1.1 christos {
766 1.1 christos field_type = tdesc_gdb_type (gdbarch, f->type);
767 1.1 christos append_composite_type_field (type, xstrdup (f->name), field_type);
768 1.1 christos
769 1.1 christos /* If any of the children of a union are vectors, flag the
770 1.1 christos union as a vector also. This allows e.g. a union of two
771 1.1 christos vector types to show up automatically in "info vector". */
772 1.1 christos if (TYPE_VECTOR (field_type))
773 1.1 christos TYPE_VECTOR (type) = 1;
774 1.1 christos }
775 1.1 christos return type;
776 1.1 christos }
777 1.1 christos
778 1.6 christos case TDESC_TYPE_FLAGS:
779 1.1 christos {
780 1.1 christos struct tdesc_type_field *f;
781 1.1 christos int ix;
782 1.6 christos
783 1.1 christos type = arch_flags_type (gdbarch, tdesc_type->name,
784 1.6 christos tdesc_type->u.u.size);
785 1.1 christos for (ix = 0;
786 1.6 christos VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f);
787 1.6 christos ix++)
788 1.6 christos {
789 1.6 christos struct type *field_type;
790 1.6 christos int bitsize = f->end - f->start + 1;
791 1.6 christos
792 1.6 christos gdb_assert (f->type != NULL);
793 1.6 christos field_type = tdesc_gdb_type (gdbarch, f->type);
794 1.6 christos append_flags_type_field (type, f->start, bitsize,
795 1.6 christos field_type, f->name);
796 1.6 christos }
797 1.6 christos
798 1.6 christos return type;
799 1.6 christos }
800 1.6 christos
801 1.6 christos case TDESC_TYPE_ENUM:
802 1.6 christos {
803 1.6 christos struct tdesc_type_field *f;
804 1.6 christos int ix;
805 1.6 christos
806 1.6 christos type = arch_type (gdbarch, TYPE_CODE_ENUM,
807 1.6 christos tdesc_type->u.u.size, tdesc_type->name);
808 1.6 christos TYPE_UNSIGNED (type) = 1;
809 1.6 christos for (ix = 0;
810 1.6 christos VEC_iterate (tdesc_type_field, tdesc_type->u.u.fields, ix, f);
811 1.6 christos ix++)
812 1.6 christos {
813 1.6 christos struct field *fld
814 1.6 christos = append_composite_type_field_raw (type, xstrdup (f->name),
815 1.6 christos NULL);
816 1.6 christos
817 1.1 christos SET_FIELD_BITPOS (fld[0], f->start);
818 1.1 christos }
819 1.1 christos
820 1.1 christos return type;
821 1.1 christos }
822 1.1 christos }
823 1.1 christos
824 1.1 christos internal_error (__FILE__, __LINE__,
825 1.1 christos "Type \"%s\" has an unknown kind %d",
826 1.1 christos tdesc_type->name, tdesc_type->kind);
827 1.1 christos }
828 1.1 christos
829 1.1 christos
831 1.1 christos /* Support for registers from target descriptions. */
832 1.1 christos
833 1.1 christos /* Construct the per-gdbarch data. */
834 1.1 christos
835 1.1 christos static void *
836 1.1 christos tdesc_data_init (struct obstack *obstack)
837 1.1 christos {
838 1.1 christos struct tdesc_arch_data *data;
839 1.1 christos
840 1.1 christos data = OBSTACK_ZALLOC (obstack, struct tdesc_arch_data);
841 1.1 christos return data;
842 1.1 christos }
843 1.1 christos
844 1.1 christos /* Similar, but for the temporary copy used during architecture
845 1.1 christos initialization. */
846 1.1 christos
847 1.3 christos struct tdesc_arch_data *
848 1.1 christos tdesc_data_alloc (void)
849 1.1 christos {
850 1.1 christos return XCNEW (struct tdesc_arch_data);
851 1.1 christos }
852 1.1 christos
853 1.1 christos /* Free something allocated by tdesc_data_alloc, if it is not going
854 1.1 christos to be used (for instance if it was unsuitable for the
855 1.1 christos architecture). */
856 1.1 christos
857 1.6 christos void
858 1.1 christos tdesc_data_cleanup (void *data_untyped)
859 1.1 christos {
860 1.1 christos struct tdesc_arch_data *data = (struct tdesc_arch_data *) data_untyped;
861 1.1 christos
862 1.1 christos VEC_free (tdesc_arch_reg, data->arch_regs);
863 1.1 christos xfree (data);
864 1.1 christos }
865 1.1 christos
866 1.1 christos /* Search FEATURE for a register named NAME. */
867 1.1 christos
868 1.1 christos static struct tdesc_reg *
869 1.1 christos tdesc_find_register_early (const struct tdesc_feature *feature,
870 1.1 christos const char *name)
871 1.1 christos {
872 1.1 christos int ixr;
873 1.1 christos struct tdesc_reg *reg;
874 1.1 christos
875 1.1 christos for (ixr = 0;
876 1.1 christos VEC_iterate (tdesc_reg_p, feature->registers, ixr, reg);
877 1.1 christos ixr++)
878 1.1 christos if (strcasecmp (reg->name, name) == 0)
879 1.1 christos return reg;
880 1.1 christos
881 1.1 christos return NULL;
882 1.1 christos }
883 1.1 christos
884 1.1 christos /* Search FEATURE for a register named NAME. Assign REGNO to it. */
885 1.1 christos
886 1.1 christos int
887 1.1 christos tdesc_numbered_register (const struct tdesc_feature *feature,
888 1.1 christos struct tdesc_arch_data *data,
889 1.1 christos int regno, const char *name)
890 1.1 christos {
891 1.1 christos struct tdesc_arch_reg arch_reg = { 0 };
892 1.1 christos struct tdesc_reg *reg = tdesc_find_register_early (feature, name);
893 1.1 christos
894 1.1 christos if (reg == NULL)
895 1.1 christos return 0;
896 1.1 christos
897 1.1 christos /* Make sure the vector includes a REGNO'th element. */
898 1.1 christos while (regno >= VEC_length (tdesc_arch_reg, data->arch_regs))
899 1.1 christos VEC_safe_push (tdesc_arch_reg, data->arch_regs, &arch_reg);
900 1.1 christos
901 1.1 christos arch_reg.reg = reg;
902 1.1 christos VEC_replace (tdesc_arch_reg, data->arch_regs, regno, &arch_reg);
903 1.1 christos return 1;
904 1.1 christos }
905 1.1 christos
906 1.1 christos /* Search FEATURE for a register named NAME, but do not assign a fixed
907 1.1 christos register number to it. */
908 1.1 christos
909 1.1 christos int
910 1.1 christos tdesc_unnumbered_register (const struct tdesc_feature *feature,
911 1.1 christos const char *name)
912 1.1 christos {
913 1.1 christos struct tdesc_reg *reg = tdesc_find_register_early (feature, name);
914 1.1 christos
915 1.1 christos if (reg == NULL)
916 1.1 christos return 0;
917 1.1 christos
918 1.1 christos return 1;
919 1.1 christos }
920 1.1 christos
921 1.1 christos /* Search FEATURE for a register whose name is in NAMES and assign
922 1.1 christos REGNO to it. */
923 1.1 christos
924 1.1 christos int
925 1.1 christos tdesc_numbered_register_choices (const struct tdesc_feature *feature,
926 1.1 christos struct tdesc_arch_data *data,
927 1.1 christos int regno, const char *const names[])
928 1.1 christos {
929 1.1 christos int i;
930 1.1 christos
931 1.1 christos for (i = 0; names[i] != NULL; i++)
932 1.1 christos if (tdesc_numbered_register (feature, data, regno, names[i]))
933 1.1 christos return 1;
934 1.1 christos
935 1.1 christos return 0;
936 1.1 christos }
937 1.1 christos
938 1.1 christos /* Search FEATURE for a register named NAME, and return its size in
939 1.1 christos bits. The register must exist. */
940 1.1 christos
941 1.1 christos int
942 1.1 christos tdesc_register_size (const struct tdesc_feature *feature,
943 1.1 christos const char *name)
944 1.1 christos {
945 1.1 christos struct tdesc_reg *reg = tdesc_find_register_early (feature, name);
946 1.1 christos
947 1.1 christos gdb_assert (reg != NULL);
948 1.1 christos return reg->bitsize;
949 1.1 christos }
950 1.1 christos
951 1.1 christos /* Look up a register by its GDB internal register number. */
952 1.1 christos
953 1.1 christos static struct tdesc_arch_reg *
954 1.1 christos tdesc_find_arch_register (struct gdbarch *gdbarch, int regno)
955 1.6 christos {
956 1.1 christos struct tdesc_arch_data *data;
957 1.1 christos
958 1.1 christos data = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
959 1.1 christos if (regno < VEC_length (tdesc_arch_reg, data->arch_regs))
960 1.1 christos return VEC_index (tdesc_arch_reg, data->arch_regs, regno);
961 1.1 christos else
962 1.1 christos return NULL;
963 1.1 christos }
964 1.1 christos
965 1.1 christos static struct tdesc_reg *
966 1.1 christos tdesc_find_register (struct gdbarch *gdbarch, int regno)
967 1.1 christos {
968 1.1 christos struct tdesc_arch_reg *reg = tdesc_find_arch_register (gdbarch, regno);
969 1.1 christos
970 1.1 christos return reg? reg->reg : NULL;
971 1.1 christos }
972 1.1 christos
973 1.1 christos /* Return the name of register REGNO, from the target description or
974 1.1 christos from an architecture-provided pseudo_register_name method. */
975 1.1 christos
976 1.1 christos const char *
977 1.1 christos tdesc_register_name (struct gdbarch *gdbarch, int regno)
978 1.1 christos {
979 1.1 christos struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno);
980 1.1 christos int num_regs = gdbarch_num_regs (gdbarch);
981 1.1 christos int num_pseudo_regs = gdbarch_num_pseudo_regs (gdbarch);
982 1.1 christos
983 1.1 christos if (reg != NULL)
984 1.1 christos return reg->name;
985 1.6 christos
986 1.6 christos if (regno >= num_regs && regno < num_regs + num_pseudo_regs)
987 1.1 christos {
988 1.1 christos struct tdesc_arch_data *data
989 1.1 christos = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
990 1.1 christos
991 1.1 christos gdb_assert (data->pseudo_register_name != NULL);
992 1.1 christos return data->pseudo_register_name (gdbarch, regno);
993 1.1 christos }
994 1.1 christos
995 1.1 christos return "";
996 1.1 christos }
997 1.1 christos
998 1.1 christos struct type *
999 1.1 christos tdesc_register_type (struct gdbarch *gdbarch, int regno)
1000 1.1 christos {
1001 1.1 christos struct tdesc_arch_reg *arch_reg = tdesc_find_arch_register (gdbarch, regno);
1002 1.1 christos struct tdesc_reg *reg = arch_reg? arch_reg->reg : NULL;
1003 1.1 christos int num_regs = gdbarch_num_regs (gdbarch);
1004 1.1 christos int num_pseudo_regs = gdbarch_num_pseudo_regs (gdbarch);
1005 1.6 christos
1006 1.6 christos if (reg == NULL && regno >= num_regs && regno < num_regs + num_pseudo_regs)
1007 1.1 christos {
1008 1.1 christos struct tdesc_arch_data *data
1009 1.1 christos = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
1010 1.1 christos
1011 1.1 christos gdb_assert (data->pseudo_register_type != NULL);
1012 1.1 christos return data->pseudo_register_type (gdbarch, regno);
1013 1.1 christos }
1014 1.1 christos
1015 1.1 christos if (reg == NULL)
1016 1.1 christos /* Return "int0_t", since "void" has a misleading size of one. */
1017 1.1 christos return builtin_type (gdbarch)->builtin_int0;
1018 1.1 christos
1019 1.1 christos if (arch_reg->type == NULL)
1020 1.1 christos {
1021 1.1 christos /* First check for a predefined or target defined type. */
1022 1.1 christos if (reg->tdesc_type)
1023 1.1 christos arch_reg->type = tdesc_gdb_type (gdbarch, reg->tdesc_type);
1024 1.1 christos
1025 1.1 christos /* Next try size-sensitive type shortcuts. */
1026 1.1 christos else if (strcmp (reg->type, "float") == 0)
1027 1.1 christos {
1028 1.1 christos if (reg->bitsize == gdbarch_float_bit (gdbarch))
1029 1.1 christos arch_reg->type = builtin_type (gdbarch)->builtin_float;
1030 1.1 christos else if (reg->bitsize == gdbarch_double_bit (gdbarch))
1031 1.1 christos arch_reg->type = builtin_type (gdbarch)->builtin_double;
1032 1.1 christos else if (reg->bitsize == gdbarch_long_double_bit (gdbarch))
1033 1.1 christos arch_reg->type = builtin_type (gdbarch)->builtin_long_double;
1034 1.1 christos else
1035 1.1 christos {
1036 1.1 christos warning (_("Register \"%s\" has an unsupported size (%d bits)"),
1037 1.1 christos reg->name, reg->bitsize);
1038 1.1 christos arch_reg->type = builtin_type (gdbarch)->builtin_double;
1039 1.1 christos }
1040 1.1 christos }
1041 1.1 christos else if (strcmp (reg->type, "int") == 0)
1042 1.1 christos {
1043 1.1 christos if (reg->bitsize == gdbarch_long_bit (gdbarch))
1044 1.1 christos arch_reg->type = builtin_type (gdbarch)->builtin_long;
1045 1.1 christos else if (reg->bitsize == TARGET_CHAR_BIT)
1046 1.1 christos arch_reg->type = builtin_type (gdbarch)->builtin_char;
1047 1.1 christos else if (reg->bitsize == gdbarch_short_bit (gdbarch))
1048 1.1 christos arch_reg->type = builtin_type (gdbarch)->builtin_short;
1049 1.1 christos else if (reg->bitsize == gdbarch_int_bit (gdbarch))
1050 1.1 christos arch_reg->type = builtin_type (gdbarch)->builtin_int;
1051 1.1 christos else if (reg->bitsize == gdbarch_long_long_bit (gdbarch))
1052 1.1 christos arch_reg->type = builtin_type (gdbarch)->builtin_long_long;
1053 1.1 christos else if (reg->bitsize == gdbarch_ptr_bit (gdbarch))
1054 1.1 christos /* A bit desperate by this point... */
1055 1.1 christos arch_reg->type = builtin_type (gdbarch)->builtin_data_ptr;
1056 1.1 christos else
1057 1.1 christos {
1058 1.1 christos warning (_("Register \"%s\" has an unsupported size (%d bits)"),
1059 1.1 christos reg->name, reg->bitsize);
1060 1.1 christos arch_reg->type = builtin_type (gdbarch)->builtin_long;
1061 1.1 christos }
1062 1.1 christos }
1063 1.1 christos
1064 1.1 christos if (arch_reg->type == NULL)
1065 1.1 christos internal_error (__FILE__, __LINE__,
1066 1.1 christos "Register \"%s\" has an unknown type \"%s\"",
1067 1.1 christos reg->name, reg->type);
1068 1.1 christos }
1069 1.1 christos
1070 1.1 christos return arch_reg->type;
1071 1.1 christos }
1072 1.1 christos
1073 1.1 christos static int
1074 1.1 christos tdesc_remote_register_number (struct gdbarch *gdbarch, int regno)
1075 1.1 christos {
1076 1.1 christos struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno);
1077 1.1 christos
1078 1.1 christos if (reg != NULL)
1079 1.1 christos return reg->target_regnum;
1080 1.1 christos else
1081 1.1 christos return -1;
1082 1.1 christos }
1083 1.1 christos
1084 1.1 christos /* Check whether REGNUM is a member of REGGROUP. Registers from the
1085 1.1 christos target description may be classified as general, float, or vector.
1086 1.1 christos Unlike a gdbarch register_reggroup_p method, this function will
1087 1.1 christos return -1 if it does not know; the caller should handle registers
1088 1.1 christos with no specified group.
1089 1.1 christos
1090 1.1 christos Arbitrary strings (other than "general", "float", and "vector")
1091 1.1 christos from the description are not used; they cause the register to be
1092 1.1 christos displayed in "info all-registers" but excluded from "info
1093 1.1 christos registers" et al. The names of containing features are also not
1094 1.1 christos used. This might be extended to display registers in some more
1095 1.1 christos useful groupings.
1096 1.1 christos
1097 1.1 christos The save-restore flag is also implemented here. */
1098 1.1 christos
1099 1.1 christos int
1100 1.1 christos tdesc_register_in_reggroup_p (struct gdbarch *gdbarch, int regno,
1101 1.1 christos struct reggroup *reggroup)
1102 1.1 christos {
1103 1.1 christos struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno);
1104 1.1 christos
1105 1.1 christos if (reg != NULL && reg->group != NULL)
1106 1.1 christos {
1107 1.1 christos int general_p = 0, float_p = 0, vector_p = 0;
1108 1.1 christos
1109 1.1 christos if (strcmp (reg->group, "general") == 0)
1110 1.1 christos general_p = 1;
1111 1.1 christos else if (strcmp (reg->group, "float") == 0)
1112 1.1 christos float_p = 1;
1113 1.1 christos else if (strcmp (reg->group, "vector") == 0)
1114 1.1 christos vector_p = 1;
1115 1.1 christos
1116 1.1 christos if (reggroup == float_reggroup)
1117 1.1 christos return float_p;
1118 1.1 christos
1119 1.1 christos if (reggroup == vector_reggroup)
1120 1.1 christos return vector_p;
1121 1.1 christos
1122 1.1 christos if (reggroup == general_reggroup)
1123 1.1 christos return general_p;
1124 1.1 christos }
1125 1.1 christos
1126 1.1 christos if (reg != NULL
1127 1.1 christos && (reggroup == save_reggroup || reggroup == restore_reggroup))
1128 1.1 christos return reg->save_restore;
1129 1.1 christos
1130 1.1 christos return -1;
1131 1.1 christos }
1132 1.1 christos
1133 1.1 christos /* Check whether REGNUM is a member of REGGROUP. Registers with no
1134 1.1 christos group specified go to the default reggroup function and are handled
1135 1.1 christos by type. */
1136 1.1 christos
1137 1.1 christos static int
1138 1.1 christos tdesc_register_reggroup_p (struct gdbarch *gdbarch, int regno,
1139 1.1 christos struct reggroup *reggroup)
1140 1.1 christos {
1141 1.1 christos int num_regs = gdbarch_num_regs (gdbarch);
1142 1.1 christos int num_pseudo_regs = gdbarch_num_pseudo_regs (gdbarch);
1143 1.1 christos int ret;
1144 1.6 christos
1145 1.6 christos if (regno >= num_regs && regno < num_regs + num_pseudo_regs)
1146 1.1 christos {
1147 1.1 christos struct tdesc_arch_data *data
1148 1.1 christos = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
1149 1.1 christos
1150 1.1 christos if (data->pseudo_register_reggroup_p != NULL)
1151 1.1 christos return data->pseudo_register_reggroup_p (gdbarch, regno, reggroup);
1152 1.1 christos /* Otherwise fall through to the default reggroup_p. */
1153 1.1 christos }
1154 1.1 christos
1155 1.1 christos ret = tdesc_register_in_reggroup_p (gdbarch, regno, reggroup);
1156 1.1 christos if (ret != -1)
1157 1.1 christos return ret;
1158 1.1 christos
1159 1.1 christos return default_register_reggroup_p (gdbarch, regno, reggroup);
1160 1.1 christos }
1161 1.1 christos
1162 1.1 christos /* Record architecture-specific functions to call for pseudo-register
1163 1.1 christos support. */
1164 1.1 christos
1165 1.1 christos void
1166 1.6 christos set_tdesc_pseudo_register_name (struct gdbarch *gdbarch,
1167 1.6 christos gdbarch_register_name_ftype *pseudo_name)
1168 1.1 christos {
1169 1.1 christos struct tdesc_arch_data *data
1170 1.1 christos = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
1171 1.1 christos
1172 1.1 christos data->pseudo_register_name = pseudo_name;
1173 1.1 christos }
1174 1.1 christos
1175 1.1 christos void
1176 1.6 christos set_tdesc_pseudo_register_type (struct gdbarch *gdbarch,
1177 1.6 christos gdbarch_register_type_ftype *pseudo_type)
1178 1.1 christos {
1179 1.1 christos struct tdesc_arch_data *data
1180 1.1 christos = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
1181 1.1 christos
1182 1.1 christos data->pseudo_register_type = pseudo_type;
1183 1.1 christos }
1184 1.1 christos
1185 1.1 christos void
1186 1.1 christos set_tdesc_pseudo_register_reggroup_p
1187 1.6 christos (struct gdbarch *gdbarch,
1188 1.6 christos gdbarch_register_reggroup_p_ftype *pseudo_reggroup_p)
1189 1.1 christos {
1190 1.1 christos struct tdesc_arch_data *data
1191 1.1 christos = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
1192 1.1 christos
1193 1.1 christos data->pseudo_register_reggroup_p = pseudo_reggroup_p;
1194 1.1 christos }
1195 1.1 christos
1196 1.1 christos /* Update GDBARCH to use the target description for registers. */
1197 1.1 christos
1198 1.1 christos void
1199 1.1 christos tdesc_use_registers (struct gdbarch *gdbarch,
1200 1.1 christos const struct target_desc *target_desc,
1201 1.1 christos struct tdesc_arch_data *early_data)
1202 1.1 christos {
1203 1.1 christos int num_regs = gdbarch_num_regs (gdbarch);
1204 1.1 christos int ixf, ixr;
1205 1.1 christos struct tdesc_feature *feature;
1206 1.1 christos struct tdesc_reg *reg;
1207 1.1 christos struct tdesc_arch_data *data;
1208 1.1 christos struct tdesc_arch_reg *arch_reg, new_arch_reg = { 0 };
1209 1.1 christos htab_t reg_hash;
1210 1.1 christos
1211 1.1 christos /* We can't use the description for registers if it doesn't describe
1212 1.1 christos any. This function should only be called after validating
1213 1.1 christos registers, so the caller should know that registers are
1214 1.6 christos included. */
1215 1.1 christos gdb_assert (tdesc_has_registers (target_desc));
1216 1.1 christos
1217 1.1 christos data = (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
1218 1.1 christos data->arch_regs = early_data->arch_regs;
1219 1.1 christos xfree (early_data);
1220 1.1 christos
1221 1.1 christos /* Build up a set of all registers, so that we can assign register
1222 1.1 christos numbers where needed. The hash table expands as necessary, so
1223 1.1 christos the initial size is arbitrary. */
1224 1.1 christos reg_hash = htab_create (37, htab_hash_pointer, htab_eq_pointer, NULL);
1225 1.1 christos for (ixf = 0;
1226 1.1 christos VEC_iterate (tdesc_feature_p, target_desc->features, ixf, feature);
1227 1.1 christos ixf++)
1228 1.1 christos for (ixr = 0;
1229 1.1 christos VEC_iterate (tdesc_reg_p, feature->registers, ixr, reg);
1230 1.1 christos ixr++)
1231 1.1 christos {
1232 1.1 christos void **slot = htab_find_slot (reg_hash, reg, INSERT);
1233 1.1 christos
1234 1.1 christos *slot = reg;
1235 1.1 christos }
1236 1.1 christos
1237 1.1 christos /* Remove any registers which were assigned numbers by the
1238 1.1 christos architecture. */
1239 1.1 christos for (ixr = 0;
1240 1.1 christos VEC_iterate (tdesc_arch_reg, data->arch_regs, ixr, arch_reg);
1241 1.1 christos ixr++)
1242 1.1 christos if (arch_reg->reg)
1243 1.1 christos htab_remove_elt (reg_hash, arch_reg->reg);
1244 1.1 christos
1245 1.1 christos /* Assign numbers to the remaining registers and add them to the
1246 1.1 christos list of registers. The new numbers are always above gdbarch_num_regs.
1247 1.1 christos Iterate over the features, not the hash table, so that the order
1248 1.1 christos matches that in the target description. */
1249 1.1 christos
1250 1.1 christos gdb_assert (VEC_length (tdesc_arch_reg, data->arch_regs) <= num_regs);
1251 1.1 christos while (VEC_length (tdesc_arch_reg, data->arch_regs) < num_regs)
1252 1.1 christos VEC_safe_push (tdesc_arch_reg, data->arch_regs, &new_arch_reg);
1253 1.1 christos for (ixf = 0;
1254 1.1 christos VEC_iterate (tdesc_feature_p, target_desc->features, ixf, feature);
1255 1.1 christos ixf++)
1256 1.1 christos for (ixr = 0;
1257 1.1 christos VEC_iterate (tdesc_reg_p, feature->registers, ixr, reg);
1258 1.1 christos ixr++)
1259 1.1 christos if (htab_find (reg_hash, reg) != NULL)
1260 1.1 christos {
1261 1.1 christos new_arch_reg.reg = reg;
1262 1.1 christos VEC_safe_push (tdesc_arch_reg, data->arch_regs, &new_arch_reg);
1263 1.1 christos num_regs++;
1264 1.1 christos }
1265 1.1 christos
1266 1.1 christos htab_delete (reg_hash);
1267 1.1 christos
1268 1.1 christos /* Update the architecture. */
1269 1.1 christos set_gdbarch_num_regs (gdbarch, num_regs);
1270 1.1 christos set_gdbarch_register_name (gdbarch, tdesc_register_name);
1271 1.1 christos set_gdbarch_register_type (gdbarch, tdesc_register_type);
1272 1.1 christos set_gdbarch_remote_register_number (gdbarch,
1273 1.1 christos tdesc_remote_register_number);
1274 1.1 christos set_gdbarch_register_reggroup_p (gdbarch, tdesc_register_reggroup_p);
1275 1.1 christos }
1276 1.1 christos
1277 1.1 christos
1279 1.1 christos /* Methods for constructing a target description. */
1280 1.1 christos
1281 1.1 christos static void
1282 1.1 christos tdesc_free_reg (struct tdesc_reg *reg)
1283 1.1 christos {
1284 1.1 christos xfree (reg->name);
1285 1.1 christos xfree (reg->type);
1286 1.1 christos xfree (reg->group);
1287 1.1 christos xfree (reg);
1288 1.1 christos }
1289 1.1 christos
1290 1.1 christos void
1291 1.3 christos tdesc_create_reg (struct tdesc_feature *feature, const char *name,
1292 1.1 christos int regnum, int save_restore, const char *group,
1293 1.1 christos int bitsize, const char *type)
1294 1.1 christos {
1295 1.1 christos struct tdesc_reg *reg = XCNEW (struct tdesc_reg);
1296 1.1 christos
1297 1.1 christos reg->name = xstrdup (name);
1298 1.1 christos reg->target_regnum = regnum;
1299 1.1 christos reg->save_restore = save_restore;
1300 1.1 christos reg->group = group ? xstrdup (group) : NULL;
1301 1.1 christos reg->bitsize = bitsize;
1302 1.1 christos reg->type = type ? xstrdup (type) : xstrdup ("<unknown>");
1303 1.1 christos
1304 1.1 christos /* If the register's type is target-defined, look it up now. We may not
1305 1.1 christos have easy access to the containing feature when we want it later. */
1306 1.1 christos reg->tdesc_type = tdesc_named_type (feature, reg->type);
1307 1.6 christos
1308 1.6 christos VEC_safe_push (tdesc_reg_p, feature->registers, reg);
1309 1.6 christos }
1310 1.6 christos
1311 1.6 christos /* Subroutine of tdesc_free_feature to simplify it.
1312 1.1 christos Note: We do not want to free any referenced types here (e.g., types of
1313 1.1 christos fields of a struct). All types of a feature are recorded in
1314 1.1 christos feature->types and are freed that way. */
1315 1.1 christos
1316 1.1 christos static void
1317 1.1 christos tdesc_free_type (struct tdesc_type *type)
1318 1.1 christos {
1319 1.6 christos switch (type->kind)
1320 1.6 christos {
1321 1.1 christos case TDESC_TYPE_STRUCT:
1322 1.1 christos case TDESC_TYPE_UNION:
1323 1.1 christos case TDESC_TYPE_FLAGS:
1324 1.1 christos case TDESC_TYPE_ENUM:
1325 1.1 christos {
1326 1.1 christos struct tdesc_type_field *f;
1327 1.1 christos int ix;
1328 1.1 christos
1329 1.1 christos for (ix = 0;
1330 1.1 christos VEC_iterate (tdesc_type_field, type->u.u.fields, ix, f);
1331 1.1 christos ix++)
1332 1.1 christos xfree (f->name);
1333 1.1 christos
1334 1.1 christos VEC_free (tdesc_type_field, type->u.u.fields);
1335 1.1 christos }
1336 1.1 christos break;
1337 1.1 christos
1338 1.1 christos default:
1339 1.1 christos break;
1340 1.1 christos }
1341 1.1 christos
1342 1.1 christos xfree (type->name);
1343 1.1 christos xfree (type);
1344 1.1 christos }
1345 1.1 christos
1346 1.3 christos struct tdesc_type *
1347 1.1 christos tdesc_create_vector (struct tdesc_feature *feature, const char *name,
1348 1.1 christos struct tdesc_type *field_type, int count)
1349 1.1 christos {
1350 1.1 christos struct tdesc_type *type = XCNEW (struct tdesc_type);
1351 1.1 christos
1352 1.1 christos type->name = xstrdup (name);
1353 1.1 christos type->kind = TDESC_TYPE_VECTOR;
1354 1.1 christos type->u.v.type = field_type;
1355 1.1 christos type->u.v.count = count;
1356 1.1 christos
1357 1.1 christos VEC_safe_push (tdesc_type_p, feature->types, type);
1358 1.1 christos return type;
1359 1.1 christos }
1360 1.3 christos
1361 1.1 christos struct tdesc_type *
1362 1.1 christos tdesc_create_struct (struct tdesc_feature *feature, const char *name)
1363 1.1 christos {
1364 1.1 christos struct tdesc_type *type = XCNEW (struct tdesc_type);
1365 1.1 christos
1366 1.1 christos type->name = xstrdup (name);
1367 1.1 christos type->kind = TDESC_TYPE_STRUCT;
1368 1.1 christos
1369 1.1 christos VEC_safe_push (tdesc_type_p, feature->types, type);
1370 1.1 christos return type;
1371 1.1 christos }
1372 1.1 christos
1373 1.1 christos /* Set the total length of TYPE. Structs which contain bitfields may
1374 1.6 christos omit the reserved bits, so the end of the last field may not
1375 1.1 christos suffice. */
1376 1.1 christos
1377 1.6 christos void
1378 1.1 christos tdesc_set_struct_size (struct tdesc_type *type, int size)
1379 1.1 christos {
1380 1.1 christos gdb_assert (type->kind == TDESC_TYPE_STRUCT);
1381 1.1 christos gdb_assert (size > 0);
1382 1.1 christos type->u.u.size = size;
1383 1.1 christos }
1384 1.3 christos
1385 1.1 christos struct tdesc_type *
1386 1.1 christos tdesc_create_union (struct tdesc_feature *feature, const char *name)
1387 1.1 christos {
1388 1.1 christos struct tdesc_type *type = XCNEW (struct tdesc_type);
1389 1.1 christos
1390 1.1 christos type->name = xstrdup (name);
1391 1.1 christos type->kind = TDESC_TYPE_UNION;
1392 1.1 christos
1393 1.1 christos VEC_safe_push (tdesc_type_p, feature->types, type);
1394 1.1 christos return type;
1395 1.6 christos }
1396 1.1 christos
1397 1.3 christos struct tdesc_type *
1398 1.1 christos tdesc_create_flags (struct tdesc_feature *feature, const char *name,
1399 1.6 christos int size)
1400 1.6 christos {
1401 1.1 christos struct tdesc_type *type = XCNEW (struct tdesc_type);
1402 1.1 christos
1403 1.6 christos gdb_assert (size > 0);
1404 1.6 christos
1405 1.6 christos type->name = xstrdup (name);
1406 1.6 christos type->kind = TDESC_TYPE_FLAGS;
1407 1.6 christos type->u.u.size = size;
1408 1.6 christos
1409 1.6 christos VEC_safe_push (tdesc_type_p, feature->types, type);
1410 1.6 christos return type;
1411 1.6 christos }
1412 1.6 christos
1413 1.6 christos struct tdesc_type *
1414 1.6 christos tdesc_create_enum (struct tdesc_feature *feature, const char *name,
1415 1.6 christos int size)
1416 1.6 christos {
1417 1.6 christos struct tdesc_type *type = XCNEW (struct tdesc_type);
1418 1.6 christos
1419 1.6 christos gdb_assert (size > 0);
1420 1.1 christos
1421 1.1 christos type->name = xstrdup (name);
1422 1.1 christos type->kind = TDESC_TYPE_ENUM;
1423 1.1 christos type->u.u.size = size;
1424 1.1 christos
1425 1.6 christos VEC_safe_push (tdesc_type_p, feature->types, type);
1426 1.1 christos return type;
1427 1.1 christos }
1428 1.1 christos
1429 1.1 christos /* Add a new field to TYPE. */
1430 1.1 christos
1431 1.1 christos void
1432 1.1 christos tdesc_add_field (struct tdesc_type *type, const char *field_name,
1433 1.1 christos struct tdesc_type *field_type)
1434 1.1 christos {
1435 1.1 christos struct tdesc_type_field f = { 0 };
1436 1.1 christos
1437 1.1 christos gdb_assert (type->kind == TDESC_TYPE_UNION
1438 1.6 christos || type->kind == TDESC_TYPE_STRUCT);
1439 1.6 christos
1440 1.6 christos f.name = xstrdup (field_name);
1441 1.6 christos f.type = field_type;
1442 1.1 christos /* Initialize these values so we know this is not a bit-field
1443 1.1 christos when we print-c-tdesc. */
1444 1.1 christos f.start = -1;
1445 1.1 christos f.end = -1;
1446 1.6 christos
1447 1.1 christos VEC_safe_push (tdesc_type_field, type->u.u.fields, &f);
1448 1.1 christos }
1449 1.6 christos
1450 1.6 christos /* Add a new typed bitfield to TYPE. */
1451 1.1 christos
1452 1.1 christos void
1453 1.1 christos tdesc_add_typed_bitfield (struct tdesc_type *type, const char *field_name,
1454 1.6 christos int start, int end, struct tdesc_type *field_type)
1455 1.6 christos {
1456 1.6 christos struct tdesc_type_field f = { 0 };
1457 1.1 christos
1458 1.1 christos gdb_assert (type->kind == TDESC_TYPE_STRUCT
1459 1.1 christos || type->kind == TDESC_TYPE_FLAGS);
1460 1.1 christos gdb_assert (start >= 0 && end >= start);
1461 1.6 christos
1462 1.1 christos f.name = xstrdup (field_name);
1463 1.1 christos f.start = start;
1464 1.1 christos f.end = end;
1465 1.1 christos f.type = field_type;
1466 1.6 christos
1467 1.6 christos VEC_safe_push (tdesc_type_field, type->u.u.fields, &f);
1468 1.6 christos }
1469 1.6 christos
1470 1.6 christos /* Add a new untyped bitfield to TYPE.
1471 1.6 christos Untyped bitfields become either uint32 or uint64 depending on the size
1472 1.6 christos of the underlying type. */
1473 1.6 christos
1474 1.6 christos void
1475 1.6 christos tdesc_add_bitfield (struct tdesc_type *type, const char *field_name,
1476 1.6 christos int start, int end)
1477 1.6 christos {
1478 1.6 christos struct tdesc_type *field_type;
1479 1.6 christos
1480 1.6 christos gdb_assert (start >= 0 && end >= start);
1481 1.6 christos
1482 1.6 christos if (type->u.u.size > 4)
1483 1.6 christos field_type = tdesc_predefined_type (TDESC_TYPE_UINT64);
1484 1.6 christos else
1485 1.6 christos field_type = tdesc_predefined_type (TDESC_TYPE_UINT32);
1486 1.6 christos
1487 1.6 christos tdesc_add_typed_bitfield (type, field_name, start, end, field_type);
1488 1.6 christos }
1489 1.1 christos
1490 1.1 christos /* A flag is just a typed(bool) single-bit bitfield.
1491 1.1 christos This function is kept to minimize changes in generated files. */
1492 1.1 christos
1493 1.6 christos void
1494 1.1 christos tdesc_add_flag (struct tdesc_type *type, int start,
1495 1.6 christos const char *flag_name)
1496 1.6 christos {
1497 1.1 christos struct tdesc_type_field f = { 0 };
1498 1.1 christos
1499 1.1 christos gdb_assert (type->kind == TDESC_TYPE_FLAGS
1500 1.6 christos || type->kind == TDESC_TYPE_STRUCT);
1501 1.6 christos
1502 1.1 christos f.name = xstrdup (flag_name);
1503 1.6 christos f.start = start;
1504 1.6 christos f.end = start;
1505 1.6 christos f.type = tdesc_predefined_type (TDESC_TYPE_BOOL);
1506 1.6 christos
1507 1.6 christos VEC_safe_push (tdesc_type_field, type->u.u.fields, &f);
1508 1.6 christos }
1509 1.6 christos
1510 1.6 christos void
1511 1.6 christos tdesc_add_enum_value (struct tdesc_type *type, int value,
1512 1.6 christos const char *name)
1513 1.6 christos {
1514 1.6 christos struct tdesc_type_field f = { 0 };
1515 1.6 christos
1516 1.6 christos gdb_assert (type->kind == TDESC_TYPE_ENUM);
1517 1.6 christos
1518 1.6 christos f.name = xstrdup (name);
1519 1.6 christos f.start = value;
1520 1.1 christos f.end = -1;
1521 1.1 christos f.type = tdesc_predefined_type (TDESC_TYPE_INT32);
1522 1.1 christos
1523 1.1 christos VEC_safe_push (tdesc_type_field, type->u.u.fields, &f);
1524 1.1 christos }
1525 1.1 christos
1526 1.1 christos static void
1527 1.1 christos tdesc_free_feature (struct tdesc_feature *feature)
1528 1.1 christos {
1529 1.1 christos struct tdesc_reg *reg;
1530 1.1 christos struct tdesc_type *type;
1531 1.1 christos int ix;
1532 1.1 christos
1533 1.1 christos for (ix = 0; VEC_iterate (tdesc_reg_p, feature->registers, ix, reg); ix++)
1534 1.1 christos tdesc_free_reg (reg);
1535 1.1 christos VEC_free (tdesc_reg_p, feature->registers);
1536 1.1 christos
1537 1.1 christos for (ix = 0; VEC_iterate (tdesc_type_p, feature->types, ix, type); ix++)
1538 1.1 christos tdesc_free_type (type);
1539 1.1 christos VEC_free (tdesc_type_p, feature->types);
1540 1.1 christos
1541 1.1 christos xfree (feature->name);
1542 1.1 christos xfree (feature);
1543 1.1 christos }
1544 1.3 christos
1545 1.1 christos struct tdesc_feature *
1546 1.1 christos tdesc_create_feature (struct target_desc *tdesc, const char *name)
1547 1.1 christos {
1548 1.1 christos struct tdesc_feature *new_feature = XCNEW (struct tdesc_feature);
1549 1.1 christos
1550 1.1 christos new_feature->name = xstrdup (name);
1551 1.1 christos
1552 1.1 christos VEC_safe_push (tdesc_feature_p, tdesc->features, new_feature);
1553 1.1 christos return new_feature;
1554 1.1 christos }
1555 1.3 christos
1556 1.1 christos struct target_desc *
1557 1.1 christos allocate_target_description (void)
1558 1.1 christos {
1559 1.1 christos return XCNEW (struct target_desc);
1560 1.1 christos }
1561 1.6 christos
1562 1.1 christos static void
1563 1.1 christos free_target_description (void *arg)
1564 1.1 christos {
1565 1.1 christos struct target_desc *target_desc = (struct target_desc *) arg;
1566 1.1 christos struct tdesc_feature *feature;
1567 1.1 christos struct property *prop;
1568 1.1 christos int ix;
1569 1.1 christos
1570 1.1 christos for (ix = 0;
1571 1.1 christos VEC_iterate (tdesc_feature_p, target_desc->features, ix, feature);
1572 1.1 christos ix++)
1573 1.1 christos tdesc_free_feature (feature);
1574 1.1 christos VEC_free (tdesc_feature_p, target_desc->features);
1575 1.1 christos
1576 1.1 christos for (ix = 0;
1577 1.1 christos VEC_iterate (property_s, target_desc->properties, ix, prop);
1578 1.1 christos ix++)
1579 1.1 christos {
1580 1.1 christos xfree (prop->key);
1581 1.1 christos xfree (prop->value);
1582 1.1 christos }
1583 1.1 christos VEC_free (property_s, target_desc->properties);
1584 1.1 christos
1585 1.1 christos VEC_free (arch_p, target_desc->compatible);
1586 1.1 christos
1587 1.1 christos xfree (target_desc);
1588 1.1 christos }
1589 1.1 christos
1590 1.1 christos struct cleanup *
1591 1.1 christos make_cleanup_free_target_description (struct target_desc *target_desc)
1592 1.1 christos {
1593 1.1 christos return make_cleanup (free_target_description, target_desc);
1594 1.1 christos }
1595 1.1 christos
1596 1.1 christos void
1597 1.1 christos tdesc_add_compatible (struct target_desc *target_desc,
1598 1.1 christos const struct bfd_arch_info *compatible)
1599 1.1 christos {
1600 1.1 christos const struct bfd_arch_info *compat;
1601 1.1 christos int ix;
1602 1.1 christos
1603 1.1 christos /* If this instance of GDB is compiled without BFD support for the
1604 1.1 christos compatible architecture, simply ignore it -- we would not be able
1605 1.1 christos to handle it anyway. */
1606 1.1 christos if (compatible == NULL)
1607 1.1 christos return;
1608 1.1 christos
1609 1.1 christos for (ix = 0; VEC_iterate (arch_p, target_desc->compatible, ix, compat);
1610 1.1 christos ix++)
1611 1.1 christos if (compat == compatible)
1612 1.1 christos internal_error (__FILE__, __LINE__,
1613 1.1 christos _("Attempted to add duplicate "
1614 1.1 christos "compatible architecture \"%s\""),
1615 1.1 christos compatible->printable_name);
1616 1.1 christos
1617 1.1 christos VEC_safe_push (arch_p, target_desc->compatible, compatible);
1618 1.1 christos }
1619 1.1 christos
1620 1.1 christos void
1621 1.1 christos set_tdesc_property (struct target_desc *target_desc,
1622 1.1 christos const char *key, const char *value)
1623 1.1 christos {
1624 1.1 christos struct property *prop, new_prop;
1625 1.1 christos int ix;
1626 1.1 christos
1627 1.1 christos gdb_assert (key != NULL && value != NULL);
1628 1.1 christos
1629 1.1 christos for (ix = 0; VEC_iterate (property_s, target_desc->properties, ix, prop);
1630 1.1 christos ix++)
1631 1.1 christos if (strcmp (prop->key, key) == 0)
1632 1.1 christos internal_error (__FILE__, __LINE__,
1633 1.1 christos _("Attempted to add duplicate property \"%s\""), key);
1634 1.1 christos
1635 1.1 christos new_prop.key = xstrdup (key);
1636 1.1 christos new_prop.value = xstrdup (value);
1637 1.1 christos VEC_safe_push (property_s, target_desc->properties, &new_prop);
1638 1.1 christos }
1639 1.1 christos
1640 1.1 christos void
1641 1.1 christos set_tdesc_architecture (struct target_desc *target_desc,
1642 1.1 christos const struct bfd_arch_info *arch)
1643 1.1 christos {
1644 1.1 christos target_desc->arch = arch;
1645 1.1 christos }
1646 1.1 christos
1647 1.1 christos void
1648 1.1 christos set_tdesc_osabi (struct target_desc *target_desc, enum gdb_osabi osabi)
1649 1.1 christos {
1650 1.1 christos target_desc->osabi = osabi;
1651 1.1 christos }
1652 1.1 christos
1653 1.1 christos
1655 1.1 christos static struct cmd_list_element *tdesc_set_cmdlist, *tdesc_show_cmdlist;
1656 1.1 christos static struct cmd_list_element *tdesc_unset_cmdlist;
1657 1.1 christos
1658 1.3 christos /* Helper functions for the CLI commands. */
1659 1.1 christos
1660 1.1 christos static void
1661 1.1 christos set_tdesc_cmd (char *args, int from_tty)
1662 1.1 christos {
1663 1.1 christos help_list (tdesc_set_cmdlist, "set tdesc ", all_commands, gdb_stdout);
1664 1.1 christos }
1665 1.1 christos
1666 1.1 christos static void
1667 1.1 christos show_tdesc_cmd (char *args, int from_tty)
1668 1.1 christos {
1669 1.1 christos cmd_show_list (tdesc_show_cmdlist, from_tty, "");
1670 1.3 christos }
1671 1.1 christos
1672 1.1 christos static void
1673 1.1 christos unset_tdesc_cmd (char *args, int from_tty)
1674 1.1 christos {
1675 1.1 christos help_list (tdesc_unset_cmdlist, "unset tdesc ", all_commands, gdb_stdout);
1676 1.1 christos }
1677 1.1 christos
1678 1.1 christos static void
1679 1.1 christos set_tdesc_filename_cmd (char *args, int from_tty,
1680 1.1 christos struct cmd_list_element *c)
1681 1.1 christos {
1682 1.1 christos xfree (target_description_filename);
1683 1.1 christos target_description_filename = xstrdup (tdesc_filename_cmd_string);
1684 1.1 christos
1685 1.1 christos target_clear_description ();
1686 1.1 christos target_find_description ();
1687 1.1 christos }
1688 1.1 christos
1689 1.1 christos static void
1690 1.1 christos show_tdesc_filename_cmd (struct ui_file *file, int from_tty,
1691 1.1 christos struct cmd_list_element *c,
1692 1.1 christos const char *value)
1693 1.1 christos {
1694 1.1 christos value = target_description_filename;
1695 1.1 christos
1696 1.1 christos if (value != NULL && *value != '\0')
1697 1.1 christos printf_filtered (_("The target description will be read from \"%s\".\n"),
1698 1.1 christos value);
1699 1.1 christos else
1700 1.1 christos printf_filtered (_("The target description will be "
1701 1.1 christos "read from the target.\n"));
1702 1.1 christos }
1703 1.1 christos
1704 1.1 christos static void
1705 1.1 christos unset_tdesc_filename_cmd (char *args, int from_tty)
1706 1.1 christos {
1707 1.1 christos xfree (target_description_filename);
1708 1.1 christos target_description_filename = NULL;
1709 1.1 christos target_clear_description ();
1710 1.1 christos target_find_description ();
1711 1.1 christos }
1712 1.1 christos
1713 1.1 christos static void
1714 1.1 christos maint_print_c_tdesc_cmd (char *args, int from_tty)
1715 1.1 christos {
1716 1.1 christos const struct target_desc *tdesc;
1717 1.1 christos const struct bfd_arch_info *compatible;
1718 1.1 christos const char *filename, *inp;
1719 1.1 christos char *function, *outp;
1720 1.1 christos struct property *prop;
1721 1.1 christos struct tdesc_feature *feature;
1722 1.1 christos struct tdesc_reg *reg;
1723 1.1 christos struct tdesc_type *type;
1724 1.1 christos struct tdesc_type_field *f;
1725 1.1 christos int ix, ix2, ix3;
1726 1.1 christos int printed_field_type = 0;
1727 1.1 christos
1728 1.1 christos /* Use the global target-supplied description, not the current
1729 1.1 christos architecture's. This lets a GDB for one architecture generate C
1730 1.1 christos for another architecture's description, even though the gdbarch
1731 1.1 christos initialization code will reject the new description. */
1732 1.1 christos tdesc = current_target_desc;
1733 1.1 christos if (tdesc == NULL)
1734 1.1 christos error (_("There is no target description to print."));
1735 1.6 christos
1736 1.1 christos if (target_description_filename == NULL)
1737 1.1 christos error (_("The current target description did not come from an XML file."));
1738 1.1 christos
1739 1.1 christos filename = lbasename (target_description_filename);
1740 1.1 christos function = (char *) alloca (strlen (filename) + 1);
1741 1.1 christos for (inp = filename, outp = function; *inp != '\0'; inp++)
1742 1.1 christos if (*inp == '.')
1743 1.1 christos break;
1744 1.1 christos else if (*inp == '-')
1745 1.1 christos *outp++ = '_';
1746 1.1 christos else
1747 1.1 christos *outp++ = *inp;
1748 1.1 christos *outp = '\0';
1749 1.1 christos
1750 1.1 christos /* Standard boilerplate. */
1751 1.1 christos printf_unfiltered ("/* THIS FILE IS GENERATED. "
1752 1.1 christos "-*- buffer-read-only: t -*- vi"
1753 1.1 christos ":set ro:\n");
1754 1.1 christos printf_unfiltered (" Original: %s */\n\n", filename);
1755 1.1 christos printf_unfiltered ("#include \"defs.h\"\n");
1756 1.1 christos printf_unfiltered ("#include \"osabi.h\"\n");
1757 1.1 christos printf_unfiltered ("#include \"target-descriptions.h\"\n");
1758 1.1 christos printf_unfiltered ("\n");
1759 1.1 christos
1760 1.1 christos printf_unfiltered ("struct target_desc *tdesc_%s;\n", function);
1761 1.1 christos printf_unfiltered ("static void\n");
1762 1.1 christos printf_unfiltered ("initialize_tdesc_%s (void)\n", function);
1763 1.1 christos printf_unfiltered ("{\n");
1764 1.1 christos printf_unfiltered
1765 1.1 christos (" struct target_desc *result = allocate_target_description ();\n");
1766 1.1 christos printf_unfiltered (" struct tdesc_feature *feature;\n");
1767 1.1 christos
1768 1.1 christos /* Now we do some "filtering" in order to know which variables to
1769 1.1 christos declare. This is needed because otherwise we would declare unused
1770 1.1 christos variables `field_type' and `type'. */
1771 1.1 christos for (ix = 0;
1772 1.1 christos VEC_iterate (tdesc_feature_p, tdesc->features, ix, feature);
1773 1.1 christos ix++)
1774 1.1 christos {
1775 1.1 christos int printed_desc_type = 0;
1776 1.1 christos
1777 1.1 christos for (ix2 = 0;
1778 1.1 christos VEC_iterate (tdesc_type_p, feature->types, ix2, type);
1779 1.1 christos ix2++)
1780 1.1 christos {
1781 1.1 christos if (!printed_field_type)
1782 1.1 christos {
1783 1.6 christos printf_unfiltered (" struct tdesc_type *field_type;\n");
1784 1.6 christos printed_field_type = 1;
1785 1.6 christos }
1786 1.1 christos
1787 1.1 christos if ((type->kind == TDESC_TYPE_UNION
1788 1.1 christos || type->kind == TDESC_TYPE_STRUCT
1789 1.1 christos || type->kind == TDESC_TYPE_FLAGS
1790 1.1 christos || type->kind == TDESC_TYPE_ENUM)
1791 1.1 christos && VEC_length (tdesc_type_field, type->u.u.fields) > 0)
1792 1.1 christos {
1793 1.1 christos printf_unfiltered (" struct tdesc_type *type;\n");
1794 1.1 christos printed_desc_type = 1;
1795 1.1 christos break;
1796 1.1 christos }
1797 1.1 christos }
1798 1.1 christos
1799 1.1 christos if (printed_desc_type)
1800 1.1 christos break;
1801 1.1 christos }
1802 1.1 christos
1803 1.1 christos printf_unfiltered ("\n");
1804 1.1 christos
1805 1.1 christos if (tdesc_architecture (tdesc) != NULL)
1806 1.1 christos {
1807 1.1 christos printf_unfiltered
1808 1.1 christos (" set_tdesc_architecture (result, bfd_scan_arch (\"%s\"));\n",
1809 1.1 christos tdesc_architecture (tdesc)->printable_name);
1810 1.1 christos printf_unfiltered ("\n");
1811 1.1 christos }
1812 1.1 christos
1813 1.1 christos if (tdesc_osabi (tdesc) > GDB_OSABI_UNKNOWN
1814 1.1 christos && tdesc_osabi (tdesc) < GDB_OSABI_INVALID)
1815 1.1 christos {
1816 1.1 christos printf_unfiltered
1817 1.1 christos (" set_tdesc_osabi (result, osabi_from_tdesc_string (\"%s\"));\n",
1818 1.1 christos gdbarch_osabi_name (tdesc_osabi (tdesc)));
1819 1.1 christos printf_unfiltered ("\n");
1820 1.1 christos }
1821 1.1 christos
1822 1.1 christos for (ix = 0; VEC_iterate (arch_p, tdesc->compatible, ix, compatible);
1823 1.1 christos ix++)
1824 1.1 christos {
1825 1.1 christos printf_unfiltered
1826 1.1 christos (" tdesc_add_compatible (result, bfd_scan_arch (\"%s\"));\n",
1827 1.1 christos compatible->printable_name);
1828 1.1 christos }
1829 1.1 christos if (ix)
1830 1.1 christos printf_unfiltered ("\n");
1831 1.1 christos
1832 1.1 christos for (ix = 0; VEC_iterate (property_s, tdesc->properties, ix, prop);
1833 1.1 christos ix++)
1834 1.1 christos {
1835 1.1 christos printf_unfiltered (" set_tdesc_property (result, \"%s\", \"%s\");\n",
1836 1.1 christos prop->key, prop->value);
1837 1.1 christos }
1838 1.1 christos
1839 1.1 christos for (ix = 0;
1840 1.1 christos VEC_iterate (tdesc_feature_p, tdesc->features, ix, feature);
1841 1.1 christos ix++)
1842 1.1 christos {
1843 1.1 christos printf_unfiltered (" \
1844 1.1 christos feature = tdesc_create_feature (result, \"%s\");\n",
1845 1.1 christos feature->name);
1846 1.1 christos
1847 1.1 christos for (ix2 = 0;
1848 1.1 christos VEC_iterate (tdesc_type_p, feature->types, ix2, type);
1849 1.1 christos ix2++)
1850 1.1 christos {
1851 1.1 christos switch (type->kind)
1852 1.1 christos {
1853 1.1 christos case TDESC_TYPE_VECTOR:
1854 1.1 christos printf_unfiltered
1855 1.1 christos (" field_type = tdesc_named_type (feature, \"%s\");\n",
1856 1.1 christos type->u.v.type->name);
1857 1.6 christos printf_unfiltered
1858 1.6 christos (" tdesc_create_vector (feature, \"%s\", field_type, %d);\n",
1859 1.6 christos type->name, type->u.v.count);
1860 1.6 christos break;
1861 1.6 christos case TDESC_TYPE_STRUCT:
1862 1.6 christos case TDESC_TYPE_FLAGS:
1863 1.6 christos if (type->kind == TDESC_TYPE_STRUCT)
1864 1.6 christos {
1865 1.6 christos printf_unfiltered
1866 1.6 christos (" type = tdesc_create_struct (feature, \"%s\");\n",
1867 1.6 christos type->name);
1868 1.6 christos if (type->u.u.size != 0)
1869 1.6 christos printf_unfiltered
1870 1.6 christos (" tdesc_set_struct_size (type, %d);\n",
1871 1.6 christos type->u.u.size);
1872 1.6 christos }
1873 1.6 christos else
1874 1.1 christos {
1875 1.1 christos printf_unfiltered
1876 1.1 christos (" type = tdesc_create_flags (feature, \"%s\", %d);\n",
1877 1.1 christos type->name, type->u.u.size);
1878 1.6 christos }
1879 1.6 christos for (ix3 = 0;
1880 1.6 christos VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f);
1881 1.6 christos ix3++)
1882 1.6 christos {
1883 1.6 christos const char *type_name;
1884 1.6 christos
1885 1.6 christos gdb_assert (f->type != NULL);
1886 1.6 christos type_name = f->type->name;
1887 1.6 christos
1888 1.6 christos /* To minimize changes to generated files, don't emit type
1889 1.6 christos info for fields that have defaulted types. */
1890 1.6 christos if (f->start != -1)
1891 1.6 christos {
1892 1.6 christos gdb_assert (f->end != -1);
1893 1.6 christos if (f->type->kind == TDESC_TYPE_BOOL)
1894 1.6 christos {
1895 1.6 christos gdb_assert (f->start == f->end);
1896 1.6 christos printf_unfiltered
1897 1.6 christos (" tdesc_add_flag (type, %d, \"%s\");\n",
1898 1.6 christos f->start, f->name);
1899 1.6 christos }
1900 1.6 christos else if ((type->u.u.size == 4
1901 1.6 christos && f->type->kind == TDESC_TYPE_UINT32)
1902 1.6 christos || (type->u.u.size == 8
1903 1.6 christos && f->type->kind == TDESC_TYPE_UINT64))
1904 1.6 christos {
1905 1.6 christos printf_unfiltered
1906 1.6 christos (" tdesc_add_bitfield (type, \"%s\", %d, %d);\n",
1907 1.6 christos f->name, f->start, f->end);
1908 1.6 christos }
1909 1.6 christos else
1910 1.6 christos {
1911 1.6 christos printf_unfiltered
1912 1.6 christos (" field_type = tdesc_named_type (feature,"
1913 1.6 christos " \"%s\");\n",
1914 1.6 christos type_name);
1915 1.6 christos printf_unfiltered
1916 1.6 christos (" tdesc_add_typed_bitfield (type, \"%s\","
1917 1.1 christos " %d, %d, field_type);\n",
1918 1.6 christos f->name, f->start, f->end);
1919 1.6 christos }
1920 1.1 christos }
1921 1.6 christos else /* Not a bitfield. */
1922 1.6 christos {
1923 1.6 christos gdb_assert (f->end == -1);
1924 1.1 christos gdb_assert (type->kind == TDESC_TYPE_STRUCT);
1925 1.1 christos printf_unfiltered
1926 1.1 christos (" field_type = tdesc_named_type (feature,"
1927 1.1 christos " \"%s\");\n",
1928 1.1 christos type_name);
1929 1.1 christos printf_unfiltered
1930 1.1 christos (" tdesc_add_field (type, \"%s\", field_type);\n",
1931 1.1 christos f->name);
1932 1.1 christos }
1933 1.1 christos }
1934 1.1 christos break;
1935 1.1 christos case TDESC_TYPE_UNION:
1936 1.1 christos printf_unfiltered
1937 1.1 christos (" type = tdesc_create_union (feature, \"%s\");\n",
1938 1.1 christos type->name);
1939 1.1 christos for (ix3 = 0;
1940 1.1 christos VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f);
1941 1.1 christos ix3++)
1942 1.1 christos {
1943 1.1 christos printf_unfiltered
1944 1.1 christos (" field_type = tdesc_named_type (feature, \"%s\");\n",
1945 1.1 christos f->type->name);
1946 1.6 christos printf_unfiltered
1947 1.1 christos (" tdesc_add_field (type, \"%s\", field_type);\n",
1948 1.6 christos f->name);
1949 1.6 christos }
1950 1.1 christos break;
1951 1.6 christos case TDESC_TYPE_ENUM:
1952 1.1 christos printf_unfiltered
1953 1.1 christos (" type = tdesc_create_enum (feature, \"%s\", %d);\n",
1954 1.6 christos type->name, type->u.u.size);
1955 1.6 christos for (ix3 = 0;
1956 1.1 christos VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f);
1957 1.1 christos ix3++)
1958 1.1 christos printf_unfiltered
1959 1.1 christos (" tdesc_add_enum_value (type, %d, \"%s\");\n",
1960 1.1 christos f->start, f->name);
1961 1.1 christos break;
1962 1.1 christos default:
1963 1.1 christos error (_("C output is not supported type \"%s\"."), type->name);
1964 1.1 christos }
1965 1.1 christos printf_unfiltered ("\n");
1966 1.1 christos }
1967 1.1 christos
1968 1.1 christos for (ix2 = 0;
1969 1.1 christos VEC_iterate (tdesc_reg_p, feature->registers, ix2, reg);
1970 1.1 christos ix2++)
1971 1.1 christos {
1972 1.1 christos printf_unfiltered (" tdesc_create_reg (feature, \"%s\", %ld, %d, ",
1973 1.1 christos reg->name, reg->target_regnum, reg->save_restore);
1974 1.1 christos if (reg->group)
1975 1.1 christos printf_unfiltered ("\"%s\", ", reg->group);
1976 1.1 christos else
1977 1.1 christos printf_unfiltered ("NULL, ");
1978 1.1 christos printf_unfiltered ("%d, \"%s\");\n", reg->bitsize, reg->type);
1979 1.1 christos }
1980 1.1 christos
1981 1.1 christos printf_unfiltered ("\n");
1982 1.1 christos }
1983 1.1 christos
1984 1.1 christos printf_unfiltered (" tdesc_%s = result;\n", function);
1985 1.1 christos printf_unfiltered ("}\n");
1986 1.1 christos }
1987 1.1 christos
1988 1.1 christos /* Provide a prototype to silence -Wmissing-prototypes. */
1989 1.1 christos extern initialize_file_ftype _initialize_target_descriptions;
1990 1.1 christos
1991 1.1 christos void
1992 1.1 christos _initialize_target_descriptions (void)
1993 1.1 christos {
1994 1.1 christos tdesc_data = gdbarch_data_register_pre_init (tdesc_data_init);
1995 1.1 christos
1996 1.1 christos add_prefix_cmd ("tdesc", class_maintenance, set_tdesc_cmd, _("\
1997 1.1 christos Set target description specific variables."),
1998 1.1 christos &tdesc_set_cmdlist, "set tdesc ",
1999 1.1 christos 0 /* allow-unknown */, &setlist);
2000 1.1 christos add_prefix_cmd ("tdesc", class_maintenance, show_tdesc_cmd, _("\
2001 1.1 christos Show target description specific variables."),
2002 1.1 christos &tdesc_show_cmdlist, "show tdesc ",
2003 1.1 christos 0 /* allow-unknown */, &showlist);
2004 1.1 christos add_prefix_cmd ("tdesc", class_maintenance, unset_tdesc_cmd, _("\
2005 1.1 christos Unset target description specific variables."),
2006 1.1 christos &tdesc_unset_cmdlist, "unset tdesc ",
2007 1.1 christos 0 /* allow-unknown */, &unsetlist);
2008 1.1 christos
2009 1.1 christos add_setshow_filename_cmd ("filename", class_obscure,
2010 1.1 christos &tdesc_filename_cmd_string,
2011 1.1 christos _("\
2012 1.1 christos Set the file to read for an XML target description"), _("\
2013 1.1 christos Show the file to read for an XML target description"), _("\
2014 1.1 christos When set, GDB will read the target description from a local\n\
2015 1.1 christos file instead of querying the remote target."),
2016 1.1 christos set_tdesc_filename_cmd,
2017 1.1 christos show_tdesc_filename_cmd,
2018 1.1 christos &tdesc_set_cmdlist, &tdesc_show_cmdlist);
2019 1.1 christos
2020 1.1 christos add_cmd ("filename", class_obscure, unset_tdesc_filename_cmd, _("\
2021 1.1 christos Unset the file to read for an XML target description. When unset,\n\
2022 1.1 christos GDB will read the description from the target."),
2023 1.1 christos &tdesc_unset_cmdlist);
2024
2025 add_cmd ("c-tdesc", class_maintenance, maint_print_c_tdesc_cmd, _("\
2026 Print the current target description as a C source file."),
2027 &maintenanceprintlist);
2028 }
2029