+2020-06-02 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ * ada-lang.c (ada_sniff_from_mangled_name): Delete function,
+ implementation moves to...
+ (ada_language::sniff_from_mangled_name): ...here. Update return
+ type.
+ (ada_language_data): Delete la_sniff_from_mangled_name
+ initializer.
+ * c-lang.c (c_language_data): Likewise.
+ (cplus_language_data): Likewise.
+ (cplus_language::sniff_from_mangled_name): New member function,
+ implementation taken from gdb_sniff_from_mangled_name.
+ (asm_language_data): Delete la_sniff_from_mangled_name
+ initializer.
+ (minimal_language_data): Likewise.
+ * cp-support.c (gdb_sniff_from_mangled_name): Delete,
+ implementation moves to cplus_language::sniff_from_mangled_name.
+ * cp-support.h (gdb_sniff_from_mangled_name): Delete declaration.
+ * d-lang.c (d_sniff_from_mangled_name): Delete, implementation
+ moves to...
+ (d_language::sniff_from_mangled_name): ...here.
+ (d_language_data): Delete la_sniff_from_mangled_name initializer.
+ * f-lang.c (f_language_data): Likewise.
+ * go-lang.c (go_sniff_from_mangled_name): Delete, implementation
+ moves to...
+ (go_language::sniff_from_mangled_name): ...here.
+ (go_language_data): Delete la_sniff_from_mangled_name initializer.
+ * language.c (language_sniff_from_mangled_name): Delete.
+ (unknown_language_data): Delete la_sniff_from_mangled_name
+ initializer.
+ (auto_language_data): Likewise.
+ * language.h (language_data): Delete la_sniff_from_mangled_name
+ field.
+ (language_defn::sniff_from_mangled_name): New function.
+ (language_sniff_from_mangled_name): Delete declaration.
+ * m2-lang.c (m2_language_data): Delete la_sniff_from_mangled_name
+ field.
+ * objc-lang.c (objc_sniff_from_mangled_name): Delete,
+ implementation moves to...
+ (objc_language::sniff_from_mangled_name): ...here.
+ (objc_language_data): Delete la_sniff_from_mangled_name initializer.
+ * opencl-lang.c (opencl_language_data): Likewise.
+ * p-lang.c (pascal_language_data): Likewise.
+ * rust-lang.c (rust_sniff_from_mangled_name): Delete,
+ implementation moves to...
+ (rust_language::sniff_from_mangled_name): ...here.
+ (rust_language_data): Delete la_sniff_from_mangled_name
+ initializer.
+ * symtab.c (symbol_find_demangled_name): Call
+ sniff_from_mangled_name member function.
+
2020-06-02 Andrew Burgess <andrew.burgess@embecosm.com>
* ada-lang.c (ada_language_data): Delete la_search_name_hash
return xstrdup (ada_decode (encoded).c_str ());
}
-/* Implement la_sniff_from_mangled_name for Ada. */
-
-static int
-ada_sniff_from_mangled_name (const char *mangled, char **out)
-{
- std::string demangled = ada_decode (mangled);
-
- *out = NULL;
-
- if (demangled != mangled && demangled[0] != '<')
- {
- /* Set the gsymbol language to Ada, but still return 0.
- Two reasons for that:
-
- 1. For Ada, we prefer computing the symbol's decoded name
- on the fly rather than pre-compute it, in order to save
- memory (Ada projects are typically very large).
-
- 2. There are some areas in the definition of the GNAT
- encoding where, with a bit of bad luck, we might be able
- to decode a non-Ada symbol, generating an incorrect
- demangled name (Eg: names ending with "TB" for instance
- are identified as task bodies and so stripped from
- the decoded name returned).
-
- Returning 1, here, but not setting *DEMANGLED, helps us get a
- little bit of the best of both worlds. Because we're last,
- we should not affect any of the other languages that were
- able to demangle the symbol before us; we get to correctly
- tag Ada symbols as such; and even if we incorrectly tagged a
- non-Ada symbol, which should be rare, any routing through the
- Ada language should be transparent (Ada tries to behave much
- like C/C++ with non-Ada symbols). */
- return 1;
- }
-
- return 0;
-}
-
\f
/* Arrays */
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 */
- ada_sniff_from_mangled_name,
NULL, /* Language specific
class_name_from_physname */
ada_op_print_tab, /* expression operators for printing */
return true;
}
+
+ /* See language.h. */
+ bool sniff_from_mangled_name (const char *mangled,
+ char **out) const override
+ {
+ std::string demangled = ada_decode (mangled);
+
+ *out = NULL;
+
+ if (demangled != mangled && demangled[0] != '<')
+ {
+ /* Set the gsymbol language to Ada, but still return 0.
+ Two reasons for that:
+
+ 1. For Ada, we prefer computing the symbol's decoded name
+ on the fly rather than pre-compute it, in order to save
+ memory (Ada projects are typically very large).
+
+ 2. There are some areas in the definition of the GNAT
+ encoding where, with a bit of bad luck, we might be able
+ to decode a non-Ada symbol, generating an incorrect
+ demangled name (Eg: names ending with "TB" for instance
+ are identified as task bodies and so stripped from
+ the decoded name returned).
+
+ Returning true, here, but not setting *DEMANGLED, helps us get
+ a little bit of the best of both worlds. Because we're last,
+ we should not affect any of the other languages that were
+ able to demangle the symbol before us; we get to correctly
+ tag Ada symbols as such; and even if we incorrectly tagged a
+ non-Ada symbol, which should be rare, any routing through the
+ Ada language should be transparent (Ada tries to behave much
+ like C/C++ with non-Ada symbols). */
+ return true;
+ }
+
+ return false;
+ }
};
/* Single instance of the Ada language class. */
true, /* la_store_sym_names_in_linkage_form_p */
basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
NULL, /* Language specific symbol demangler */
- NULL,
NULL, /* Language specific
class_name_from_physname */
c_op_print_tab, /* expression operators for printing */
false, /* la_store_sym_names_in_linkage_form_p */
cp_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
gdb_demangle, /* Language specific symbol demangler */
- gdb_sniff_from_mangled_name,
cp_class_name_from_physname, /* Language specific
class_name_from_physname */
c_op_print_tab, /* expression operators for printing */
{
return cp_search_name_hash (name);
}
+
+ /* See language.h. */
+ bool sniff_from_mangled_name (const char *mangled,
+ char **demangled) const override
+ {
+ *demangled = gdb_demangle (mangled, DMGL_PARAMS | DMGL_ANSI);
+ return *demangled != NULL;
+ }
};
/* The single instance of the C++ language class. */
true, /* la_store_sym_names_in_linkage_form_p */
basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
NULL, /* Language specific symbol demangler */
- NULL,
NULL, /* Language specific
class_name_from_physname */
c_op_print_tab, /* expression operators for printing */
true, /* la_store_sym_names_in_linkage_form_p */
basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
NULL, /* Language specific symbol demangler */
- NULL,
NULL, /* Language specific
class_name_from_physname */
c_op_print_tab, /* expression operators for printing */
/* See cp-support.h. */
-int
-gdb_sniff_from_mangled_name (const char *mangled, char **demangled)
-{
- *demangled = gdb_demangle (mangled, DMGL_PARAMS | DMGL_ANSI);
- return *demangled != NULL;
-}
-
-/* See cp-support.h. */
-
unsigned int
cp_search_name_hash (const char *search_name)
{
char *gdb_demangle (const char *name, int options);
-/* Like gdb_demangle, but suitable for use as la_sniff_from_mangled_name. */
-
-int gdb_sniff_from_mangled_name (const char *mangled, char **demangled);
-
#endif /* CP_SUPPORT_H */
return gdb_demangle (symbol, options | DMGL_DLANG);
}
-/* la_sniff_from_mangled_name implementation for D. */
-
-static int
-d_sniff_from_mangled_name (const char *mangled, char **demangled)
-{
- *demangled = d_demangle (mangled, 0);
- return *demangled != NULL;
-}
-
/* Table mapping opcodes into strings for printing operators
and precedences of the operators. */
static const struct op_print d_op_print_tab[] =
false, /* la_store_sym_names_in_linkage_form_p */
d_lookup_symbol_nonlocal,
d_demangle, /* Language specific symbol demangler. */
- d_sniff_from_mangled_name,
NULL, /* Language specific
class_name_from_physname. */
d_op_print_tab, /* Expression operators for printing. */
lai->bool_type_symbol = "bool";
lai->bool_type_default = builtin->builtin_bool;
}
+
+ /* See language.h. */
+ bool sniff_from_mangled_name (const char *mangled,
+ char **demangled) const override
+ {
+ *demangled = d_demangle (mangled, 0);
+ return *demangled != NULL;
+ }
};
/* Single instance of the D language class. */
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,
NULL, /* Language specific
class_name_from_physname */
f_op_print_tab, /* expression operators for printing */
return result;
}
-/* la_sniff_from_mangled_name for Go. */
-
-static int
-go_sniff_from_mangled_name (const char *mangled, char **demangled)
-{
- *demangled = go_demangle (mangled, 0);
- return *demangled != NULL;
-}
-
/* Given a Go symbol, return its package or NULL if unknown.
Space for the result is malloc'd, caller must free. */
false, /* la_store_sym_names_in_linkage_form_p */
basic_lookup_symbol_nonlocal,
go_demangle, /* Language specific symbol demangler. */
- go_sniff_from_mangled_name,
NULL, /* Language specific
class_name_from_physname. */
go_op_print_tab, /* Expression operators for printing. */
lai->bool_type_symbol = "bool";
lai->bool_type_default = builtin->builtin_bool;
}
+
+ /* See language.h. */
+ bool sniff_from_mangled_name (const char *mangled,
+ char **demangled) const override
+ {
+ *demangled = go_demangle (mangled, 0);
+ return *demangled != NULL;
+ }
};
/* Single instance of the Go language class. */
return NULL;
}
-/* See language.h. */
-
-int
-language_sniff_from_mangled_name (const struct language_defn *lang,
- const char *mangled, char **demangled)
-{
- gdb_assert (lang != NULL);
-
- if (lang->la_sniff_from_mangled_name == NULL)
- {
- *demangled = NULL;
- return 0;
- }
-
- return lang->la_sniff_from_mangled_name (mangled, demangled);
-}
-
/* Return class name from physname or NULL. */
char *
language_class_name_from_physname (const struct language_defn *lang,
true, /* store_sym_names_in_linkage_form_p */
basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
unk_lang_demangle, /* Language specific symbol demangler */
- NULL,
unk_lang_class_name, /* Language specific
class_name_from_physname */
unk_op_print_tab, /* expression operators for printing */
false, /* store_sym_names_in_linkage_form_p */
basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
unk_lang_demangle, /* Language specific symbol demangler */
- NULL,
unk_lang_class_name, /* Language specific
class_name_from_physname */
unk_op_print_tab, /* expression operators for printing */
/* Return demangled language symbol, or NULL. */
char *(*la_demangle) (const char *mangled, int options);
- /* Demangle a symbol according to this language's rules. Unlike
- la_demangle, this does not take any options.
-
- *DEMANGLED will be set by this function.
-
- If this function returns 0, then *DEMANGLED must always be set
- to NULL.
-
- If this function returns 1, the implementation may set this to
- a xmalloc'd string holding the demangled form. However, it is
- not required to. The string, if any, is owned by the caller.
-
- The resulting string should be of the form that will be
- installed into a symbol. */
- int (*la_sniff_from_mangled_name) (const char *mangled, char **demangled);
-
/* Return class name of a mangled method name or NULL. */
char *(*la_class_name_from_physname) (const char *physname);
/* Hash the given symbol search name. */
virtual unsigned int search_name_hash (const char *name) const;
+ /* Demangle a symbol according to this language's rules. Unlike
+ la_demangle, this does not take any options.
+
+ *DEMANGLED will be set by this function.
+
+ If this function returns false, then *DEMANGLED must always be set
+ to NULL.
+
+ If this function returns true, the implementation may set this to
+ a xmalloc'd string holding the demangled form. However, it is
+ not required to. The string, if any, is owned by the caller.
+
+ The resulting string should be of the form that will be
+ installed into a symbol. */
+ virtual bool sniff_from_mangled_name (const char *mangled,
+ char **demangled) const
+ {
+ *demangled = nullptr;
+ return false;
+ }
+
/* List of all known languages. */
static const struct language_defn *languages[nr_languages];
};
extern char *language_demangle (const struct language_defn *current_language,
const char *mangled, int options);
-/* A wrapper for la_sniff_from_mangled_name. The arguments and result
- are as for the method. */
-
-extern int language_sniff_from_mangled_name (const struct language_defn *lang,
- const char *mangled,
- char **demangled);
-
/* Return class name from physname, or NULL. */
extern char *language_class_name_from_physname (const struct language_defn *,
const char *physname);
false, /* la_store_sym_names_in_linkage_form_p */
basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
NULL, /* Language specific symbol demangler */
- NULL,
NULL, /* Language specific
class_name_from_physname */
m2_op_print_tab, /* expression operators for printing */
return NULL; /* Not an objc mangled name. */
}
-/* la_sniff_from_mangled_name for ObjC. */
-
-static int
-objc_sniff_from_mangled_name (const char *mangled, char **demangled)
-{
- *demangled = objc_demangle (mangled, 0);
- return *demangled != NULL;
-}
-
/* Determine if we are currently in the Objective-C dispatch function.
If so, get the address of the method function that the dispatcher
would call and use that as the function to step into instead. Also
false, /* la_store_sym_names_in_linkage_form_p */
basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
objc_demangle, /* Language specific symbol demangler */
- objc_sniff_from_mangled_name,
NULL, /* Language specific
class_name_from_physname */
objc_op_print_tab, /* Expression operators for printing */
{
c_language_arch_info (gdbarch, lai);
}
+
+ /* See language.h. */
+ bool sniff_from_mangled_name (const char *mangled,
+ char **demangled) const override
+ {
+ *demangled = objc_demangle (mangled, 0);
+ return *demangled != NULL;
+ }
};
/* Single instance of the class representing the Objective-C language. */
false, /* la_store_sym_names_in_linkage_form_p */
basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
NULL, /* Language specific symbol demangler */
- NULL,
NULL, /* Language specific
class_name_from_physname */
c_op_print_tab, /* expression operators for printing */
false, /* la_store_sym_names_in_linkage_form_p */
basic_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
NULL, /* Language specific symbol demangler */
- NULL,
NULL, /* Language specific class_name_from_physname */
pascal_op_print_tab, /* expression operators for printing */
1, /* c-style arrays */
\f
-/* la_sniff_from_mangled_name for Rust. */
-
-static int
-rust_sniff_from_mangled_name (const char *mangled, char **demangled)
-{
- *demangled = gdb_demangle (mangled, DMGL_PARAMS | DMGL_ANSI);
- return *demangled != NULL;
-}
-
-\f
-
/* la_watch_location_expression for Rust. */
static gdb::unique_xmalloc_ptr<char>
false, /* la_store_sym_names_in_linkage_form_p */
rust_lookup_symbol_nonlocal, /* lookup_symbol_nonlocal */
gdb_demangle, /* Language specific symbol demangler */
- rust_sniff_from_mangled_name,
NULL, /* Language specific
class_name_from_physname */
c_op_print_tab, /* expression operators for printing */
lai->bool_type_default = types[rust_primitive_bool];
lai->string_char_type = types[rust_primitive_u8];
}
+
+ /* See language.h. */
+ bool sniff_from_mangled_name (const char *mangled,
+ char **demangled) const override
+ {
+ *demangled = gdb_demangle (mangled, DMGL_PARAMS | DMGL_ANSI);
+ return *demangled != NULL;
+ }
};
/* Single instance of the Rust language class. */
{
const struct language_defn *lang = language_def (gsymbol->language ());
- language_sniff_from_mangled_name (lang, mangled, &demangled);
+ lang->sniff_from_mangled_name (mangled, &demangled);
return demangled;
}
enum language l = (enum language) i;
const struct language_defn *lang = language_def (l);
- if (language_sniff_from_mangled_name (lang, mangled, &demangled))
+ if (lang->sniff_from_mangled_name (mangled, &demangled))
{
gsymbol->m_language = l;
return demangled;