From 0a50df5dabfe12c8bf20f4f724622ff38ef7828b Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Thu, 14 May 2020 19:03:45 +0100 Subject: [PATCH] gdb: Convert language la_demangle field to a method This commit changes the language_data::la_demangle function pointer member variable into a member function of language_defn. The only slightly "weird" change in this commit is in f-lang.c, where I have given the Fortran language a demangle method that is identical to the default language_defn::demangle. The only reason for this is to give me somewhere to copy the comment that was previously embedded within the f_language_data structure. There should be no user visible changes after this commit. gdb/ChangeLog: * ada-lang.c (ada_language_data): Delete la_demangle initializer. (ada_language::demangle): New member function. * c-lang.c (c_language_data): Delete la_demangle initializer. (cplus_language_data): Delete la_demangle initializer. (cplus_language::demangle): New member function. (asm_language_data): Delete la_demangle initializer. (minimal_language_data): Delete la_demangle initializer. * d-lang.c (d_language_data): Delete la_demangle initializer. (d_language::demangle): New member function. * f-lang.c (f_language_data): Delete la_demangle initializer. (f_language::demangle): New member function. * go-lang.c (go_language_data): Delete la_demangle initializer. (go_language::demangle): New member function. * language.c (language_demangle): Update. (unk_lang_demangle): Delete. (unknown_language_data): Delete la_demangle initializer. (unknown_language::demangle): New member function. (auto_language_data): Delete la_demangle initializer. (auto_language::demangle): New member function. * language.h (language_data): Delete la_demangle field. (language_defn::demangle): New function. * m2-lang.c (m2_language_data): Delete la_demangle initializer. * objc-lang.c (objc_language_data): Delete la_demangle initializer. (objc_language::demangle): New member function. * opencl-lang.c (opencl_language_data): Delete la_demangle initializer. * p-lang.c (pascal_language_data): Likewise. * rust-lang.c (rust_language_data): Likewise. (rust_language::demangle): New member functi --- gdb/ChangeLog | 33 +++++++++++++++++++++++++++++++++ gdb/ada-lang.c | 8 +++++++- gdb/c-lang.c | 11 +++++++---- gdb/d-lang.c | 8 +++++++- gdb/f-lang.c | 19 ++++++++++++------- gdb/go-lang.c | 8 +++++++- gdb/language.c | 28 ++++++++++++++++++---------- gdb/language.h | 9 ++++++--- gdb/m2-lang.c | 1 - gdb/objc-lang.c | 8 +++++++- gdb/opencl-lang.c | 1 - gdb/p-lang.c | 1 - gdb/rust-lang.c | 8 +++++++- 13 files changed, 111 insertions(+), 32 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index bf690af9c43..1390be1933f 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,36 @@ +2020-06-02 Andrew Burgess + + * ada-lang.c (ada_language_data): Delete la_demangle initializer. + (ada_language::demangle): New member function. + * c-lang.c (c_language_data): Delete la_demangle initializer. + (cplus_language_data): Delete la_demangle initializer. + (cplus_language::demangle): New member function. + (asm_language_data): Delete la_demangle initializer. + (minimal_language_data): Delete la_demangle initializer. + * d-lang.c (d_language_data): Delete la_demangle initializer. + (d_language::demangle): New member function. + * f-lang.c (f_language_data): Delete la_demangle initializer. + (f_language::demangle): New member function. + * go-lang.c (go_language_data): Delete la_demangle initializer. + (go_language::demangle): New member function. + * language.c (language_demangle): Update. + (unk_lang_demangle): Delete. + (unknown_language_data): Delete la_demangle initializer. + (unknown_language::demangle): New member function. + (auto_language_data): Delete la_demangle initializer. + (auto_language::demangle): New member function. + * language.h (language_data): Delete la_demangle field. + (language_defn::demangle): New function. + * m2-lang.c (m2_language_data): Delete la_demangle initializer. + * objc-lang.c (objc_language_data): Delete la_demangle + initializer. + (objc_language::demangle): New member function. + * opencl-lang.c (opencl_language_data): Delete la_demangle + initializer. + * p-lang.c (pascal_language_data): Likewise. + * rust-lang.c (rust_language_data): Likewise. + (rust_language::demangle): New member function. + 2020-06-02 Andrew Burgess * ada-lang.c (ada_language_data): Delete la_print_type diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index f84f02f897d..42e57093bf9 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -13926,7 +13926,6 @@ extern const struct language_data ada_language_data = NULL, /* name_of_this */ true, /* la_store_sym_names_in_linkage_form_p */ ada_lookup_symbol_nonlocal, /* Looking up non-local symbols. */ - ada_la_decode, /* Language specific symbol demangler */ NULL, /* Language specific class_name_from_physname */ ada_op_print_tab, /* expression operators for printing */ @@ -14108,6 +14107,13 @@ public: /* See language.h. */ + char *demangle (const char *mangled, int options) const override + { + return ada_la_decode (mangled, options); + } + + /* See language.h. */ + void print_type (struct type *type, const char *varstring, struct ui_file *stream, int show, int level, const struct type_print_options *flags) const override diff --git a/gdb/c-lang.c b/gdb/c-lang.c index abcdc528867..de7a1bda346 100644 --- a/gdb/c-lang.c +++ b/gdb/c-lang.c @@ -912,7 +912,6 @@ extern const struct language_data c_language_data = NULL, /* name_of_this */ true, /* la_store_sym_names_in_linkage_form_p */ basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ - NULL, /* Language specific symbol demangler */ NULL, /* Language specific class_name_from_physname */ c_op_print_tab, /* expression operators for printing */ @@ -1022,7 +1021,6 @@ extern const struct language_data cplus_language_data = "this", /* name_of_this */ false, /* la_store_sym_names_in_linkage_form_p */ cp_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ - gdb_demangle, /* Language specific symbol demangler */ cp_class_name_from_physname, /* Language specific class_name_from_physname */ c_op_print_tab, /* expression operators for printing */ @@ -1146,6 +1144,13 @@ public: /* See language.h. */ + char *demangle (const char *mangled, int options) const override + { + return gdb_demangle (mangled, options); + } + + /* See language.h. */ + void print_type (struct type *type, const char *varstring, struct ui_file *stream, int show, int level, const struct type_print_options *flags) const override @@ -1188,7 +1193,6 @@ extern const struct language_data asm_language_data = NULL, /* name_of_this */ true, /* la_store_sym_names_in_linkage_form_p */ basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ - NULL, /* Language specific symbol demangler */ NULL, /* Language specific class_name_from_physname */ c_op_print_tab, /* expression operators for printing */ @@ -1263,7 +1267,6 @@ extern const struct language_data minimal_language_data = NULL, /* name_of_this */ true, /* la_store_sym_names_in_linkage_form_p */ basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ - NULL, /* Language specific symbol demangler */ NULL, /* Language specific class_name_from_physname */ c_op_print_tab, /* expression operators for printing */ diff --git a/gdb/d-lang.c b/gdb/d-lang.c index 815b59734e0..fb56e1e9baf 100644 --- a/gdb/d-lang.c +++ b/gdb/d-lang.c @@ -155,7 +155,6 @@ extern const struct language_data d_language_data = "this", false, /* la_store_sym_names_in_linkage_form_p */ d_lookup_symbol_nonlocal, - d_demangle, /* Language specific symbol demangler. */ NULL, /* Language specific class_name_from_physname. */ d_op_print_tab, /* Expression operators for printing. */ @@ -254,6 +253,13 @@ public: /* See language.h. */ + char *demangle (const char *mangled, int options) const override + { + return d_demangle (mangled, options); + } + + /* See language.h. */ + void print_type (struct type *type, const char *varstring, struct ui_file *stream, int show, int level, const struct type_print_options *flags) const override diff --git a/gdb/f-lang.c b/gdb/f-lang.c index 1b0fec68c0e..bd5f78ccbef 100644 --- a/gdb/f-lang.c +++ b/gdb/f-lang.c @@ -615,13 +615,6 @@ extern const struct language_data f_language_data = NULL, /* name_of_this */ false, /* la_store_sym_names_in_linkage_form_p */ cp_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ - - /* We could support demangling here to provide module namespaces - also for inferiors with only minimal symbol table (ELF symbols). - Just the mangling standard is not standardized across compilers - and there is no DW_AT_producer available for inferiors with only - the ELF symbols to check the mangling kind. */ - NULL, /* Language specific symbol demangler */ NULL, /* Language specific class_name_from_physname */ f_op_print_tab, /* expression operators for printing */ @@ -692,6 +685,18 @@ public: /* See language.h. */ + char *demangle (const char *mangled, int options) const override + { + /* We could support demangling here to provide module namespaces + also for inferiors with only minimal symbol table (ELF symbols). + Just the mangling standard is not standardized across compilers + and there is no DW_AT_producer available for inferiors with only + the ELF symbols to check the mangling kind. */ + return nullptr; + } + + /* See language.h. */ + void print_type (struct type *type, const char *varstring, struct ui_file *stream, int show, int level, const struct type_print_options *flags) const override diff --git a/gdb/go-lang.c b/gdb/go-lang.c index 1ec53474cf0..6bd87aa597b 100644 --- a/gdb/go-lang.c +++ b/gdb/go-lang.c @@ -540,7 +540,6 @@ extern const struct language_data go_language_data = NULL, /* name_of_this */ false, /* la_store_sym_names_in_linkage_form_p */ basic_lookup_symbol_nonlocal, - go_demangle, /* Language specific symbol demangler. */ NULL, /* Language specific class_name_from_physname. */ go_op_print_tab, /* Expression operators for printing. */ @@ -628,6 +627,13 @@ public: /* See language.h. */ + char *demangle (const char *mangled, int options) const override + { + return go_demangle (mangled, options); + } + + /* See language.h. */ + void print_type (struct type *type, const char *varstring, struct ui_file *stream, int show, int level, const struct type_print_options *flags) const override diff --git a/gdb/language.c b/gdb/language.c index c8f0349901b..c447eaba0c5 100644 --- a/gdb/language.c +++ b/gdb/language.c @@ -589,8 +589,8 @@ char * language_demangle (const struct language_defn *current_language, const char *mangled, int options) { - if (current_language != NULL && current_language->la_demangle) - return current_language->la_demangle (mangled, options); + if (current_language != NULL) + return current_language->demangle (mangled, options); return NULL; } @@ -749,12 +749,6 @@ static CORE_ADDR unk_lang_trampoline (struct frame_info *frame, CORE_ADDR pc) return 0; } -/* Unknown languages just use the cplus demangler. */ -static char *unk_lang_demangle (const char *mangled, int options) -{ - return gdb_demangle (mangled, options); -} - static char *unk_lang_class_name (const char *mangled) { return NULL; @@ -800,7 +794,6 @@ extern const struct language_data unknown_language_data = "this", /* name_of_this */ true, /* store_sym_names_in_linkage_form_p */ basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ - unk_lang_demangle, /* Language specific symbol demangler */ unk_lang_class_name, /* Language specific class_name_from_physname */ unk_op_print_tab, /* expression operators for printing */ @@ -840,6 +833,14 @@ public: { error (_("unimplemented unknown_language::print_type called")); } + + /* See language.h. */ + + char *demangle (const char *mangled, int options) const override + { + /* The unknown language just uses the C++ demangler. */ + return gdb_demangle (mangled, options); + } }; /* Single instance of the unknown language class. */ @@ -871,7 +872,6 @@ extern const struct language_data auto_language_data = "this", /* name_of_this */ false, /* store_sym_names_in_linkage_form_p */ basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ - unk_lang_demangle, /* Language specific symbol demangler */ unk_lang_class_name, /* Language specific class_name_from_physname */ unk_op_print_tab, /* expression operators for printing */ @@ -911,6 +911,14 @@ public: { error (_("unimplemented auto_language::print_type called")); } + + /* See language.h. */ + + char *demangle (const char *mangled, int options) const override + { + /* The auto language just uses the C++ demangler. */ + return gdb_demangle (mangled, options); + } }; /* Single instance of the fake "auto" language. */ diff --git a/gdb/language.h b/gdb/language.h index 8defe959015..c456189b14d 100644 --- a/gdb/language.h +++ b/gdb/language.h @@ -310,9 +310,6 @@ struct language_data const struct block *, const domain_enum); - /* Return demangled language symbol, or NULL. */ - char *(*la_demangle) (const char *mangled, int options); - /* Return class name of a mangled method name or NULL. */ char *(*la_class_name_from_physname) (const char *physname); @@ -512,6 +509,12 @@ struct language_defn : language_data return false; } + /* Return demangled language symbol version of MANGLED, or NULL. */ + virtual char *demangle (const char *mangled, int options) const + { + return nullptr; + } + /* Print a type using syntax appropriate for this language. */ virtual void print_type (struct type *, const char *, struct ui_file *, int, diff --git a/gdb/m2-lang.c b/gdb/m2-lang.c index 098a2aadd95..a83cf1451b1 100644 --- a/gdb/m2-lang.c +++ b/gdb/m2-lang.c @@ -374,7 +374,6 @@ extern const struct language_data m2_language_data = NULL, /* name_of_this */ false, /* la_store_sym_names_in_linkage_form_p */ basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ - NULL, /* Language specific symbol demangler */ NULL, /* Language specific class_name_from_physname */ m2_op_print_tab, /* expression operators for printing */ diff --git a/gdb/objc-lang.c b/gdb/objc-lang.c index 0566ce8f188..1e3d1fd3616 100644 --- a/gdb/objc-lang.c +++ b/gdb/objc-lang.c @@ -380,7 +380,6 @@ extern const struct language_data objc_language_data = "self", /* name_of_this */ false, /* la_store_sym_names_in_linkage_form_p */ basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ - objc_demangle, /* Language specific symbol demangler */ NULL, /* Language specific class_name_from_physname */ objc_op_print_tab, /* Expression operators for printing */ @@ -422,6 +421,13 @@ public: /* See language.h. */ + char *demangle (const char *mangled, int options) const override + { + return objc_demangle (mangled, options); + } + + /* See language.h. */ + void print_type (struct type *type, const char *varstring, struct ui_file *stream, int show, int level, const struct type_print_options *flags) const override diff --git a/gdb/opencl-lang.c b/gdb/opencl-lang.c index d1ca29d32f7..d98b228bc74 100644 --- a/gdb/opencl-lang.c +++ b/gdb/opencl-lang.c @@ -1028,7 +1028,6 @@ extern const struct language_data opencl_language_data = NULL, /* name_of_this */ false, /* la_store_sym_names_in_linkage_form_p */ basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ - NULL, /* Language specific symbol demangler */ NULL, /* Language specific class_name_from_physname */ c_op_print_tab, /* expression operators for printing */ diff --git a/gdb/p-lang.c b/gdb/p-lang.c index 9aa03de6a59..50b913e8b6c 100644 --- a/gdb/p-lang.c +++ b/gdb/p-lang.c @@ -405,7 +405,6 @@ extern const struct language_data pascal_language_data = "this", /* name_of_this */ false, /* la_store_sym_names_in_linkage_form_p */ basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ - NULL, /* Language specific symbol demangler */ NULL, /* Language specific class_name_from_physname */ pascal_op_print_tab, /* expression operators for printing */ 1, /* c-style arrays */ diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c index f78686ae1c8..8848e975228 100644 --- a/gdb/rust-lang.c +++ b/gdb/rust-lang.c @@ -2060,7 +2060,6 @@ extern const struct language_data rust_language_data = NULL, /* name_of_this */ false, /* la_store_sym_names_in_linkage_form_p */ rust_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */ - gdb_demangle, /* Language specific symbol demangler */ NULL, /* Language specific class_name_from_physname */ c_op_print_tab, /* expression operators for printing */ @@ -2136,6 +2135,13 @@ public: /* See language.h. */ + char *demangle (const char *mangled, int options) const override + { + return gdb_demangle (mangled, options); + } + + /* See language.h. */ + void print_type (struct type *type, const char *varstring, struct ui_file *stream, int show, int level, const struct type_print_options *flags) const override -- 2.30.2