xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/cp-support.h (revision 8b657b0747480f8989760d71343d6dd33f8d4cf9)
1 /* Helper routines for C++ support in GDB.
2    Copyright (C) 2002-2023 Free Software Foundation, Inc.
3 
4    Contributed by MontaVista Software.
5    Namespace support contributed by David Carlton.
6 
7    This file is part of GDB.
8 
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.
13 
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.
18 
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/>.  */
21 
22 #ifndef CP_SUPPORT_H
23 #define CP_SUPPORT_H
24 
25 /* We need this for 'domain_enum', alas...  */
26 
27 #include "symtab.h"
28 #include "gdbsupport/gdb_vecs.h"
29 #include "gdbsupport/gdb_obstack.h"
30 #include "gdbsupport/array-view.h"
31 #include <vector>
32 
33 /* Opaque declarations.  */
34 
35 struct symbol;
36 struct block;
37 struct buildsym_compunit;
38 struct objfile;
39 struct type;
40 struct demangle_component;
41 struct using_direct;
42 
43 /* A string representing the name of the anonymous namespace used in GDB.  */
44 
45 #define CP_ANONYMOUS_NAMESPACE_STR "(anonymous namespace)"
46 
47 /* The length of the string representing the anonymous namespace.  */
48 
49 #define CP_ANONYMOUS_NAMESPACE_LEN 21
50 
51 /* A string representing the start of an operator name.  */
52 
53 #define CP_OPERATOR_STR "operator"
54 
55 /* The length of CP_OPERATOR_STR.  */
56 
57 #define CP_OPERATOR_LEN 8
58 
59 /* The result of parsing a name.  */
60 
61 struct demangle_parse_info
62 {
63   demangle_parse_info ();
64 
65   ~demangle_parse_info ();
66 
67   /* The memory used during the parse.  */
68   struct demangle_info *info;
69 
70   /* The result of the parse.  */
71   struct demangle_component *tree;
72 
73   /* Any temporary memory used during typedef replacement.  */
74   struct obstack obstack;
75 };
76 
77 
78 /* Functions from cp-support.c.  */
79 
80 extern gdb::unique_xmalloc_ptr<char> cp_canonicalize_string
81   (const char *string);
82 
83 extern gdb::unique_xmalloc_ptr<char> cp_canonicalize_string_no_typedefs
84   (const char *string);
85 
86 typedef const char *(canonicalization_ftype) (struct type *, void *);
87 
88 extern gdb::unique_xmalloc_ptr<char> cp_canonicalize_string_full
89   (const char *string, canonicalization_ftype *finder, void *data);
90 
91 extern char *cp_class_name_from_physname (const char *physname);
92 
93 extern char *method_name_from_physname (const char *physname);
94 
95 extern unsigned int cp_find_first_component (const char *name);
96 
97 extern unsigned int cp_entire_prefix_len (const char *name);
98 
99 extern gdb::unique_xmalloc_ptr<char> cp_func_name (const char *full_name);
100 
101 extern gdb::unique_xmalloc_ptr<char> cp_remove_params
102   (const char *demanged_name);
103 
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);
111 
112 extern std::vector<symbol *> make_symbol_overload_list (const char *,
113 							const char *);
114 
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);
119 
120 extern struct type *cp_lookup_rtti_type (const char *name,
121 					 const struct block *block);
122 
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);
129 
130 /* Implement the "get_symbol_name_matcher" language_defn method for C++.  */
131 extern symbol_name_matcher_ftype *cp_get_symbol_name_matcher
132   (const lookup_name_info &lookup_name);
133 
134 /* Functions/variables from cp-namespace.c.  */
135 
136 extern int cp_is_in_anonymous (const char *symbol_name);
137 
138 extern void cp_scan_for_anonymous_namespaces (struct buildsym_compunit *,
139 					      const struct symbol *symbol,
140 					      struct objfile *objfile);
141 
142 extern struct block_symbol cp_lookup_symbol_nonlocal
143      (const struct language_defn *langdef,
144       const char *name,
145       const struct block *block,
146       const domain_enum domain);
147 
148 extern struct block_symbol
149   cp_lookup_symbol_namespace (const char *the_namespace,
150 			      const char *name,
151 			      const struct block *block,
152 			      const domain_enum domain);
153 
154 extern struct block_symbol cp_lookup_symbol_imports_or_template
155      (const char *scope,
156       const char *name,
157       const struct block *block,
158       const domain_enum domain);
159 
160 extern struct block_symbol
161   cp_lookup_nested_symbol (struct type *parent_type,
162 			   const char *nested_name,
163 			   const struct block *block,
164 			   const domain_enum domain);
165 
166 struct type *cp_lookup_transparent_type (const char *name);
167 
168 /* See description in cp-namespace.c.  */
169 
170 struct type *cp_find_type_baseclass_by_name (struct type *parent_type,
171 					     const char *name);
172 
173 /* Functions from cp-name-parser.y.  */
174 
175 extern std::unique_ptr<demangle_parse_info> cp_demangled_name_to_comp
176      (const char *demangled_name, std::string *errmsg);
177 
178 /* Convert RESULT to a string.  ESTIMATED_LEN is used only as a guide
179    to the length of the result.  */
180 
181 extern gdb::unique_xmalloc_ptr<char> cp_comp_to_string
182   (struct demangle_component *result, int estimated_len);
183 
184 extern void cp_merge_demangle_parse_infos (struct demangle_parse_info *,
185 					   struct demangle_component *,
186 					   struct demangle_parse_info *);
187 
188 /* The list of "maint cplus" commands.  */
189 
190 extern struct cmd_list_element *maint_cplus_cmd_list;
191 
192 /* Wrappers for bfd and libiberty demangling entry points.  Note they
193    all force DMGL_VERBOSE so that callers don't need to.  This is so
194    that GDB consistently uses DMGL_VERBOSE throughout -- we want
195    libiberty's demangler to expand standard substitutions to their
196    full template name.  */
197 
198 /* A wrapper for bfd_demangle.  */
199 
200 gdb::unique_xmalloc_ptr<char> gdb_demangle (const char *name, int options);
201 
202 /* A wrapper for cplus_demangle_print.  */
203 
204 extern char *gdb_cplus_demangle_print (int options,
205 				       struct demangle_component *tree,
206 				       int estimated_length,
207 				       size_t *p_allocated_size);
208 
209 /* Find an instance of the character C in the string S that is outside
210    of all parenthesis pairs, single-quoted strings, and double-quoted
211    strings.  Also, ignore the char within a template name, like a ','
212    within foo<int, int>.  */
213 
214 extern const char *find_toplevel_char (const char *s, char c);
215 
216 #endif /* CP_SUPPORT_H */
217