aboutsummaryrefslogtreecommitdiff
path: root/gdb/c-lang.c
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2020-10-30 20:40:59 +0000
committerAndrew Burgess <andrew.burgess@embecosm.com>2020-11-12 23:36:25 +0000
commit7bea47f0012c208d935c50d3b7ce9af7d34482b7 (patch)
tree2af27e112306612fdb6c55597687ef6640f312e0 /gdb/c-lang.c
parentbf6e5d01d7b149e116a008bd4348983c6f56e9ba (diff)
downloadgdb-7bea47f0012c208d935c50d3b7ce9af7d34482b7.zip
gdb-7bea47f0012c208d935c50d3b7ce9af7d34482b7.tar.gz
gdb-7bea47f0012c208d935c50d3b7ce9af7d34482b7.tar.bz2
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.
Diffstat (limited to 'gdb/c-lang.c')
-rw-r--r--gdb/c-lang.c194
1 files changed, 62 insertions, 132 deletions
diff --git a/gdb/c-lang.c b/gdb/c-lang.c
index 329986c..8dbce39 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. */