diff options
author | Alan Hayward <alan.hayward@arm.com> | 2018-04-18 11:47:55 +0100 |
---|---|---|
committer | Alan Hayward <alan.hayward@arm.com> | 2018-04-18 14:00:39 +0100 |
commit | eee8a18dd2d4b62ed5e03324b099508717886193 (patch) | |
tree | 93d3506d470207104d420559f8f751243b2b1859 /gdb/common/tdesc.h | |
parent | 82ec9bc7055ca76f1f7dd344f3f58bf6aecec7c8 (diff) | |
download | binutils-eee8a18dd2d4b62ed5e03324b099508717886193.zip binutils-eee8a18dd2d4b62ed5e03324b099508717886193.tar.gz binutils-eee8a18dd2d4b62ed5e03324b099508717886193.tar.bz2 |
Commonise tdesc types and makes use of them in gdbserver tdesc
gdb/
* common/tdesc.c (tdesc_predefined_type): Move to here.
(tdesc_named_type): Likewise.
(tdesc_create_vector): Likewise.
(tdesc_create_struct): Likewise.
(tdesc_set_struct_size): Likewise.
(tdesc_create_union): Likewise.
(tdesc_create_flags): Likewise.
(tdesc_create_enum): Likewise.
(tdesc_add_field): Likewise.
(tdesc_add_typed_bitfield): Likewise.
(tdesc_add_bitfield): Likewise.
(tdesc_add_flag): Likewise.
(tdesc_add_enum_value): Likewise.
* common/tdesc.h (struct tdesc_type_builtin): Likewise.
(struct tdesc_type_vector): Likewise.
(struct tdesc_type_field): Likewise.
(struct tdesc_type_with_fields): Likewise.
(tdesc_create_enum): Add declaration.
(tdesc_add_typed_bitfield): Likewise.
(tdesc_add_enum_value): Likewise.
* target-descriptions.c (tdesc_type_field): Move from here.
(tdesc_type_builtin): Likewise.
(tdesc_type_vector): Likewise.
(tdesc_type_with_fields): Likewise.
(tdesc_predefined_types): Likewise.
(tdesc_named_type): Likewise.
(tdesc_create_vector): Likewise.
(tdesc_create_struct): Likewise.
(tdesc_set_struct_size): Likewise.
(tdesc_create_union): Likewise.
(tdesc_create_flags): Likewise.
(tdesc_create_enum): Likewise.
(tdesc_add_field): Likewise.
(tdesc_add_typed_bitfield): Likewise.
(tdesc_add_bitfield): Likewise.
(tdesc_add_flag): Likewise.
(tdesc_add_enum_value): Likewise.
* gdb/target-descriptions.h (tdesc_create_enum): Likewise.
(tdesc_add_typed_bitfield): Likewise.
(tdesc_add_enum_value): Likewise.
gdbserver/
* tdesc.c (tdesc_create_flags): Remove.
(tdesc_add_flag): Likewise.
(tdesc_named_type): Likewise.
(tdesc_create_union): Likewise.
(tdesc_create_struct): Likewise.
(tdesc_create_vector): Likewise.
(tdesc_add_bitfield): Likewise.
(tdesc_add_field): Likewise.
(tdesc_set_struct_size): Likewise.
Diffstat (limited to 'gdb/common/tdesc.h')
-rw-r--r-- | gdb/common/tdesc.h | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/gdb/common/tdesc.h b/gdb/common/tdesc.h index b501dfa..7f4222b 100644 --- a/gdb/common/tdesc.h +++ b/gdb/common/tdesc.h @@ -189,6 +189,72 @@ struct tdesc_type : tdesc_element typedef std::unique_ptr<tdesc_type> tdesc_type_up; +struct tdesc_type_builtin : tdesc_type +{ + tdesc_type_builtin (const std::string &name, enum tdesc_type_kind kind) + : tdesc_type (name, kind) + {} + + void accept (tdesc_element_visitor &v) const override + { + v.visit (this); + } +}; + +/* tdesc_type for vector types. */ + +struct tdesc_type_vector : tdesc_type +{ + tdesc_type_vector (const std::string &name, tdesc_type *element_type_, + int count_) + : tdesc_type (name, TDESC_TYPE_VECTOR), + element_type (element_type_), count (count_) + {} + + void accept (tdesc_element_visitor &v) const override + { + v.visit (this); + } + + struct tdesc_type *element_type; + int count; +}; + +/* A named type from a target description. */ + +struct tdesc_type_field +{ + tdesc_type_field (const std::string &name_, tdesc_type *type_, + int start_, int end_) + : name (name_), type (type_), start (start_), end (end_) + {} + + std::string name; + struct tdesc_type *type; + /* For non-enum-values, either both are -1 (non-bitfield), or both are + not -1 (bitfield). For enum values, start is the value (which could be + -1), end is -1. */ + int start, end; +}; + +/* tdesc_type for struct, union, flags, and enum types. */ + +struct tdesc_type_with_fields : tdesc_type +{ + tdesc_type_with_fields (const std::string &name, tdesc_type_kind kind, + int size_ = 0) + : tdesc_type (name, kind), size (size_) + {} + + void accept (tdesc_element_visitor &v) const override + { + v.visit (this); + } + + std::vector<tdesc_type_field> fields; + int size; +}; + /* A feature from a target description. Each feature is a collection of other elements, e.g. registers and types. */ @@ -264,11 +330,23 @@ tdesc_type_with_fields *tdesc_create_flags (struct tdesc_feature *feature, const char *name, int size); +/* Return the created enum tdesc_type named NAME in FEATURE. */ +tdesc_type_with_fields *tdesc_create_enum (struct tdesc_feature *feature, + const char *name, + int size); + /* Add a new field to TYPE. FIELD_NAME is its name, and FIELD_TYPE is its type. */ void tdesc_add_field (tdesc_type_with_fields *type, const char *field_name, struct tdesc_type *field_type); +/* Add a new bitfield to TYPE, with range START to END. FIELD_NAME is its name, + and FIELD_TYPE is its type. */ +void tdesc_add_typed_bitfield (tdesc_type_with_fields *type, + const char *field_name, + int start, int end, + struct tdesc_type *field_type); + /* Set the total length of TYPE. Structs which contain bitfields may omit the reserved bits, so the end of the last field may not suffice. */ @@ -285,6 +363,10 @@ void tdesc_add_bitfield (tdesc_type_with_fields *type, const char *field_name, void tdesc_add_flag (tdesc_type_with_fields *type, int start, const char *flag_name); +/* Add field with VALUE and NAME to the enum TYPE. */ +void tdesc_add_enum_value (tdesc_type_with_fields *type, int value, + const char *name); + /* Create a register in feature FEATURE. */ void tdesc_create_reg (struct tdesc_feature *feature, const char *name, int regnum, int save_restore, const char *group, |