1 1.1 christos /* Helper routines for C++ support in GDB. 2 1.11 christos Copyright (C) 2002-2024 Free Software Foundation, Inc. 3 1.1 christos 4 1.1 christos Contributed by MontaVista Software. 5 1.1 christos 6 1.1 christos This file is part of GDB. 7 1.1 christos 8 1.1 christos This program is free software; you can redistribute it and/or modify 9 1.1 christos it under the terms of the GNU General Public License as published by 10 1.1 christos the Free Software Foundation; either version 3 of the License, or 11 1.1 christos (at your option) any later version. 12 1.1 christos 13 1.1 christos This program is distributed in the hope that it will be useful, 14 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of 15 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 1.1 christos GNU General Public License for more details. 17 1.1 christos 18 1.1 christos You should have received a copy of the GNU General Public License 19 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 20 1.1 christos 21 1.1 christos #include "cp-support.h" 22 1.11 christos #include "language.h" 23 1.1 christos #include "demangle.h" 24 1.11 christos #include "cli/cli-cmds.h" 25 1.1 christos #include "dictionary.h" 26 1.1 christos #include "objfiles.h" 27 1.1 christos #include "frame.h" 28 1.1 christos #include "symtab.h" 29 1.1 christos #include "block.h" 30 1.1 christos #include "complaints.h" 31 1.1 christos #include "gdbtypes.h" 32 1.1 christos #include "expression.h" 33 1.1 christos #include "value.h" 34 1.1 christos #include "cp-abi.h" 35 1.6 christos #include "namespace.h" 36 1.3 christos #include <signal.h> 37 1.9 christos #include "gdbsupport/gdb_setjmp.h" 38 1.11 christos #include "gdbsupport/gdb-safe-ctype.h" 39 1.9 christos #include "gdbsupport/selftest.h" 40 1.9 christos #include "gdbsupport/gdb-sigmask.h" 41 1.9 christos #include <atomic> 42 1.9 christos #include "event-top.h" 43 1.9 christos #include "run-on-main-thread.h" 44 1.10 christos #include "typeprint.h" 45 1.11 christos #include "inferior.h" 46 1.1 christos 47 1.1 christos #define d_left(dc) (dc)->u.s_binary.left 48 1.1 christos #define d_right(dc) (dc)->u.s_binary.right 49 1.1 christos 50 1.1 christos /* Functions related to demangled name parsing. */ 51 1.1 christos 52 1.1 christos static unsigned int cp_find_first_component_aux (const char *name, 53 1.1 christos int permissive); 54 1.1 christos 55 1.1 christos static void demangled_name_complaint (const char *name); 56 1.1 christos 57 1.8 christos /* Functions related to overload resolution. */ 58 1.1 christos 59 1.1 christos static void overload_list_add_symbol (struct symbol *sym, 60 1.8 christos const char *oload_name, 61 1.8 christos std::vector<symbol *> *overload_list); 62 1.1 christos 63 1.8 christos static void add_symbol_overload_list_using 64 1.8 christos (const char *func_name, const char *the_namespace, 65 1.8 christos std::vector<symbol *> *overload_list); 66 1.8 christos 67 1.8 christos static void add_symbol_overload_list_qualified 68 1.8 christos (const char *func_name, 69 1.8 christos std::vector<symbol *> *overload_list); 70 1.1 christos 71 1.1 christos /* The list of "maint cplus" commands. */ 72 1.1 christos 73 1.1 christos struct cmd_list_element *maint_cplus_cmd_list = NULL; 74 1.1 christos 75 1.1 christos static void 76 1.1 christos replace_typedefs (struct demangle_parse_info *info, 77 1.1 christos struct demangle_component *ret_comp, 78 1.1 christos canonicalization_ftype *finder, 79 1.1 christos void *data); 80 1.1 christos 81 1.10 christos static struct demangle_component * 82 1.10 christos gdb_cplus_demangle_v3_components (const char *mangled, 83 1.10 christos int options, void **mem); 84 1.10 christos 85 1.1 christos /* A convenience function to copy STRING into OBSTACK, returning a pointer 86 1.1 christos to the newly allocated string and saving the number of bytes saved in LEN. 87 1.1 christos 88 1.1 christos It does not copy the terminating '\0' byte! */ 89 1.1 christos 90 1.1 christos static char * 91 1.1 christos copy_string_to_obstack (struct obstack *obstack, const char *string, 92 1.1 christos long *len) 93 1.1 christos { 94 1.1 christos *len = strlen (string); 95 1.6 christos return (char *) obstack_copy (obstack, string, *len); 96 1.1 christos } 97 1.1 christos 98 1.1 christos /* Return 1 if STRING is clearly already in canonical form. This 99 1.1 christos function is conservative; things which it does not recognize are 100 1.1 christos assumed to be non-canonical, and the parser will sort them out 101 1.1 christos afterwards. This speeds up the critical path for alphanumeric 102 1.1 christos identifiers. */ 103 1.1 christos 104 1.1 christos static int 105 1.1 christos cp_already_canonical (const char *string) 106 1.1 christos { 107 1.1 christos /* Identifier start character [a-zA-Z_]. */ 108 1.1 christos if (!ISIDST (string[0])) 109 1.1 christos return 0; 110 1.1 christos 111 1.1 christos /* These are the only two identifiers which canonicalize to other 112 1.1 christos than themselves or an error: unsigned -> unsigned int and 113 1.1 christos signed -> int. */ 114 1.1 christos if (string[0] == 'u' && strcmp (&string[1], "nsigned") == 0) 115 1.1 christos return 0; 116 1.1 christos else if (string[0] == 's' && strcmp (&string[1], "igned") == 0) 117 1.1 christos return 0; 118 1.1 christos 119 1.1 christos /* Identifier character [a-zA-Z0-9_]. */ 120 1.1 christos while (ISIDNUM (string[1])) 121 1.1 christos string++; 122 1.1 christos 123 1.1 christos if (string[1] == '\0') 124 1.1 christos return 1; 125 1.1 christos else 126 1.1 christos return 0; 127 1.1 christos } 128 1.1 christos 129 1.1 christos /* Inspect the given RET_COMP for its type. If it is a typedef, 130 1.1 christos replace the node with the typedef's tree. 131 1.1 christos 132 1.1 christos Returns 1 if any typedef substitutions were made, 0 otherwise. */ 133 1.1 christos 134 1.1 christos static int 135 1.1 christos inspect_type (struct demangle_parse_info *info, 136 1.1 christos struct demangle_component *ret_comp, 137 1.1 christos canonicalization_ftype *finder, 138 1.1 christos void *data) 139 1.1 christos { 140 1.1 christos char *name; 141 1.1 christos struct symbol *sym; 142 1.1 christos 143 1.1 christos /* Copy the symbol's name from RET_COMP and look it up 144 1.1 christos in the symbol table. */ 145 1.1 christos name = (char *) alloca (ret_comp->u.s_name.len + 1); 146 1.1 christos memcpy (name, ret_comp->u.s_name.s, ret_comp->u.s_name.len); 147 1.1 christos name[ret_comp->u.s_name.len] = '\0'; 148 1.1 christos 149 1.1 christos sym = NULL; 150 1.1 christos 151 1.9 christos try 152 1.5 christos { 153 1.11 christos sym = lookup_symbol (name, 0, SEARCH_VFT, 0).symbol; 154 1.5 christos } 155 1.9 christos catch (const gdb_exception &except) 156 1.5 christos { 157 1.5 christos return 0; 158 1.5 christos } 159 1.5 christos 160 1.5 christos if (sym != NULL) 161 1.1 christos { 162 1.10 christos struct type *otype = sym->type (); 163 1.1 christos 164 1.1 christos if (finder != NULL) 165 1.1 christos { 166 1.1 christos const char *new_name = (*finder) (otype, data); 167 1.1 christos 168 1.1 christos if (new_name != NULL) 169 1.1 christos { 170 1.1 christos ret_comp->u.s_name.s = new_name; 171 1.1 christos ret_comp->u.s_name.len = strlen (new_name); 172 1.1 christos return 1; 173 1.1 christos } 174 1.1 christos 175 1.1 christos return 0; 176 1.1 christos } 177 1.1 christos 178 1.1 christos /* If the type is a typedef or namespace alias, replace it. */ 179 1.9 christos if (otype->code () == TYPE_CODE_TYPEDEF 180 1.9 christos || otype->code () == TYPE_CODE_NAMESPACE) 181 1.1 christos { 182 1.1 christos long len; 183 1.1 christos int is_anon; 184 1.1 christos struct type *type; 185 1.7 christos std::unique_ptr<demangle_parse_info> i; 186 1.1 christos 187 1.1 christos /* Get the real type of the typedef. */ 188 1.1 christos type = check_typedef (otype); 189 1.1 christos 190 1.9 christos /* If the symbol name is the same as the original type name, 191 1.9 christos don't substitute. That would cause infinite recursion in 192 1.9 christos symbol lookups, as the typedef symbol is often the first 193 1.9 christos found symbol in the symbol table. 194 1.9 christos 195 1.9 christos However, this can happen in a number of situations, such as: 196 1.9 christos 197 1.9 christos If the symbol is a namespace and its type name is no different 198 1.1 christos than the name we looked up, this symbol is not a namespace 199 1.9 christos alias and does not need to be substituted. 200 1.9 christos 201 1.9 christos If the symbol is typedef and its type name is the same 202 1.9 christos as the symbol's name, e.g., "typedef struct foo foo;". */ 203 1.9 christos if (type->name () != nullptr 204 1.9 christos && strcmp (type->name (), name) == 0) 205 1.1 christos return 0; 206 1.1 christos 207 1.9 christos is_anon = (type->name () == NULL 208 1.9 christos && (type->code () == TYPE_CODE_ENUM 209 1.9 christos || type->code () == TYPE_CODE_STRUCT 210 1.9 christos || type->code () == TYPE_CODE_UNION)); 211 1.1 christos if (is_anon) 212 1.1 christos { 213 1.1 christos struct type *last = otype; 214 1.1 christos 215 1.1 christos /* Find the last typedef for the type. */ 216 1.10 christos while (last->target_type () != NULL 217 1.10 christos && (last->target_type ()->code () 218 1.1 christos == TYPE_CODE_TYPEDEF)) 219 1.10 christos last = last->target_type (); 220 1.1 christos 221 1.1 christos /* If there is only one typedef for this anonymous type, 222 1.1 christos do not substitute it. */ 223 1.1 christos if (type == otype) 224 1.1 christos return 0; 225 1.1 christos else 226 1.1 christos /* Use the last typedef seen as the type for this 227 1.1 christos anonymous type. */ 228 1.1 christos type = last; 229 1.1 christos } 230 1.1 christos 231 1.7 christos string_file buf; 232 1.9 christos try 233 1.7 christos { 234 1.10 christos /* Avoid using the current language. If the language is 235 1.10 christos C, and TYPE is a struct/class, the printed type is 236 1.10 christos prefixed with "struct " or "class ", which we don't 237 1.10 christos want when we're expanding a C++ typedef. Print using 238 1.10 christos the type symbol's language to expand a C++ typedef 239 1.10 christos the C++ way even if the current language is C. */ 240 1.10 christos const language_defn *lang = language_def (sym->language ()); 241 1.10 christos lang->print_type (type, "", &buf, -1, 0, &type_print_raw_options); 242 1.7 christos } 243 1.1 christos /* If type_print threw an exception, there is little point 244 1.1 christos in continuing, so just bow out gracefully. */ 245 1.9 christos catch (const gdb_exception_error &except) 246 1.1 christos { 247 1.1 christos return 0; 248 1.1 christos } 249 1.1 christos 250 1.7 christos len = buf.size (); 251 1.9 christos name = obstack_strdup (&info->obstack, buf.string ()); 252 1.1 christos 253 1.1 christos /* Turn the result into a new tree. Note that this 254 1.1 christos tree will contain pointers into NAME, so NAME cannot 255 1.1 christos be free'd until all typedef conversion is done and 256 1.1 christos the final result is converted into a string. */ 257 1.1 christos i = cp_demangled_name_to_comp (name, NULL); 258 1.1 christos if (i != NULL) 259 1.1 christos { 260 1.1 christos /* Merge the two trees. */ 261 1.11 christos cp_merge_demangle_parse_infos (info, ret_comp, std::move (i)); 262 1.1 christos 263 1.1 christos /* Replace any newly introduced typedefs -- but not 264 1.1 christos if the type is anonymous (that would lead to infinite 265 1.1 christos looping). */ 266 1.1 christos if (!is_anon) 267 1.1 christos replace_typedefs (info, ret_comp, finder, data); 268 1.1 christos } 269 1.1 christos else 270 1.1 christos { 271 1.1 christos /* This shouldn't happen unless the type printer has 272 1.1 christos output something that the name parser cannot grok. 273 1.1 christos Nonetheless, an ounce of prevention... 274 1.1 christos 275 1.1 christos Canonicalize the name again, and store it in the 276 1.1 christos current node (RET_COMP). */ 277 1.9 christos gdb::unique_xmalloc_ptr<char> canon 278 1.9 christos = cp_canonicalize_string_no_typedefs (name); 279 1.1 christos 280 1.9 christos if (canon != nullptr) 281 1.1 christos { 282 1.7 christos /* Copy the canonicalization into the obstack. */ 283 1.9 christos name = copy_string_to_obstack (&info->obstack, canon.get (), &len); 284 1.1 christos } 285 1.1 christos 286 1.1 christos ret_comp->u.s_name.s = name; 287 1.1 christos ret_comp->u.s_name.len = len; 288 1.1 christos } 289 1.1 christos 290 1.1 christos return 1; 291 1.1 christos } 292 1.1 christos } 293 1.1 christos 294 1.1 christos return 0; 295 1.1 christos } 296 1.1 christos 297 1.9 christos /* Helper for replace_typedefs_qualified_name to handle 298 1.9 christos DEMANGLE_COMPONENT_TEMPLATE. TMPL is the template node. BUF is 299 1.9 christos the buffer that holds the qualified name being built by 300 1.9 christos replace_typedefs_qualified_name. REPL is the node that will be 301 1.9 christos rewritten as a DEMANGLE_COMPONENT_NAME node holding the 'template 302 1.9 christos plus template arguments' name with typedefs replaced. */ 303 1.9 christos 304 1.9 christos static bool 305 1.9 christos replace_typedefs_template (struct demangle_parse_info *info, 306 1.9 christos string_file &buf, 307 1.9 christos struct demangle_component *tmpl, 308 1.9 christos struct demangle_component *repl, 309 1.9 christos canonicalization_ftype *finder, 310 1.9 christos void *data) 311 1.9 christos { 312 1.9 christos demangle_component *tmpl_arglist = d_right (tmpl); 313 1.9 christos 314 1.9 christos /* Replace typedefs in the template argument list. */ 315 1.9 christos replace_typedefs (info, tmpl_arglist, finder, data); 316 1.9 christos 317 1.9 christos /* Convert 'template + replaced template argument list' to a string 318 1.9 christos and replace the REPL node. */ 319 1.9 christos gdb::unique_xmalloc_ptr<char> tmpl_str = cp_comp_to_string (tmpl, 100); 320 1.9 christos if (tmpl_str == nullptr) 321 1.9 christos { 322 1.9 christos /* If something went astray, abort typedef substitutions. */ 323 1.9 christos return false; 324 1.9 christos } 325 1.9 christos buf.puts (tmpl_str.get ()); 326 1.9 christos 327 1.9 christos repl->type = DEMANGLE_COMPONENT_NAME; 328 1.9 christos repl->u.s_name.s = obstack_strdup (&info->obstack, buf.string ()); 329 1.9 christos repl->u.s_name.len = buf.size (); 330 1.9 christos return true; 331 1.9 christos } 332 1.9 christos 333 1.1 christos /* Replace any typedefs appearing in the qualified name 334 1.1 christos (DEMANGLE_COMPONENT_QUAL_NAME) represented in RET_COMP for the name parse 335 1.1 christos given in INFO. */ 336 1.1 christos 337 1.1 christos static void 338 1.1 christos replace_typedefs_qualified_name (struct demangle_parse_info *info, 339 1.1 christos struct demangle_component *ret_comp, 340 1.1 christos canonicalization_ftype *finder, 341 1.1 christos void *data) 342 1.1 christos { 343 1.7 christos string_file buf; 344 1.1 christos struct demangle_component *comp = ret_comp; 345 1.1 christos 346 1.1 christos /* Walk each node of the qualified name, reconstructing the name of 347 1.1 christos this element. With every node, check for any typedef substitutions. 348 1.1 christos If a substitution has occurred, replace the qualified name node 349 1.1 christos with a DEMANGLE_COMPONENT_NAME node representing the new, typedef- 350 1.1 christos substituted name. */ 351 1.1 christos while (comp->type == DEMANGLE_COMPONENT_QUAL_NAME) 352 1.1 christos { 353 1.9 christos if (d_left (comp)->type == DEMANGLE_COMPONENT_TEMPLATE) 354 1.9 christos { 355 1.9 christos /* Convert 'template + replaced template argument list' to a 356 1.9 christos string and replace the top DEMANGLE_COMPONENT_QUAL_NAME 357 1.9 christos node. */ 358 1.9 christos if (!replace_typedefs_template (info, buf, 359 1.9 christos d_left (comp), d_left (ret_comp), 360 1.9 christos finder, data)) 361 1.9 christos return; 362 1.9 christos 363 1.9 christos buf.clear (); 364 1.9 christos d_right (ret_comp) = d_right (comp); 365 1.9 christos comp = ret_comp; 366 1.9 christos 367 1.9 christos /* Fallback to DEMANGLE_COMPONENT_NAME processing. We want 368 1.9 christos to call inspect_type for this template, in case we have a 369 1.9 christos template alias, like: 370 1.9 christos template<typename T> using alias = base<int, t>; 371 1.9 christos in which case we want inspect_type to do a replacement like: 372 1.9 christos alias<int> -> base<int, int> 373 1.9 christos */ 374 1.9 christos } 375 1.9 christos 376 1.1 christos if (d_left (comp)->type == DEMANGLE_COMPONENT_NAME) 377 1.1 christos { 378 1.5 christos struct demangle_component newobj; 379 1.1 christos 380 1.7 christos buf.write (d_left (comp)->u.s_name.s, d_left (comp)->u.s_name.len); 381 1.5 christos newobj.type = DEMANGLE_COMPONENT_NAME; 382 1.9 christos newobj.u.s_name.s = obstack_strdup (&info->obstack, buf.string ()); 383 1.8 christos newobj.u.s_name.len = buf.size (); 384 1.5 christos if (inspect_type (info, &newobj, finder, data)) 385 1.1 christos { 386 1.8 christos char *s; 387 1.1 christos long slen; 388 1.1 christos 389 1.1 christos /* A typedef was substituted in NEW. Convert it to a 390 1.1 christos string and replace the top DEMANGLE_COMPONENT_QUAL_NAME 391 1.1 christos node. */ 392 1.1 christos 393 1.7 christos buf.clear (); 394 1.8 christos gdb::unique_xmalloc_ptr<char> n 395 1.8 christos = cp_comp_to_string (&newobj, 100); 396 1.1 christos if (n == NULL) 397 1.1 christos { 398 1.1 christos /* If something went astray, abort typedef substitutions. */ 399 1.1 christos return; 400 1.1 christos } 401 1.1 christos 402 1.8 christos s = copy_string_to_obstack (&info->obstack, n.get (), &slen); 403 1.1 christos 404 1.1 christos d_left (ret_comp)->type = DEMANGLE_COMPONENT_NAME; 405 1.1 christos d_left (ret_comp)->u.s_name.s = s; 406 1.1 christos d_left (ret_comp)->u.s_name.len = slen; 407 1.1 christos d_right (ret_comp) = d_right (comp); 408 1.1 christos comp = ret_comp; 409 1.1 christos continue; 410 1.1 christos } 411 1.1 christos } 412 1.1 christos else 413 1.1 christos { 414 1.1 christos /* The current node is not a name, so simply replace any 415 1.1 christos typedefs in it. Then print it to the stream to continue 416 1.1 christos checking for more typedefs in the tree. */ 417 1.1 christos replace_typedefs (info, d_left (comp), finder, data); 418 1.8 christos gdb::unique_xmalloc_ptr<char> name 419 1.8 christos = cp_comp_to_string (d_left (comp), 100); 420 1.1 christos if (name == NULL) 421 1.1 christos { 422 1.1 christos /* If something went astray, abort typedef substitutions. */ 423 1.1 christos return; 424 1.1 christos } 425 1.8 christos buf.puts (name.get ()); 426 1.1 christos } 427 1.1 christos 428 1.7 christos buf.write ("::", 2); 429 1.1 christos comp = d_right (comp); 430 1.1 christos } 431 1.1 christos 432 1.9 christos /* If the next component is DEMANGLE_COMPONENT_TEMPLATE or 433 1.9 christos DEMANGLE_COMPONENT_NAME, save the qualified name assembled above 434 1.9 christos and append the name given by COMP. Then use this reassembled 435 1.9 christos name to check for a typedef. */ 436 1.9 christos 437 1.9 christos if (comp->type == DEMANGLE_COMPONENT_TEMPLATE) 438 1.9 christos { 439 1.9 christos /* Replace the top (DEMANGLE_COMPONENT_QUAL_NAME) node with a 440 1.9 christos DEMANGLE_COMPONENT_NAME node containing the whole name. */ 441 1.9 christos if (!replace_typedefs_template (info, buf, comp, ret_comp, finder, data)) 442 1.9 christos return; 443 1.9 christos inspect_type (info, ret_comp, finder, data); 444 1.9 christos } 445 1.9 christos else if (comp->type == DEMANGLE_COMPONENT_NAME) 446 1.1 christos { 447 1.7 christos buf.write (comp->u.s_name.s, comp->u.s_name.len); 448 1.1 christos 449 1.1 christos /* Replace the top (DEMANGLE_COMPONENT_QUAL_NAME) node 450 1.1 christos with a DEMANGLE_COMPONENT_NAME node containing the whole 451 1.1 christos name. */ 452 1.1 christos ret_comp->type = DEMANGLE_COMPONENT_NAME; 453 1.9 christos ret_comp->u.s_name.s = obstack_strdup (&info->obstack, buf.string ()); 454 1.8 christos ret_comp->u.s_name.len = buf.size (); 455 1.1 christos inspect_type (info, ret_comp, finder, data); 456 1.1 christos } 457 1.1 christos else 458 1.1 christos replace_typedefs (info, comp, finder, data); 459 1.1 christos } 460 1.1 christos 461 1.1 christos 462 1.1 christos /* A function to check const and volatile qualifiers for argument types. 463 1.1 christos 464 1.1 christos "Parameter declarations that differ only in the presence 465 1.1 christos or absence of `const' and/or `volatile' are equivalent." 466 1.1 christos C++ Standard N3290, clause 13.1.3 #4. */ 467 1.1 christos 468 1.1 christos static void 469 1.1 christos check_cv_qualifiers (struct demangle_component *ret_comp) 470 1.1 christos { 471 1.1 christos while (d_left (ret_comp) != NULL 472 1.1 christos && (d_left (ret_comp)->type == DEMANGLE_COMPONENT_CONST 473 1.1 christos || d_left (ret_comp)->type == DEMANGLE_COMPONENT_VOLATILE)) 474 1.1 christos { 475 1.1 christos d_left (ret_comp) = d_left (d_left (ret_comp)); 476 1.1 christos } 477 1.1 christos } 478 1.1 christos 479 1.1 christos /* Walk the parse tree given by RET_COMP, replacing any typedefs with 480 1.1 christos their basic types. */ 481 1.1 christos 482 1.1 christos static void 483 1.1 christos replace_typedefs (struct demangle_parse_info *info, 484 1.1 christos struct demangle_component *ret_comp, 485 1.1 christos canonicalization_ftype *finder, 486 1.1 christos void *data) 487 1.1 christos { 488 1.1 christos if (ret_comp) 489 1.1 christos { 490 1.1 christos if (finder != NULL 491 1.1 christos && (ret_comp->type == DEMANGLE_COMPONENT_NAME 492 1.1 christos || ret_comp->type == DEMANGLE_COMPONENT_QUAL_NAME 493 1.1 christos || ret_comp->type == DEMANGLE_COMPONENT_TEMPLATE 494 1.1 christos || ret_comp->type == DEMANGLE_COMPONENT_BUILTIN_TYPE)) 495 1.1 christos { 496 1.8 christos gdb::unique_xmalloc_ptr<char> local_name 497 1.8 christos = cp_comp_to_string (ret_comp, 10); 498 1.1 christos 499 1.1 christos if (local_name != NULL) 500 1.1 christos { 501 1.5 christos struct symbol *sym = NULL; 502 1.1 christos 503 1.1 christos sym = NULL; 504 1.9 christos try 505 1.1 christos { 506 1.8 christos sym = lookup_symbol (local_name.get (), 0, 507 1.11 christos SEARCH_VFT, 0).symbol; 508 1.1 christos } 509 1.9 christos catch (const gdb_exception &except) 510 1.5 christos { 511 1.5 christos } 512 1.5 christos 513 1.5 christos if (sym != NULL) 514 1.1 christos { 515 1.10 christos struct type *otype = sym->type (); 516 1.1 christos const char *new_name = (*finder) (otype, data); 517 1.1 christos 518 1.1 christos if (new_name != NULL) 519 1.1 christos { 520 1.1 christos ret_comp->type = DEMANGLE_COMPONENT_NAME; 521 1.1 christos ret_comp->u.s_name.s = new_name; 522 1.1 christos ret_comp->u.s_name.len = strlen (new_name); 523 1.1 christos return; 524 1.1 christos } 525 1.1 christos } 526 1.1 christos } 527 1.1 christos } 528 1.1 christos 529 1.1 christos switch (ret_comp->type) 530 1.1 christos { 531 1.1 christos case DEMANGLE_COMPONENT_ARGLIST: 532 1.1 christos check_cv_qualifiers (ret_comp); 533 1.11 christos [[fallthrough]]; 534 1.1 christos 535 1.1 christos case DEMANGLE_COMPONENT_FUNCTION_TYPE: 536 1.1 christos case DEMANGLE_COMPONENT_TEMPLATE: 537 1.1 christos case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST: 538 1.1 christos case DEMANGLE_COMPONENT_TYPED_NAME: 539 1.1 christos replace_typedefs (info, d_left (ret_comp), finder, data); 540 1.1 christos replace_typedefs (info, d_right (ret_comp), finder, data); 541 1.1 christos break; 542 1.1 christos 543 1.1 christos case DEMANGLE_COMPONENT_NAME: 544 1.1 christos inspect_type (info, ret_comp, finder, data); 545 1.1 christos break; 546 1.1 christos 547 1.1 christos case DEMANGLE_COMPONENT_QUAL_NAME: 548 1.1 christos replace_typedefs_qualified_name (info, ret_comp, finder, data); 549 1.1 christos break; 550 1.1 christos 551 1.1 christos case DEMANGLE_COMPONENT_LOCAL_NAME: 552 1.1 christos case DEMANGLE_COMPONENT_CTOR: 553 1.1 christos case DEMANGLE_COMPONENT_ARRAY_TYPE: 554 1.1 christos case DEMANGLE_COMPONENT_PTRMEM_TYPE: 555 1.1 christos replace_typedefs (info, d_right (ret_comp), finder, data); 556 1.1 christos break; 557 1.1 christos 558 1.1 christos case DEMANGLE_COMPONENT_CONST: 559 1.1 christos case DEMANGLE_COMPONENT_RESTRICT: 560 1.1 christos case DEMANGLE_COMPONENT_VOLATILE: 561 1.1 christos case DEMANGLE_COMPONENT_VOLATILE_THIS: 562 1.1 christos case DEMANGLE_COMPONENT_CONST_THIS: 563 1.1 christos case DEMANGLE_COMPONENT_RESTRICT_THIS: 564 1.1 christos case DEMANGLE_COMPONENT_POINTER: 565 1.1 christos case DEMANGLE_COMPONENT_REFERENCE: 566 1.7 christos case DEMANGLE_COMPONENT_RVALUE_REFERENCE: 567 1.1 christos replace_typedefs (info, d_left (ret_comp), finder, data); 568 1.1 christos break; 569 1.1 christos 570 1.1 christos default: 571 1.1 christos break; 572 1.1 christos } 573 1.1 christos } 574 1.1 christos } 575 1.1 christos 576 1.7 christos /* Parse STRING and convert it to canonical form, resolving any 577 1.7 christos typedefs. If parsing fails, or if STRING is already canonical, 578 1.9 christos return nullptr. Otherwise return the canonical form. If 579 1.7 christos FINDER is not NULL, then type components are passed to FINDER to be 580 1.7 christos looked up. DATA is passed verbatim to FINDER. */ 581 1.1 christos 582 1.9 christos gdb::unique_xmalloc_ptr<char> 583 1.1 christos cp_canonicalize_string_full (const char *string, 584 1.1 christos canonicalization_ftype *finder, 585 1.1 christos void *data) 586 1.1 christos { 587 1.1 christos unsigned int estimated_len; 588 1.7 christos std::unique_ptr<demangle_parse_info> info; 589 1.1 christos 590 1.1 christos estimated_len = strlen (string) * 2; 591 1.1 christos info = cp_demangled_name_to_comp (string, NULL); 592 1.1 christos if (info != NULL) 593 1.1 christos { 594 1.1 christos /* Replace all the typedefs in the tree. */ 595 1.7 christos replace_typedefs (info.get (), info->tree, finder, data); 596 1.1 christos 597 1.1 christos /* Convert the tree back into a string. */ 598 1.8 christos gdb::unique_xmalloc_ptr<char> us = cp_comp_to_string (info->tree, 599 1.8 christos estimated_len); 600 1.8 christos gdb_assert (us); 601 1.1 christos 602 1.1 christos /* Finally, compare the original string with the computed 603 1.1 christos name, returning NULL if they are the same. */ 604 1.9 christos if (strcmp (us.get (), string) == 0) 605 1.9 christos return nullptr; 606 1.9 christos 607 1.9 christos return us; 608 1.1 christos } 609 1.1 christos 610 1.9 christos return nullptr; 611 1.1 christos } 612 1.1 christos 613 1.1 christos /* Like cp_canonicalize_string_full, but always passes NULL for 614 1.1 christos FINDER. */ 615 1.1 christos 616 1.9 christos gdb::unique_xmalloc_ptr<char> 617 1.1 christos cp_canonicalize_string_no_typedefs (const char *string) 618 1.1 christos { 619 1.1 christos return cp_canonicalize_string_full (string, NULL, NULL); 620 1.1 christos } 621 1.1 christos 622 1.1 christos /* Parse STRING and convert it to canonical form. If parsing fails, 623 1.9 christos or if STRING is already canonical, return nullptr. 624 1.7 christos Otherwise return the canonical form. */ 625 1.1 christos 626 1.9 christos gdb::unique_xmalloc_ptr<char> 627 1.1 christos cp_canonicalize_string (const char *string) 628 1.1 christos { 629 1.7 christos std::unique_ptr<demangle_parse_info> info; 630 1.1 christos unsigned int estimated_len; 631 1.1 christos 632 1.1 christos if (cp_already_canonical (string)) 633 1.9 christos return nullptr; 634 1.1 christos 635 1.1 christos info = cp_demangled_name_to_comp (string, NULL); 636 1.1 christos if (info == NULL) 637 1.9 christos return nullptr; 638 1.1 christos 639 1.1 christos estimated_len = strlen (string) * 2; 640 1.8 christos gdb::unique_xmalloc_ptr<char> us (cp_comp_to_string (info->tree, 641 1.8 christos estimated_len)); 642 1.1 christos 643 1.8 christos if (!us) 644 1.1 christos { 645 1.1 christos warning (_("internal error: string \"%s\" failed to be canonicalized"), 646 1.1 christos string); 647 1.9 christos return nullptr; 648 1.1 christos } 649 1.1 christos 650 1.9 christos if (strcmp (us.get (), string) == 0) 651 1.9 christos return nullptr; 652 1.1 christos 653 1.9 christos return us; 654 1.1 christos } 655 1.1 christos 656 1.1 christos /* Convert a mangled name to a demangle_component tree. *MEMORY is 657 1.1 christos set to the block of used memory that should be freed when finished 658 1.1 christos with the tree. DEMANGLED_P is set to the char * that should be 659 1.1 christos freed when finished with the tree, or NULL if none was needed. 660 1.1 christos OPTIONS will be passed to the demangler. */ 661 1.1 christos 662 1.7 christos static std::unique_ptr<demangle_parse_info> 663 1.1 christos mangled_name_to_comp (const char *mangled_name, int options, 664 1.10 christos void **memory, 665 1.10 christos gdb::unique_xmalloc_ptr<char> *demangled_p) 666 1.1 christos { 667 1.1 christos /* If it looks like a v3 mangled name, then try to go directly 668 1.1 christos to trees. */ 669 1.1 christos if (mangled_name[0] == '_' && mangled_name[1] == 'Z') 670 1.1 christos { 671 1.1 christos struct demangle_component *ret; 672 1.1 christos 673 1.10 christos ret = gdb_cplus_demangle_v3_components (mangled_name, 674 1.10 christos options, memory); 675 1.1 christos if (ret) 676 1.1 christos { 677 1.11 christos auto info = std::make_unique<demangle_parse_info> (); 678 1.1 christos info->tree = ret; 679 1.1 christos *demangled_p = NULL; 680 1.1 christos return info; 681 1.1 christos } 682 1.1 christos } 683 1.1 christos 684 1.1 christos /* If it doesn't, or if that failed, then try to demangle the 685 1.1 christos name. */ 686 1.10 christos gdb::unique_xmalloc_ptr<char> demangled_name = gdb_demangle (mangled_name, 687 1.10 christos options); 688 1.1 christos if (demangled_name == NULL) 689 1.1 christos return NULL; 690 1.1 christos 691 1.1 christos /* If we could demangle the name, parse it to build the component 692 1.1 christos tree. */ 693 1.7 christos std::unique_ptr<demangle_parse_info> info 694 1.10 christos = cp_demangled_name_to_comp (demangled_name.get (), NULL); 695 1.1 christos 696 1.1 christos if (info == NULL) 697 1.10 christos return NULL; 698 1.1 christos 699 1.10 christos *demangled_p = std::move (demangled_name); 700 1.1 christos return info; 701 1.1 christos } 702 1.1 christos 703 1.1 christos /* Return the name of the class containing method PHYSNAME. */ 704 1.1 christos 705 1.1 christos char * 706 1.1 christos cp_class_name_from_physname (const char *physname) 707 1.1 christos { 708 1.1 christos void *storage = NULL; 709 1.10 christos gdb::unique_xmalloc_ptr<char> demangled_name; 710 1.8 christos gdb::unique_xmalloc_ptr<char> ret; 711 1.1 christos struct demangle_component *ret_comp, *prev_comp, *cur_comp; 712 1.7 christos std::unique_ptr<demangle_parse_info> info; 713 1.1 christos int done; 714 1.1 christos 715 1.1 christos info = mangled_name_to_comp (physname, DMGL_ANSI, 716 1.1 christos &storage, &demangled_name); 717 1.1 christos if (info == NULL) 718 1.1 christos return NULL; 719 1.1 christos 720 1.1 christos done = 0; 721 1.1 christos ret_comp = info->tree; 722 1.1 christos 723 1.1 christos /* First strip off any qualifiers, if we have a function or 724 1.1 christos method. */ 725 1.1 christos while (!done) 726 1.1 christos switch (ret_comp->type) 727 1.1 christos { 728 1.1 christos case DEMANGLE_COMPONENT_CONST: 729 1.1 christos case DEMANGLE_COMPONENT_RESTRICT: 730 1.1 christos case DEMANGLE_COMPONENT_VOLATILE: 731 1.1 christos case DEMANGLE_COMPONENT_CONST_THIS: 732 1.1 christos case DEMANGLE_COMPONENT_RESTRICT_THIS: 733 1.1 christos case DEMANGLE_COMPONENT_VOLATILE_THIS: 734 1.1 christos case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL: 735 1.10 christos ret_comp = d_left (ret_comp); 736 1.10 christos break; 737 1.1 christos default: 738 1.1 christos done = 1; 739 1.1 christos break; 740 1.1 christos } 741 1.1 christos 742 1.1 christos /* If what we have now is a function, discard the argument list. */ 743 1.1 christos if (ret_comp->type == DEMANGLE_COMPONENT_TYPED_NAME) 744 1.1 christos ret_comp = d_left (ret_comp); 745 1.1 christos 746 1.1 christos /* If what we have now is a template, strip off the template 747 1.1 christos arguments. The left subtree may be a qualified name. */ 748 1.1 christos if (ret_comp->type == DEMANGLE_COMPONENT_TEMPLATE) 749 1.1 christos ret_comp = d_left (ret_comp); 750 1.1 christos 751 1.1 christos /* What we have now should be a name, possibly qualified. 752 1.1 christos Additional qualifiers could live in the left subtree or the right 753 1.1 christos subtree. Find the last piece. */ 754 1.1 christos done = 0; 755 1.1 christos prev_comp = NULL; 756 1.1 christos cur_comp = ret_comp; 757 1.1 christos while (!done) 758 1.1 christos switch (cur_comp->type) 759 1.1 christos { 760 1.1 christos case DEMANGLE_COMPONENT_QUAL_NAME: 761 1.1 christos case DEMANGLE_COMPONENT_LOCAL_NAME: 762 1.1 christos prev_comp = cur_comp; 763 1.10 christos cur_comp = d_right (cur_comp); 764 1.10 christos break; 765 1.1 christos case DEMANGLE_COMPONENT_TEMPLATE: 766 1.1 christos case DEMANGLE_COMPONENT_NAME: 767 1.1 christos case DEMANGLE_COMPONENT_CTOR: 768 1.1 christos case DEMANGLE_COMPONENT_DTOR: 769 1.1 christos case DEMANGLE_COMPONENT_OPERATOR: 770 1.1 christos case DEMANGLE_COMPONENT_EXTENDED_OPERATOR: 771 1.1 christos done = 1; 772 1.1 christos break; 773 1.1 christos default: 774 1.1 christos done = 1; 775 1.1 christos cur_comp = NULL; 776 1.1 christos break; 777 1.1 christos } 778 1.1 christos 779 1.1 christos if (cur_comp != NULL && prev_comp != NULL) 780 1.1 christos { 781 1.1 christos /* We want to discard the rightmost child of PREV_COMP. */ 782 1.1 christos *prev_comp = *d_left (prev_comp); 783 1.1 christos /* The ten is completely arbitrary; we don't have a good 784 1.1 christos estimate. */ 785 1.1 christos ret = cp_comp_to_string (ret_comp, 10); 786 1.1 christos } 787 1.1 christos 788 1.1 christos xfree (storage); 789 1.8 christos return ret.release (); 790 1.1 christos } 791 1.1 christos 792 1.1 christos /* Return the child of COMP which is the basename of a method, 793 1.1 christos variable, et cetera. All scope qualifiers are discarded, but 794 1.1 christos template arguments will be included. The component tree may be 795 1.1 christos modified. */ 796 1.1 christos 797 1.1 christos static struct demangle_component * 798 1.1 christos unqualified_name_from_comp (struct demangle_component *comp) 799 1.1 christos { 800 1.1 christos struct demangle_component *ret_comp = comp, *last_template; 801 1.1 christos int done; 802 1.1 christos 803 1.1 christos done = 0; 804 1.1 christos last_template = NULL; 805 1.1 christos while (!done) 806 1.1 christos switch (ret_comp->type) 807 1.1 christos { 808 1.1 christos case DEMANGLE_COMPONENT_QUAL_NAME: 809 1.1 christos case DEMANGLE_COMPONENT_LOCAL_NAME: 810 1.10 christos ret_comp = d_right (ret_comp); 811 1.10 christos break; 812 1.1 christos case DEMANGLE_COMPONENT_TYPED_NAME: 813 1.10 christos ret_comp = d_left (ret_comp); 814 1.10 christos break; 815 1.1 christos case DEMANGLE_COMPONENT_TEMPLATE: 816 1.1 christos gdb_assert (last_template == NULL); 817 1.1 christos last_template = ret_comp; 818 1.1 christos ret_comp = d_left (ret_comp); 819 1.1 christos break; 820 1.1 christos case DEMANGLE_COMPONENT_CONST: 821 1.1 christos case DEMANGLE_COMPONENT_RESTRICT: 822 1.1 christos case DEMANGLE_COMPONENT_VOLATILE: 823 1.1 christos case DEMANGLE_COMPONENT_CONST_THIS: 824 1.1 christos case DEMANGLE_COMPONENT_RESTRICT_THIS: 825 1.1 christos case DEMANGLE_COMPONENT_VOLATILE_THIS: 826 1.1 christos case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL: 827 1.10 christos ret_comp = d_left (ret_comp); 828 1.10 christos break; 829 1.1 christos case DEMANGLE_COMPONENT_NAME: 830 1.1 christos case DEMANGLE_COMPONENT_CTOR: 831 1.1 christos case DEMANGLE_COMPONENT_DTOR: 832 1.1 christos case DEMANGLE_COMPONENT_OPERATOR: 833 1.1 christos case DEMANGLE_COMPONENT_EXTENDED_OPERATOR: 834 1.1 christos done = 1; 835 1.1 christos break; 836 1.1 christos default: 837 1.1 christos return NULL; 838 1.1 christos break; 839 1.1 christos } 840 1.1 christos 841 1.1 christos if (last_template) 842 1.1 christos { 843 1.1 christos d_left (last_template) = ret_comp; 844 1.1 christos return last_template; 845 1.1 christos } 846 1.1 christos 847 1.1 christos return ret_comp; 848 1.1 christos } 849 1.1 christos 850 1.1 christos /* Return the name of the method whose linkage name is PHYSNAME. */ 851 1.1 christos 852 1.1 christos char * 853 1.1 christos method_name_from_physname (const char *physname) 854 1.1 christos { 855 1.1 christos void *storage = NULL; 856 1.10 christos gdb::unique_xmalloc_ptr<char> demangled_name; 857 1.8 christos gdb::unique_xmalloc_ptr<char> ret; 858 1.1 christos struct demangle_component *ret_comp; 859 1.7 christos std::unique_ptr<demangle_parse_info> info; 860 1.1 christos 861 1.1 christos info = mangled_name_to_comp (physname, DMGL_ANSI, 862 1.1 christos &storage, &demangled_name); 863 1.1 christos if (info == NULL) 864 1.1 christos return NULL; 865 1.1 christos 866 1.1 christos ret_comp = unqualified_name_from_comp (info->tree); 867 1.1 christos 868 1.1 christos if (ret_comp != NULL) 869 1.1 christos /* The ten is completely arbitrary; we don't have a good 870 1.1 christos estimate. */ 871 1.1 christos ret = cp_comp_to_string (ret_comp, 10); 872 1.1 christos 873 1.1 christos xfree (storage); 874 1.8 christos return ret.release (); 875 1.1 christos } 876 1.1 christos 877 1.1 christos /* If FULL_NAME is the demangled name of a C++ function (including an 878 1.1 christos arg list, possibly including namespace/class qualifications), 879 1.1 christos return a new string containing only the function name (without the 880 1.8 christos arg list/class qualifications). Otherwise, return NULL. */ 881 1.1 christos 882 1.8 christos gdb::unique_xmalloc_ptr<char> 883 1.1 christos cp_func_name (const char *full_name) 884 1.1 christos { 885 1.8 christos gdb::unique_xmalloc_ptr<char> ret; 886 1.1 christos struct demangle_component *ret_comp; 887 1.7 christos std::unique_ptr<demangle_parse_info> info; 888 1.1 christos 889 1.1 christos info = cp_demangled_name_to_comp (full_name, NULL); 890 1.1 christos if (!info) 891 1.8 christos return nullptr; 892 1.1 christos 893 1.1 christos ret_comp = unqualified_name_from_comp (info->tree); 894 1.1 christos 895 1.1 christos if (ret_comp != NULL) 896 1.1 christos ret = cp_comp_to_string (ret_comp, 10); 897 1.1 christos 898 1.1 christos return ret; 899 1.1 christos } 900 1.1 christos 901 1.8 christos /* Helper for cp_remove_params. DEMANGLED_NAME is the name of a 902 1.8 christos function, including parameters and (optionally) a return type. 903 1.8 christos Return the name of the function without parameters or return type, 904 1.8 christos or NULL if we can not parse the name. If REQUIRE_PARAMS is false, 905 1.8 christos then tolerate a non-existing or unbalanced parameter list. */ 906 1.1 christos 907 1.8 christos static gdb::unique_xmalloc_ptr<char> 908 1.8 christos cp_remove_params_1 (const char *demangled_name, bool require_params) 909 1.1 christos { 910 1.8 christos bool done = false; 911 1.1 christos struct demangle_component *ret_comp; 912 1.7 christos std::unique_ptr<demangle_parse_info> info; 913 1.8 christos gdb::unique_xmalloc_ptr<char> ret; 914 1.1 christos 915 1.1 christos if (demangled_name == NULL) 916 1.1 christos return NULL; 917 1.1 christos 918 1.1 christos info = cp_demangled_name_to_comp (demangled_name, NULL); 919 1.1 christos if (info == NULL) 920 1.1 christos return NULL; 921 1.1 christos 922 1.1 christos /* First strip off any qualifiers, if we have a function or method. */ 923 1.1 christos ret_comp = info->tree; 924 1.1 christos while (!done) 925 1.1 christos switch (ret_comp->type) 926 1.1 christos { 927 1.1 christos case DEMANGLE_COMPONENT_CONST: 928 1.1 christos case DEMANGLE_COMPONENT_RESTRICT: 929 1.1 christos case DEMANGLE_COMPONENT_VOLATILE: 930 1.1 christos case DEMANGLE_COMPONENT_CONST_THIS: 931 1.1 christos case DEMANGLE_COMPONENT_RESTRICT_THIS: 932 1.1 christos case DEMANGLE_COMPONENT_VOLATILE_THIS: 933 1.1 christos case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL: 934 1.10 christos ret_comp = d_left (ret_comp); 935 1.10 christos break; 936 1.1 christos default: 937 1.8 christos done = true; 938 1.1 christos break; 939 1.1 christos } 940 1.1 christos 941 1.1 christos /* What we have now should be a function. Return its name. */ 942 1.1 christos if (ret_comp->type == DEMANGLE_COMPONENT_TYPED_NAME) 943 1.1 christos ret = cp_comp_to_string (d_left (ret_comp), 10); 944 1.8 christos else if (!require_params 945 1.8 christos && (ret_comp->type == DEMANGLE_COMPONENT_NAME 946 1.8 christos || ret_comp->type == DEMANGLE_COMPONENT_QUAL_NAME 947 1.8 christos || ret_comp->type == DEMANGLE_COMPONENT_TEMPLATE)) 948 1.8 christos ret = cp_comp_to_string (ret_comp, 10); 949 1.1 christos 950 1.1 christos return ret; 951 1.1 christos } 952 1.1 christos 953 1.8 christos /* DEMANGLED_NAME is the name of a function, including parameters and 954 1.8 christos (optionally) a return type. Return the name of the function 955 1.8 christos without parameters or return type, or NULL if we can not parse the 956 1.8 christos name. */ 957 1.8 christos 958 1.8 christos gdb::unique_xmalloc_ptr<char> 959 1.8 christos cp_remove_params (const char *demangled_name) 960 1.8 christos { 961 1.8 christos return cp_remove_params_1 (demangled_name, true); 962 1.8 christos } 963 1.8 christos 964 1.8 christos /* See cp-support.h. */ 965 1.8 christos 966 1.8 christos gdb::unique_xmalloc_ptr<char> 967 1.8 christos cp_remove_params_if_any (const char *demangled_name, bool completion_mode) 968 1.8 christos { 969 1.8 christos /* Trying to remove parameters from the empty string fails. If 970 1.8 christos we're completing / matching everything, avoid returning NULL 971 1.8 christos which would make callers interpret the result as an error. */ 972 1.8 christos if (demangled_name[0] == '\0' && completion_mode) 973 1.9 christos return make_unique_xstrdup (""); 974 1.8 christos 975 1.8 christos gdb::unique_xmalloc_ptr<char> without_params 976 1.8 christos = cp_remove_params_1 (demangled_name, false); 977 1.8 christos 978 1.8 christos if (without_params == NULL && completion_mode) 979 1.8 christos { 980 1.8 christos std::string copy = demangled_name; 981 1.8 christos 982 1.8 christos while (!copy.empty ()) 983 1.8 christos { 984 1.8 christos copy.pop_back (); 985 1.8 christos without_params = cp_remove_params_1 (copy.c_str (), false); 986 1.8 christos if (without_params != NULL) 987 1.8 christos break; 988 1.8 christos } 989 1.8 christos } 990 1.8 christos 991 1.8 christos return without_params; 992 1.8 christos } 993 1.8 christos 994 1.1 christos /* Here are some random pieces of trivia to keep in mind while trying 995 1.1 christos to take apart demangled names: 996 1.1 christos 997 1.1 christos - Names can contain function arguments or templates, so the process 998 1.1 christos has to be, to some extent recursive: maybe keep track of your 999 1.1 christos depth based on encountering <> and (). 1000 1.1 christos 1001 1.1 christos - Parentheses don't just have to happen at the end of a name: they 1002 1.1 christos can occur even if the name in question isn't a function, because 1003 1.1 christos a template argument might be a type that's a function. 1004 1.1 christos 1005 1.1 christos - Conversely, even if you're trying to deal with a function, its 1006 1.1 christos demangled name might not end with ')': it could be a const or 1007 1.1 christos volatile class method, in which case it ends with "const" or 1008 1.1 christos "volatile". 1009 1.1 christos 1010 1.1 christos - Parentheses are also used in anonymous namespaces: a variable 1011 1.1 christos 'foo' in an anonymous namespace gets demangled as "(anonymous 1012 1.1 christos namespace)::foo". 1013 1.1 christos 1014 1.1 christos - And operator names can contain parentheses or angle brackets. */ 1015 1.1 christos 1016 1.1 christos /* FIXME: carlton/2003-03-13: We have several functions here with 1017 1.1 christos overlapping functionality; can we combine them? Also, do they 1018 1.1 christos handle all the above considerations correctly? */ 1019 1.1 christos 1020 1.1 christos 1021 1.1 christos /* This returns the length of first component of NAME, which should be 1022 1.1 christos the demangled name of a C++ variable/function/method/etc. 1023 1.1 christos Specifically, it returns the index of the first colon forming the 1024 1.1 christos boundary of the first component: so, given 'A::foo' or 'A::B::foo' 1025 1.1 christos it returns the 1, and given 'foo', it returns 0. */ 1026 1.1 christos 1027 1.1 christos /* The character in NAME indexed by the return value is guaranteed to 1028 1.1 christos always be either ':' or '\0'. */ 1029 1.1 christos 1030 1.1 christos /* NOTE: carlton/2003-03-13: This function is currently only intended 1031 1.1 christos for internal use: it's probably not entirely safe when called on 1032 1.1 christos user-generated input, because some of the 'index += 2' lines in 1033 1.1 christos cp_find_first_component_aux might go past the end of malformed 1034 1.1 christos input. */ 1035 1.1 christos 1036 1.1 christos unsigned int 1037 1.1 christos cp_find_first_component (const char *name) 1038 1.1 christos { 1039 1.1 christos return cp_find_first_component_aux (name, 0); 1040 1.1 christos } 1041 1.1 christos 1042 1.1 christos /* Helper function for cp_find_first_component. Like that function, 1043 1.1 christos it returns the length of the first component of NAME, but to make 1044 1.1 christos the recursion easier, it also stops if it reaches an unexpected ')' 1045 1.1 christos or '>' if the value of PERMISSIVE is nonzero. */ 1046 1.1 christos 1047 1.1 christos static unsigned int 1048 1.1 christos cp_find_first_component_aux (const char *name, int permissive) 1049 1.1 christos { 1050 1.1 christos unsigned int index = 0; 1051 1.1 christos /* Operator names can show up in unexpected places. Since these can 1052 1.1 christos contain parentheses or angle brackets, they can screw up the 1053 1.1 christos recursion. But not every string 'operator' is part of an 1054 1.9 christos operator name: e.g. you could have a variable 'cooperator'. So 1055 1.1 christos this variable tells us whether or not we should treat the string 1056 1.1 christos 'operator' as starting an operator. */ 1057 1.1 christos int operator_possible = 1; 1058 1.1 christos 1059 1.1 christos for (;; ++index) 1060 1.1 christos { 1061 1.1 christos switch (name[index]) 1062 1.1 christos { 1063 1.1 christos case '<': 1064 1.1 christos /* Template; eat it up. The calls to cp_first_component 1065 1.1 christos should only return (I hope!) when they reach the '>' 1066 1.1 christos terminating the component or a '::' between two 1067 1.1 christos components. (Hence the '+ 2'.) */ 1068 1.1 christos index += 1; 1069 1.1 christos for (index += cp_find_first_component_aux (name + index, 1); 1070 1.1 christos name[index] != '>'; 1071 1.1 christos index += cp_find_first_component_aux (name + index, 1)) 1072 1.1 christos { 1073 1.1 christos if (name[index] != ':') 1074 1.1 christos { 1075 1.1 christos demangled_name_complaint (name); 1076 1.1 christos return strlen (name); 1077 1.1 christos } 1078 1.1 christos index += 2; 1079 1.1 christos } 1080 1.1 christos operator_possible = 1; 1081 1.1 christos break; 1082 1.1 christos case '(': 1083 1.1 christos /* Similar comment as to '<'. */ 1084 1.1 christos index += 1; 1085 1.1 christos for (index += cp_find_first_component_aux (name + index, 1); 1086 1.1 christos name[index] != ')'; 1087 1.1 christos index += cp_find_first_component_aux (name + index, 1)) 1088 1.1 christos { 1089 1.1 christos if (name[index] != ':') 1090 1.1 christos { 1091 1.1 christos demangled_name_complaint (name); 1092 1.1 christos return strlen (name); 1093 1.1 christos } 1094 1.1 christos index += 2; 1095 1.1 christos } 1096 1.1 christos operator_possible = 1; 1097 1.1 christos break; 1098 1.1 christos case '>': 1099 1.1 christos case ')': 1100 1.1 christos if (permissive) 1101 1.1 christos return index; 1102 1.1 christos else 1103 1.1 christos { 1104 1.1 christos demangled_name_complaint (name); 1105 1.1 christos return strlen (name); 1106 1.1 christos } 1107 1.1 christos case '\0': 1108 1.6 christos return index; 1109 1.1 christos case ':': 1110 1.6 christos /* ':' marks a component iff the next character is also a ':'. 1111 1.6 christos Otherwise it is probably malformed input. */ 1112 1.6 christos if (name[index + 1] == ':') 1113 1.6 christos return index; 1114 1.6 christos break; 1115 1.1 christos case 'o': 1116 1.1 christos /* Operator names can screw up the recursion. */ 1117 1.1 christos if (operator_possible 1118 1.8 christos && startswith (name + index, CP_OPERATOR_STR)) 1119 1.1 christos { 1120 1.8 christos index += CP_OPERATOR_LEN; 1121 1.1 christos while (ISSPACE(name[index])) 1122 1.1 christos ++index; 1123 1.1 christos switch (name[index]) 1124 1.1 christos { 1125 1.8 christos case '\0': 1126 1.8 christos return index; 1127 1.1 christos /* Skip over one less than the appropriate number of 1128 1.1 christos characters: the for loop will skip over the last 1129 1.1 christos one. */ 1130 1.1 christos case '<': 1131 1.1 christos if (name[index + 1] == '<') 1132 1.1 christos index += 1; 1133 1.1 christos else 1134 1.1 christos index += 0; 1135 1.1 christos break; 1136 1.1 christos case '>': 1137 1.1 christos case '-': 1138 1.1 christos if (name[index + 1] == '>') 1139 1.1 christos index += 1; 1140 1.1 christos else 1141 1.1 christos index += 0; 1142 1.1 christos break; 1143 1.1 christos case '(': 1144 1.1 christos index += 1; 1145 1.1 christos break; 1146 1.1 christos default: 1147 1.1 christos index += 0; 1148 1.1 christos break; 1149 1.1 christos } 1150 1.1 christos } 1151 1.1 christos operator_possible = 0; 1152 1.1 christos break; 1153 1.1 christos case ' ': 1154 1.1 christos case ',': 1155 1.1 christos case '.': 1156 1.1 christos case '&': 1157 1.1 christos case '*': 1158 1.1 christos /* NOTE: carlton/2003-04-18: I'm not sure what the precise 1159 1.1 christos set of relevant characters are here: it's necessary to 1160 1.1 christos include any character that can show up before 'operator' 1161 1.1 christos in a demangled name, and it's safe to include any 1162 1.1 christos character that can't be part of an identifier's name. */ 1163 1.1 christos operator_possible = 1; 1164 1.1 christos break; 1165 1.1 christos default: 1166 1.1 christos operator_possible = 0; 1167 1.1 christos break; 1168 1.1 christos } 1169 1.1 christos } 1170 1.1 christos } 1171 1.1 christos 1172 1.1 christos /* Complain about a demangled name that we don't know how to parse. 1173 1.1 christos NAME is the demangled name in question. */ 1174 1.1 christos 1175 1.1 christos static void 1176 1.1 christos demangled_name_complaint (const char *name) 1177 1.1 christos { 1178 1.8 christos complaint ("unexpected demangled name '%s'", name); 1179 1.1 christos } 1180 1.1 christos 1181 1.1 christos /* If NAME is the fully-qualified name of a C++ 1182 1.1 christos function/variable/method/etc., this returns the length of its 1183 1.1 christos entire prefix: all of the namespaces and classes that make up its 1184 1.1 christos name. Given 'A::foo', it returns 1, given 'A::B::foo', it returns 1185 1.1 christos 4, given 'foo', it returns 0. */ 1186 1.1 christos 1187 1.1 christos unsigned int 1188 1.1 christos cp_entire_prefix_len (const char *name) 1189 1.1 christos { 1190 1.1 christos unsigned int current_len = cp_find_first_component (name); 1191 1.1 christos unsigned int previous_len = 0; 1192 1.1 christos 1193 1.1 christos while (name[current_len] != '\0') 1194 1.1 christos { 1195 1.1 christos gdb_assert (name[current_len] == ':'); 1196 1.1 christos previous_len = current_len; 1197 1.1 christos /* Skip the '::'. */ 1198 1.1 christos current_len += 2; 1199 1.1 christos current_len += cp_find_first_component (name + current_len); 1200 1.1 christos } 1201 1.1 christos 1202 1.1 christos return previous_len; 1203 1.1 christos } 1204 1.1 christos 1205 1.1 christos /* Overload resolution functions. */ 1206 1.1 christos 1207 1.1 christos /* Test to see if SYM is a symbol that we haven't seen corresponding 1208 1.8 christos to a function named OLOAD_NAME. If so, add it to 1209 1.8 christos OVERLOAD_LIST. */ 1210 1.1 christos 1211 1.1 christos static void 1212 1.1 christos overload_list_add_symbol (struct symbol *sym, 1213 1.8 christos const char *oload_name, 1214 1.8 christos std::vector<symbol *> *overload_list) 1215 1.1 christos { 1216 1.1 christos /* If there is no type information, we can't do anything, so 1217 1.1 christos skip. */ 1218 1.10 christos if (sym->type () == NULL) 1219 1.1 christos return; 1220 1.1 christos 1221 1.1 christos /* skip any symbols that we've already considered. */ 1222 1.8 christos for (symbol *listed_sym : *overload_list) 1223 1.9 christos if (strcmp (sym->linkage_name (), listed_sym->linkage_name ()) == 0) 1224 1.1 christos return; 1225 1.1 christos 1226 1.1 christos /* Get the demangled name without parameters */ 1227 1.8 christos gdb::unique_xmalloc_ptr<char> sym_name 1228 1.9 christos = cp_remove_params (sym->natural_name ()); 1229 1.1 christos if (!sym_name) 1230 1.1 christos return; 1231 1.1 christos 1232 1.1 christos /* skip symbols that cannot match */ 1233 1.8 christos if (strcmp (sym_name.get (), oload_name) != 0) 1234 1.8 christos return; 1235 1.1 christos 1236 1.8 christos overload_list->push_back (sym); 1237 1.1 christos } 1238 1.1 christos 1239 1.1 christos /* Return a null-terminated list of pointers to function symbols that 1240 1.1 christos are named FUNC_NAME and are visible within NAMESPACE. */ 1241 1.1 christos 1242 1.8 christos struct std::vector<symbol *> 1243 1.1 christos make_symbol_overload_list (const char *func_name, 1244 1.5 christos const char *the_namespace) 1245 1.1 christos { 1246 1.1 christos const char *name; 1247 1.8 christos std::vector<symbol *> overload_list; 1248 1.1 christos 1249 1.8 christos overload_list.reserve (100); 1250 1.1 christos 1251 1.8 christos add_symbol_overload_list_using (func_name, the_namespace, &overload_list); 1252 1.1 christos 1253 1.5 christos if (the_namespace[0] == '\0') 1254 1.1 christos name = func_name; 1255 1.1 christos else 1256 1.1 christos { 1257 1.1 christos char *concatenated_name 1258 1.6 christos = (char *) alloca (strlen (the_namespace) + 2 + strlen (func_name) + 1); 1259 1.5 christos strcpy (concatenated_name, the_namespace); 1260 1.1 christos strcat (concatenated_name, "::"); 1261 1.1 christos strcat (concatenated_name, func_name); 1262 1.1 christos name = concatenated_name; 1263 1.1 christos } 1264 1.1 christos 1265 1.8 christos add_symbol_overload_list_qualified (name, &overload_list); 1266 1.8 christos return overload_list; 1267 1.1 christos } 1268 1.1 christos 1269 1.1 christos /* Add all symbols with a name matching NAME in BLOCK to the overload 1270 1.1 christos list. */ 1271 1.1 christos 1272 1.1 christos static void 1273 1.8 christos add_symbol_overload_list_block (const char *name, 1274 1.8 christos const struct block *block, 1275 1.8 christos std::vector<symbol *> *overload_list) 1276 1.1 christos { 1277 1.8 christos lookup_name_info lookup_name (name, symbol_name_match_type::FULL); 1278 1.8 christos 1279 1.11 christos for (struct symbol *sym : block_iterator_range (block, &lookup_name)) 1280 1.8 christos overload_list_add_symbol (sym, name, overload_list); 1281 1.1 christos } 1282 1.1 christos 1283 1.1 christos /* Adds the function FUNC_NAME from NAMESPACE to the overload set. */ 1284 1.1 christos 1285 1.1 christos static void 1286 1.8 christos add_symbol_overload_list_namespace (const char *func_name, 1287 1.8 christos const char *the_namespace, 1288 1.8 christos std::vector<symbol *> *overload_list) 1289 1.1 christos { 1290 1.1 christos const char *name; 1291 1.1 christos const struct block *block = NULL; 1292 1.1 christos 1293 1.5 christos if (the_namespace[0] == '\0') 1294 1.1 christos name = func_name; 1295 1.1 christos else 1296 1.1 christos { 1297 1.1 christos char *concatenated_name 1298 1.6 christos = (char *) alloca (strlen (the_namespace) + 2 + strlen (func_name) + 1); 1299 1.1 christos 1300 1.5 christos strcpy (concatenated_name, the_namespace); 1301 1.1 christos strcat (concatenated_name, "::"); 1302 1.1 christos strcat (concatenated_name, func_name); 1303 1.1 christos name = concatenated_name; 1304 1.1 christos } 1305 1.1 christos 1306 1.1 christos /* Look in the static block. */ 1307 1.11 christos block = get_selected_block (0); 1308 1.11 christos block = block == nullptr ? nullptr : block->static_block (); 1309 1.11 christos if (block != nullptr) 1310 1.11 christos { 1311 1.11 christos add_symbol_overload_list_block (name, block, overload_list); 1312 1.11 christos 1313 1.11 christos /* Look in the global block. */ 1314 1.11 christos block = block->global_block (); 1315 1.11 christos if (block) 1316 1.11 christos add_symbol_overload_list_block (name, block, overload_list); 1317 1.11 christos } 1318 1.1 christos } 1319 1.1 christos 1320 1.1 christos /* Search the namespace of the given type and namespace of and public 1321 1.1 christos base types. */ 1322 1.1 christos 1323 1.1 christos static void 1324 1.8 christos add_symbol_overload_list_adl_namespace (struct type *type, 1325 1.8 christos const char *func_name, 1326 1.8 christos std::vector<symbol *> *overload_list) 1327 1.1 christos { 1328 1.5 christos char *the_namespace; 1329 1.1 christos const char *type_name; 1330 1.1 christos int i, prefix_len; 1331 1.1 christos 1332 1.10 christos while (type->is_pointer_or_reference () 1333 1.10 christos || type->code () == TYPE_CODE_ARRAY 1334 1.10 christos || type->code () == TYPE_CODE_TYPEDEF) 1335 1.1 christos { 1336 1.9 christos if (type->code () == TYPE_CODE_TYPEDEF) 1337 1.9 christos type = check_typedef (type); 1338 1.1 christos else 1339 1.10 christos type = type->target_type (); 1340 1.1 christos } 1341 1.1 christos 1342 1.9 christos type_name = type->name (); 1343 1.1 christos 1344 1.1 christos if (type_name == NULL) 1345 1.1 christos return; 1346 1.1 christos 1347 1.1 christos prefix_len = cp_entire_prefix_len (type_name); 1348 1.1 christos 1349 1.1 christos if (prefix_len != 0) 1350 1.1 christos { 1351 1.6 christos the_namespace = (char *) alloca (prefix_len + 1); 1352 1.5 christos strncpy (the_namespace, type_name, prefix_len); 1353 1.5 christos the_namespace[prefix_len] = '\0'; 1354 1.1 christos 1355 1.8 christos add_symbol_overload_list_namespace (func_name, the_namespace, 1356 1.8 christos overload_list); 1357 1.1 christos } 1358 1.1 christos 1359 1.1 christos /* Check public base type */ 1360 1.9 christos if (type->code () == TYPE_CODE_STRUCT) 1361 1.1 christos for (i = 0; i < TYPE_N_BASECLASSES (type); i++) 1362 1.1 christos { 1363 1.1 christos if (BASETYPE_VIA_PUBLIC (type, i)) 1364 1.8 christos add_symbol_overload_list_adl_namespace (TYPE_BASECLASS (type, i), 1365 1.8 christos func_name, 1366 1.8 christos overload_list); 1367 1.1 christos } 1368 1.1 christos } 1369 1.1 christos 1370 1.8 christos /* Adds to OVERLOAD_LIST the overload list overload candidates for 1371 1.8 christos FUNC_NAME found through argument dependent lookup. */ 1372 1.1 christos 1373 1.8 christos void 1374 1.8 christos add_symbol_overload_list_adl (gdb::array_view<type *> arg_types, 1375 1.8 christos const char *func_name, 1376 1.8 christos std::vector<symbol *> *overload_list) 1377 1.8 christos { 1378 1.8 christos for (type *arg_type : arg_types) 1379 1.8 christos add_symbol_overload_list_adl_namespace (arg_type, func_name, 1380 1.8 christos overload_list); 1381 1.1 christos } 1382 1.1 christos 1383 1.1 christos /* This applies the using directives to add namespaces to search in, 1384 1.1 christos and then searches for overloads in all of those namespaces. It 1385 1.1 christos adds the symbols found to sym_return_val. Arguments are as in 1386 1.1 christos make_symbol_overload_list. */ 1387 1.1 christos 1388 1.1 christos static void 1389 1.8 christos add_symbol_overload_list_using (const char *func_name, 1390 1.8 christos const char *the_namespace, 1391 1.8 christos std::vector<symbol *> *overload_list) 1392 1.1 christos { 1393 1.1 christos const struct block *block; 1394 1.1 christos 1395 1.1 christos /* First, go through the using directives. If any of them apply, 1396 1.1 christos look in the appropriate namespaces for new functions to match 1397 1.1 christos on. */ 1398 1.1 christos 1399 1.1 christos for (block = get_selected_block (0); 1400 1.1 christos block != NULL; 1401 1.10 christos block = block->superblock ()) 1402 1.12 christos for (using_direct *current : block->get_using ()) 1403 1.1 christos { 1404 1.1 christos /* Prevent recursive calls. */ 1405 1.1 christos if (current->searched) 1406 1.1 christos continue; 1407 1.1 christos 1408 1.10 christos /* If this is a namespace alias or imported declaration ignore 1409 1.1 christos it. */ 1410 1.10 christos if (current->alias != NULL || current->declaration != NULL) 1411 1.10 christos continue; 1412 1.1 christos 1413 1.10 christos if (strcmp (the_namespace, current->import_dest) == 0) 1414 1.1 christos { 1415 1.1 christos /* Mark this import as searched so that the recursive call 1416 1.1 christos does not search it again. */ 1417 1.8 christos scoped_restore reset_directive_searched 1418 1.8 christos = make_scoped_restore (¤t->searched, 1); 1419 1.1 christos 1420 1.8 christos add_symbol_overload_list_using (func_name, 1421 1.8 christos current->import_src, 1422 1.8 christos overload_list); 1423 1.1 christos } 1424 1.1 christos } 1425 1.1 christos 1426 1.1 christos /* Now, add names for this namespace. */ 1427 1.8 christos add_symbol_overload_list_namespace (func_name, the_namespace, 1428 1.8 christos overload_list); 1429 1.1 christos } 1430 1.1 christos 1431 1.1 christos /* This does the bulk of the work of finding overloaded symbols. 1432 1.1 christos FUNC_NAME is the name of the overloaded function we're looking for 1433 1.1 christos (possibly including namespace info). */ 1434 1.1 christos 1435 1.1 christos static void 1436 1.8 christos add_symbol_overload_list_qualified (const char *func_name, 1437 1.8 christos std::vector<symbol *> *overload_list) 1438 1.1 christos { 1439 1.10 christos const struct block *surrounding_static_block = 0; 1440 1.1 christos 1441 1.1 christos /* Look through the partial symtabs for all symbols which begin by 1442 1.1 christos matching FUNC_NAME. Make sure we read that symbol table in. */ 1443 1.1 christos 1444 1.8 christos for (objfile *objf : current_program_space->objfiles ()) 1445 1.10 christos objf->expand_symtabs_for_function (func_name); 1446 1.1 christos 1447 1.1 christos /* Search upwards from currently selected frame (so that we can 1448 1.1 christos complete on local vars. */ 1449 1.1 christos 1450 1.10 christos for (const block *b = get_selected_block (0); 1451 1.10 christos b != nullptr; 1452 1.10 christos b = b->superblock ()) 1453 1.8 christos add_symbol_overload_list_block (func_name, b, overload_list); 1454 1.1 christos 1455 1.11 christos surrounding_static_block = get_selected_block (0); 1456 1.11 christos surrounding_static_block = (surrounding_static_block == nullptr 1457 1.11 christos ? nullptr 1458 1.11 christos : surrounding_static_block->static_block ()); 1459 1.1 christos 1460 1.1 christos /* Go through the symtabs and check the externs and statics for 1461 1.1 christos symbols which match. */ 1462 1.1 christos 1463 1.10 christos const block *block = get_selected_block (0); 1464 1.11 christos struct objfile *current_objfile = block ? block->objfile () : nullptr; 1465 1.10 christos 1466 1.10 christos gdbarch_iterate_over_objfiles_in_search_order 1467 1.11 christos (current_objfile ? current_objfile->arch () : current_inferior ()->arch (), 1468 1.10 christos [func_name, surrounding_static_block, &overload_list] 1469 1.10 christos (struct objfile *obj) 1470 1.10 christos { 1471 1.10 christos for (compunit_symtab *cust : obj->compunits ()) 1472 1.10 christos { 1473 1.10 christos QUIT; 1474 1.10 christos const struct block *b = cust->blockvector ()->global_block (); 1475 1.10 christos add_symbol_overload_list_block (func_name, b, overload_list); 1476 1.10 christos 1477 1.10 christos b = cust->blockvector ()->static_block (); 1478 1.10 christos /* Don't do this block twice. */ 1479 1.10 christos if (b == surrounding_static_block) 1480 1.10 christos continue; 1481 1.10 christos 1482 1.10 christos add_symbol_overload_list_block (func_name, b, overload_list); 1483 1.10 christos } 1484 1.1 christos 1485 1.10 christos return 0; 1486 1.10 christos }, current_objfile); 1487 1.1 christos } 1488 1.1 christos 1489 1.1 christos /* Lookup the rtti type for a class name. */ 1490 1.1 christos 1491 1.1 christos struct type * 1492 1.9 christos cp_lookup_rtti_type (const char *name, const struct block *block) 1493 1.1 christos { 1494 1.1 christos struct symbol * rtti_sym; 1495 1.1 christos struct type * rtti_type; 1496 1.1 christos 1497 1.11 christos rtti_sym = lookup_symbol (name, block, 1498 1.11 christos SEARCH_TYPE_DOMAIN | SEARCH_STRUCT_DOMAIN, 1499 1.11 christos nullptr).symbol; 1500 1.1 christos 1501 1.1 christos if (rtti_sym == NULL) 1502 1.1 christos { 1503 1.1 christos warning (_("RTTI symbol not found for class '%s'"), name); 1504 1.1 christos return NULL; 1505 1.1 christos } 1506 1.1 christos 1507 1.10 christos if (rtti_sym->aclass () != LOC_TYPEDEF) 1508 1.1 christos { 1509 1.1 christos warning (_("RTTI symbol for class '%s' is not a type"), name); 1510 1.1 christos return NULL; 1511 1.1 christos } 1512 1.1 christos 1513 1.10 christos rtti_type = check_typedef (rtti_sym->type ()); 1514 1.1 christos 1515 1.9 christos switch (rtti_type->code ()) 1516 1.1 christos { 1517 1.3 christos case TYPE_CODE_STRUCT: 1518 1.1 christos break; 1519 1.1 christos case TYPE_CODE_NAMESPACE: 1520 1.1 christos /* chastain/2003-11-26: the symbol tables often contain fake 1521 1.1 christos symbols for namespaces with the same name as the struct. 1522 1.1 christos This warning is an indication of a bug in the lookup order 1523 1.1 christos or a bug in the way that the symbol tables are populated. */ 1524 1.1 christos warning (_("RTTI symbol for class '%s' is a namespace"), name); 1525 1.1 christos return NULL; 1526 1.1 christos default: 1527 1.1 christos warning (_("RTTI symbol for class '%s' has bad type"), name); 1528 1.1 christos return NULL; 1529 1.1 christos } 1530 1.1 christos 1531 1.1 christos return rtti_type; 1532 1.1 christos } 1533 1.1 christos 1534 1.3 christos #ifdef HAVE_WORKING_FORK 1535 1.3 christos 1536 1.9 christos /* If true, attempt to catch crashes in the demangler and print 1537 1.3 christos useful debugging information. */ 1538 1.3 christos 1539 1.9 christos static bool catch_demangler_crashes = true; 1540 1.3 christos 1541 1.3 christos /* Stack context and environment for demangler crash recovery. */ 1542 1.3 christos 1543 1.9 christos static thread_local SIGJMP_BUF *gdb_demangle_jmp_buf; 1544 1.3 christos 1545 1.9 christos /* If true, attempt to dump core from the signal handler. */ 1546 1.3 christos 1547 1.9 christos static std::atomic<bool> gdb_demangle_attempt_core_dump; 1548 1.3 christos 1549 1.3 christos /* Signal handler for gdb_demangle. */ 1550 1.3 christos 1551 1.3 christos static void 1552 1.3 christos gdb_demangle_signal_handler (int signo) 1553 1.3 christos { 1554 1.3 christos if (gdb_demangle_attempt_core_dump) 1555 1.3 christos { 1556 1.3 christos if (fork () == 0) 1557 1.3 christos dump_core (); 1558 1.3 christos 1559 1.9 christos gdb_demangle_attempt_core_dump = false; 1560 1.3 christos } 1561 1.3 christos 1562 1.9 christos SIGLONGJMP (*gdb_demangle_jmp_buf, signo); 1563 1.9 christos } 1564 1.9 christos 1565 1.9 christos /* A helper for gdb_demangle that reports a demangling failure. */ 1566 1.9 christos 1567 1.9 christos static void 1568 1.9 christos report_failed_demangle (const char *name, bool core_dump_allowed, 1569 1.9 christos int crash_signal) 1570 1.9 christos { 1571 1.9 christos static bool error_reported = false; 1572 1.9 christos 1573 1.9 christos if (!error_reported) 1574 1.9 christos { 1575 1.9 christos std::string short_msg 1576 1.9 christos = string_printf (_("unable to demangle '%s' " 1577 1.9 christos "(demangler failed with signal %d)"), 1578 1.9 christos name, crash_signal); 1579 1.9 christos 1580 1.9 christos std::string long_msg 1581 1.9 christos = string_printf ("%s:%d: %s: %s", __FILE__, __LINE__, 1582 1.9 christos "demangler-warning", short_msg.c_str ()); 1583 1.9 christos 1584 1.9 christos target_terminal::scoped_restore_terminal_state term_state; 1585 1.9 christos target_terminal::ours_for_output (); 1586 1.9 christos 1587 1.9 christos begin_line (); 1588 1.9 christos if (core_dump_allowed) 1589 1.10 christos gdb_printf (gdb_stderr, 1590 1.10 christos _("%s\nAttempting to dump core.\n"), 1591 1.10 christos long_msg.c_str ()); 1592 1.9 christos else 1593 1.9 christos warn_cant_dump_core (long_msg.c_str ()); 1594 1.9 christos 1595 1.9 christos demangler_warning (__FILE__, __LINE__, "%s", short_msg.c_str ()); 1596 1.9 christos 1597 1.9 christos error_reported = true; 1598 1.9 christos } 1599 1.3 christos } 1600 1.3 christos 1601 1.3 christos #endif 1602 1.3 christos 1603 1.1 christos /* A wrapper for bfd_demangle. */ 1604 1.1 christos 1605 1.10 christos gdb::unique_xmalloc_ptr<char> 1606 1.1 christos gdb_demangle (const char *name, int options) 1607 1.1 christos { 1608 1.10 christos gdb::unique_xmalloc_ptr<char> result; 1609 1.3 christos int crash_signal = 0; 1610 1.3 christos 1611 1.3 christos #ifdef HAVE_WORKING_FORK 1612 1.10 christos scoped_segv_handler_restore restore_segv 1613 1.10 christos (catch_demangler_crashes 1614 1.10 christos ? gdb_demangle_signal_handler 1615 1.10 christos : nullptr); 1616 1.9 christos 1617 1.9 christos bool core_dump_allowed = gdb_demangle_attempt_core_dump; 1618 1.9 christos SIGJMP_BUF jmp_buf; 1619 1.9 christos scoped_restore restore_jmp_buf 1620 1.9 christos = make_scoped_restore (&gdb_demangle_jmp_buf, &jmp_buf); 1621 1.3 christos if (catch_demangler_crashes) 1622 1.3 christos { 1623 1.9 christos /* The signal handler may keep the signal blocked when we longjmp out 1624 1.10 christos of it. If we have sigprocmask, we can use it to unblock the signal 1625 1.9 christos afterwards and we can avoid the performance overhead of saving the 1626 1.9 christos signal mask just in case the signal gets triggered. Otherwise, just 1627 1.9 christos tell sigsetjmp to save the mask. */ 1628 1.9 christos #ifdef HAVE_SIGPROCMASK 1629 1.9 christos crash_signal = SIGSETJMP (*gdb_demangle_jmp_buf, 0); 1630 1.3 christos #else 1631 1.9 christos crash_signal = SIGSETJMP (*gdb_demangle_jmp_buf, 1); 1632 1.3 christos #endif 1633 1.3 christos } 1634 1.3 christos #endif 1635 1.3 christos 1636 1.3 christos if (crash_signal == 0) 1637 1.10 christos result.reset (bfd_demangle (NULL, name, options | DMGL_VERBOSE)); 1638 1.3 christos 1639 1.3 christos #ifdef HAVE_WORKING_FORK 1640 1.3 christos if (catch_demangler_crashes) 1641 1.3 christos { 1642 1.9 christos if (crash_signal != 0) 1643 1.10 christos { 1644 1.9 christos #ifdef HAVE_SIGPROCMASK 1645 1.9 christos /* If we got the signal, SIGSEGV may still be blocked; restore it. */ 1646 1.9 christos sigset_t segv_sig_set; 1647 1.9 christos sigemptyset (&segv_sig_set); 1648 1.9 christos sigaddset (&segv_sig_set, SIGSEGV); 1649 1.9 christos gdb_sigmask (SIG_UNBLOCK, &segv_sig_set, NULL); 1650 1.3 christos #endif 1651 1.3 christos 1652 1.9 christos /* If there was a failure, we can't report it here, because 1653 1.9 christos we might be in a background thread. Instead, arrange for 1654 1.9 christos the reporting to happen on the main thread. */ 1655 1.10 christos std::string copy = name; 1656 1.11 christos run_on_main_thread ([=, copy = std::move (copy)] () 1657 1.10 christos { 1658 1.10 christos report_failed_demangle (copy.c_str (), core_dump_allowed, 1659 1.10 christos crash_signal); 1660 1.10 christos }); 1661 1.3 christos 1662 1.10 christos result = NULL; 1663 1.10 christos } 1664 1.3 christos } 1665 1.3 christos #endif 1666 1.3 christos 1667 1.3 christos return result; 1668 1.1 christos } 1669 1.1 christos 1670 1.6 christos /* See cp-support.h. */ 1671 1.6 christos 1672 1.10 christos char * 1673 1.10 christos gdb_cplus_demangle_print (int options, 1674 1.10 christos struct demangle_component *tree, 1675 1.10 christos int estimated_length, 1676 1.10 christos size_t *p_allocated_size) 1677 1.10 christos { 1678 1.10 christos return cplus_demangle_print (options | DMGL_VERBOSE, tree, 1679 1.10 christos estimated_length, p_allocated_size); 1680 1.10 christos } 1681 1.10 christos 1682 1.10 christos /* A wrapper for cplus_demangle_v3_components that forces 1683 1.10 christos DMGL_VERBOSE. */ 1684 1.10 christos 1685 1.10 christos static struct demangle_component * 1686 1.10 christos gdb_cplus_demangle_v3_components (const char *mangled, 1687 1.10 christos int options, void **mem) 1688 1.10 christos { 1689 1.10 christos return cplus_demangle_v3_components (mangled, options | DMGL_VERBOSE, mem); 1690 1.10 christos } 1691 1.10 christos 1692 1.10 christos /* See cp-support.h. */ 1693 1.10 christos 1694 1.8 christos unsigned int 1695 1.8 christos cp_search_name_hash (const char *search_name) 1696 1.8 christos { 1697 1.8 christos /* cp_entire_prefix_len assumes a fully-qualified name with no 1698 1.8 christos leading "::". */ 1699 1.8 christos if (startswith (search_name, "::")) 1700 1.8 christos search_name += 2; 1701 1.8 christos 1702 1.8 christos unsigned int prefix_len = cp_entire_prefix_len (search_name); 1703 1.8 christos if (prefix_len != 0) 1704 1.8 christos search_name += prefix_len + 2; 1705 1.8 christos 1706 1.8 christos unsigned int hash = 0; 1707 1.8 christos for (const char *string = search_name; *string != '\0'; ++string) 1708 1.8 christos { 1709 1.12 christos const char *before_skip = string; 1710 1.8 christos string = skip_spaces (string); 1711 1.8 christos 1712 1.8 christos if (*string == '(') 1713 1.8 christos break; 1714 1.8 christos 1715 1.12 christos /* Could it be the beginning of a function name? 1716 1.12 christos If yes, does it begin with the keyword "operator"? */ 1717 1.12 christos if ((string != before_skip || string == search_name) 1718 1.12 christos && (string[0] == 'o' && startswith (string, CP_OPERATOR_STR))) 1719 1.12 christos { 1720 1.12 christos /* Hash the "operator" part. */ 1721 1.12 christos for (size_t i = 0; i < CP_OPERATOR_LEN; ++i) 1722 1.12 christos hash = SYMBOL_HASH_NEXT (hash, *string++); 1723 1.12 christos 1724 1.12 christos string = skip_spaces (string); 1725 1.12 christos 1726 1.12 christos /* If no more data to process, stop right now. This is specially 1727 1.12 christos intended for SEARCH_NAMEs that end with "operator". In such 1728 1.12 christos cases, the whole string is processed and STRING is pointing to a 1729 1.12 christos null-byte. Letting the loop body resume naturally would lead to 1730 1.12 christos a "++string" that causes STRING to point past the null-byte. */ 1731 1.12 christos if (string[0] == '\0') 1732 1.12 christos break; 1733 1.12 christos 1734 1.12 christos /* "<" and "<<" are sequences of interest here. This covers 1735 1.12 christos "operator{<,<<,<=,<=>}". In the last 2 cases, the "=" and "=>" 1736 1.12 christos parts are handled by the next iterations of the loop like other 1737 1.12 christos input chars. The goal is to process all the operator-related '<' 1738 1.12 christos chars, so that later if a '<' is visited it can be inferred for 1739 1.12 christos sure that it is the beginning of a template parameter list. 1740 1.12 christos 1741 1.12 christos STRING is a null-byte terminated string. If string[0] is not 1742 1.12 christos a null-byte, according to the previous check, string[1] is not 1743 1.12 christos past the end of the allocation and can be referenced safely. */ 1744 1.12 christos if (string[0] == '<') 1745 1.12 christos { 1746 1.12 christos hash = SYMBOL_HASH_NEXT (hash, *string); 1747 1.12 christos if (string[1] == '<') 1748 1.12 christos hash = SYMBOL_HASH_NEXT (hash, *++string); 1749 1.12 christos continue; 1750 1.12 christos } 1751 1.12 christos } 1752 1.12 christos 1753 1.8 christos /* Ignore ABI tags such as "[abi:cxx11]. */ 1754 1.8 christos if (*string == '[' 1755 1.8 christos && startswith (string + 1, "abi:") 1756 1.8 christos && string[5] != ':') 1757 1.8 christos break; 1758 1.8 christos 1759 1.12 christos /* Ignore template parameter lists. The likely "operator{<,<<,<=,<=>}" 1760 1.12 christos are already taken care of. Therefore, any encounter of '<' character 1761 1.12 christos at this point is related to template lists. */ 1762 1.12 christos if (*string == '<') 1763 1.10 christos break; 1764 1.10 christos 1765 1.8 christos hash = SYMBOL_HASH_NEXT (hash, *string); 1766 1.8 christos } 1767 1.8 christos return hash; 1768 1.8 christos } 1769 1.8 christos 1770 1.12 christos #if GDB_SELF_TEST 1771 1.12 christos 1772 1.12 christos namespace selftests { 1773 1.12 christos 1774 1.12 christos static void 1775 1.12 christos test_cp_search_name_hash () 1776 1.12 christos { 1777 1.12 christos SELF_CHECK (cp_search_name_hash ("void func<(enum_test)0>(int*, int)") 1778 1.12 christos == cp_search_name_hash ("void func")); 1779 1.12 christos SELF_CHECK (cp_search_name_hash ("operator") 1780 1.12 christos != cp_search_name_hash ("operator<")); 1781 1.12 christos SELF_CHECK (cp_search_name_hash ("operator") 1782 1.12 christos != cp_search_name_hash ("operator<<")); 1783 1.12 christos SELF_CHECK (cp_search_name_hash ("operator<") 1784 1.12 christos != cp_search_name_hash ("operator<<")); 1785 1.12 christos SELF_CHECK (cp_search_name_hash ("operator<") 1786 1.12 christos == cp_search_name_hash ("operator <")); 1787 1.12 christos SELF_CHECK (cp_search_name_hash ("operator") 1788 1.12 christos != cp_search_name_hash ("foo_operator")); 1789 1.12 christos SELF_CHECK (cp_search_name_hash ("operator") 1790 1.12 christos != cp_search_name_hash ("operator_foo")); 1791 1.12 christos SELF_CHECK (cp_search_name_hash ("operator<") 1792 1.12 christos != cp_search_name_hash ("foo_operator")); 1793 1.12 christos SELF_CHECK (cp_search_name_hash ("operator<") 1794 1.12 christos != cp_search_name_hash ("operator_foo")); 1795 1.12 christos SELF_CHECK (cp_search_name_hash ("operator<<") 1796 1.12 christos != cp_search_name_hash ("foo_operator")); 1797 1.12 christos SELF_CHECK (cp_search_name_hash ("operator<<") 1798 1.12 christos != cp_search_name_hash ("operator_foo")); 1799 1.12 christos 1800 1.12 christos SELF_CHECK (cp_search_name_hash ("func") 1801 1.12 christos == cp_search_name_hash ("func[abi:cxx11]")); 1802 1.12 christos } 1803 1.12 christos 1804 1.12 christos } /* namespace selftests */ 1805 1.12 christos 1806 1.12 christos #endif /* GDB_SELF_TEST */ 1807 1.12 christos 1808 1.8 christos /* Helper for cp_symbol_name_matches (i.e., symbol_name_matcher_ftype 1809 1.8 christos implementation for symbol_name_match_type::WILD matching). Split 1810 1.8 christos to a separate function for unit-testing convenience. 1811 1.8 christos 1812 1.8 christos If SYMBOL_SEARCH_NAME has more scopes than LOOKUP_NAME, we try to 1813 1.8 christos match ignoring the extra leading scopes of SYMBOL_SEARCH_NAME. 1814 1.8 christos This allows conveniently setting breakpoints on functions/methods 1815 1.8 christos inside any namespace/class without specifying the fully-qualified 1816 1.8 christos name. 1817 1.8 christos 1818 1.8 christos E.g., these match: 1819 1.8 christos 1820 1.8 christos [symbol search name] [lookup name] 1821 1.8 christos foo::bar::func foo::bar::func 1822 1.8 christos foo::bar::func bar::func 1823 1.8 christos foo::bar::func func 1824 1.8 christos 1825 1.8 christos While these don't: 1826 1.8 christos 1827 1.8 christos [symbol search name] [lookup name] 1828 1.8 christos foo::zbar::func bar::func 1829 1.8 christos foo::bar::func foo::func 1830 1.8 christos 1831 1.8 christos See more examples in the test_cp_symbol_name_matches selftest 1832 1.8 christos function below. 1833 1.8 christos 1834 1.8 christos See symbol_name_matcher_ftype for description of SYMBOL_SEARCH_NAME 1835 1.8 christos and COMP_MATCH_RES. 1836 1.8 christos 1837 1.8 christos LOOKUP_NAME/LOOKUP_NAME_LEN is the name we're looking up. 1838 1.8 christos 1839 1.8 christos See strncmp_iw_with_mode for description of MODE. 1840 1.8 christos */ 1841 1.8 christos 1842 1.8 christos static bool 1843 1.8 christos cp_symbol_name_matches_1 (const char *symbol_search_name, 1844 1.8 christos const char *lookup_name, 1845 1.8 christos size_t lookup_name_len, 1846 1.8 christos strncmp_iw_mode mode, 1847 1.8 christos completion_match_result *comp_match_res) 1848 1.8 christos { 1849 1.8 christos const char *sname = symbol_search_name; 1850 1.8 christos completion_match_for_lcd *match_for_lcd 1851 1.8 christos = (comp_match_res != NULL ? &comp_match_res->match_for_lcd : NULL); 1852 1.8 christos 1853 1.11 christos gdb_assert (match_for_lcd == nullptr || match_for_lcd->empty ()); 1854 1.11 christos 1855 1.8 christos while (true) 1856 1.8 christos { 1857 1.8 christos if (strncmp_iw_with_mode (sname, lookup_name, lookup_name_len, 1858 1.10 christos mode, language_cplus, match_for_lcd, true) == 0) 1859 1.8 christos { 1860 1.8 christos if (comp_match_res != NULL) 1861 1.8 christos { 1862 1.8 christos /* Note here we set different MATCH and MATCH_FOR_LCD 1863 1.8 christos strings. This is because with 1864 1.8 christos 1865 1.8 christos (gdb) b push_bac[TAB] 1866 1.8 christos 1867 1.8 christos we want the completion matches to list 1868 1.8 christos 1869 1.8 christos std::vector<int>::push_back(...) 1870 1.8 christos std::vector<char>::push_back(...) 1871 1.8 christos 1872 1.8 christos etc., which are SYMBOL_SEARCH_NAMEs, while we want 1873 1.8 christos the input line to auto-complete to 1874 1.8 christos 1875 1.8 christos (gdb) push_back(...) 1876 1.8 christos 1877 1.8 christos which is SNAME, not to 1878 1.8 christos 1879 1.8 christos (gdb) std::vector< 1880 1.8 christos 1881 1.8 christos which would be the regular common prefix between all 1882 1.8 christos the matches otherwise. */ 1883 1.8 christos comp_match_res->set_match (symbol_search_name, sname); 1884 1.8 christos } 1885 1.8 christos return true; 1886 1.8 christos } 1887 1.8 christos 1888 1.11 christos /* Clear match_for_lcd so the next strncmp_iw_with_mode call starts 1889 1.11 christos from scratch. */ 1890 1.11 christos if (match_for_lcd != nullptr) 1891 1.11 christos match_for_lcd->clear (); 1892 1.11 christos 1893 1.8 christos unsigned int len = cp_find_first_component (sname); 1894 1.8 christos 1895 1.8 christos if (sname[len] == '\0') 1896 1.8 christos return false; 1897 1.8 christos 1898 1.8 christos gdb_assert (sname[len] == ':'); 1899 1.8 christos /* Skip the '::'. */ 1900 1.8 christos sname += len + 2; 1901 1.8 christos } 1902 1.8 christos } 1903 1.8 christos 1904 1.8 christos /* C++ symbol_name_matcher_ftype implementation. */ 1905 1.8 christos 1906 1.8 christos static bool 1907 1.8 christos cp_fq_symbol_name_matches (const char *symbol_search_name, 1908 1.8 christos const lookup_name_info &lookup_name, 1909 1.8 christos completion_match_result *comp_match_res) 1910 1.8 christos { 1911 1.8 christos /* Get the demangled name. */ 1912 1.8 christos const std::string &name = lookup_name.cplus ().lookup_name (); 1913 1.8 christos completion_match_for_lcd *match_for_lcd 1914 1.8 christos = (comp_match_res != NULL ? &comp_match_res->match_for_lcd : NULL); 1915 1.8 christos strncmp_iw_mode mode = (lookup_name.completion_mode () 1916 1.8 christos ? strncmp_iw_mode::NORMAL 1917 1.8 christos : strncmp_iw_mode::MATCH_PARAMS); 1918 1.8 christos 1919 1.8 christos if (strncmp_iw_with_mode (symbol_search_name, 1920 1.8 christos name.c_str (), name.size (), 1921 1.8 christos mode, language_cplus, match_for_lcd) == 0) 1922 1.8 christos { 1923 1.8 christos if (comp_match_res != NULL) 1924 1.8 christos comp_match_res->set_match (symbol_search_name); 1925 1.8 christos return true; 1926 1.8 christos } 1927 1.8 christos 1928 1.8 christos return false; 1929 1.8 christos } 1930 1.8 christos 1931 1.8 christos /* C++ symbol_name_matcher_ftype implementation for wild matches. 1932 1.8 christos Defers work to cp_symbol_name_matches_1. */ 1933 1.8 christos 1934 1.8 christos static bool 1935 1.8 christos cp_symbol_name_matches (const char *symbol_search_name, 1936 1.8 christos const lookup_name_info &lookup_name, 1937 1.8 christos completion_match_result *comp_match_res) 1938 1.8 christos { 1939 1.8 christos /* Get the demangled name. */ 1940 1.8 christos const std::string &name = lookup_name.cplus ().lookup_name (); 1941 1.8 christos 1942 1.8 christos strncmp_iw_mode mode = (lookup_name.completion_mode () 1943 1.8 christos ? strncmp_iw_mode::NORMAL 1944 1.8 christos : strncmp_iw_mode::MATCH_PARAMS); 1945 1.8 christos 1946 1.8 christos return cp_symbol_name_matches_1 (symbol_search_name, 1947 1.8 christos name.c_str (), name.size (), 1948 1.8 christos mode, comp_match_res); 1949 1.8 christos } 1950 1.8 christos 1951 1.8 christos /* See cp-support.h. */ 1952 1.8 christos 1953 1.8 christos symbol_name_matcher_ftype * 1954 1.8 christos cp_get_symbol_name_matcher (const lookup_name_info &lookup_name) 1955 1.8 christos { 1956 1.8 christos switch (lookup_name.match_type ()) 1957 1.8 christos { 1958 1.8 christos case symbol_name_match_type::FULL: 1959 1.8 christos case symbol_name_match_type::EXPRESSION: 1960 1.8 christos case symbol_name_match_type::SEARCH_NAME: 1961 1.8 christos return cp_fq_symbol_name_matches; 1962 1.8 christos case symbol_name_match_type::WILD: 1963 1.8 christos return cp_symbol_name_matches; 1964 1.8 christos } 1965 1.8 christos 1966 1.8 christos gdb_assert_not_reached (""); 1967 1.8 christos } 1968 1.8 christos 1969 1.8 christos #if GDB_SELF_TEST 1970 1.8 christos 1971 1.8 christos namespace selftests { 1972 1.8 christos 1973 1.9 christos static void 1974 1.8 christos test_cp_symbol_name_matches () 1975 1.8 christos { 1976 1.8 christos #define CHECK_MATCH(SYMBOL, INPUT) \ 1977 1.8 christos SELF_CHECK (cp_symbol_name_matches_1 (SYMBOL, \ 1978 1.8 christos INPUT, sizeof (INPUT) - 1, \ 1979 1.8 christos strncmp_iw_mode::MATCH_PARAMS, \ 1980 1.8 christos NULL)) 1981 1.8 christos 1982 1.8 christos #define CHECK_NOT_MATCH(SYMBOL, INPUT) \ 1983 1.8 christos SELF_CHECK (!cp_symbol_name_matches_1 (SYMBOL, \ 1984 1.8 christos INPUT, sizeof (INPUT) - 1, \ 1985 1.8 christos strncmp_iw_mode::MATCH_PARAMS, \ 1986 1.8 christos NULL)) 1987 1.8 christos 1988 1.8 christos /* Like CHECK_MATCH, and also check that INPUT (and all substrings 1989 1.8 christos that start at index 0) completes to SYMBOL. */ 1990 1.8 christos #define CHECK_MATCH_C(SYMBOL, INPUT) \ 1991 1.8 christos do \ 1992 1.8 christos { \ 1993 1.8 christos CHECK_MATCH (SYMBOL, INPUT); \ 1994 1.8 christos for (size_t i = 0; i < sizeof (INPUT) - 1; i++) \ 1995 1.8 christos SELF_CHECK (cp_symbol_name_matches_1 (SYMBOL, INPUT, i, \ 1996 1.8 christos strncmp_iw_mode::NORMAL, \ 1997 1.8 christos NULL)); \ 1998 1.8 christos } while (0) 1999 1.8 christos 2000 1.8 christos /* Like CHECK_NOT_MATCH, and also check that INPUT does NOT complete 2001 1.8 christos to SYMBOL. */ 2002 1.8 christos #define CHECK_NOT_MATCH_C(SYMBOL, INPUT) \ 2003 1.8 christos do \ 2004 1.8 christos { \ 2005 1.8 christos CHECK_NOT_MATCH (SYMBOL, INPUT); \ 2006 1.8 christos SELF_CHECK (!cp_symbol_name_matches_1 (SYMBOL, INPUT, \ 2007 1.8 christos sizeof (INPUT) - 1, \ 2008 1.8 christos strncmp_iw_mode::NORMAL, \ 2009 1.8 christos NULL)); \ 2010 1.8 christos } while (0) 2011 1.8 christos 2012 1.8 christos /* Lookup name without parens matches all overloads. */ 2013 1.8 christos CHECK_MATCH_C ("function()", "function"); 2014 1.8 christos CHECK_MATCH_C ("function(int)", "function"); 2015 1.8 christos 2016 1.8 christos /* Check whitespace around parameters is ignored. */ 2017 1.8 christos CHECK_MATCH_C ("function()", "function ()"); 2018 1.8 christos CHECK_MATCH_C ("function ( )", "function()"); 2019 1.8 christos CHECK_MATCH_C ("function ()", "function( )"); 2020 1.8 christos CHECK_MATCH_C ("func(int)", "func( int )"); 2021 1.8 christos CHECK_MATCH_C ("func(int)", "func ( int ) "); 2022 1.8 christos CHECK_MATCH_C ("func ( int )", "func( int )"); 2023 1.8 christos CHECK_MATCH_C ("func ( int )", "func ( int ) "); 2024 1.8 christos 2025 1.8 christos /* Check symbol name prefixes aren't incorrectly matched. */ 2026 1.8 christos CHECK_NOT_MATCH ("func", "function"); 2027 1.8 christos CHECK_NOT_MATCH ("function", "func"); 2028 1.8 christos CHECK_NOT_MATCH ("function()", "func"); 2029 1.8 christos 2030 1.8 christos /* Check that if the lookup name includes parameters, only the right 2031 1.8 christos overload matches. */ 2032 1.8 christos CHECK_MATCH_C ("function(int)", "function(int)"); 2033 1.8 christos CHECK_NOT_MATCH_C ("function(int)", "function()"); 2034 1.8 christos 2035 1.8 christos /* Check that whitespace within symbol names is not ignored. */ 2036 1.8 christos CHECK_NOT_MATCH_C ("function", "func tion"); 2037 1.8 christos CHECK_NOT_MATCH_C ("func__tion", "func_ _tion"); 2038 1.8 christos CHECK_NOT_MATCH_C ("func11tion", "func1 1tion"); 2039 1.8 christos 2040 1.8 christos /* Check the converse, which can happen with template function, 2041 1.8 christos where the return type is part of the demangled name. */ 2042 1.8 christos CHECK_NOT_MATCH_C ("func tion", "function"); 2043 1.8 christos CHECK_NOT_MATCH_C ("func1 1tion", "func11tion"); 2044 1.8 christos CHECK_NOT_MATCH_C ("func_ _tion", "func__tion"); 2045 1.8 christos 2046 1.8 christos /* Within parameters too. */ 2047 1.8 christos CHECK_NOT_MATCH_C ("func(param)", "func(par am)"); 2048 1.8 christos 2049 1.8 christos /* Check handling of whitespace around C++ operators. */ 2050 1.8 christos CHECK_NOT_MATCH_C ("operator<<", "opera tor<<"); 2051 1.8 christos CHECK_NOT_MATCH_C ("operator<<", "operator< <"); 2052 1.8 christos CHECK_NOT_MATCH_C ("operator<<", "operator < <"); 2053 1.8 christos CHECK_NOT_MATCH_C ("operator==", "operator= ="); 2054 1.8 christos CHECK_NOT_MATCH_C ("operator==", "operator = ="); 2055 1.8 christos CHECK_MATCH_C ("operator<<", "operator <<"); 2056 1.8 christos CHECK_MATCH_C ("operator<<()", "operator <<"); 2057 1.8 christos CHECK_NOT_MATCH_C ("operator<<()", "operator<<(int)"); 2058 1.8 christos CHECK_NOT_MATCH_C ("operator<<(int)", "operator<<()"); 2059 1.8 christos CHECK_MATCH_C ("operator==", "operator =="); 2060 1.8 christos CHECK_MATCH_C ("operator==()", "operator =="); 2061 1.8 christos CHECK_MATCH_C ("operator <<", "operator<<"); 2062 1.8 christos CHECK_MATCH_C ("operator ==", "operator=="); 2063 1.8 christos CHECK_MATCH_C ("operator bool", "operator bool"); 2064 1.8 christos CHECK_MATCH_C ("operator bool ()", "operator bool"); 2065 1.8 christos CHECK_MATCH_C ("operatorX<<", "operatorX < <"); 2066 1.8 christos CHECK_MATCH_C ("Xoperator<<", "Xoperator < <"); 2067 1.8 christos 2068 1.8 christos CHECK_MATCH_C ("operator()(int)", "operator()(int)"); 2069 1.8 christos CHECK_MATCH_C ("operator()(int)", "operator ( ) ( int )"); 2070 1.8 christos CHECK_MATCH_C ("operator()<long>(int)", "operator ( ) < long > ( int )"); 2071 1.8 christos /* The first "()" is not the parameter list. */ 2072 1.8 christos CHECK_NOT_MATCH ("operator()(int)", "operator"); 2073 1.8 christos 2074 1.8 christos /* Misc user-defined operator tests. */ 2075 1.8 christos 2076 1.8 christos CHECK_NOT_MATCH_C ("operator/=()", "operator ^="); 2077 1.8 christos /* Same length at end of input. */ 2078 1.8 christos CHECK_NOT_MATCH_C ("operator>>", "operator[]"); 2079 1.8 christos /* Same length but not at end of input. */ 2080 1.8 christos CHECK_NOT_MATCH_C ("operator>>()", "operator[]()"); 2081 1.8 christos 2082 1.8 christos CHECK_MATCH_C ("base::operator char*()", "base::operator char*()"); 2083 1.8 christos CHECK_MATCH_C ("base::operator char*()", "base::operator char * ()"); 2084 1.8 christos CHECK_MATCH_C ("base::operator char**()", "base::operator char * * ()"); 2085 1.8 christos CHECK_MATCH ("base::operator char**()", "base::operator char * *"); 2086 1.8 christos CHECK_MATCH_C ("base::operator*()", "base::operator*()"); 2087 1.8 christos CHECK_NOT_MATCH_C ("base::operator char*()", "base::operatorc"); 2088 1.8 christos CHECK_NOT_MATCH ("base::operator char*()", "base::operator char"); 2089 1.8 christos CHECK_NOT_MATCH ("base::operator char*()", "base::operat"); 2090 1.8 christos 2091 1.8 christos /* Check handling of whitespace around C++ scope operators. */ 2092 1.8 christos CHECK_NOT_MATCH_C ("foo::bar", "foo: :bar"); 2093 1.8 christos CHECK_MATCH_C ("foo::bar", "foo :: bar"); 2094 1.8 christos CHECK_MATCH_C ("foo :: bar", "foo::bar"); 2095 1.8 christos 2096 1.8 christos CHECK_MATCH_C ("abc::def::ghi()", "abc::def::ghi()"); 2097 1.8 christos CHECK_MATCH_C ("abc::def::ghi ( )", "abc::def::ghi()"); 2098 1.8 christos CHECK_MATCH_C ("abc::def::ghi()", "abc::def::ghi ( )"); 2099 1.8 christos CHECK_MATCH_C ("function()", "function()"); 2100 1.8 christos CHECK_MATCH_C ("bar::function()", "bar::function()"); 2101 1.8 christos 2102 1.8 christos /* Wild matching tests follow. */ 2103 1.8 christos 2104 1.8 christos /* Tests matching symbols in some scope. */ 2105 1.8 christos CHECK_MATCH_C ("foo::function()", "function"); 2106 1.8 christos CHECK_MATCH_C ("foo::function(int)", "function"); 2107 1.8 christos CHECK_MATCH_C ("foo::bar::function()", "function"); 2108 1.8 christos CHECK_MATCH_C ("bar::function()", "bar::function"); 2109 1.8 christos CHECK_MATCH_C ("foo::bar::function()", "bar::function"); 2110 1.8 christos CHECK_MATCH_C ("foo::bar::function(int)", "bar::function"); 2111 1.8 christos 2112 1.8 christos /* Same, with parameters in the lookup name. */ 2113 1.8 christos CHECK_MATCH_C ("foo::function()", "function()"); 2114 1.8 christos CHECK_MATCH_C ("foo::bar::function()", "function()"); 2115 1.8 christos CHECK_MATCH_C ("foo::function(int)", "function(int)"); 2116 1.8 christos CHECK_MATCH_C ("foo::function()", "foo::function()"); 2117 1.8 christos CHECK_MATCH_C ("foo::bar::function()", "bar::function()"); 2118 1.8 christos CHECK_MATCH_C ("foo::bar::function(int)", "bar::function(int)"); 2119 1.8 christos CHECK_MATCH_C ("bar::function()", "bar::function()"); 2120 1.8 christos 2121 1.8 christos CHECK_NOT_MATCH_C ("foo::bar::function(int)", "bar::function()"); 2122 1.8 christos 2123 1.8 christos CHECK_MATCH_C ("(anonymous namespace)::bar::function(int)", 2124 1.8 christos "bar::function(int)"); 2125 1.8 christos CHECK_MATCH_C ("foo::(anonymous namespace)::bar::function(int)", 2126 1.8 christos "function(int)"); 2127 1.8 christos 2128 1.8 christos /* Lookup scope wider than symbol scope, should not match. */ 2129 1.8 christos CHECK_NOT_MATCH_C ("function()", "bar::function"); 2130 1.8 christos CHECK_NOT_MATCH_C ("function()", "bar::function()"); 2131 1.8 christos 2132 1.8 christos /* Explicit global scope doesn't match. */ 2133 1.8 christos CHECK_NOT_MATCH_C ("foo::function()", "::function"); 2134 1.8 christos CHECK_NOT_MATCH_C ("foo::function()", "::function()"); 2135 1.8 christos CHECK_NOT_MATCH_C ("foo::function(int)", "::function()"); 2136 1.8 christos CHECK_NOT_MATCH_C ("foo::function(int)", "::function(int)"); 2137 1.8 christos 2138 1.8 christos /* Test ABI tag matching/ignoring. */ 2139 1.8 christos 2140 1.8 christos /* If the symbol name has an ABI tag, but the lookup name doesn't, 2141 1.8 christos then the ABI tag in the symbol name is ignored. */ 2142 1.8 christos CHECK_MATCH_C ("function[abi:foo]()", "function"); 2143 1.8 christos CHECK_MATCH_C ("function[abi:foo](int)", "function"); 2144 1.8 christos CHECK_MATCH_C ("function[abi:foo]()", "function ()"); 2145 1.8 christos CHECK_NOT_MATCH_C ("function[abi:foo]()", "function (int)"); 2146 1.8 christos 2147 1.8 christos CHECK_MATCH_C ("function[abi:foo]()", "function[abi:foo]"); 2148 1.8 christos CHECK_MATCH_C ("function[abi:foo](int)", "function[abi:foo]"); 2149 1.8 christos CHECK_MATCH_C ("function[abi:foo]()", "function[abi:foo] ()"); 2150 1.8 christos CHECK_MATCH_C ("function[abi:foo][abi:bar]()", "function"); 2151 1.8 christos CHECK_MATCH_C ("function[abi:foo][abi:bar](int)", "function"); 2152 1.8 christos CHECK_MATCH_C ("function[abi:foo][abi:bar]()", "function[abi:foo]"); 2153 1.8 christos CHECK_MATCH_C ("function[abi:foo][abi:bar](int)", "function[abi:foo]"); 2154 1.8 christos CHECK_MATCH_C ("function[abi:foo][abi:bar]()", "function[abi:foo] ()"); 2155 1.8 christos CHECK_NOT_MATCH_C ("function[abi:foo][abi:bar]()", "function[abi:foo] (int)"); 2156 1.8 christos 2157 1.8 christos CHECK_MATCH_C ("function [abi:foo][abi:bar] ( )", "function [abi:foo]"); 2158 1.8 christos 2159 1.8 christos /* If the symbol name does not have an ABI tag, while the lookup 2160 1.8 christos name has one, then there's no match. */ 2161 1.8 christos CHECK_NOT_MATCH_C ("function()", "function[abi:foo]()"); 2162 1.8 christos CHECK_NOT_MATCH_C ("function()", "function[abi:foo]"); 2163 1.8 christos } 2164 1.8 christos 2165 1.8 christos /* If non-NULL, return STR wrapped in quotes. Otherwise, return a 2166 1.8 christos "<null>" string (with no quotes). */ 2167 1.8 christos 2168 1.8 christos static std::string 2169 1.8 christos quote (const char *str) 2170 1.8 christos { 2171 1.8 christos if (str != NULL) 2172 1.9 christos return std::string (1, '"') + str + '"'; 2173 1.8 christos else 2174 1.8 christos return "<null>"; 2175 1.8 christos } 2176 1.8 christos 2177 1.8 christos /* Check that removing parameter info out of NAME produces EXPECTED. 2178 1.8 christos COMPLETION_MODE indicates whether we're testing normal and 2179 1.8 christos completion mode. FILE and LINE are used to provide better test 2180 1.11 christos location information in case the check fails. */ 2181 1.8 christos 2182 1.8 christos static void 2183 1.8 christos check_remove_params (const char *file, int line, 2184 1.8 christos const char *name, const char *expected, 2185 1.8 christos bool completion_mode) 2186 1.8 christos { 2187 1.8 christos gdb::unique_xmalloc_ptr<char> result 2188 1.8 christos = cp_remove_params_if_any (name, completion_mode); 2189 1.8 christos 2190 1.8 christos if ((expected == NULL) != (result == NULL) 2191 1.8 christos || (expected != NULL 2192 1.8 christos && strcmp (result.get (), expected) != 0)) 2193 1.8 christos { 2194 1.8 christos error (_("%s:%d: make-paramless self-test failed: (completion=%d) " 2195 1.8 christos "\"%s\" -> %s, expected %s"), 2196 1.8 christos file, line, completion_mode, name, 2197 1.8 christos quote (result.get ()).c_str (), quote (expected).c_str ()); 2198 1.8 christos } 2199 1.8 christos } 2200 1.8 christos 2201 1.8 christos /* Entry point for cp_remove_params unit tests. */ 2202 1.8 christos 2203 1.8 christos static void 2204 1.8 christos test_cp_remove_params () 2205 1.8 christos { 2206 1.8 christos /* Check that removing parameter info out of NAME produces EXPECTED. 2207 1.8 christos Checks both normal and completion modes. */ 2208 1.8 christos #define CHECK(NAME, EXPECTED) \ 2209 1.8 christos do \ 2210 1.8 christos { \ 2211 1.8 christos check_remove_params (__FILE__, __LINE__, NAME, EXPECTED, false); \ 2212 1.8 christos check_remove_params (__FILE__, __LINE__, NAME, EXPECTED, true); \ 2213 1.8 christos } \ 2214 1.8 christos while (0) 2215 1.8 christos 2216 1.8 christos /* Similar, but used when NAME is incomplete -- i.e., is has 2217 1.8 christos unbalanced parentheses. In this case, looking for the exact name 2218 1.8 christos should fail / return empty. */ 2219 1.8 christos #define CHECK_INCOMPL(NAME, EXPECTED) \ 2220 1.8 christos do \ 2221 1.8 christos { \ 2222 1.8 christos check_remove_params (__FILE__, __LINE__, NAME, NULL, false); \ 2223 1.8 christos check_remove_params (__FILE__, __LINE__, NAME, EXPECTED, true); \ 2224 1.8 christos } \ 2225 1.8 christos while (0) 2226 1.8 christos 2227 1.8 christos CHECK ("function()", "function"); 2228 1.8 christos CHECK_INCOMPL ("function(", "function"); 2229 1.8 christos CHECK ("function() const", "function"); 2230 1.8 christos 2231 1.8 christos CHECK ("(anonymous namespace)::A::B::C", 2232 1.8 christos "(anonymous namespace)::A::B::C"); 2233 1.8 christos 2234 1.8 christos CHECK ("A::(anonymous namespace)", 2235 1.8 christos "A::(anonymous namespace)"); 2236 1.8 christos 2237 1.8 christos CHECK_INCOMPL ("A::(anonymou", "A"); 2238 1.8 christos 2239 1.8 christos CHECK ("A::foo<int>()", 2240 1.8 christos "A::foo<int>"); 2241 1.8 christos 2242 1.8 christos CHECK_INCOMPL ("A::foo<int>(", 2243 1.8 christos "A::foo<int>"); 2244 1.8 christos 2245 1.8 christos CHECK ("A::foo<(anonymous namespace)::B>::func(int)", 2246 1.8 christos "A::foo<(anonymous namespace)::B>::func"); 2247 1.8 christos 2248 1.8 christos CHECK_INCOMPL ("A::foo<(anonymous namespace)::B>::func(in", 2249 1.8 christos "A::foo<(anonymous namespace)::B>::func"); 2250 1.8 christos 2251 1.8 christos CHECK_INCOMPL ("A::foo<(anonymous namespace)::B>::", 2252 1.8 christos "A::foo<(anonymous namespace)::B>"); 2253 1.8 christos 2254 1.8 christos CHECK_INCOMPL ("A::foo<(anonymous namespace)::B>:", 2255 1.8 christos "A::foo<(anonymous namespace)::B>"); 2256 1.8 christos 2257 1.8 christos CHECK ("A::foo<(anonymous namespace)::B>", 2258 1.8 christos "A::foo<(anonymous namespace)::B>"); 2259 1.8 christos 2260 1.8 christos CHECK_INCOMPL ("A::foo<(anonymous namespace)::B", 2261 1.8 christos "A::foo"); 2262 1.8 christos 2263 1.8 christos CHECK ("A::foo<void(int)>::func(int)", 2264 1.8 christos "A::foo<void(int)>::func"); 2265 1.8 christos 2266 1.8 christos CHECK_INCOMPL ("A::foo<void(int", 2267 1.8 christos "A::foo"); 2268 1.8 christos 2269 1.8 christos #undef CHECK 2270 1.8 christos #undef CHECK_INCOMPL 2271 1.8 christos } 2272 1.8 christos 2273 1.8 christos } // namespace selftests 2274 1.8 christos 2275 1.8 christos #endif /* GDB_SELF_CHECK */ 2276 1.8 christos 2277 1.1 christos /* This is a front end for cp_find_first_component, for unit testing. 2278 1.1 christos Be careful when using it: see the NOTE above 2279 1.1 christos cp_find_first_component. */ 2280 1.1 christos 2281 1.1 christos static void 2282 1.8 christos first_component_command (const char *arg, int from_tty) 2283 1.1 christos { 2284 1.1 christos if (!arg) 2285 1.1 christos return; 2286 1.1 christos 2287 1.11 christos int len = cp_find_first_component (arg); 2288 1.11 christos gdb_printf ("%.*s\n", len, arg); 2289 1.1 christos } 2290 1.1 christos 2291 1.1 christos /* Implement "info vtbl". */ 2292 1.1 christos 2293 1.1 christos static void 2294 1.8 christos info_vtbl_command (const char *arg, int from_tty) 2295 1.1 christos { 2296 1.1 christos struct value *value; 2297 1.1 christos 2298 1.1 christos value = parse_and_eval (arg); 2299 1.1 christos cplus_print_vtable (value); 2300 1.1 christos } 2301 1.1 christos 2302 1.10 christos /* See description in cp-support.h. */ 2303 1.10 christos 2304 1.10 christos const char * 2305 1.10 christos find_toplevel_char (const char *s, char c) 2306 1.10 christos { 2307 1.10 christos int quoted = 0; /* zero if we're not in quotes; 2308 1.10 christos '"' if we're in a double-quoted string; 2309 1.10 christos '\'' if we're in a single-quoted string. */ 2310 1.10 christos int depth = 0; /* Number of unclosed parens we've seen. */ 2311 1.10 christos const char *scan; 2312 1.10 christos 2313 1.10 christos for (scan = s; *scan; scan++) 2314 1.10 christos { 2315 1.10 christos if (quoted) 2316 1.10 christos { 2317 1.10 christos if (*scan == quoted) 2318 1.10 christos quoted = 0; 2319 1.10 christos else if (*scan == '\\' && *(scan + 1)) 2320 1.10 christos scan++; 2321 1.10 christos } 2322 1.10 christos else if (*scan == c && ! quoted && depth == 0) 2323 1.10 christos return scan; 2324 1.10 christos else if (*scan == '"' || *scan == '\'') 2325 1.10 christos quoted = *scan; 2326 1.10 christos else if (*scan == '(' || *scan == '<') 2327 1.10 christos depth++; 2328 1.10 christos else if ((*scan == ')' || *scan == '>') && depth > 0) 2329 1.10 christos depth--; 2330 1.10 christos else if (*scan == 'o' && !quoted && depth == 0) 2331 1.10 christos { 2332 1.10 christos /* Handle C++ operator names. */ 2333 1.10 christos if (strncmp (scan, CP_OPERATOR_STR, CP_OPERATOR_LEN) == 0) 2334 1.10 christos { 2335 1.10 christos scan += CP_OPERATOR_LEN; 2336 1.10 christos if (*scan == c) 2337 1.10 christos return scan; 2338 1.10 christos while (ISSPACE (*scan)) 2339 1.10 christos { 2340 1.10 christos ++scan; 2341 1.10 christos if (*scan == c) 2342 1.10 christos return scan; 2343 1.10 christos } 2344 1.10 christos if (*scan == '\0') 2345 1.10 christos break; 2346 1.10 christos 2347 1.10 christos switch (*scan) 2348 1.10 christos { 2349 1.10 christos /* Skip over one less than the appropriate number of 2350 1.10 christos characters: the for loop will skip over the last 2351 1.10 christos one. */ 2352 1.10 christos case '<': 2353 1.10 christos if (scan[1] == '<') 2354 1.10 christos { 2355 1.10 christos scan++; 2356 1.10 christos if (*scan == c) 2357 1.10 christos return scan; 2358 1.10 christos } 2359 1.10 christos break; 2360 1.10 christos case '>': 2361 1.10 christos if (scan[1] == '>') 2362 1.10 christos { 2363 1.10 christos scan++; 2364 1.10 christos if (*scan == c) 2365 1.10 christos return scan; 2366 1.10 christos } 2367 1.10 christos break; 2368 1.10 christos } 2369 1.10 christos } 2370 1.10 christos } 2371 1.10 christos } 2372 1.10 christos 2373 1.10 christos return 0; 2374 1.10 christos } 2375 1.10 christos 2376 1.9 christos void _initialize_cp_support (); 2377 1.1 christos void 2378 1.9 christos _initialize_cp_support () 2379 1.1 christos { 2380 1.10 christos cmd_list_element *maintenance_cplus 2381 1.10 christos = add_basic_prefix_cmd ("cplus", class_maintenance, 2382 1.10 christos _("C++ maintenance commands."), 2383 1.10 christos &maint_cplus_cmd_list, 2384 1.10 christos 0, &maintenancelist); 2385 1.10 christos add_alias_cmd ("cp", maintenance_cplus, class_maintenance, 1, 2386 1.1 christos &maintenancelist); 2387 1.1 christos 2388 1.1 christos add_cmd ("first_component", 2389 1.1 christos class_maintenance, 2390 1.1 christos first_component_command, 2391 1.1 christos _("Print the first class/namespace component of NAME."), 2392 1.1 christos &maint_cplus_cmd_list); 2393 1.1 christos 2394 1.1 christos add_info ("vtbl", info_vtbl_command, 2395 1.1 christos _("Show the virtual function table for a C++ object.\n\ 2396 1.1 christos Usage: info vtbl EXPRESSION\n\ 2397 1.1 christos Evaluate EXPRESSION and display the virtual function table for the\n\ 2398 1.1 christos resulting object.")); 2399 1.3 christos 2400 1.3 christos #ifdef HAVE_WORKING_FORK 2401 1.3 christos add_setshow_boolean_cmd ("catch-demangler-crashes", class_maintenance, 2402 1.3 christos &catch_demangler_crashes, _("\ 2403 1.3 christos Set whether to attempt to catch demangler crashes."), _("\ 2404 1.3 christos Show whether to attempt to catch demangler crashes."), _("\ 2405 1.3 christos If enabled GDB will attempt to catch demangler crashes and\n\ 2406 1.3 christos display the offending symbol."), 2407 1.3 christos NULL, 2408 1.3 christos NULL, 2409 1.3 christos &maintenance_set_cmdlist, 2410 1.3 christos &maintenance_show_cmdlist); 2411 1.9 christos 2412 1.9 christos gdb_demangle_attempt_core_dump = can_dump_core (LIMIT_CUR); 2413 1.3 christos #endif 2414 1.8 christos 2415 1.8 christos #if GDB_SELF_TEST 2416 1.8 christos selftests::register_test ("cp_symbol_name_matches", 2417 1.8 christos selftests::test_cp_symbol_name_matches); 2418 1.8 christos selftests::register_test ("cp_remove_params", 2419 1.8 christos selftests::test_cp_remove_params); 2420 1.12 christos selftests::register_test ("cp_search_name_hash", 2421 1.12 christos selftests::test_cp_search_name_hash); 2422 1.8 christos #endif 2423 1.1 christos } 2424