From 7bea47f0012c208d935c50d3b7ce9af7d34482b7 Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Fri, 30 Oct 2020 20:40:59 +0000 Subject: [PATCH] gdb: rewrite how per language primitive types are managed Consider the following GDB session: $ gdb (gdb) set language c (gdb) ptype void type = void (gdb) set language fortran (gdb) ptype void No symbol table is loaded. Use the "file" command. (gdb) With no symbol file loaded GDB and the language set to C GDB knows about the type void, while when the language is set to Fortran GDB doesn't know about the void, why is that? In f-lang.c, f_language::language_arch_info, we do have this line: lai->primitive_type_vector [f_primitive_type_void] = builtin->builtin_void; where we add the void type to the list of primitive types that GDB should always know about, so what's going wrong? It turns out that the primitive types are stored in a C style array, indexed by an enum, so Fortran uses `enum f_primitive_types'. The array is allocated and populated in each languages language_arch_info member function. The array is allocated with an extra entry at the end which is left as a NULL value, and this indicates the end of the array of types. Unfortunately for Fortran, a type is not assigned for each element in the enum. As a result the final populated array has gaps in it, gaps which are initialised to NULL, and so every time we iterate over the list (for Fortran) we stop early, and never reach the void type. This has been the case since 2007 when this functionality was added to GDB in commit cad351d11d6c3f6487cd. Obviously I could just fix Fortran by ensuring that either the enum is trimmed, or we create types for the missing types. However, I think a better approach would be to move to C++ data structures and removed the fixed enum indexing into the array approach. After this commit the primitive types are pushed into a vector, and GDB just iterates over the vector in the obvious way when it needs to hunt for a type. After this commit all the currently defined primitive types can be found when the language is set to Fortran, for example: $ gdb (gdb) set language fortran (gdb) ptype void type = void (gdb) A new test checks this functionality. I didn't see any other languages with similar issues, but I could have missed something. gdb/ChangeLog: * ada-exp.y (find_primitive_type): Make parameter const. * ada-lang.c (enum ada_primitive_types): Delete. (ada_language::language_arch_info): Update. * c-lang.c (enum c_primitive_types): Delete. (c_language_arch_info): Update. (enum cplus_primitive_types): Delete. (cplus_language::language_arch_info): Update. * d-lang.c (enum d_primitive_types): Delete. (d_language::language_arch_info): Update. * f-lang.c (enum f_primitive_types): Delete. (f_language::language_arch_info): Update. * go-lang.c (enum go_primitive_types): Delete. (go_language::language_arch_info): Update. * language.c (auto_or_unknown_language::language_arch_info): Update. (language_gdbarch_post_init): Use obstack_new, use array indexing. (language_string_char_type): Add header comment, call function in language_arch_info. (language_bool_type): Likewise (language_arch_info::bool_type): Define. (language_lookup_primitive_type_1): Delete. (language_lookup_primitive_type): Rewrite as a templated function to call function in language_arch_info, then instantiate twice. (language_arch_info::type_and_symbol::alloc_type_symbol): Define. (language_arch_info::lookup_primitive_type_and_symbol): Define. (language_arch_info::lookup_primitive_type): Define twice with different signatures. (language_arch_info::lookup_primitive_type_as_symbol): Define. (language_lookup_primitive_type_as_symbol): Rewrite to call a member function in language_arch_info. * language.h (language_arch_info): Complete rewrite. (language_lookup_primitive_type): Make templated. * m2-lang.c (enum m2_primitive_types): Delete. (m2_language::language_arch_info): Update. * opencl-lang.c (OCL_P_TYPE): Delete. (enum opencl_primitive_types): Delete. (opencl_type_data): Delete. (builtin_opencl_type): Delete. (lookup_opencl_vector_type): Update. (opencl_language::language_arch_info): Update, lots of content moved from... (build_opencl_types): ...here. This function is now deleted. (_initialize_opencl_language): Delete. * p-lang.c (enum pascal_primitive_types): Delete. (pascal_language::language_arch_info): Update. * rust-lang.c (enum rust_primitive_types): Delete. (rust_language::language_arch_info): Update. gdb/testsuite/ChangeLog: * gdb.fortran/types.exp: Add more tests. --- gdb/ChangeLog | 50 ++++++ gdb/ada-exp.y | 2 +- gdb/ada-lang.c | 106 +++++------- gdb/c-lang.c | 194 +++++++--------------- gdb/d-lang.c | 119 ++++---------- gdb/f-lang.c | 66 +++----- gdb/go-lang.c | 95 ++++------- gdb/language.c | 205 +++++++++++------------ gdb/language.h | 143 ++++++++++++++-- gdb/m2-lang.c | 42 ++--- gdb/opencl-lang.c | 244 +++++++++------------------- gdb/p-lang.c | 87 +++------- gdb/rust-lang.c | 78 ++++----- gdb/testsuite/ChangeLog | 4 + gdb/testsuite/gdb.fortran/types.exp | 11 ++ 15 files changed, 630 insertions(+), 816 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index abcd02bd170..4ab418396f6 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,53 @@ +2020-11-12 Andrew Burgess + + * ada-exp.y (find_primitive_type): Make parameter const. + * ada-lang.c (enum ada_primitive_types): Delete. + (ada_language::language_arch_info): Update. + * c-lang.c (enum c_primitive_types): Delete. + (c_language_arch_info): Update. + (enum cplus_primitive_types): Delete. + (cplus_language::language_arch_info): Update. + * d-lang.c (enum d_primitive_types): Delete. + (d_language::language_arch_info): Update. + * f-lang.c (enum f_primitive_types): Delete. + (f_language::language_arch_info): Update. + * go-lang.c (enum go_primitive_types): Delete. + (go_language::language_arch_info): Update. + * language.c (auto_or_unknown_language::language_arch_info): + Update. + (language_gdbarch_post_init): Use obstack_new, use array indexing. + (language_string_char_type): Add header comment, call function in + language_arch_info. + (language_bool_type): Likewise + (language_arch_info::bool_type): Define. + (language_lookup_primitive_type_1): Delete. + (language_lookup_primitive_type): Rewrite as a templated function + to call function in language_arch_info, then instantiate twice. + (language_arch_info::type_and_symbol::alloc_type_symbol): Define. + (language_arch_info::lookup_primitive_type_and_symbol): Define. + (language_arch_info::lookup_primitive_type): Define twice with + different signatures. + (language_arch_info::lookup_primitive_type_as_symbol): Define. + (language_lookup_primitive_type_as_symbol): Rewrite to call a + member function in language_arch_info. + * language.h (language_arch_info): Complete rewrite. + (language_lookup_primitive_type): Make templated. + * m2-lang.c (enum m2_primitive_types): Delete. + (m2_language::language_arch_info): Update. + * opencl-lang.c (OCL_P_TYPE): Delete. + (enum opencl_primitive_types): Delete. + (opencl_type_data): Delete. + (builtin_opencl_type): Delete. + (lookup_opencl_vector_type): Update. + (opencl_language::language_arch_info): Update, lots of content + moved from... + (build_opencl_types): ...here. This function is now deleted. + (_initialize_opencl_language): Delete. + * p-lang.c (enum pascal_primitive_types): Delete. + (pascal_language::language_arch_info): Update. + * rust-lang.c (enum rust_primitive_types): Delete. + (rust_language::language_arch_info): Update. + 2020-11-12 Simon Marchi * dwarf2/read.c (dw2_do_instantiate_symtab): Fix call to diff --git a/gdb/ada-exp.y b/gdb/ada-exp.y index 83d711cce8b..636ec5845b9 100644 --- a/gdb/ada-exp.y +++ b/gdb/ada-exp.y @@ -1026,7 +1026,7 @@ select_possible_type_sym (const std::vector &syms) } static struct type* -find_primitive_type (struct parser_state *par_state, char *name) +find_primitive_type (struct parser_state *par_state, const char *name) { struct type *type; type = language_lookup_primitive_type (par_state->language (), diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index fe3ea7009a6..714227d24dd 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -13594,24 +13594,6 @@ static const struct op_print ada_op_print_tab[] = { {"'size", OP_ATR_SIZE, PREC_SUFFIX, 1}, {NULL, OP_NULL, PREC_SUFFIX, 0} }; - -enum ada_primitive_types { - ada_primitive_type_int, - ada_primitive_type_long, - ada_primitive_type_short, - ada_primitive_type_char, - ada_primitive_type_float, - ada_primitive_type_double, - ada_primitive_type_void, - ada_primitive_type_long_long, - ada_primitive_type_long_double, - ada_primitive_type_natural, - ada_primitive_type_positive, - ada_primitive_type_system_address, - ada_primitive_type_storage_offset, - nr_ada_primitive_types -}; - /* Language vector */ @@ -13838,63 +13820,51 @@ public: { const struct builtin_type *builtin = builtin_type (gdbarch); - lai->primitive_type_vector - = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_ada_primitive_types + 1, - struct type *); - - lai->primitive_type_vector [ada_primitive_type_int] - = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), - 0, "integer"); - lai->primitive_type_vector [ada_primitive_type_long] - = arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch), - 0, "long_integer"); - lai->primitive_type_vector [ada_primitive_type_short] - = arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch), - 0, "short_integer"); - lai->string_char_type - = lai->primitive_type_vector [ada_primitive_type_char] - = arch_character_type (gdbarch, TARGET_CHAR_BIT, 0, "character"); - lai->primitive_type_vector [ada_primitive_type_float] - = arch_float_type (gdbarch, gdbarch_float_bit (gdbarch), - "float", gdbarch_float_format (gdbarch)); - lai->primitive_type_vector [ada_primitive_type_double] - = arch_float_type (gdbarch, gdbarch_double_bit (gdbarch), - "long_float", gdbarch_double_format (gdbarch)); - lai->primitive_type_vector [ada_primitive_type_long_long] - = arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch), - 0, "long_long_integer"); - lai->primitive_type_vector [ada_primitive_type_long_double] - = arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch), - "long_long_float", gdbarch_long_double_format (gdbarch)); - lai->primitive_type_vector [ada_primitive_type_natural] - = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), - 0, "natural"); - lai->primitive_type_vector [ada_primitive_type_positive] - = arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), - 0, "positive"); - lai->primitive_type_vector [ada_primitive_type_void] - = builtin->builtin_void; - - lai->primitive_type_vector [ada_primitive_type_system_address] + /* Helper function to allow shorter lines below. */ + auto add = [&] (struct type *t) + { + lai->add_primitive_type (t); + }; + + add (arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), + 0, "integer")); + add (arch_integer_type (gdbarch, gdbarch_long_bit (gdbarch), + 0, "long_integer")); + add (arch_integer_type (gdbarch, gdbarch_short_bit (gdbarch), + 0, "short_integer")); + struct type *char_type = arch_character_type (gdbarch, TARGET_CHAR_BIT, + 0, "character"); + lai->set_string_char_type (char_type); + add (char_type); + add (arch_float_type (gdbarch, gdbarch_float_bit (gdbarch), + "float", gdbarch_float_format (gdbarch))); + add (arch_float_type (gdbarch, gdbarch_double_bit (gdbarch), + "long_float", gdbarch_double_format (gdbarch))); + add (arch_integer_type (gdbarch, gdbarch_long_long_bit (gdbarch), + 0, "long_long_integer")); + add (arch_float_type (gdbarch, gdbarch_long_double_bit (gdbarch), + "long_long_float", + gdbarch_long_double_format (gdbarch))); + add (arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), + 0, "natural")); + add (arch_integer_type (gdbarch, gdbarch_int_bit (gdbarch), + 0, "positive")); + add (builtin->builtin_void); + + struct type *system_addr_ptr = lookup_pointer_type (arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void")); - lai->primitive_type_vector [ada_primitive_type_system_address] - ->set_name ("system__address"); + system_addr_ptr->set_name ("system__address"); + add (system_addr_ptr); /* Create the equivalent of the System.Storage_Elements.Storage_Offset type. This is a signed integral type whose size is the same as the size of addresses. */ - { - unsigned int addr_length = TYPE_LENGTH - (lai->primitive_type_vector [ada_primitive_type_system_address]); - - lai->primitive_type_vector [ada_primitive_type_storage_offset] - = arch_integer_type (gdbarch, addr_length * HOST_CHAR_BIT, 0, - "storage_offset"); - } + unsigned int addr_length = TYPE_LENGTH (system_addr_ptr); + add (arch_integer_type (gdbarch, addr_length * HOST_CHAR_BIT, 0, + "storage_offset")); - lai->bool_type_symbol = NULL; - lai->bool_type_default = builtin->builtin_bool; + lai->set_bool_type (builtin->builtin_bool); } /* See language.h. */ diff --git a/gdb/c-lang.c b/gdb/c-lang.c index 329986ce88c..8dbce398932 100644 --- a/gdb/c-lang.c +++ b/gdb/c-lang.c @@ -803,29 +803,6 @@ const struct op_print c_op_print_tab[] = {NULL, OP_NULL, PREC_PREFIX, 0} }; -enum c_primitive_types { - c_primitive_type_int, - c_primitive_type_long, - c_primitive_type_short, - c_primitive_type_char, - c_primitive_type_float, - c_primitive_type_double, - c_primitive_type_void, - c_primitive_type_long_long, - c_primitive_type_signed_char, - c_primitive_type_unsigned_char, - c_primitive_type_unsigned_short, - c_primitive_type_unsigned_int, - c_primitive_type_unsigned_long, - c_primitive_type_unsigned_long_long, - c_primitive_type_long_double, - c_primitive_type_complex, - c_primitive_type_double_complex, - c_primitive_type_decfloat, - c_primitive_type_decdouble, - c_primitive_type_declong, - nr_c_primitive_types -}; void c_language_arch_info (struct gdbarch *gdbarch, @@ -833,32 +810,35 @@ c_language_arch_info (struct gdbarch *gdbarch, { const struct builtin_type *builtin = builtin_type (gdbarch); - lai->string_char_type = builtin->builtin_char; - lai->primitive_type_vector - = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_c_primitive_types + 1, - struct type *); - lai->primitive_type_vector [c_primitive_type_int] = builtin->builtin_int; - lai->primitive_type_vector [c_primitive_type_long] = builtin->builtin_long; - lai->primitive_type_vector [c_primitive_type_short] = builtin->builtin_short; - lai->primitive_type_vector [c_primitive_type_char] = builtin->builtin_char; - lai->primitive_type_vector [c_primitive_type_float] = builtin->builtin_float; - lai->primitive_type_vector [c_primitive_type_double] = builtin->builtin_double; - lai->primitive_type_vector [c_primitive_type_void] = builtin->builtin_void; - lai->primitive_type_vector [c_primitive_type_long_long] = builtin->builtin_long_long; - lai->primitive_type_vector [c_primitive_type_signed_char] = builtin->builtin_signed_char; - lai->primitive_type_vector [c_primitive_type_unsigned_char] = builtin->builtin_unsigned_char; - lai->primitive_type_vector [c_primitive_type_unsigned_short] = builtin->builtin_unsigned_short; - lai->primitive_type_vector [c_primitive_type_unsigned_int] = builtin->builtin_unsigned_int; - lai->primitive_type_vector [c_primitive_type_unsigned_long] = builtin->builtin_unsigned_long; - lai->primitive_type_vector [c_primitive_type_unsigned_long_long] = builtin->builtin_unsigned_long_long; - lai->primitive_type_vector [c_primitive_type_long_double] = builtin->builtin_long_double; - lai->primitive_type_vector [c_primitive_type_complex] = builtin->builtin_complex; - lai->primitive_type_vector [c_primitive_type_double_complex] = builtin->builtin_double_complex; - lai->primitive_type_vector [c_primitive_type_decfloat] = builtin->builtin_decfloat; - lai->primitive_type_vector [c_primitive_type_decdouble] = builtin->builtin_decdouble; - lai->primitive_type_vector [c_primitive_type_declong] = builtin->builtin_declong; - - lai->bool_type_default = builtin->builtin_int; + /* Helper function to allow shorter lines below. */ + auto add = [&] (struct type * t) + { + lai->add_primitive_type (t); + }; + + add (builtin->builtin_int); + add (builtin->builtin_long); + add (builtin->builtin_short); + add (builtin->builtin_char); + add (builtin->builtin_float); + add (builtin->builtin_double); + add (builtin->builtin_void); + add (builtin->builtin_long_long); + add (builtin->builtin_signed_char); + add (builtin->builtin_unsigned_char); + add (builtin->builtin_unsigned_short); + add (builtin->builtin_unsigned_int); + add (builtin->builtin_unsigned_long); + add (builtin->builtin_unsigned_long_long); + add (builtin->builtin_long_double); + add (builtin->builtin_complex); + add (builtin->builtin_double_complex); + add (builtin->builtin_decfloat); + add (builtin->builtin_decdouble); + add (builtin->builtin_declong); + + lai->set_string_char_type (builtin->builtin_char); + lai->set_bool_type (builtin->builtin_int); } const struct exp_descriptor exp_descriptor_c = @@ -955,34 +935,6 @@ public: static c_language c_language_defn; -enum cplus_primitive_types { - cplus_primitive_type_int, - cplus_primitive_type_long, - cplus_primitive_type_short, - cplus_primitive_type_char, - cplus_primitive_type_float, - cplus_primitive_type_double, - cplus_primitive_type_void, - cplus_primitive_type_long_long, - cplus_primitive_type_signed_char, - cplus_primitive_type_unsigned_char, - cplus_primitive_type_unsigned_short, - cplus_primitive_type_unsigned_int, - cplus_primitive_type_unsigned_long, - cplus_primitive_type_unsigned_long_long, - cplus_primitive_type_long_double, - cplus_primitive_type_complex, - cplus_primitive_type_double_complex, - cplus_primitive_type_bool, - cplus_primitive_type_decfloat, - cplus_primitive_type_decdouble, - cplus_primitive_type_declong, - cplus_primitive_type_char16_t, - cplus_primitive_type_char32_t, - cplus_primitive_type_wchar_t, - nr_cplus_primitive_types -}; - /* A class for the C++ language. */ class cplus_language : public language_defn @@ -1025,61 +977,39 @@ public: { const struct builtin_type *builtin = builtin_type (gdbarch); - lai->string_char_type = builtin->builtin_char; - lai->primitive_type_vector - = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_cplus_primitive_types + 1, - struct type *); - lai->primitive_type_vector [cplus_primitive_type_int] - = builtin->builtin_int; - lai->primitive_type_vector [cplus_primitive_type_long] - = builtin->builtin_long; - lai->primitive_type_vector [cplus_primitive_type_short] - = builtin->builtin_short; - lai->primitive_type_vector [cplus_primitive_type_char] - = builtin->builtin_char; - lai->primitive_type_vector [cplus_primitive_type_float] - = builtin->builtin_float; - lai->primitive_type_vector [cplus_primitive_type_double] - = builtin->builtin_double; - lai->primitive_type_vector [cplus_primitive_type_void] - = builtin->builtin_void; - lai->primitive_type_vector [cplus_primitive_type_long_long] - = builtin->builtin_long_long; - lai->primitive_type_vector [cplus_primitive_type_signed_char] - = builtin->builtin_signed_char; - lai->primitive_type_vector [cplus_primitive_type_unsigned_char] - = builtin->builtin_unsigned_char; - lai->primitive_type_vector [cplus_primitive_type_unsigned_short] - = builtin->builtin_unsigned_short; - lai->primitive_type_vector [cplus_primitive_type_unsigned_int] - = builtin->builtin_unsigned_int; - lai->primitive_type_vector [cplus_primitive_type_unsigned_long] - = builtin->builtin_unsigned_long; - lai->primitive_type_vector [cplus_primitive_type_unsigned_long_long] - = builtin->builtin_unsigned_long_long; - lai->primitive_type_vector [cplus_primitive_type_long_double] - = builtin->builtin_long_double; - lai->primitive_type_vector [cplus_primitive_type_complex] - = builtin->builtin_complex; - lai->primitive_type_vector [cplus_primitive_type_double_complex] - = builtin->builtin_double_complex; - lai->primitive_type_vector [cplus_primitive_type_bool] - = builtin->builtin_bool; - lai->primitive_type_vector [cplus_primitive_type_decfloat] - = builtin->builtin_decfloat; - lai->primitive_type_vector [cplus_primitive_type_decdouble] - = builtin->builtin_decdouble; - lai->primitive_type_vector [cplus_primitive_type_declong] - = builtin->builtin_declong; - lai->primitive_type_vector [cplus_primitive_type_char16_t] - = builtin->builtin_char16; - lai->primitive_type_vector [cplus_primitive_type_char32_t] - = builtin->builtin_char32; - lai->primitive_type_vector [cplus_primitive_type_wchar_t] - = builtin->builtin_wchar; - - lai->bool_type_symbol = "bool"; - lai->bool_type_default = builtin->builtin_bool; + /* Helper function to allow shorter lines below. */ + auto add = [&] (struct type * t) + { + lai->add_primitive_type (t); + }; + + add (builtin->builtin_int); + add (builtin->builtin_long); + add (builtin->builtin_short); + add (builtin->builtin_char); + add (builtin->builtin_float); + add (builtin->builtin_double); + add (builtin->builtin_void); + add (builtin->builtin_long_long); + add (builtin->builtin_signed_char); + add (builtin->builtin_unsigned_char); + add (builtin->builtin_unsigned_short); + add (builtin->builtin_unsigned_int); + add (builtin->builtin_unsigned_long); + add (builtin->builtin_unsigned_long_long); + add (builtin->builtin_long_double); + add (builtin->builtin_complex); + add (builtin->builtin_double_complex); + add (builtin->builtin_bool); + add (builtin->builtin_decfloat); + add (builtin->builtin_decdouble); + add (builtin->builtin_declong); + add (builtin->builtin_char16); + add (builtin->builtin_char32); + add (builtin->builtin_wchar); + + lai->set_string_char_type (builtin->builtin_char); + lai->set_bool_type (builtin->builtin_bool, "bool"); } /* See language.h. */ diff --git a/gdb/d-lang.c b/gdb/d-lang.c index 2537f046c16..2e7b7b64cb8 100644 --- a/gdb/d-lang.c +++ b/gdb/d-lang.c @@ -94,36 +94,6 @@ static const struct op_print d_op_print_tab[] = {NULL, OP_NULL, PREC_PREFIX, 0} }; -/* Mapping of all D basic data types into the language vector. */ - -enum d_primitive_types { - d_primitive_type_void, - d_primitive_type_bool, - d_primitive_type_byte, - d_primitive_type_ubyte, - d_primitive_type_short, - d_primitive_type_ushort, - d_primitive_type_int, - d_primitive_type_uint, - d_primitive_type_long, - d_primitive_type_ulong, - d_primitive_type_cent, /* Signed 128 bit integer. */ - d_primitive_type_ucent, /* Unsigned 128 bit integer. */ - d_primitive_type_float, - d_primitive_type_double, - d_primitive_type_real, - d_primitive_type_ifloat, /* Imaginary float types. */ - d_primitive_type_idouble, - d_primitive_type_ireal, - d_primitive_type_cfloat, /* Complex number of two float values. */ - d_primitive_type_cdouble, - d_primitive_type_creal, - d_primitive_type_char, /* Unsigned character types. */ - d_primitive_type_wchar, - d_primitive_type_dchar, - nr_d_primitive_types -}; - /* Class representing the D language. */ class d_language : public language_defn @@ -157,62 +127,39 @@ public: { const struct builtin_d_type *builtin = builtin_d_type (gdbarch); - lai->string_char_type = builtin->builtin_char; - lai->primitive_type_vector - = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_d_primitive_types + 1, - struct type *); - - lai->primitive_type_vector [d_primitive_type_void] - = builtin->builtin_void; - lai->primitive_type_vector [d_primitive_type_bool] - = builtin->builtin_bool; - lai->primitive_type_vector [d_primitive_type_byte] - = builtin->builtin_byte; - lai->primitive_type_vector [d_primitive_type_ubyte] - = builtin->builtin_ubyte; - lai->primitive_type_vector [d_primitive_type_short] - = builtin->builtin_short; - lai->primitive_type_vector [d_primitive_type_ushort] - = builtin->builtin_ushort; - lai->primitive_type_vector [d_primitive_type_int] - = builtin->builtin_int; - lai->primitive_type_vector [d_primitive_type_uint] - = builtin->builtin_uint; - lai->primitive_type_vector [d_primitive_type_long] - = builtin->builtin_long; - lai->primitive_type_vector [d_primitive_type_ulong] - = builtin->builtin_ulong; - lai->primitive_type_vector [d_primitive_type_cent] - = builtin->builtin_cent; - lai->primitive_type_vector [d_primitive_type_ucent] - = builtin->builtin_ucent; - lai->primitive_type_vector [d_primitive_type_float] - = builtin->builtin_float; - lai->primitive_type_vector [d_primitive_type_double] - = builtin->builtin_double; - lai->primitive_type_vector [d_primitive_type_real] - = builtin->builtin_real; - lai->primitive_type_vector [d_primitive_type_ifloat] - = builtin->builtin_ifloat; - lai->primitive_type_vector [d_primitive_type_idouble] - = builtin->builtin_idouble; - lai->primitive_type_vector [d_primitive_type_ireal] - = builtin->builtin_ireal; - lai->primitive_type_vector [d_primitive_type_cfloat] - = builtin->builtin_cfloat; - lai->primitive_type_vector [d_primitive_type_cdouble] - = builtin->builtin_cdouble; - lai->primitive_type_vector [d_primitive_type_creal] - = builtin->builtin_creal; - lai->primitive_type_vector [d_primitive_type_char] - = builtin->builtin_char; - lai->primitive_type_vector [d_primitive_type_wchar] - = builtin->builtin_wchar; - lai->primitive_type_vector [d_primitive_type_dchar] - = builtin->builtin_dchar; - - lai->bool_type_symbol = "bool"; - lai->bool_type_default = builtin->builtin_bool; + /* Helper function to allow shorter lines below. */ + auto add = [&] (struct type * t) + { + lai->add_primitive_type (t); + }; + + add (builtin->builtin_void); + add (builtin->builtin_bool); + add (builtin->builtin_byte); + add (builtin->builtin_ubyte); + add (builtin->builtin_short); + add (builtin->builtin_ushort); + add (builtin->builtin_int); + add (builtin->builtin_uint); + add (builtin->builtin_long); + add (builtin->builtin_ulong); + add (builtin->builtin_cent); + add (builtin->builtin_ucent); + add (builtin->builtin_float); + add (builtin->builtin_double); + add (builtin->builtin_real); + add (builtin->builtin_ifloat); + add (builtin->builtin_idouble); + add (builtin->builtin_ireal); + add (builtin->builtin_cfloat); + add (builtin->builtin_cdouble); + add (builtin->builtin_creal); + add (builtin->builtin_char); + add (builtin->builtin_wchar); + add (builtin->builtin_dchar); + + lai->set_string_char_type (builtin->builtin_char); + lai->set_bool_type (builtin->builtin_bool, "bool"); } /* See language.h. */ diff --git a/gdb/f-lang.c b/gdb/f-lang.c index b775fae2e79..75cc05e2a71 100644 --- a/gdb/f-lang.c +++ b/gdb/f-lang.c @@ -97,22 +97,6 @@ const struct op_print f_language::op_print_tab[] = {NULL, OP_NULL, PREC_REPEAT, 0} }; -enum f_primitive_types { - f_primitive_type_character, - f_primitive_type_logical, - f_primitive_type_logical_s1, - f_primitive_type_logical_s2, - f_primitive_type_logical_s8, - f_primitive_type_integer, - f_primitive_type_integer_s2, - f_primitive_type_real, - f_primitive_type_real_s8, - f_primitive_type_real_s16, - f_primitive_type_complex_s8, - f_primitive_type_complex_s16, - f_primitive_type_void, - nr_f_primitive_types -}; /* Called from fortran_value_subarray to take a slice of an array or a string. ARRAY is the array or string to be accessed. EXP, POS, and @@ -720,36 +704,26 @@ f_language::language_arch_info (struct gdbarch *gdbarch, { const struct builtin_f_type *builtin = builtin_f_type (gdbarch); - lai->string_char_type = builtin->builtin_character; - lai->primitive_type_vector - = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_f_primitive_types + 1, - struct type *); - - lai->primitive_type_vector [f_primitive_type_character] - = builtin->builtin_character; - lai->primitive_type_vector [f_primitive_type_logical] - = builtin->builtin_logical; - lai->primitive_type_vector [f_primitive_type_logical_s1] - = builtin->builtin_logical_s1; - lai->primitive_type_vector [f_primitive_type_logical_s2] - = builtin->builtin_logical_s2; - lai->primitive_type_vector [f_primitive_type_logical_s8] - = builtin->builtin_logical_s8; - lai->primitive_type_vector [f_primitive_type_real] - = builtin->builtin_real; - lai->primitive_type_vector [f_primitive_type_real_s8] - = builtin->builtin_real_s8; - lai->primitive_type_vector [f_primitive_type_real_s16] - = builtin->builtin_real_s16; - lai->primitive_type_vector [f_primitive_type_complex_s8] - = builtin->builtin_complex_s8; - lai->primitive_type_vector [f_primitive_type_complex_s16] - = builtin->builtin_complex_s16; - lai->primitive_type_vector [f_primitive_type_void] - = builtin->builtin_void; - - lai->bool_type_symbol = "logical"; - lai->bool_type_default = builtin->builtin_logical_s2; + /* Helper function to allow shorter lines below. */ + auto add = [&] (struct type * t) + { + lai->add_primitive_type (t); + }; + + add (builtin->builtin_character); + add (builtin->builtin_logical); + add (builtin->builtin_logical_s1); + add (builtin->builtin_logical_s2); + add (builtin->builtin_logical_s8); + add (builtin->builtin_real); + add (builtin->builtin_real_s8); + add (builtin->builtin_real_s16); + add (builtin->builtin_complex_s8); + add (builtin->builtin_complex_s16); + add (builtin->builtin_void); + + lai->set_string_char_type (builtin->builtin_character); + lai->set_bool_type (builtin->builtin_logical_s2, "logical"); } /* See language.h. */ diff --git a/gdb/go-lang.c b/gdb/go-lang.c index 01cd3a47690..4547b52219b 100644 --- a/gdb/go-lang.c +++ b/gdb/go-lang.c @@ -482,28 +482,6 @@ static const struct op_print go_op_print_tab[] = {NULL, OP_NULL, PREC_SUFFIX, 0} }; -enum go_primitive_types { - go_primitive_type_void, - go_primitive_type_char, - go_primitive_type_bool, - go_primitive_type_int, - go_primitive_type_uint, - go_primitive_type_uintptr, - go_primitive_type_int8, - go_primitive_type_int16, - go_primitive_type_int32, - go_primitive_type_int64, - go_primitive_type_uint8, - go_primitive_type_uint16, - go_primitive_type_uint32, - go_primitive_type_uint64, - go_primitive_type_float32, - go_primitive_type_float64, - go_primitive_type_complex64, - go_primitive_type_complex128, - nr_go_primitive_types -}; - /* Class representing the Go language. */ class go_language : public language_defn @@ -529,51 +507,34 @@ public: { const struct builtin_go_type *builtin = builtin_go_type (gdbarch); - lai->string_char_type = builtin->builtin_char; - - lai->primitive_type_vector - = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_go_primitive_types + 1, - struct type *); - - lai->primitive_type_vector [go_primitive_type_void] - = builtin->builtin_void; - lai->primitive_type_vector [go_primitive_type_char] - = builtin->builtin_char; - lai->primitive_type_vector [go_primitive_type_bool] - = builtin->builtin_bool; - lai->primitive_type_vector [go_primitive_type_int] - = builtin->builtin_int; - lai->primitive_type_vector [go_primitive_type_uint] - = builtin->builtin_uint; - lai->primitive_type_vector [go_primitive_type_uintptr] - = builtin->builtin_uintptr; - lai->primitive_type_vector [go_primitive_type_int8] - = builtin->builtin_int8; - lai->primitive_type_vector [go_primitive_type_int16] - = builtin->builtin_int16; - lai->primitive_type_vector [go_primitive_type_int32] - = builtin->builtin_int32; - lai->primitive_type_vector [go_primitive_type_int64] - = builtin->builtin_int64; - lai->primitive_type_vector [go_primitive_type_uint8] - = builtin->builtin_uint8; - lai->primitive_type_vector [go_primitive_type_uint16] - = builtin->builtin_uint16; - lai->primitive_type_vector [go_primitive_type_uint32] - = builtin->builtin_uint32; - lai->primitive_type_vector [go_primitive_type_uint64] - = builtin->builtin_uint64; - lai->primitive_type_vector [go_primitive_type_float32] - = builtin->builtin_float32; - lai->primitive_type_vector [go_primitive_type_float64] - = builtin->builtin_float64; - lai->primitive_type_vector [go_primitive_type_complex64] - = builtin->builtin_complex64; - lai->primitive_type_vector [go_primitive_type_complex128] - = builtin->builtin_complex128; - - lai->bool_type_symbol = "bool"; - lai->bool_type_default = builtin->builtin_bool; + /* Helper function to allow shorter lines below. */ + auto add = [&] (struct type * t) -> struct type * + { + lai->add_primitive_type (t); + return t; + }; + + add (builtin->builtin_void); + add (builtin->builtin_char); + add (builtin->builtin_bool); + add (builtin->builtin_int); + add (builtin->builtin_uint); + add (builtin->builtin_uintptr); + add (builtin->builtin_int8); + add (builtin->builtin_int16); + add (builtin->builtin_int32); + add (builtin->builtin_int64); + add (builtin->builtin_uint8); + add (builtin->builtin_uint16); + add (builtin->builtin_uint32); + add (builtin->builtin_uint64); + add (builtin->builtin_float32); + add (builtin->builtin_float64); + add (builtin->builtin_complex64); + add (builtin->builtin_complex128); + + lai->set_string_char_type (builtin->builtin_char); + lai->set_bool_type (builtin->builtin_bool, "bool"); } /* See language.h. */ diff --git a/gdb/language.c b/gdb/language.c index 1a0e20ea950..579cf9198c8 100644 --- a/gdb/language.c +++ b/gdb/language.c @@ -797,10 +797,8 @@ public: void language_arch_info (struct gdbarch *gdbarch, struct language_arch_info *lai) const override { - lai->string_char_type = builtin_type (gdbarch)->builtin_char; - lai->bool_type_default = builtin_type (gdbarch)->builtin_int; - lai->primitive_type_vector = GDBARCH_OBSTACK_CALLOC (gdbarch, 1, - struct type *); + lai->set_string_char_type (builtin_type (gdbarch)->builtin_char); + lai->set_bool_type (builtin_type (gdbarch)->builtin_int); } /* See language.h. */ @@ -985,102 +983,71 @@ struct language_gdbarch static void * language_gdbarch_post_init (struct gdbarch *gdbarch) { - struct language_gdbarch *l; - - l = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct language_gdbarch); + struct language_gdbarch *l + = obstack_new (gdbarch_obstack (gdbarch)); for (const auto &lang : language_defn::languages) { gdb_assert (lang != nullptr); - lang->language_arch_info (gdbarch, - l->arch_info + lang->la_language); + lang->language_arch_info (gdbarch, &l->arch_info[lang->la_language]); } return l; } +/* See language.h. */ + struct type * language_string_char_type (const struct language_defn *la, struct gdbarch *gdbarch) { struct language_gdbarch *ld = (struct language_gdbarch *) gdbarch_data (gdbarch, language_gdbarch_data); - - return ld->arch_info[la->la_language].string_char_type; + return ld->arch_info[la->la_language].string_char_type (); } +/* See language.h. */ + struct type * language_bool_type (const struct language_defn *la, struct gdbarch *gdbarch) { struct language_gdbarch *ld = (struct language_gdbarch *) gdbarch_data (gdbarch, language_gdbarch_data); + return ld->arch_info[la->la_language].bool_type (); +} + +/* See language.h. */ - if (ld->arch_info[la->la_language].bool_type_symbol) +struct type * +language_arch_info::bool_type () const +{ + if (m_bool_type_name != nullptr) { struct symbol *sym; - sym = lookup_symbol (ld->arch_info[la->la_language].bool_type_symbol, - NULL, VAR_DOMAIN, NULL).symbol; - if (sym) + sym = lookup_symbol (m_bool_type_name, NULL, VAR_DOMAIN, NULL).symbol; + if (sym != nullptr) { struct type *type = SYMBOL_TYPE (sym); - - if (type && type->code () == TYPE_CODE_BOOL) + if (type != nullptr && type->code () == TYPE_CODE_BOOL) return type; } } - return ld->arch_info[la->la_language].bool_type_default; -} - -/* Helper function for primitive type lookup. */ - -static struct type ** -language_lookup_primitive_type_1 (const struct language_arch_info *lai, - const char *name) -{ - struct type **p; - - for (p = lai->primitive_type_vector; (*p) != NULL; p++) - { - if (strcmp ((*p)->name (), name) == 0) - return p; - } - return NULL; + return m_bool_type_default; } /* See language.h. */ -struct type * -language_lookup_primitive_type (const struct language_defn *la, - struct gdbarch *gdbarch, - const char *name) -{ - struct language_gdbarch *ld = - (struct language_gdbarch *) gdbarch_data (gdbarch, language_gdbarch_data); - struct type **typep; - - typep = language_lookup_primitive_type_1 (&ld->arch_info[la->la_language], - name); - if (typep == NULL) - return NULL; - return *typep; -} - -/* Helper function for type lookup as a symbol. - Create the symbol corresponding to type TYPE in language LANG. */ - -static struct symbol * -language_alloc_type_symbol (enum language lang, struct type *type) +struct symbol * +language_arch_info::type_and_symbol::alloc_type_symbol + (enum language lang, struct type *type) { struct symbol *symbol; struct gdbarch *gdbarch; - gdb_assert (!TYPE_OBJFILE_OWNED (type)); - gdbarch = TYPE_OWNER (type).gdbarch; symbol = new (gdbarch_obstack (gdbarch)) struct symbol (); - symbol->m_name = type->name (); symbol->set_language (lang, nullptr); symbol->owner.arch = gdbarch; @@ -1089,41 +1056,88 @@ language_alloc_type_symbol (enum language lang, struct type *type) SYMBOL_TYPE (symbol) = type; SYMBOL_DOMAIN (symbol) = VAR_DOMAIN; SYMBOL_ACLASS_INDEX (symbol) = LOC_TYPEDEF; - return symbol; } -/* Initialize the primitive type symbols of language LD. - The primitive type vector must have already been initialized. */ +/* See language.h. */ -static void -language_init_primitive_type_symbols (struct language_arch_info *lai, - const struct language_defn *la, - struct gdbarch *gdbarch) +language_arch_info::type_and_symbol * +language_arch_info::lookup_primitive_type_and_symbol (const char *name) { - int n; + for (struct type_and_symbol &tas : primitive_types_and_symbols) + { + if (strcmp (tas.type ()->name (), name) == 0) + return &tas; + } - gdb_assert (lai->primitive_type_vector != NULL); + return nullptr; +} + +/* See language.h. */ - for (n = 0; lai->primitive_type_vector[n] != NULL; ++n) - continue; +struct type * +language_arch_info::lookup_primitive_type (const char *name) +{ + type_and_symbol *tas = lookup_primitive_type_and_symbol (name); + if (tas != nullptr) + return tas->type (); + return nullptr; +} - lai->primitive_type_symbols - = GDBARCH_OBSTACK_CALLOC (gdbarch, n + 1, struct symbol *); +/* See language.h. */ - for (n = 0; lai->primitive_type_vector[n] != NULL; ++n) +struct type * +language_arch_info::lookup_primitive_type + (std::function filter) +{ + for (struct type_and_symbol &tas : primitive_types_and_symbols) { - lai->primitive_type_symbols[n] - = language_alloc_type_symbol (la->la_language, - lai->primitive_type_vector[n]); + if (filter (tas.type ())) + return tas.type (); } - /* Note: The result of symbol lookup is normally a symbol *and* the block - it was found in. Builtin types don't live in blocks. We *could* give - them one, but there is no current need so to keep things simple symbol - lookup is extended to allow for BLOCK_FOUND to be NULL. */ + return nullptr; +} + +/* See language.h. */ + +struct symbol * +language_arch_info::lookup_primitive_type_as_symbol (const char *name, + enum language lang) +{ + type_and_symbol *tas = lookup_primitive_type_and_symbol (name); + if (tas != nullptr) + return tas->symbol (lang); + return nullptr; +} + +/* See language.h. */ + +template +struct type * +language_lookup_primitive_type (const struct language_defn *la, + struct gdbarch *gdbarch, + T arg) +{ + struct language_gdbarch *ld = + (struct language_gdbarch *) gdbarch_data (gdbarch, language_gdbarch_data); + return ld->arch_info[la->la_language].lookup_primitive_type (arg); } +/* Template instantiation. */ + +template struct type * +language_lookup_primitive_type (const struct language_defn *la, + struct gdbarch *gdbarch, + const char *arg); + +/* Template instantiation. */ + +template struct type * +language_lookup_primitive_type (const struct language_defn *la, + struct gdbarch *gdbarch, + std::function arg); + /* See language.h. */ struct symbol * @@ -1134,33 +1148,24 @@ language_lookup_primitive_type_as_symbol (const struct language_defn *la, struct language_gdbarch *ld = (struct language_gdbarch *) gdbarch_data (gdbarch, language_gdbarch_data); struct language_arch_info *lai = &ld->arch_info[la->la_language]; - struct type **typep; - struct symbol *sym; if (symbol_lookup_debug) - { - fprintf_unfiltered (gdb_stdlog, - "language_lookup_primitive_type_as_symbol" - " (%s, %s, %s)", - la->name (), host_address_to_string (gdbarch), name); - } - - typep = language_lookup_primitive_type_1 (lai, name); - if (typep == NULL) - { - if (symbol_lookup_debug) - fprintf_unfiltered (gdb_stdlog, " = NULL\n"); - return NULL; - } - - /* The set of symbols is lazily initialized. */ - if (lai->primitive_type_symbols == NULL) - language_init_primitive_type_symbols (lai, la, gdbarch); + fprintf_unfiltered (gdb_stdlog, + "language_lookup_primitive_type_as_symbol" + " (%s, %s, %s)", + la->name (), host_address_to_string (gdbarch), name); - sym = lai->primitive_type_symbols[typep - lai->primitive_type_vector]; + struct symbol *sym + = lai->lookup_primitive_type_as_symbol (name, la->la_language); if (symbol_lookup_debug) fprintf_unfiltered (gdb_stdlog, " = %s\n", host_address_to_string (sym)); + + /* Note: The result of symbol lookup is normally a symbol *and* the block + it was found in. Builtin types don't live in blocks. We *could* give + them one, but there is no current need so to keep things simple symbol + lookup is extended to allow for BLOCK_FOUND to be NULL. */ + return sym; } diff --git a/gdb/language.h b/gdb/language.h index 951343fd9a3..1b602646651 100644 --- a/gdb/language.h +++ b/gdb/language.h @@ -89,23 +89,129 @@ enum macro_expansion struct language_arch_info { - /* Its primitive types. This is a vector ended by a NULL pointer. - These types can be specified by name in parsing types in - expressions, regardless of whether the program being debugged - actually defines such a type. */ - struct type **primitive_type_vector; + /* A default constructor. */ + language_arch_info () = default; - /* Symbol wrappers around primitive_type_vector, so that the symbol lookup - machinery can return them. */ - struct symbol **primitive_type_symbols; + DISABLE_COPY_AND_ASSIGN (language_arch_info); + + /* Set the default boolean type to be TYPE. If NAME is not nullptr then + before using TYPE a symbol called NAME will be looked up, and the type + of this symbol will be used instead. Should only be called once when + performing setup for a particular language in combination with a + particular gdbarch. */ + void set_bool_type (struct type *type, const char *name = nullptr) + { + gdb_assert (m_bool_type_default == nullptr); + gdb_assert (m_bool_type_name == nullptr); + gdb_assert (type != nullptr); + m_bool_type_default = type; + m_bool_type_name = name; + } + + /* Set the type to be used for characters within a string. Should only + be called once when performing setup for a particular language in + combination with a particular gdbarch. */ + void set_string_char_type (struct type *type) + { + gdb_assert (m_string_char_type == nullptr); + gdb_assert (type != nullptr); + m_string_char_type = type; + } + + /* Return the type for characters within a string. */ + struct type *string_char_type () const + { return m_string_char_type; } + + /* Return the type to be used for booleans. */ + struct type *bool_type () const; + + /* Add TYPE to the list of primitive types for this particular language, + with this OS/ABI combination. */ + void add_primitive_type (struct type *type) + { + gdb_assert (type != nullptr); + primitive_types_and_symbols.push_back (type_and_symbol (type)); + } + + /* Lookup a primitive type called NAME. Will return nullptr if no + matching type is found. */ + struct type *lookup_primitive_type (const char *name); + + /* Lookup a primitive type for which FILTER returns true. Will return + nullptr if no matching type is found. */ + struct type *lookup_primitive_type + (std::function filter); + + /* Lookup a primitive type called NAME and return the type as a symbol. + LANG is the language for which type is being looked up. */ + struct symbol *lookup_primitive_type_as_symbol (const char *name, + enum language lang); +private: + + /* A structure storing a type and a corresponding symbol. The type is + defined at construction time, while the symbol is lazily created only + when asked for, but is then cached for future use. */ + struct type_and_symbol + { + /* Constructor. */ + explicit type_and_symbol (struct type *type) + : m_type (type) + { /* Nothing. */ } + + /* Default move constructor. */ + type_and_symbol (type_and_symbol&&) = default; + + DISABLE_COPY_AND_ASSIGN (type_and_symbol); + + /* Return the type from this object. */ + struct type *type () const + { return m_type; } + + /* Create and return a symbol wrapping M_TYPE from this object. */ + struct symbol *symbol (enum language lang) + { + if (m_symbol == nullptr) + m_symbol = alloc_type_symbol (lang, m_type); + return m_symbol; + } + + private: + /* The type primitive type. */ + struct type *m_type = nullptr; + + /* A symbol wrapping M_TYPE, only created when first asked for. */ + struct symbol *m_symbol = nullptr; + + /* Helper function for type lookup as a symbol. Create the symbol + corresponding to type TYPE in language LANG. */ + static struct symbol *alloc_type_symbol (enum language lang, + struct type *type); + }; + + /* Lookup a type_and_symbol entry from the primitive_types_and_symbols + vector for a type matching NAME. Return a pointer to the + type_and_symbol object from the vector. This will return nullptr if + there is no type matching NAME found. */ + type_and_symbol *lookup_primitive_type_and_symbol (const char *name); + + /* Vector of the primitive types added through add_primitive_type. These + types can be specified by name in parsing types in expressions, + regardless of whether the program being debugged actually defines such + a type. + + Within the vector each type is paired with a lazily created symbol, + which can be fetched by the symbol lookup machinery, should they be + needed. */ + std::vector primitive_types_and_symbols; /* Type of elements of strings. */ - struct type *string_char_type; + struct type *m_string_char_type = nullptr; /* Symbol name of type to use as boolean type, if defined. */ - const char *bool_type_symbol; + const char *m_bool_type_name = nullptr; + /* Otherwise, this is the default boolean builtin type. */ - struct type *bool_type_default; + struct type *m_bool_type_default = nullptr; }; /* In a language (particularly C++) a function argument of an aggregate @@ -601,18 +707,27 @@ extern enum language_mode } language_mode; +/* Return the type that should be used for booleans for language L in + GDBARCH. */ + struct type *language_bool_type (const struct language_defn *l, struct gdbarch *gdbarch); +/* Return the type that should be used for characters within a string for + language L in GDBARCH. */ + struct type *language_string_char_type (const struct language_defn *l, struct gdbarch *gdbarch); -/* Look up type NAME in language L, and return its definition for architecture - GDBARCH. Returns NULL if not found. */ +/* Look up a type from the set of OS/ABI specific types defined in GDBARCH + for language L. ARG is used for selecting the matching type, and is + passed through to the corresponding lookup_primitive_type member + function inside the language_arch_info class. */ +template struct type *language_lookup_primitive_type (const struct language_defn *l, struct gdbarch *gdbarch, - const char *name); + T arg); /* Wrapper around language_lookup_primitive_type to return the corresponding symbol. */ diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c index 1ede3ae78c3..1155469e0a5 100644 --- a/gdb/m2-lang.c +++ b/gdb/m2-lang.c @@ -161,16 +161,6 @@ const struct op_print m2_language::op_print_tab[] = {NULL, OP_NULL, PREC_BUILTIN_FUNCTION, 0} }; -/* The built-in types of Modula-2. */ - -enum m2_primitive_types { - m2_primitive_type_char, - m2_primitive_type_int, - m2_primitive_type_card, - m2_primitive_type_real, - m2_primitive_type_bool, - nr_m2_primitive_types -}; const struct exp_descriptor m2_language::exp_descriptor_modula2 = { @@ -194,24 +184,20 @@ m2_language::language_arch_info (struct gdbarch *gdbarch, { const struct builtin_m2_type *builtin = builtin_m2_type (gdbarch); - lai->string_char_type = builtin->builtin_char; - lai->primitive_type_vector - = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_m2_primitive_types + 1, - struct type *); - - lai->primitive_type_vector [m2_primitive_type_char] - = builtin->builtin_char; - lai->primitive_type_vector [m2_primitive_type_int] - = builtin->builtin_int; - lai->primitive_type_vector [m2_primitive_type_card] - = builtin->builtin_card; - lai->primitive_type_vector [m2_primitive_type_real] - = builtin->builtin_real; - lai->primitive_type_vector [m2_primitive_type_bool] - = builtin->builtin_bool; - - lai->bool_type_symbol = "BOOLEAN"; - lai->bool_type_default = builtin->builtin_bool; + /* Helper function to allow shorter lines below. */ + auto add = [&] (struct type * t) + { + lai->add_primitive_type (t); + }; + + add (builtin->builtin_char); + add (builtin->builtin_int); + add (builtin->builtin_card); + add (builtin->builtin_real); + add (builtin->builtin_bool); + + lai->set_string_char_type (builtin->builtin_char); + lai->set_bool_type (builtin->builtin_bool, "BOOLEAN"); } /* See languge.h. */ diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c index 38b98dec3d2..11032b1864e 100644 --- a/gdb/opencl-lang.c +++ b/gdb/opencl-lang.c @@ -28,49 +28,6 @@ #include "c-lang.h" #include "gdbarch.h" -/* This macro generates enum values from a given type. */ - -#define OCL_P_TYPE(TYPE)\ - opencl_primitive_type_##TYPE,\ - opencl_primitive_type_##TYPE##2,\ - opencl_primitive_type_##TYPE##3,\ - opencl_primitive_type_##TYPE##4,\ - opencl_primitive_type_##TYPE##8,\ - opencl_primitive_type_##TYPE##16 - -enum opencl_primitive_types { - OCL_P_TYPE (char), - OCL_P_TYPE (uchar), - OCL_P_TYPE (short), - OCL_P_TYPE (ushort), - OCL_P_TYPE (int), - OCL_P_TYPE (uint), - OCL_P_TYPE (long), - OCL_P_TYPE (ulong), - OCL_P_TYPE (half), - OCL_P_TYPE (float), - OCL_P_TYPE (double), - opencl_primitive_type_bool, - opencl_primitive_type_unsigned_char, - opencl_primitive_type_unsigned_short, - opencl_primitive_type_unsigned_int, - opencl_primitive_type_unsigned_long, - opencl_primitive_type_size_t, - opencl_primitive_type_ptrdiff_t, - opencl_primitive_type_intptr_t, - opencl_primitive_type_uintptr_t, - opencl_primitive_type_void, - nr_opencl_primitive_types -}; - -static struct gdbarch_data *opencl_type_data; - -static struct type ** -builtin_opencl_type (struct gdbarch *gdbarch) -{ - return (struct type **) gdbarch_data (gdbarch, opencl_type_data); -} - /* Returns the corresponding OpenCL vector type from the given type code, the length of the element type, the unsigned flag and the amount of elements (N). */ @@ -80,10 +37,7 @@ lookup_opencl_vector_type (struct gdbarch *gdbarch, enum type_code code, unsigned int el_length, unsigned int flag_unsigned, int n) { - int i; unsigned int length; - struct type *type = NULL; - struct type **types = builtin_opencl_type (gdbarch); /* Check if n describes a valid OpenCL vector size (2, 3, 4, 8, 16). */ if (n != 2 && n != 3 && n != 4 && n != 8 && n != 16) @@ -92,24 +46,20 @@ lookup_opencl_vector_type (struct gdbarch *gdbarch, enum type_code code, /* Triple vectors have the size of a quad vector. */ length = (n == 3) ? el_length * 4 : el_length * n; - for (i = 0; i < nr_opencl_primitive_types; i++) - { - LONGEST lowb, highb; - - if (types[i]->code () == TYPE_CODE_ARRAY && types[i]->is_vector () - && get_array_bounds (types[i], &lowb, &highb) - && TYPE_TARGET_TYPE (types[i])->code () == code - && TYPE_TARGET_TYPE (types[i])->is_unsigned () == flag_unsigned - && TYPE_LENGTH (TYPE_TARGET_TYPE (types[i])) == el_length - && TYPE_LENGTH (types[i]) == length - && highb - lowb + 1 == n) - { - type = types[i]; - break; - } - } - - return type; + std::function filter = [&] (struct type *type) + { + LONGEST lowb, highb; + + return (type->code () == TYPE_CODE_ARRAY && type->is_vector () + && get_array_bounds (type, &lowb, &highb) + && TYPE_TARGET_TYPE (type)->code () == code + && TYPE_TARGET_TYPE (type)->is_unsigned () == flag_unsigned + && TYPE_LENGTH (TYPE_TARGET_TYPE (type)) == el_length + && TYPE_LENGTH (type) == length + && highb - lowb + 1 == n); + }; + const struct language_defn *lang = language_def (language_opencl); + return language_lookup_primitive_type (lang, gdbarch, filter); } /* Returns nonzero if the array ARR contains duplicates within @@ -1026,17 +976,77 @@ public: void language_arch_info (struct gdbarch *gdbarch, struct language_arch_info *lai) const override { - struct type **types = builtin_opencl_type (gdbarch); + /* Helper function to allow shorter lines below. */ + auto add = [&] (struct type * t) -> struct type * + { + lai->add_primitive_type (t); + return t; + }; - /* Copy primitive types vector from gdbarch. */ - lai->primitive_type_vector = types; +/* Helper macro to create strings. */ +#define OCL_STRING(S) #S + +/* This macro allocates and assigns the type struct pointers + for the vector types. */ +#define BUILD_OCL_VTYPES(TYPE, ELEMENT_TYPE) \ + do \ + { \ + struct type *tmp; \ + tmp = add (init_vector_type (ELEMENT_TYPE, 2)); \ + tmp->set_name (OCL_STRING(TYPE ## 2)); \ + tmp = add (init_vector_type (ELEMENT_TYPE, 3)); \ + tmp->set_name (OCL_STRING(TYPE ## 3)); \ + TYPE_LENGTH (tmp) = 4 * TYPE_LENGTH (ELEMENT_TYPE); \ + tmp = add (init_vector_type (ELEMENT_TYPE, 4)); \ + tmp->set_name (OCL_STRING(TYPE ## 4)); \ + tmp = add (init_vector_type (ELEMENT_TYPE, 8)); \ + tmp->set_name (OCL_STRING(TYPE ## 8)); \ + tmp = init_vector_type (ELEMENT_TYPE, 16); \ + tmp->set_name (OCL_STRING(TYPE ## 16)); \ + } \ + while (false) + + struct type *el_type, *char_type, *int_type; + + char_type = el_type = add (arch_integer_type (gdbarch, 8, 0, "char")); + BUILD_OCL_VTYPES (char, el_type); + el_type = add (arch_integer_type (gdbarch, 8, 1, "uchar")); + BUILD_OCL_VTYPES (uchar, el_type); + el_type = add (arch_integer_type (gdbarch, 16, 0, "short")); + BUILD_OCL_VTYPES (short, el_type); + el_type = add (arch_integer_type (gdbarch, 16, 1, "ushort")); + BUILD_OCL_VTYPES (ushort, el_type); + int_type = el_type = add (arch_integer_type (gdbarch, 32, 0, "int")); + BUILD_OCL_VTYPES (int, el_type); + el_type = add (arch_integer_type (gdbarch, 32, 1, "uint")); + BUILD_OCL_VTYPES (uint, el_type); + el_type = add (arch_integer_type (gdbarch, 64, 0, "long")); + BUILD_OCL_VTYPES (long, el_type); + el_type = add (arch_integer_type (gdbarch, 64, 1, "ulong")); + BUILD_OCL_VTYPES (ulong, el_type); + el_type = add (arch_float_type (gdbarch, 16, "half", floatformats_ieee_half)); + BUILD_OCL_VTYPES (half, el_type); + el_type = add (arch_float_type (gdbarch, 32, "float", floatformats_ieee_single)); + BUILD_OCL_VTYPES (float, el_type); + el_type = add (arch_float_type (gdbarch, 64, "double", floatformats_ieee_double)); + BUILD_OCL_VTYPES (double, el_type); + + add (arch_boolean_type (gdbarch, 8, 1, "bool")); + add (arch_integer_type (gdbarch, 8, 1, "unsigned char")); + add (arch_integer_type (gdbarch, 16, 1, "unsigned short")); + add (arch_integer_type (gdbarch, 32, 1, "unsigned int")); + add (arch_integer_type (gdbarch, 64, 1, "unsigned long")); + add (arch_integer_type (gdbarch, gdbarch_ptr_bit (gdbarch), 1, "size_t")); + add (arch_integer_type (gdbarch, gdbarch_ptr_bit (gdbarch), 0, "ptrdiff_t")); + add (arch_integer_type (gdbarch, gdbarch_ptr_bit (gdbarch), 0, "intptr_t")); + add (arch_integer_type (gdbarch, gdbarch_ptr_bit (gdbarch), 1, "uintptr_t")); + add (arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void")); /* Type of elements of strings. */ - lai->string_char_type = types [opencl_primitive_type_char]; + lai->set_string_char_type (char_type); /* Specifies the return type of logical and relational operations. */ - lai->bool_type_symbol = "int"; - lai->bool_type_default = types [opencl_primitive_type_int]; + lai->set_bool_type (int_type, "int"); } /* See language.h. */ @@ -1078,97 +1088,3 @@ public: /* Single instance of the OpenCL language class. */ static opencl_language opencl_language_defn; - -static void * -build_opencl_types (struct gdbarch *gdbarch) -{ - struct type **types - = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_opencl_primitive_types + 1, - struct type *); - -/* Helper macro to create strings. */ -#define OCL_STRING(S) #S -/* This macro allocates and assigns the type struct pointers - for the vector types. */ -#define BUILD_OCL_VTYPES(TYPE)\ - types[opencl_primitive_type_##TYPE##2] \ - = init_vector_type (types[opencl_primitive_type_##TYPE], 2); \ - types[opencl_primitive_type_##TYPE##2]->set_name (OCL_STRING(TYPE ## 2)); \ - types[opencl_primitive_type_##TYPE##3] \ - = init_vector_type (types[opencl_primitive_type_##TYPE], 3); \ - types[opencl_primitive_type_##TYPE##3]->set_name (OCL_STRING(TYPE ## 3)); \ - TYPE_LENGTH (types[opencl_primitive_type_##TYPE##3]) \ - = 4 * TYPE_LENGTH (types[opencl_primitive_type_##TYPE]); \ - types[opencl_primitive_type_##TYPE##4] \ - = init_vector_type (types[opencl_primitive_type_##TYPE], 4); \ - types[opencl_primitive_type_##TYPE##4]->set_name (OCL_STRING(TYPE ## 4)); \ - types[opencl_primitive_type_##TYPE##8] \ - = init_vector_type (types[opencl_primitive_type_##TYPE], 8); \ - types[opencl_primitive_type_##TYPE##8]->set_name (OCL_STRING(TYPE ## 8)); \ - types[opencl_primitive_type_##TYPE##16] \ - = init_vector_type (types[opencl_primitive_type_##TYPE], 16); \ - types[opencl_primitive_type_##TYPE##16]->set_name (OCL_STRING(TYPE ## 16)) - - types[opencl_primitive_type_char] - = arch_integer_type (gdbarch, 8, 0, "char"); - BUILD_OCL_VTYPES (char); - types[opencl_primitive_type_uchar] - = arch_integer_type (gdbarch, 8, 1, "uchar"); - BUILD_OCL_VTYPES (uchar); - types[opencl_primitive_type_short] - = arch_integer_type (gdbarch, 16, 0, "short"); - BUILD_OCL_VTYPES (short); - types[opencl_primitive_type_ushort] - = arch_integer_type (gdbarch, 16, 1, "ushort"); - BUILD_OCL_VTYPES (ushort); - types[opencl_primitive_type_int] - = arch_integer_type (gdbarch, 32, 0, "int"); - BUILD_OCL_VTYPES (int); - types[opencl_primitive_type_uint] - = arch_integer_type (gdbarch, 32, 1, "uint"); - BUILD_OCL_VTYPES (uint); - types[opencl_primitive_type_long] - = arch_integer_type (gdbarch, 64, 0, "long"); - BUILD_OCL_VTYPES (long); - types[opencl_primitive_type_ulong] - = arch_integer_type (gdbarch, 64, 1, "ulong"); - BUILD_OCL_VTYPES (ulong); - types[opencl_primitive_type_half] - = arch_float_type (gdbarch, 16, "half", floatformats_ieee_half); - BUILD_OCL_VTYPES (half); - types[opencl_primitive_type_float] - = arch_float_type (gdbarch, 32, "float", floatformats_ieee_single); - BUILD_OCL_VTYPES (float); - types[opencl_primitive_type_double] - = arch_float_type (gdbarch, 64, "double", floatformats_ieee_double); - BUILD_OCL_VTYPES (double); - types[opencl_primitive_type_bool] - = arch_boolean_type (gdbarch, 8, 1, "bool"); - types[opencl_primitive_type_unsigned_char] - = arch_integer_type (gdbarch, 8, 1, "unsigned char"); - types[opencl_primitive_type_unsigned_short] - = arch_integer_type (gdbarch, 16, 1, "unsigned short"); - types[opencl_primitive_type_unsigned_int] - = arch_integer_type (gdbarch, 32, 1, "unsigned int"); - types[opencl_primitive_type_unsigned_long] - = arch_integer_type (gdbarch, 64, 1, "unsigned long"); - types[opencl_primitive_type_size_t] - = arch_integer_type (gdbarch, gdbarch_ptr_bit (gdbarch), 1, "size_t"); - types[opencl_primitive_type_ptrdiff_t] - = arch_integer_type (gdbarch, gdbarch_ptr_bit (gdbarch), 0, "ptrdiff_t"); - types[opencl_primitive_type_intptr_t] - = arch_integer_type (gdbarch, gdbarch_ptr_bit (gdbarch), 0, "intptr_t"); - types[opencl_primitive_type_uintptr_t] - = arch_integer_type (gdbarch, gdbarch_ptr_bit (gdbarch), 1, "uintptr_t"); - types[opencl_primitive_type_void] - = arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void"); - - return types; -} - -void _initialize_opencl_language (); -void -_initialize_opencl_language () -{ - opencl_type_data = gdbarch_data_register_post_init (build_opencl_types); -} diff --git a/gdb/p-lang.c b/gdb/p-lang.c index 9498dc09897..1610c0accae 100644 --- a/gdb/p-lang.c +++ b/gdb/p-lang.c @@ -227,26 +227,6 @@ const struct op_print pascal_op_print_tab[] = {NULL, OP_NULL, PREC_PREFIX, 0} }; -enum pascal_primitive_types { - pascal_primitive_type_int, - pascal_primitive_type_long, - pascal_primitive_type_short, - pascal_primitive_type_char, - pascal_primitive_type_float, - pascal_primitive_type_double, - pascal_primitive_type_void, - pascal_primitive_type_long_long, - pascal_primitive_type_signed_char, - pascal_primitive_type_unsigned_char, - pascal_primitive_type_unsigned_short, - pascal_primitive_type_unsigned_int, - pascal_primitive_type_unsigned_long, - pascal_primitive_type_unsigned_long_long, - pascal_primitive_type_long_double, - pascal_primitive_type_complex, - pascal_primitive_type_double_complex, - nr_pascal_primitive_types -}; /* Class representing the Pascal language. */ @@ -282,47 +262,32 @@ public: { const struct builtin_type *builtin = builtin_type (gdbarch); - lai->string_char_type = builtin->builtin_char; - lai->primitive_type_vector - = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_pascal_primitive_types + 1, - struct type *); - lai->primitive_type_vector [pascal_primitive_type_int] - = builtin->builtin_int; - lai->primitive_type_vector [pascal_primitive_type_long] - = builtin->builtin_long; - lai->primitive_type_vector [pascal_primitive_type_short] - = builtin->builtin_short; - lai->primitive_type_vector [pascal_primitive_type_char] - = builtin->builtin_char; - lai->primitive_type_vector [pascal_primitive_type_float] - = builtin->builtin_float; - lai->primitive_type_vector [pascal_primitive_type_double] - = builtin->builtin_double; - lai->primitive_type_vector [pascal_primitive_type_void] - = builtin->builtin_void; - lai->primitive_type_vector [pascal_primitive_type_long_long] - = builtin->builtin_long_long; - lai->primitive_type_vector [pascal_primitive_type_signed_char] - = builtin->builtin_signed_char; - lai->primitive_type_vector [pascal_primitive_type_unsigned_char] - = builtin->builtin_unsigned_char; - lai->primitive_type_vector [pascal_primitive_type_unsigned_short] - = builtin->builtin_unsigned_short; - lai->primitive_type_vector [pascal_primitive_type_unsigned_int] - = builtin->builtin_unsigned_int; - lai->primitive_type_vector [pascal_primitive_type_unsigned_long] - = builtin->builtin_unsigned_long; - lai->primitive_type_vector [pascal_primitive_type_unsigned_long_long] - = builtin->builtin_unsigned_long_long; - lai->primitive_type_vector [pascal_primitive_type_long_double] - = builtin->builtin_long_double; - lai->primitive_type_vector [pascal_primitive_type_complex] - = builtin->builtin_complex; - lai->primitive_type_vector [pascal_primitive_type_double_complex] - = builtin->builtin_double_complex; - - lai->bool_type_symbol = "boolean"; - lai->bool_type_default = builtin->builtin_bool; + /* Helper function to allow shorter lines below. */ + auto add = [&] (struct type * t) + { + lai->add_primitive_type (t); + }; + + add (builtin->builtin_int); + add (builtin->builtin_long); + add (builtin->builtin_short); + add (builtin->builtin_char); + add (builtin->builtin_float); + add (builtin->builtin_double); + add (builtin->builtin_void); + add (builtin->builtin_long_long); + add (builtin->builtin_signed_char); + add (builtin->builtin_unsigned_char); + add (builtin->builtin_unsigned_short); + add (builtin->builtin_unsigned_int); + add (builtin->builtin_unsigned_long); + add (builtin->builtin_unsigned_long_long); + add (builtin->builtin_long_double); + add (builtin->builtin_complex); + add (builtin->builtin_double_complex); + + lai->set_string_char_type (builtin->builtin_char); + lai->set_bool_type (builtin->builtin_bool, "boolean"); } /* See language.h. */ diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index a50f3b77a20..407be569308 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -961,27 +961,6 @@ rust_slice_type (const char *name, struct type *elt_type, return type; } -enum rust_primitive_types -{ - rust_primitive_bool, - rust_primitive_char, - rust_primitive_i8, - rust_primitive_u8, - rust_primitive_i16, - rust_primitive_u16, - rust_primitive_i32, - rust_primitive_u32, - rust_primitive_i64, - rust_primitive_u64, - rust_primitive_isize, - rust_primitive_usize, - rust_primitive_f32, - rust_primitive_f64, - rust_primitive_unit, - rust_primitive_str, - nr_rust_primitive_types -}; - /* A helper for rust_evaluate_subexp that handles OP_FUNCALL. */ @@ -1927,39 +1906,40 @@ public: { const struct builtin_type *builtin = builtin_type (gdbarch); - struct type **types - = GDBARCH_OBSTACK_CALLOC (gdbarch, nr_rust_primitive_types + 1, - struct type *); - - types[rust_primitive_bool] = arch_boolean_type (gdbarch, 8, 1, "bool"); - types[rust_primitive_char] = arch_character_type (gdbarch, 32, 1, "char"); - types[rust_primitive_i8] = arch_integer_type (gdbarch, 8, 0, "i8"); - types[rust_primitive_u8] = arch_integer_type (gdbarch, 8, 1, "u8"); - types[rust_primitive_i16] = arch_integer_type (gdbarch, 16, 0, "i16"); - types[rust_primitive_u16] = arch_integer_type (gdbarch, 16, 1, "u16"); - types[rust_primitive_i32] = arch_integer_type (gdbarch, 32, 0, "i32"); - types[rust_primitive_u32] = arch_integer_type (gdbarch, 32, 1, "u32"); - types[rust_primitive_i64] = arch_integer_type (gdbarch, 64, 0, "i64"); - types[rust_primitive_u64] = arch_integer_type (gdbarch, 64, 1, "u64"); + /* Helper function to allow shorter lines below. */ + auto add = [&] (struct type * t) -> struct type * + { + lai->add_primitive_type (t); + return t; + }; + + struct type *bool_type + = add (arch_boolean_type (gdbarch, 8, 1, "bool")); + add (arch_character_type (gdbarch, 32, 1, "char")); + add (arch_integer_type (gdbarch, 8, 0, "i8")); + struct type *u8_type + = add (arch_integer_type (gdbarch, 8, 1, "u8")); + add (arch_integer_type (gdbarch, 16, 0, "i16")); + add (arch_integer_type (gdbarch, 16, 1, "u16")); + add (arch_integer_type (gdbarch, 32, 0, "i32")); + add (arch_integer_type (gdbarch, 32, 1, "u32")); + add (arch_integer_type (gdbarch, 64, 0, "i64")); + add (arch_integer_type (gdbarch, 64, 1, "u64")); unsigned int length = 8 * TYPE_LENGTH (builtin->builtin_data_ptr); - types[rust_primitive_isize] = arch_integer_type (gdbarch, length, 0, "isize"); - types[rust_primitive_usize] = arch_integer_type (gdbarch, length, 1, "usize"); - - types[rust_primitive_f32] = arch_float_type (gdbarch, 32, "f32", - floatformats_ieee_single); - types[rust_primitive_f64] = arch_float_type (gdbarch, 64, "f64", - floatformats_ieee_double); + add (arch_integer_type (gdbarch, length, 0, "isize")); + struct type *usize_type + = add (arch_integer_type (gdbarch, length, 1, "usize")); - types[rust_primitive_unit] = arch_integer_type (gdbarch, 0, 1, "()"); + add (arch_float_type (gdbarch, 32, "f32", floatformats_ieee_single)); + add (arch_float_type (gdbarch, 64, "f64", floatformats_ieee_double)); + add (arch_integer_type (gdbarch, 0, 1, "()")); - struct type *tem = make_cv_type (1, 0, types[rust_primitive_u8], NULL); - types[rust_primitive_str] = rust_slice_type ("&str", tem, - types[rust_primitive_usize]); + struct type *tem = make_cv_type (1, 0, u8_type, NULL); + add (rust_slice_type ("&str", tem, usize_type)); - lai->primitive_type_vector = types; - lai->bool_type_default = types[rust_primitive_bool]; - lai->string_char_type = types[rust_primitive_u8]; + lai->set_bool_type (bool_type); + lai->set_string_char_type (u8_type); } /* See language.h. */ diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index f23721eee86..8cff6467603 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2020-11-12 Andrew Burgess + + * gdb.fortran/types.exp: Add more tests. + 2020-11-12 Tom Tromey PR rust/26799: diff --git a/gdb/testsuite/gdb.fortran/types.exp b/gdb/testsuite/gdb.fortran/types.exp index 8c1ca5cece8..39dc13b6a3e 100644 --- a/gdb/testsuite/gdb.fortran/types.exp +++ b/gdb/testsuite/gdb.fortran/types.exp @@ -71,6 +71,16 @@ proc test_float_literal_types_accepted {} { gdb_test "pt 10e20" "type = real\\*\[0-9\]+" } +# Test the the primitive Fortran types, those that GDB should always +# know, even if the program does not define them, are in fact, known. +proc test_primitive_types_known {} { + foreach type {void character logical*1 integer*2 integer*8 \ + logical*2 logical*8 integer logical*4 real \ + real*8 real*16} { + gdb_test "ptype $type" [string_to_regexp "type = $type"] + } +} + # Start with a fresh gdb. gdb_exit @@ -80,6 +90,7 @@ gdb_reinitialize_dir $srcdir/$subdir gdb_test "set print sevenbit-strings" "" if [set_lang_fortran] then { + test_primitive_types_known test_integer_literal_types_accepted test_integer_literal_types_rejected test_logical_literal_types_accepted -- 2.30.2