1 /* Helper routines for C++ support in GDB.
2 Copyright (C) 2002-2019 Free Software Foundation, Inc.
4 Contributed by MontaVista Software.
5 Namespace support contributed by David Carlton.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
25 /* We need this for 'domain_enum', alas... */
28 #include "common/vec.h"
29 #include "common/gdb_vecs.h"
30 #include "gdb_obstack.h"
31 #include "common/array-view.h"
34 /* Opaque declarations. */
38 struct buildsym_compunit;
41 struct demangle_component;
44 /* A string representing the name of the anonymous namespace used in GDB. */
46 #define CP_ANONYMOUS_NAMESPACE_STR "(anonymous namespace)"
48 /* The length of the string representing the anonymous namespace. */
50 #define CP_ANONYMOUS_NAMESPACE_LEN 21
52 /* A string representing the start of an operator name. */
54 #define CP_OPERATOR_STR "operator"
56 /* The length of CP_OPERATOR_STR. */
58 #define CP_OPERATOR_LEN 8
60 /* The result of parsing a name. */
62 struct demangle_parse_info
64 demangle_parse_info ();
66 ~demangle_parse_info ();
68 /* The memory used during the parse. */
69 struct demangle_info *info;
71 /* The result of the parse. */
72 struct demangle_component *tree;
74 /* Any temporary memory used during typedef replacement. */
75 struct obstack obstack;
79 /* Functions from cp-support.c. */
81 extern std::string cp_canonicalize_string (const char *string);
83 extern std::string cp_canonicalize_string_no_typedefs (const char *string);
85 typedef const char *(canonicalization_ftype) (struct type *, void *);
87 extern std::string cp_canonicalize_string_full (const char *string,
88 canonicalization_ftype *finder,
91 extern char *cp_class_name_from_physname (const char *physname);
93 extern char *method_name_from_physname (const char *physname);
95 extern unsigned int cp_find_first_component (const char *name);
97 extern unsigned int cp_entire_prefix_len (const char *name);
99 extern gdb::unique_xmalloc_ptr<char> cp_func_name (const char *full_name);
101 extern gdb::unique_xmalloc_ptr<char> cp_remove_params
102 (const char *demanged_name);
104 /* DEMANGLED_NAME is the name of a function, (optionally) including
105 parameters and (optionally) a return type. Return the name of the
106 function without parameters or return type, or NULL if we can not
107 parse the name. If COMPLETION_MODE is true, then tolerate a
108 non-existing or unbalanced parameter list. */
109 extern gdb::unique_xmalloc_ptr<char> cp_remove_params_if_any
110 (const char *demangled_name, bool completion_mode);
112 extern std::vector<symbol *> make_symbol_overload_list (const char *,
115 extern void add_symbol_overload_list_adl
116 (gdb::array_view<type *> arg_types,
117 const char *func_name,
118 std::vector<symbol *> *overload_list);
120 extern struct type *cp_lookup_rtti_type (const char *name,
121 const struct block *block);
123 /* Produce an unsigned hash value from SEARCH_NAME that is compatible
124 with cp_symbol_name_matches. Only the last component in
125 "foo::bar::function()" is considered for hashing purposes (i.e.,
126 the entire prefix is skipped), so that later on looking up for
127 "function" or "bar::function" in all namespaces is possible. */
128 extern unsigned int cp_search_name_hash (const char *search_name);
130 /* Implement the "la_get_symbol_name_matcher" language_defn method for
132 extern symbol_name_matcher_ftype *cp_get_symbol_name_matcher
133 (const lookup_name_info &lookup_name);
135 /* Functions/variables from cp-namespace.c. */
137 extern int cp_is_in_anonymous (const char *symbol_name);
139 extern void cp_scan_for_anonymous_namespaces (struct buildsym_compunit *,
140 const struct symbol *symbol,
141 struct objfile *objfile);
143 extern struct block_symbol cp_lookup_symbol_nonlocal
144 (const struct language_defn *langdef,
146 const struct block *block,
147 const domain_enum domain);
149 extern struct block_symbol
150 cp_lookup_symbol_namespace (const char *the_namespace,
152 const struct block *block,
153 const domain_enum domain);
155 extern struct block_symbol cp_lookup_symbol_imports_or_template
158 const struct block *block,
159 const domain_enum domain);
161 extern struct block_symbol
162 cp_lookup_nested_symbol (struct type *parent_type,
163 const char *nested_name,
164 const struct block *block,
165 const domain_enum domain);
167 struct type *cp_lookup_transparent_type (const char *name);
169 /* See description in cp-namespace.c. */
171 struct type *cp_find_type_baseclass_by_name (struct type *parent_type,
174 /* Functions from cp-name-parser.y. */
176 extern std::unique_ptr<demangle_parse_info> cp_demangled_name_to_comp
177 (const char *demangled_name, std::string *errmsg);
179 extern gdb::unique_xmalloc_ptr<char> cp_comp_to_string
180 (struct demangle_component *result, int estimated_len);
182 extern void cp_merge_demangle_parse_infos (struct demangle_parse_info *,
183 struct demangle_component *,
184 struct demangle_parse_info *);
186 /* The list of "maint cplus" commands. */
188 extern struct cmd_list_element *maint_cplus_cmd_list;
190 /* A wrapper for bfd_demangle. */
192 char *gdb_demangle (const char *name, int options);
194 /* Like gdb_demangle, but suitable for use as la_sniff_from_mangled_name. */
196 int gdb_sniff_from_mangled_name (const char *mangled, char **demangled);
198 #endif /* CP_SUPPORT_H */