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.
This commit is contained in:
parent
721b08c686
commit
4be290b251
14 changed files with 177 additions and 0 deletions
40
gdb/c-lang.c
40
gdb/c-lang.c
|
@ -715,6 +715,42 @@ c_watch_location_expression (struct type *type, CORE_ADDR addr)
|
|||
(xstrprintf ("* (%s *) %s", name.c_str (), core_addr_to_string (addr)));
|
||||
}
|
||||
|
||||
/* See c-lang.h. */
|
||||
|
||||
bool
|
||||
c_is_string_type_p (struct type *type)
|
||||
{
|
||||
type = check_typedef (type);
|
||||
while (TYPE_CODE (type) == TYPE_CODE_REF)
|
||||
{
|
||||
type = TYPE_TARGET_TYPE (type);
|
||||
type = check_typedef (type);
|
||||
}
|
||||
|
||||
switch (TYPE_CODE (type))
|
||||
{
|
||||
case TYPE_CODE_ARRAY:
|
||||
{
|
||||
/* See if target type looks like a string. */
|
||||
struct type *array_target_type = TYPE_TARGET_TYPE (type);
|
||||
return (TYPE_LENGTH (type) > 0
|
||||
&& TYPE_LENGTH (array_target_type) > 0
|
||||
&& c_textual_element_type (array_target_type, 0));
|
||||
}
|
||||
case TYPE_CODE_STRING:
|
||||
return true;
|
||||
case TYPE_CODE_PTR:
|
||||
{
|
||||
struct type *element_type = TYPE_TARGET_TYPE (type);
|
||||
return c_textual_element_type (element_type, 0);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/* Table mapping opcodes into strings for printing operators
|
||||
and precedences of the operators. */
|
||||
|
@ -874,6 +910,7 @@ extern const struct language_defn c_language_defn =
|
|||
&c_varobj_ops,
|
||||
c_get_compile_context,
|
||||
c_compute_program,
|
||||
c_is_string_type_p,
|
||||
"{...}" /* la_struct_too_deep_ellipsis */
|
||||
};
|
||||
|
||||
|
@ -1019,6 +1056,7 @@ extern const struct language_defn cplus_language_defn =
|
|||
&cplus_varobj_ops,
|
||||
cplus_get_compile_context,
|
||||
cplus_compute_program,
|
||||
c_is_string_type_p,
|
||||
"{...}" /* la_struct_too_deep_ellipsis */
|
||||
};
|
||||
|
||||
|
@ -1073,6 +1111,7 @@ extern const struct language_defn asm_language_defn =
|
|||
&default_varobj_ops,
|
||||
NULL,
|
||||
NULL,
|
||||
c_is_string_type_p,
|
||||
"{...}" /* la_struct_too_deep_ellipsis */
|
||||
};
|
||||
|
||||
|
@ -1127,5 +1166,6 @@ extern const struct language_defn minimal_language_defn =
|
|||
&default_varobj_ops,
|
||||
NULL,
|
||||
NULL,
|
||||
c_is_string_type_p,
|
||||
"{...}" /* la_struct_too_deep_ellipsis */
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue