1 /* Copyright (C) 2006-2024 Free Software Foundation, Inc.
3 This file is part of GDB.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 #ifndef COMMON_TDESC_H
19 #define COMMON_TDESC_H
21 #include "gdbsupport/osabi.h"
25 struct tdesc_type_builtin
;
26 struct tdesc_type_vector
;
27 struct tdesc_type_with_fields
;
31 /* The interface to visit different elements of target description. */
33 class tdesc_element_visitor
36 virtual void visit_pre (const target_desc
*e
)
39 virtual void visit_post (const target_desc
*e
)
42 virtual void visit_pre (const tdesc_feature
*e
)
45 virtual void visit_post (const tdesc_feature
*e
)
48 virtual void visit (const tdesc_type_builtin
*e
)
51 virtual void visit (const tdesc_type_vector
*e
)
54 virtual void visit (const tdesc_type_with_fields
*e
)
57 virtual void visit (const tdesc_reg
*e
)
64 virtual void accept (tdesc_element_visitor
&v
) const = 0;
67 /* An individual register from a target description. */
69 struct tdesc_reg
: tdesc_element
71 tdesc_reg (struct tdesc_feature
*feature
, const std::string
&name_
,
72 int regnum
, int save_restore_
, const char *group_
,
73 int bitsize_
, const char *type_
);
75 virtual ~tdesc_reg () = default;
77 DISABLE_COPY_AND_ASSIGN (tdesc_reg
);
79 /* The name of this register. In standard features, it may be
80 recognized by the architecture support code, or it may be purely
84 /* The register number used by this target to refer to this
85 register. This is used for remote p/P packets and to determine
86 the ordering of registers in the remote g/G packets. */
89 /* If this flag is set, GDB should save and restore this register
90 around calls to an inferior function. */
93 /* The name of the register group containing this register, or empty
94 if the group should be automatically determined from the
95 register's type. If this is "general", "float", or "vector", the
96 corresponding "info" command should display this register's
97 value. It can be an arbitrary string, but should be limited to
98 alphanumeric characters and internal hyphens. Currently other
99 strings are ignored (treated as empty). */
102 /* The size of the register, in bits. */
105 /* The type of the register. This string corresponds to either
106 a named type from the target description or a predefined
110 /* The target-described type corresponding to TYPE, if found. */
111 struct tdesc_type
*tdesc_type
;
113 void accept (tdesc_element_visitor
&v
) const override
118 bool operator== (const tdesc_reg
&other
) const
120 return (name
== other
.name
121 && target_regnum
== other
.target_regnum
122 && save_restore
== other
.save_restore
123 && bitsize
== other
.bitsize
124 && group
== other
.group
125 && type
== other
.type
);
128 bool operator!= (const tdesc_reg
&other
) const
130 return !(*this == other
);
134 typedef std::unique_ptr
<tdesc_reg
> tdesc_reg_up
;
136 /* Declaration of a structure that holds information about one
137 "compatibility" entry within a target description. */
139 struct tdesc_compatible_info
;
141 /* A pointer to a single piece of compatibility information. */
143 typedef std::unique_ptr
<tdesc_compatible_info
> tdesc_compatible_info_up
;
145 /* Return a vector of compatibility information pointers from the target
146 description TARGET_DESC. */
148 const std::vector
<tdesc_compatible_info_up
> &tdesc_compatible_info_list
149 (const target_desc
*target_desc
);
151 /* Return the architecture name from a compatibility information
154 const char *tdesc_compatible_info_arch_name
155 (const tdesc_compatible_info_up
&compatible
);
159 /* Predefined types. */
173 TDESC_TYPE_IEEE_HALF
,
174 TDESC_TYPE_IEEE_SINGLE
,
175 TDESC_TYPE_IEEE_DOUBLE
,
176 TDESC_TYPE_ARM_FPA_EXT
,
180 /* Types defined by a target feature. */
188 struct tdesc_type
: tdesc_element
190 tdesc_type (const std::string
&name_
, enum tdesc_type_kind kind_
)
191 : name (name_
), kind (kind_
)
194 virtual ~tdesc_type () = default;
196 DISABLE_COPY_AND_ASSIGN (tdesc_type
);
198 /* The name of this type. */
201 /* Identify the kind of this type. */
202 enum tdesc_type_kind kind
;
204 bool operator== (const tdesc_type
&other
) const
206 return name
== other
.name
&& kind
== other
.kind
;
209 bool operator!= (const tdesc_type
&other
) const
211 return !(*this == other
);
215 typedef std::unique_ptr
<tdesc_type
> tdesc_type_up
;
217 struct tdesc_type_builtin
: tdesc_type
219 tdesc_type_builtin (const std::string
&name
, enum tdesc_type_kind kind
)
220 : tdesc_type (name
, kind
)
223 void accept (tdesc_element_visitor
&v
) const override
229 /* tdesc_type for vector types. */
231 struct tdesc_type_vector
: tdesc_type
233 tdesc_type_vector (const std::string
&name
, tdesc_type
*element_type_
,
235 : tdesc_type (name
, TDESC_TYPE_VECTOR
),
236 element_type (element_type_
), count (count_
)
239 void accept (tdesc_element_visitor
&v
) const override
244 struct tdesc_type
*element_type
;
248 /* A named type from a target description. */
250 struct tdesc_type_field
252 tdesc_type_field (const std::string
&name_
, tdesc_type
*type_
,
253 int start_
, int end_
)
254 : name (name_
), type (type_
), start (start_
), end (end_
)
258 struct tdesc_type
*type
;
259 /* For non-enum-values, either both are -1 (non-bitfield), or both are
260 not -1 (bitfield). For enum values, start is the value (which could be
265 /* tdesc_type for struct, union, flags, and enum types. */
267 struct tdesc_type_with_fields
: tdesc_type
269 tdesc_type_with_fields (const std::string
&name
, tdesc_type_kind kind
,
271 : tdesc_type (name
, kind
), size (size_
)
274 void accept (tdesc_element_visitor
&v
) const override
279 std::vector
<tdesc_type_field
> fields
;
283 /* A feature from a target description. Each feature is a collection
284 of other elements, e.g. registers and types. */
286 struct tdesc_feature
: tdesc_element
288 tdesc_feature (const std::string
&name_
)
292 virtual ~tdesc_feature () = default;
294 DISABLE_COPY_AND_ASSIGN (tdesc_feature
);
296 /* The name of this feature. It may be recognized by the architecture
300 /* The registers associated with this feature. */
301 std::vector
<tdesc_reg_up
> registers
;
303 /* The types associated with this feature. */
304 std::vector
<tdesc_type_up
> types
;
306 void accept (tdesc_element_visitor
&v
) const override
;
308 bool operator== (const tdesc_feature
&other
) const;
310 bool operator!= (const tdesc_feature
&other
) const
312 return !(*this == other
);
316 typedef std::unique_ptr
<tdesc_feature
> tdesc_feature_up
;
318 /* A deleter adapter for a target_desc. There are different
319 implementations of this deleter class in gdb and gdbserver because even
320 though the target_desc name is shared between the two projects, the
321 actual implementations of target_desc are completely different. */
323 struct target_desc_deleter
325 void operator() (struct target_desc
*desc
) const;
328 /* A unique pointer specialization that holds a target_desc. */
330 typedef std::unique_ptr
<target_desc
, target_desc_deleter
> target_desc_up
;
332 /* Allocate a new target_desc. */
333 target_desc_up
allocate_target_description (void);
335 /* Set TARGET_DESC's architecture by NAME. */
336 void set_tdesc_architecture (target_desc
*target_desc
,
339 /* Return the architecture associated with this target description as a string,
340 or NULL if no architecture was specified. */
341 const char *tdesc_architecture_name (const struct target_desc
*target_desc
);
343 /* Set TARGET_DESC's osabi to OSABI. */
344 void set_tdesc_osabi (target_desc
*target_desc
, enum gdb_osabi osabi
);
346 /* Return the osabi associated with this target description as a string,
347 or NULL if no osabi was specified. */
348 const char *tdesc_osabi_name (const struct target_desc
*target_desc
);
350 /* Return the type associated with ID in the context of FEATURE, or
352 struct tdesc_type
*tdesc_named_type (const struct tdesc_feature
*feature
,
355 /* Return the created feature named NAME in target description TDESC. */
356 struct tdesc_feature
*tdesc_create_feature (struct target_desc
*tdesc
,
359 /* Return the created vector tdesc_type named NAME in FEATURE. */
360 struct tdesc_type
*tdesc_create_vector (struct tdesc_feature
*feature
,
362 struct tdesc_type
*field_type
,
365 /* Return the created struct tdesc_type named NAME in FEATURE. */
366 tdesc_type_with_fields
*tdesc_create_struct (struct tdesc_feature
*feature
,
369 /* Return the created union tdesc_type named NAME in FEATURE. */
370 tdesc_type_with_fields
*tdesc_create_union (struct tdesc_feature
*feature
,
373 /* Return the created flags tdesc_type named NAME in FEATURE. */
374 tdesc_type_with_fields
*tdesc_create_flags (struct tdesc_feature
*feature
,
378 /* Return the created enum tdesc_type named NAME in FEATURE. */
379 tdesc_type_with_fields
*tdesc_create_enum (struct tdesc_feature
*feature
,
383 /* Add a new field to TYPE. FIELD_NAME is its name, and FIELD_TYPE is
385 void tdesc_add_field (tdesc_type_with_fields
*type
, const char *field_name
,
386 struct tdesc_type
*field_type
);
388 /* Add a new bitfield to TYPE, with range START to END. FIELD_NAME is its name,
389 and FIELD_TYPE is its type. */
390 void tdesc_add_typed_bitfield (tdesc_type_with_fields
*type
,
391 const char *field_name
,
393 struct tdesc_type
*field_type
);
395 /* Set the total length of TYPE. Structs which contain bitfields may
396 omit the reserved bits, so the end of the last field may not
398 void tdesc_set_struct_size (tdesc_type_with_fields
*type
, int size
);
400 /* Add a new untyped bitfield to TYPE.
401 Untyped bitfields become either uint32 or uint64 depending on the size
402 of the underlying type. */
403 void tdesc_add_bitfield (tdesc_type_with_fields
*type
, const char *field_name
,
406 /* A flag is just a typed(bool) single-bit bitfield.
407 This function is kept to minimize changes in generated files. */
408 void tdesc_add_flag (tdesc_type_with_fields
*type
, int start
,
409 const char *flag_name
);
411 /* Add field with VALUE and NAME to the enum TYPE. */
412 void tdesc_add_enum_value (tdesc_type_with_fields
*type
, int value
,
415 /* Create a register in feature FEATURE. */
416 void tdesc_create_reg (struct tdesc_feature
*feature
, const char *name
,
417 int regnum
, int save_restore
, const char *group
,
418 int bitsize
, const char *type
);
420 /* Return the tdesc in string XML format. */
422 const char *tdesc_get_features_xml (const target_desc
*tdesc
);
424 /* Print target description as xml. */
426 class print_xml_feature
: public tdesc_element_visitor
429 print_xml_feature (std::string
*buffer_
)
430 : m_buffer (buffer_
),
434 void visit_pre (const target_desc
*e
) override
;
435 void visit_post (const target_desc
*e
) override
;
436 void visit_pre (const tdesc_feature
*e
) override
;
437 void visit_post (const tdesc_feature
*e
) override
;
438 void visit (const tdesc_type_builtin
*type
) override
;
439 void visit (const tdesc_type_vector
*type
) override
;
440 void visit (const tdesc_type_with_fields
*type
) override
;
441 void visit (const tdesc_reg
*reg
) override
;
445 /* Called with a positive value of ADJUST when we move inside an element,
446 for example inside <target>, and with a negative value when we leave
447 the element. In this class this function does nothing, but a
448 sub-class can override this to track the current level of nesting. */
449 void indent (int adjust
)
451 m_depth
+= (adjust
* 2);
454 /* Functions to add lines to the output buffer M_BUFFER. Each of these
455 functions appends a newline, so don't include one in the strings being
457 void add_line (const std::string
&str
);
458 void add_line (const char *fmt
, ...) ATTRIBUTE_PRINTF (2, 3);
460 /* The buffer we are writing too. */
461 std::string
*m_buffer
;
463 /* The current indentation depth. */
467 #endif /* COMMON_TDESC_H */