diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2019-04-09 23:06:41 +0100 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2019-04-29 22:01:08 +0100 |
commit | 4be290b2517839872ef7de47230be8dbd291a7e5 (patch) | |
tree | 67bf7edccf42c7d295af015c818bc7e80ead3a31 /gdb/rust-lang.c | |
parent | gdb: Introduce new language field la_struct_too_deep_ellipsis (diff) | |
download | binutils-gdb-4be290b2517839872ef7de47230be8dbd291a7e5.tar.gz binutils-gdb-4be290b2517839872ef7de47230be8dbd291a7e5.tar.bz2 binutils-gdb-4be290b2517839872ef7de47230be8dbd291a7e5.zip |
gdb: Introduce new language field la_is_string_type_p
This commit is preparation work for the next commit, and by itself
makes no user visible change to GDB. I've split this work into a
separate commit in order to make code review easier.
This commit adds a new field 'la_is_string_type_p' to the language
struct, this predicate will return true if a type is a string type for
the given language.
Some languages already have a "is this a string" predicate that I was
able to reuse, while for other languages I've had to add a new
predicate. In this case I took inspiration from the value printing
code for that language - what different conditions would result in
printing something as a string.
A default "is this a string" method has also been added that looks for
TYPE_CODE_STRING, this is the fallback I've used for a couple of
languages.
In this commit I add the new field and initialise it for each
language, however at this stage the new field is never used.
gdb/ChangeLog:
* ada-lang.c (ada_language_defn): Initialise new field.
* c-lang.c (c_is_string_type_p): New function.
(c_language_defn): Initialise new field.
(cplus_language_defn): Initialise new field.
(asm_language_defn): Initialise new field.
(minimal_language_defn): Initialise new field.
* c-lang.h (c_is_string_type_p): Declare new function.
* d-lang.c (d_language_defn): Initialise new field.
* f-lang.c (f_is_string_type_p): New function.
(f_language_defn): Initialise new field.
* go-lang.c (go_is_string_type_p): New function.
(go_language_defn): Initialise new field.
* language.c (default_is_string_type_p): New function.
(unknown_language_defn): Initialise new field.
(auto_language_defn): Initialise new field.
* language.h (struct language_defn) <la_is_string_type_p>: New
member variable.
(default_is_string_type_p): Declare new function.
* m2-lang.c (m2_language_defn): Initialise new field.
* objc-lang.c (objc_language_defn): Initialise new field.
* opencl-lang.c (opencl_language_defn): Initialise new field.
* p-lang.c (pascal_is_string_type_p): New function.
(pascal_language_defn): Initialise new field.
* rust-lang.c (rust_is_string_type_p): New function.
(rust_language_defn): Initialise new field.
Diffstat (limited to 'gdb/rust-lang.c')
-rw-r--r-- | gdb/rust-lang.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index 8faafd49cdd..2fada465d65 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -226,6 +226,26 @@ rust_chartype_p (struct type *type) && TYPE_UNSIGNED (type)); } +/* Return true if TYPE is a string type. */ + +static bool +rust_is_string_type_p (struct type *type) +{ + LONGEST low_bound, high_bound; + + type = check_typedef (type); + return ((TYPE_CODE (type) == TYPE_CODE_STRING) + || (TYPE_CODE (type) == TYPE_CODE_PTR + && (TYPE_CODE (TYPE_TARGET_TYPE (type)) == TYPE_CODE_ARRAY + && rust_u8_type_p (TYPE_TARGET_TYPE (TYPE_TARGET_TYPE (type))) + && get_array_bounds (TYPE_TARGET_TYPE (type), &low_bound, + &high_bound))) + || (TYPE_CODE (type) == TYPE_CODE_STRUCT + && !rust_enum_p (type) + && rust_slice_type_p (type) + && strcmp (TYPE_NAME (type), "&str") == 0)); +} + /* If VALUE represents a trait object pointer, return the underlying pointer with the correct (i.e., runtime) type. Otherwise, return NULL. */ @@ -2142,5 +2162,6 @@ extern const struct language_defn rust_language_defn = &default_varobj_ops, NULL, NULL, + rust_is_string_type_p, "{...}" /* la_struct_too_deep_ellipsis */ }; |