37#include "gdbsupport/gdb_setjmp.h"
38#include "safe-ctype.h"
39#include "gdbsupport/selftest.h"
40#include "gdbsupport/gdb-sigmask.h"
46#define d_left(dc) (dc)->u.s_binary.left
47#define d_right(dc) (dc)->u.s_binary.right
59 const char *oload_name,
60 std::vector<symbol *> *overload_list);
63 (
const char *func_name,
const char *the_namespace,
64 std::vector<symbol *> *overload_list);
67 (
const char *func_name,
68 std::vector<symbol *> *overload_list);
76 struct demangle_component *ret_comp,
80static struct demangle_component *
82 int options,
void **mem);
93 *len = strlen (
string);
94 return (
char *) obstack_copy (obstack,
string, *len);
107 if (!ISIDST (
string[0]))
113 if (
string[0] ==
'u' && strcmp (&
string[1],
"nsigned") == 0)
115 else if (
string[0] ==
's' && strcmp (&
string[1],
"igned") == 0)
119 while (ISIDNUM (
string[1]))
122 if (
string[1] ==
'\0')
135 struct demangle_component *ret_comp,
144 name = (
char *) alloca (ret_comp->u.s_name.len + 1);
145 memcpy (
name, ret_comp->u.s_name.s, ret_comp->u.s_name.len);
146 name[ret_comp->u.s_name.len] =
'\0';
154 catch (
const gdb_exception &except)
165 const char *new_name = (*finder) (otype, data);
167 if (new_name != NULL)
169 ret_comp->u.s_name.s = new_name;
170 ret_comp->u.s_name.len = strlen (new_name);
178 if (otype->
code () == TYPE_CODE_TYPEDEF
179 || otype->
code () == TYPE_CODE_NAMESPACE)
184 std::unique_ptr<demangle_parse_info> i;
208 ||
type->
code () == TYPE_CODE_STRUCT
209 ||
type->
code () == TYPE_CODE_UNION));
212 struct type *last = otype;
217 == TYPE_CODE_TYPEDEF))
244 catch (
const gdb_exception_error &except)
250 name = obstack_strdup (&info->obstack, buf.
string ());
276 gdb::unique_xmalloc_ptr<char> canon
279 if (canon !=
nullptr)
285 ret_comp->u.s_name.s =
name;
286 ret_comp->u.s_name.len = len;
306 struct demangle_component *tmpl,
307 struct demangle_component *repl,
311 demangle_component *tmpl_arglist =
d_right (tmpl);
319 if (tmpl_str ==
nullptr)
324 buf.
puts (tmpl_str.get ());
326 repl->type = DEMANGLE_COMPONENT_NAME;
327 repl->u.s_name.s = obstack_strdup (&info->obstack, buf.
string ());
328 repl->u.s_name.len = buf.
size ();
338 struct demangle_component *ret_comp,
343 struct demangle_component *comp = ret_comp;
350 while (comp->type == DEMANGLE_COMPONENT_QUAL_NAME)
352 if (
d_left (comp)->
type == DEMANGLE_COMPONENT_TEMPLATE)
375 if (
d_left (comp)->
type == DEMANGLE_COMPONENT_NAME)
377 struct demangle_component newobj;
380 newobj.type = DEMANGLE_COMPONENT_NAME;
381 newobj.u.s_name.s = obstack_strdup (&info->obstack, buf.
string ());
382 newobj.u.s_name.len = buf.
size ();
393 gdb::unique_xmalloc_ptr<char> n
403 d_left (ret_comp)->type = DEMANGLE_COMPONENT_NAME;
404 d_left (ret_comp)->u.s_name.s = s;
405 d_left (ret_comp)->u.s_name.len = slen;
417 gdb::unique_xmalloc_ptr<char>
name
436 if (comp->type == DEMANGLE_COMPONENT_TEMPLATE)
444 else if (comp->type == DEMANGLE_COMPONENT_NAME)
446 buf.
write (comp->u.s_name.s, comp->u.s_name.len);
451 ret_comp->type = DEMANGLE_COMPONENT_NAME;
452 ret_comp->u.s_name.s = obstack_strdup (&info->obstack, buf.
string ());
453 ret_comp->u.s_name.len = buf.
size ();
470 while (
d_left (ret_comp) != NULL
471 && (
d_left (ret_comp)->
type == DEMANGLE_COMPONENT_CONST
472 ||
d_left (ret_comp)->
type == DEMANGLE_COMPONENT_VOLATILE))
483 struct demangle_component *ret_comp,
490 && (ret_comp->type == DEMANGLE_COMPONENT_NAME
491 || ret_comp->type == DEMANGLE_COMPONENT_QUAL_NAME
492 || ret_comp->type == DEMANGLE_COMPONENT_TEMPLATE
493 || ret_comp->type == DEMANGLE_COMPONENT_BUILTIN_TYPE))
495 gdb::unique_xmalloc_ptr<char> local_name
498 if (local_name != NULL)
500 struct symbol *sym = NULL;
508 catch (
const gdb_exception &except)
515 const char *new_name = (*finder) (otype, data);
517 if (new_name != NULL)
519 ret_comp->type = DEMANGLE_COMPONENT_NAME;
520 ret_comp->u.s_name.s = new_name;
521 ret_comp->u.s_name.len = strlen (new_name);
528 switch (ret_comp->type)
530 case DEMANGLE_COMPONENT_ARGLIST:
534 case DEMANGLE_COMPONENT_FUNCTION_TYPE:
535 case DEMANGLE_COMPONENT_TEMPLATE:
536 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
537 case DEMANGLE_COMPONENT_TYPED_NAME:
542 case DEMANGLE_COMPONENT_NAME:
546 case DEMANGLE_COMPONENT_QUAL_NAME:
550 case DEMANGLE_COMPONENT_LOCAL_NAME:
551 case DEMANGLE_COMPONENT_CTOR:
552 case DEMANGLE_COMPONENT_ARRAY_TYPE:
553 case DEMANGLE_COMPONENT_PTRMEM_TYPE:
557 case DEMANGLE_COMPONENT_CONST:
558 case DEMANGLE_COMPONENT_RESTRICT:
559 case DEMANGLE_COMPONENT_VOLATILE:
560 case DEMANGLE_COMPONENT_VOLATILE_THIS:
561 case DEMANGLE_COMPONENT_CONST_THIS:
562 case DEMANGLE_COMPONENT_RESTRICT_THIS:
563 case DEMANGLE_COMPONENT_POINTER:
564 case DEMANGLE_COMPONENT_REFERENCE:
565 case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
581gdb::unique_xmalloc_ptr<char>
586 unsigned int estimated_len;
587 std::unique_ptr<demangle_parse_info> info;
589 estimated_len = strlen (
string) * 2;
603 if (strcmp (us.get (),
string) == 0)
615gdb::unique_xmalloc_ptr<char>
625gdb::unique_xmalloc_ptr<char>
628 std::unique_ptr<demangle_parse_info> info;
629 unsigned int estimated_len;
638 estimated_len = strlen (
string) * 2;
644 warning (_(
"internal error: string \"%s\" failed to be canonicalized"),
649 if (strcmp (us.get (),
string) == 0)
661static std::unique_ptr<demangle_parse_info>
664 gdb::unique_xmalloc_ptr<char> *demangled_p)
668 if (mangled_name[0] ==
'_' && mangled_name[1] ==
'Z')
670 struct demangle_component *ret;
685 gdb::unique_xmalloc_ptr<char> demangled_name =
gdb_demangle (mangled_name,
687 if (demangled_name == NULL)
692 std::unique_ptr<demangle_parse_info> info
698 *demangled_p = std::move (demangled_name);
707 void *storage = NULL;
708 gdb::unique_xmalloc_ptr<char> demangled_name;
709 gdb::unique_xmalloc_ptr<char> ret;
710 struct demangle_component *ret_comp, *prev_comp, *cur_comp;
711 std::unique_ptr<demangle_parse_info> info;
715 &storage, &demangled_name);
720 ret_comp = info->tree;
725 switch (ret_comp->type)
727 case DEMANGLE_COMPONENT_CONST:
728 case DEMANGLE_COMPONENT_RESTRICT:
729 case DEMANGLE_COMPONENT_VOLATILE:
730 case DEMANGLE_COMPONENT_CONST_THIS:
731 case DEMANGLE_COMPONENT_RESTRICT_THIS:
732 case DEMANGLE_COMPONENT_VOLATILE_THIS:
733 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
734 ret_comp =
d_left (ret_comp);
742 if (ret_comp->type == DEMANGLE_COMPONENT_TYPED_NAME)
743 ret_comp =
d_left (ret_comp);
747 if (ret_comp->type == DEMANGLE_COMPONENT_TEMPLATE)
748 ret_comp =
d_left (ret_comp);
757 switch (cur_comp->type)
759 case DEMANGLE_COMPONENT_QUAL_NAME:
760 case DEMANGLE_COMPONENT_LOCAL_NAME:
761 prev_comp = cur_comp;
764 case DEMANGLE_COMPONENT_TEMPLATE:
765 case DEMANGLE_COMPONENT_NAME:
766 case DEMANGLE_COMPONENT_CTOR:
767 case DEMANGLE_COMPONENT_DTOR:
768 case DEMANGLE_COMPONENT_OPERATOR:
769 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
778 if (cur_comp != NULL && prev_comp != NULL)
781 *prev_comp = *
d_left (prev_comp);
788 return ret.release ();
796static struct demangle_component *
799 struct demangle_component *ret_comp = comp, *last_template;
803 last_template = NULL;
805 switch (ret_comp->type)
807 case DEMANGLE_COMPONENT_QUAL_NAME:
808 case DEMANGLE_COMPONENT_LOCAL_NAME:
811 case DEMANGLE_COMPONENT_TYPED_NAME:
812 ret_comp =
d_left (ret_comp);
814 case DEMANGLE_COMPONENT_TEMPLATE:
815 gdb_assert (last_template == NULL);
816 last_template = ret_comp;
817 ret_comp =
d_left (ret_comp);
819 case DEMANGLE_COMPONENT_CONST:
820 case DEMANGLE_COMPONENT_RESTRICT:
821 case DEMANGLE_COMPONENT_VOLATILE:
822 case DEMANGLE_COMPONENT_CONST_THIS:
823 case DEMANGLE_COMPONENT_RESTRICT_THIS:
824 case DEMANGLE_COMPONENT_VOLATILE_THIS:
825 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
826 ret_comp =
d_left (ret_comp);
828 case DEMANGLE_COMPONENT_NAME:
829 case DEMANGLE_COMPONENT_CTOR:
830 case DEMANGLE_COMPONENT_DTOR:
831 case DEMANGLE_COMPONENT_OPERATOR:
832 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
842 d_left (last_template) = ret_comp;
843 return last_template;
854 void *storage = NULL;
855 gdb::unique_xmalloc_ptr<char> demangled_name;
856 gdb::unique_xmalloc_ptr<char> ret;
857 struct demangle_component *ret_comp;
858 std::unique_ptr<demangle_parse_info> info;
861 &storage, &demangled_name);
867 if (ret_comp != NULL)
873 return ret.release ();
881gdb::unique_xmalloc_ptr<char>
884 gdb::unique_xmalloc_ptr<char> ret;
885 struct demangle_component *ret_comp;
886 std::unique_ptr<demangle_parse_info> info;
894 if (ret_comp != NULL)
906static gdb::unique_xmalloc_ptr<char>
910 struct demangle_component *ret_comp;
911 std::unique_ptr<demangle_parse_info> info;
912 gdb::unique_xmalloc_ptr<char> ret;
914 if (demangled_name == NULL)
922 ret_comp = info->tree;
924 switch (ret_comp->type)
926 case DEMANGLE_COMPONENT_CONST:
927 case DEMANGLE_COMPONENT_RESTRICT:
928 case DEMANGLE_COMPONENT_VOLATILE:
929 case DEMANGLE_COMPONENT_CONST_THIS:
930 case DEMANGLE_COMPONENT_RESTRICT_THIS:
931 case DEMANGLE_COMPONENT_VOLATILE_THIS:
932 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
933 ret_comp =
d_left (ret_comp);
941 if (ret_comp->type == DEMANGLE_COMPONENT_TYPED_NAME)
943 else if (!require_params
944 && (ret_comp->type == DEMANGLE_COMPONENT_NAME
945 || ret_comp->type == DEMANGLE_COMPONENT_QUAL_NAME
946 || ret_comp->type == DEMANGLE_COMPONENT_TEMPLATE))
957gdb::unique_xmalloc_ptr<char>
965gdb::unique_xmalloc_ptr<char>
971 if (demangled_name[0] ==
'\0' && completion_mode)
972 return make_unique_xstrdup (
"");
974 gdb::unique_xmalloc_ptr<char> without_params
977 if (without_params == NULL && completion_mode)
979 std::string copy = demangled_name;
981 while (!copy.empty ())
985 if (without_params != NULL)
990 return without_params;
1049 unsigned int index = 0;
1056 int operator_possible = 1;
1060 switch (
name[index])
1072 if (
name[index] !=
':')
1075 return strlen (
name);
1079 operator_possible = 1;
1088 if (
name[index] !=
':')
1091 return strlen (
name);
1095 operator_possible = 1;
1104 return strlen (
name);
1111 if (
name[index + 1] ==
':')
1116 if (operator_possible
1120 while (ISSPACE(
name[index]))
1122 switch (
name[index])
1130 if (
name[index + 1] ==
'<')
1137 if (
name[index + 1] ==
'>')
1150 operator_possible = 0;
1162 operator_possible = 1;
1165 operator_possible = 0;
1190 unsigned int previous_len = 0;
1192 while (
name[current_len] !=
'\0')
1194 gdb_assert (
name[current_len] ==
':');
1195 previous_len = current_len;
1201 return previous_len;
1212 const char *oload_name,
1213 std::vector<symbol *> *overload_list)
1217 if (sym->
type () == NULL)
1221 for (
symbol *listed_sym : *overload_list)
1222 if (strcmp (sym->
linkage_name (), listed_sym->linkage_name ()) == 0)
1226 gdb::unique_xmalloc_ptr<char> sym_name
1232 if (strcmp (sym_name.get (), oload_name) != 0)
1235 overload_list->push_back (sym);
1241struct std::vector<
symbol *>
1243 const char *the_namespace)
1246 std::vector<symbol *> overload_list;
1248 overload_list.reserve (100);
1252 if (the_namespace[0] ==
'\0')
1256 char *concatenated_name
1257 = (
char *) alloca (strlen (the_namespace) + 2 + strlen (func_name) + 1);
1258 strcpy (concatenated_name, the_namespace);
1259 strcat (concatenated_name,
"::");
1260 strcat (concatenated_name, func_name);
1261 name = concatenated_name;
1265 return overload_list;
1274 std::vector<symbol *> *overload_list)
1289 const char *the_namespace,
1290 std::vector<symbol *> *overload_list)
1295 if (the_namespace[0] ==
'\0')
1299 char *concatenated_name
1300 = (
char *) alloca (strlen (the_namespace) + 2 + strlen (func_name) + 1);
1302 strcpy (concatenated_name, the_namespace);
1303 strcat (concatenated_name,
"::");
1304 strcat (concatenated_name, func_name);
1305 name = concatenated_name;
1325 const char *func_name,
1326 std::vector<symbol *> *overload_list)
1328 char *the_namespace;
1329 const char *type_name;
1333 ||
type->
code () == TYPE_CODE_ARRAY
1334 ||
type->
code () == TYPE_CODE_TYPEDEF)
1336 if (
type->
code () == TYPE_CODE_TYPEDEF)
1344 if (type_name == NULL)
1349 if (prefix_len != 0)
1351 the_namespace = (
char *) alloca (prefix_len + 1);
1352 strncpy (the_namespace, type_name, prefix_len);
1353 the_namespace[prefix_len] =
'\0';
1360 if (
type->
code () == TYPE_CODE_STRUCT)
1375 const char *func_name,
1376 std::vector<symbol *> *overload_list)
1378 for (
type *arg_type : arg_types)
1390 const char *the_namespace,
1391 std::vector<symbol *> *overload_list)
1405 current = current->
next)
1416 if (strcmp (the_namespace, current->
import_dest) == 0)
1420 scoped_restore reset_directive_searched
1421 = make_scoped_restore (¤t->
searched, 1);
1440 std::vector<symbol *> *overload_list)
1442 const struct block *surrounding_static_block = 0;
1448 objf->expand_symtabs_for_function (func_name);
1468 [func_name, surrounding_static_block, &overload_list]
1474 const struct block *b = cust->blockvector ()->global_block ();
1477 b = cust->blockvector ()->static_block ();
1479 if (b == surrounding_static_block)
1486 }, current_objfile);
1494 struct symbol * rtti_sym;
1495 struct type * rtti_type;
1501 if (rtti_sym == NULL)
1503 warning (_(
"RTTI symbol not found for class '%s'"),
name);
1509 warning (_(
"RTTI symbol for class '%s' is not a type"),
name);
1515 switch (rtti_type->
code ())
1517 case TYPE_CODE_STRUCT:
1519 case TYPE_CODE_NAMESPACE:
1524 warning (_(
"RTTI symbol for class '%s' is a namespace"),
name);
1527 warning (_(
"RTTI symbol for class '%s' has bad type"),
name);
1534#ifdef HAVE_WORKING_FORK
1539static bool catch_demangler_crashes =
true;
1543static thread_local SIGJMP_BUF *gdb_demangle_jmp_buf;
1547static std::atomic<bool> gdb_demangle_attempt_core_dump;
1552gdb_demangle_signal_handler (
int signo)
1554 if (gdb_demangle_attempt_core_dump)
1559 gdb_demangle_attempt_core_dump =
false;
1562 SIGLONGJMP (*gdb_demangle_jmp_buf, signo);
1568report_failed_demangle (
const char *
name,
bool core_dump_allowed,
1571 static bool error_reported =
false;
1573 if (!error_reported)
1575 std::string short_msg
1576 = string_printf (_(
"unable to demangle '%s' "
1577 "(demangler failed with signal %d)"),
1578 name, crash_signal);
1580 std::string long_msg
1581 = string_printf (
"%s:%d: %s: %s", __FILE__, __LINE__,
1582 "demangler-warning", short_msg.c_str ());
1588 if (core_dump_allowed)
1590 _(
"%s\nAttempting to dump core.\n"),
1597 error_reported =
true;
1605gdb::unique_xmalloc_ptr<char>
1608 gdb::unique_xmalloc_ptr<char> result;
1609 int crash_signal = 0;
1611#ifdef HAVE_WORKING_FORK
1613 (catch_demangler_crashes
1614 ? gdb_demangle_signal_handler
1617 bool core_dump_allowed = gdb_demangle_attempt_core_dump;
1619 scoped_restore restore_jmp_buf
1620 = make_scoped_restore (&gdb_demangle_jmp_buf, &jmp_buf);
1621 if (catch_demangler_crashes)
1628#ifdef HAVE_SIGPROCMASK
1629 crash_signal = SIGSETJMP (*gdb_demangle_jmp_buf, 0);
1631 crash_signal = SIGSETJMP (*gdb_demangle_jmp_buf, 1);
1636 if (crash_signal == 0)
1637 result.reset (bfd_demangle (NULL,
name, options | DMGL_VERBOSE));
1639#ifdef HAVE_WORKING_FORK
1640 if (catch_demangler_crashes)
1642 if (crash_signal != 0)
1644#ifdef HAVE_SIGPROCMASK
1646 sigset_t segv_sig_set;
1647 sigemptyset (&segv_sig_set);
1648 sigaddset (&segv_sig_set, SIGSEGV);
1649 gdb_sigmask (SIG_UNBLOCK, &segv_sig_set, NULL);
1655 std::string copy =
name;
1658 report_failed_demangle (copy.c_str (), core_dump_allowed,
1674 struct demangle_component *tree,
1675 int estimated_length,
1676 size_t *p_allocated_size)
1678 return cplus_demangle_print (options | DMGL_VERBOSE, tree,
1679 estimated_length, p_allocated_size);
1685static struct demangle_component *
1687 int options,
void **mem)
1689 return cplus_demangle_v3_components (mangled, options | DMGL_VERBOSE, mem);
1699 if (startswith (search_name,
"::"))
1703 if (prefix_len != 0)
1704 search_name += prefix_len + 2;
1706 unsigned int hash = 0;
1707 for (
const char *
string = search_name; *
string !=
'\0'; ++string)
1709 string = skip_spaces (
string);
1716 && startswith (
string + 1,
"abi:")
1717 &&
string[5] !=
':')
1721 if (
string[0] ==
'<'
1722 &&
string[1] !=
'(' &&
string[1] !=
'<' &&
string[1] !=
'='
1723 &&
string[1] !=
' ' &&
string[1] !=
'\0')
1767 const char *lookup_name,
1768 size_t lookup_name_len,
1772 const char *sname = symbol_search_name;
1774 = (comp_match_res != NULL ? &comp_match_res->
match_for_lcd : NULL);
1781 if (comp_match_res != NULL)
1804 comp_match_res->
set_match (symbol_search_name, sname);
1811 if (sname[len] ==
'\0')
1814 gdb_assert (sname[len] ==
':');
1830 = (comp_match_res != NULL ? &comp_match_res->
match_for_lcd : NULL);
1839 if (comp_match_res != NULL)
1840 comp_match_res->
set_match (symbol_search_name);
1864 mode, comp_match_res);
1882 gdb_assert_not_reached (
"");
1890test_cp_symbol_name_matches ()
1892#define CHECK_MATCH(SYMBOL, INPUT) \
1893 SELF_CHECK (cp_symbol_name_matches_1 (SYMBOL, \
1894 INPUT, sizeof (INPUT) - 1, \
1895 strncmp_iw_mode::MATCH_PARAMS, \
1898#define CHECK_NOT_MATCH(SYMBOL, INPUT) \
1899 SELF_CHECK (!cp_symbol_name_matches_1 (SYMBOL, \
1900 INPUT, sizeof (INPUT) - 1, \
1901 strncmp_iw_mode::MATCH_PARAMS, \
1906#define CHECK_MATCH_C(SYMBOL, INPUT) \
1909 CHECK_MATCH (SYMBOL, INPUT); \
1910 for (size_t i = 0; i < sizeof (INPUT) - 1; i++) \
1911 SELF_CHECK (cp_symbol_name_matches_1 (SYMBOL, INPUT, i, \
1912 strncmp_iw_mode::NORMAL, \
1918#define CHECK_NOT_MATCH_C(SYMBOL, INPUT) \
1921 CHECK_NOT_MATCH (SYMBOL, INPUT); \
1922 SELF_CHECK (!cp_symbol_name_matches_1 (SYMBOL, INPUT, \
1923 sizeof (INPUT) - 1, \
1924 strncmp_iw_mode::NORMAL, \
1929 CHECK_MATCH_C (
"function()",
"function");
1930 CHECK_MATCH_C (
"function(int)",
"function");
1933 CHECK_MATCH_C (
"function()",
"function ()");
1934 CHECK_MATCH_C (
"function ( )",
"function()");
1935 CHECK_MATCH_C (
"function ()",
"function( )");
1936 CHECK_MATCH_C (
"func(int)",
"func( int )");
1937 CHECK_MATCH_C (
"func(int)",
"func ( int ) ");
1938 CHECK_MATCH_C (
"func ( int )",
"func( int )");
1939 CHECK_MATCH_C (
"func ( int )",
"func ( int ) ");
1942 CHECK_NOT_MATCH (
"func",
"function");
1943 CHECK_NOT_MATCH (
"function",
"func");
1944 CHECK_NOT_MATCH (
"function()",
"func");
1948 CHECK_MATCH_C (
"function(int)",
"function(int)");
1949 CHECK_NOT_MATCH_C (
"function(int)",
"function()");
1952 CHECK_NOT_MATCH_C (
"function",
"func tion");
1953 CHECK_NOT_MATCH_C (
"func__tion",
"func_ _tion");
1954 CHECK_NOT_MATCH_C (
"func11tion",
"func1 1tion");
1958 CHECK_NOT_MATCH_C (
"func tion",
"function");
1959 CHECK_NOT_MATCH_C (
"func1 1tion",
"func11tion");
1960 CHECK_NOT_MATCH_C (
"func_ _tion",
"func__tion");
1963 CHECK_NOT_MATCH_C (
"func(param)",
"func(par am)");
1966 CHECK_NOT_MATCH_C (
"operator<<",
"opera tor<<");
1967 CHECK_NOT_MATCH_C (
"operator<<",
"operator< <");
1968 CHECK_NOT_MATCH_C (
"operator<<",
"operator < <");
1969 CHECK_NOT_MATCH_C (
"operator==",
"operator= =");
1970 CHECK_NOT_MATCH_C (
"operator==",
"operator = =");
1971 CHECK_MATCH_C (
"operator<<",
"operator <<");
1972 CHECK_MATCH_C (
"operator<<()",
"operator <<");
1973 CHECK_NOT_MATCH_C (
"operator<<()",
"operator<<(int)");
1974 CHECK_NOT_MATCH_C (
"operator<<(int)",
"operator<<()");
1975 CHECK_MATCH_C (
"operator==",
"operator ==");
1976 CHECK_MATCH_C (
"operator==()",
"operator ==");
1977 CHECK_MATCH_C (
"operator <<",
"operator<<");
1978 CHECK_MATCH_C (
"operator ==",
"operator==");
1979 CHECK_MATCH_C (
"operator bool",
"operator bool");
1980 CHECK_MATCH_C (
"operator bool ()",
"operator bool");
1981 CHECK_MATCH_C (
"operatorX<<",
"operatorX < <");
1982 CHECK_MATCH_C (
"Xoperator<<",
"Xoperator < <");
1984 CHECK_MATCH_C (
"operator()(int)",
"operator()(int)");
1985 CHECK_MATCH_C (
"operator()(int)",
"operator ( ) ( int )");
1986 CHECK_MATCH_C (
"operator()<long>(int)",
"operator ( ) < long > ( int )");
1988 CHECK_NOT_MATCH (
"operator()(int)",
"operator");
1992 CHECK_NOT_MATCH_C (
"operator/=()",
"operator ^=");
1994 CHECK_NOT_MATCH_C (
"operator>>",
"operator[]");
1996 CHECK_NOT_MATCH_C (
"operator>>()",
"operator[]()");
1998 CHECK_MATCH_C (
"base::operator char*()",
"base::operator char*()");
1999 CHECK_MATCH_C (
"base::operator char*()",
"base::operator char * ()");
2000 CHECK_MATCH_C (
"base::operator char**()",
"base::operator char * * ()");
2001 CHECK_MATCH (
"base::operator char**()",
"base::operator char * *");
2002 CHECK_MATCH_C (
"base::operator*()",
"base::operator*()");
2003 CHECK_NOT_MATCH_C (
"base::operator char*()",
"base::operatorc");
2004 CHECK_NOT_MATCH (
"base::operator char*()",
"base::operator char");
2005 CHECK_NOT_MATCH (
"base::operator char*()",
"base::operat");
2008 CHECK_NOT_MATCH_C (
"foo::bar",
"foo: :bar");
2009 CHECK_MATCH_C (
"foo::bar",
"foo :: bar");
2010 CHECK_MATCH_C (
"foo :: bar",
"foo::bar");
2012 CHECK_MATCH_C (
"abc::def::ghi()",
"abc::def::ghi()");
2013 CHECK_MATCH_C (
"abc::def::ghi ( )",
"abc::def::ghi()");
2014 CHECK_MATCH_C (
"abc::def::ghi()",
"abc::def::ghi ( )");
2015 CHECK_MATCH_C (
"function()",
"function()");
2016 CHECK_MATCH_C (
"bar::function()",
"bar::function()");
2021 CHECK_MATCH_C (
"foo::function()",
"function");
2022 CHECK_MATCH_C (
"foo::function(int)",
"function");
2023 CHECK_MATCH_C (
"foo::bar::function()",
"function");
2024 CHECK_MATCH_C (
"bar::function()",
"bar::function");
2025 CHECK_MATCH_C (
"foo::bar::function()",
"bar::function");
2026 CHECK_MATCH_C (
"foo::bar::function(int)",
"bar::function");
2029 CHECK_MATCH_C (
"foo::function()",
"function()");
2030 CHECK_MATCH_C (
"foo::bar::function()",
"function()");
2031 CHECK_MATCH_C (
"foo::function(int)",
"function(int)");
2032 CHECK_MATCH_C (
"foo::function()",
"foo::function()");
2033 CHECK_MATCH_C (
"foo::bar::function()",
"bar::function()");
2034 CHECK_MATCH_C (
"foo::bar::function(int)",
"bar::function(int)");
2035 CHECK_MATCH_C (
"bar::function()",
"bar::function()");
2037 CHECK_NOT_MATCH_C (
"foo::bar::function(int)",
"bar::function()");
2039 CHECK_MATCH_C (
"(anonymous namespace)::bar::function(int)",
2040 "bar::function(int)");
2041 CHECK_MATCH_C (
"foo::(anonymous namespace)::bar::function(int)",
2045 CHECK_NOT_MATCH_C (
"function()",
"bar::function");
2046 CHECK_NOT_MATCH_C (
"function()",
"bar::function()");
2049 CHECK_NOT_MATCH_C (
"foo::function()",
"::function");
2050 CHECK_NOT_MATCH_C (
"foo::function()",
"::function()");
2051 CHECK_NOT_MATCH_C (
"foo::function(int)",
"::function()");
2052 CHECK_NOT_MATCH_C (
"foo::function(int)",
"::function(int)");
2058 CHECK_MATCH_C (
"function[abi:foo]()",
"function");
2059 CHECK_MATCH_C (
"function[abi:foo](int)",
"function");
2060 CHECK_MATCH_C (
"function[abi:foo]()",
"function ()");
2061 CHECK_NOT_MATCH_C (
"function[abi:foo]()",
"function (int)");
2063 CHECK_MATCH_C (
"function[abi:foo]()",
"function[abi:foo]");
2064 CHECK_MATCH_C (
"function[abi:foo](int)",
"function[abi:foo]");
2065 CHECK_MATCH_C (
"function[abi:foo]()",
"function[abi:foo] ()");
2066 CHECK_MATCH_C (
"function[abi:foo][abi:bar]()",
"function");
2067 CHECK_MATCH_C (
"function[abi:foo][abi:bar](int)",
"function");
2068 CHECK_MATCH_C (
"function[abi:foo][abi:bar]()",
"function[abi:foo]");
2069 CHECK_MATCH_C (
"function[abi:foo][abi:bar](int)",
"function[abi:foo]");
2070 CHECK_MATCH_C (
"function[abi:foo][abi:bar]()",
"function[abi:foo] ()");
2071 CHECK_NOT_MATCH_C (
"function[abi:foo][abi:bar]()",
"function[abi:foo] (int)");
2073 CHECK_MATCH_C (
"function [abi:foo][abi:bar] ( )",
"function [abi:foo]");
2077 CHECK_NOT_MATCH_C (
"function()",
"function[abi:foo]()");
2078 CHECK_NOT_MATCH_C (
"function()",
"function[abi:foo]");
2085quote (
const char *str)
2088 return std::string (1,
'"') + str +
'"';
2099check_remove_params (
const char *file,
int line,
2100 const char *
name,
const char *expected,
2101 bool completion_mode)
2103 gdb::unique_xmalloc_ptr<char> result
2106 if ((expected == NULL) != (result == NULL)
2107 || (expected != NULL
2108 && strcmp (result.get (), expected) != 0))
2110 error (_(
"%s:%d: make-paramless self-test failed: (completion=%d) "
2111 "\"%s\" -> %s, expected %s"),
2112 file, line, completion_mode,
name,
2113 quote (result.get ()).c_str (), quote (expected).c_str ());
2120test_cp_remove_params ()
2124#define CHECK(NAME, EXPECTED) \
2127 check_remove_params (__FILE__, __LINE__, NAME, EXPECTED, false); \
2128 check_remove_params (__FILE__, __LINE__, NAME, EXPECTED, true); \
2135#define CHECK_INCOMPL(NAME, EXPECTED) \
2138 check_remove_params (__FILE__, __LINE__, NAME, NULL, false); \
2139 check_remove_params (__FILE__, __LINE__, NAME, EXPECTED, true); \
2143 CHECK (
"function()",
"function");
2145 CHECK (
"function() const",
"function");
2147 CHECK (
"(anonymous namespace)::A::B::C",
2148 "(anonymous namespace)::A::B::C");
2150 CHECK (
"A::(anonymous namespace)",
2151 "A::(anonymous namespace)");
2155 CHECK (
"A::foo<int>()",
2161 CHECK (
"A::foo<(anonymous namespace)::B>::func(int)",
2162 "A::foo<(anonymous namespace)::B>::func");
2165 "A::foo<(anonymous namespace)::B>::func");
2168 "A::foo<(anonymous namespace)::B>");
2171 "A::foo<(anonymous namespace)::B>");
2173 CHECK (
"A::foo<(anonymous namespace)::B>",
2174 "A::foo<(anonymous namespace)::B>");
2182 CHECK (
"A::foo<void(int)>::func(int)",
2183 "A::foo<void(int)>::func");
2214 prefix = (
char *) alloca (len + 1);
2216 memcpy (
prefix, arg, len);
2248 if (*
scan == quoted)
2250 else if (*
scan ==
'\\' && *(
scan + 1))
2253 else if (*
scan == c && ! quoted && depth == 0)
2255 else if (*
scan ==
'"' || *
scan ==
'\'')
2257 else if (*
scan ==
'(' || *
scan ==
'<')
2259 else if ((*
scan ==
')' || *
scan ==
'>') && depth > 0)
2261 else if (*
scan ==
'o' && !quoted && depth == 0)
2269 while (ISSPACE (*
scan))
2313 _(
"C++ maintenance commands."),
2322 _(
"Print the first class/namespace component of NAME."),
2326 _(
"Show the virtual function table for a C++ object.\n\
2327Usage: info vtbl EXPRESSION\n\
2328Evaluate EXPRESSION and display the virtual function table for the\n\
2329resulting object."));
2331#ifdef HAVE_WORKING_FORK
2333 &catch_demangler_crashes, _(
"\
2334Set whether to attempt to catch demangler crashes."), _(
"\
2335Show whether to attempt to catch demangler crashes."), _(
"\
2336If enabled GDB will attempt to catch demangler crashes and\n\
2337display the offending symbol."),
2347 selftests::register_test (
"cp_symbol_name_matches",
2348 selftests::test_cp_symbol_name_matches);
2349 selftests::register_test (
"cp_remove_params",
2350 selftests::test_cp_remove_params);
struct gdbarch * target_gdbarch(void)
const struct block * block_global_block(const struct block *block)
struct objfile * block_objfile(const struct block *block)
struct using_direct * block_using(const struct block *block)
const struct block * block_static_block(const struct block *block)
#define ALL_BLOCK_SYMBOLS_WITH_NAME(block, name, iter, sym)
const demangle_for_lookup_info & cplus() const
symbol_name_match_type match_type() const
bool completion_mode() const
void write(const char *buf, long length_buf) override
const std::string & string()
static void ours_for_output()
virtual void puts(const char *str)
struct cmd_list_element * maintenancelist
struct cmd_list_element * maintenance_show_cmdlist
struct cmd_list_element * maintenance_set_cmdlist
struct cmd_list_element * add_alias_cmd(const char *name, cmd_list_element *target, enum command_class theclass, int abbrev_flag, struct cmd_list_element **list)
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **list)
set_show_commands add_setshow_boolean_cmd(const char *name, enum command_class theclass, bool *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_func_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
struct cmd_list_element * add_basic_prefix_cmd(const char *name, enum command_class theclass, const char *doc, struct cmd_list_element **subcommands, int allow_unknown, struct cmd_list_element **list)
struct cmd_list_element * add_info(const char *name, cmd_simple_func_ftype *fun, const char *doc)
#define complaint(FMT,...)
void cplus_print_vtable(struct value *value)
struct std::unique_ptr< demangle_parse_info > cp_demangled_name_to_comp(const char *demangled_name, std::string *errmsg)
gdb::unique_xmalloc_ptr< char > cp_comp_to_string(struct demangle_component *result, int estimated_len)
void cp_merge_demangle_parse_infos(struct demangle_parse_info *dest, struct demangle_component *target, struct demangle_parse_info *src)
static void add_symbol_overload_list_using(const char *func_name, const char *the_namespace, std::vector< symbol * > *overload_list)
static unsigned int cp_find_first_component_aux(const char *name, int permissive)
static void info_vtbl_command(const char *arg, int from_tty)
static bool cp_symbol_name_matches_1(const char *symbol_search_name, const char *lookup_name, size_t lookup_name_len, strncmp_iw_mode mode, completion_match_result *comp_match_res)
static void add_symbol_overload_list_qualified(const char *func_name, std::vector< symbol * > *overload_list)
static bool cp_symbol_name_matches(const char *symbol_search_name, const lookup_name_info &lookup_name, completion_match_result *comp_match_res)
static int cp_already_canonical(const char *string)
static bool cp_fq_symbol_name_matches(const char *symbol_search_name, const lookup_name_info &lookup_name, completion_match_result *comp_match_res)
gdb::unique_xmalloc_ptr< char > cp_canonicalize_string_full(const char *string, canonicalization_ftype *finder, void *data)
static int inspect_type(struct demangle_parse_info *info, struct demangle_component *ret_comp, canonicalization_ftype *finder, void *data)
gdb::unique_xmalloc_ptr< char > cp_func_name(const char *full_name)
char * gdb_cplus_demangle_print(int options, struct demangle_component *tree, int estimated_length, size_t *p_allocated_size)
gdb::unique_xmalloc_ptr< char > gdb_demangle(const char *name, int options)
gdb::unique_xmalloc_ptr< char > cp_remove_params(const char *demangled_name)
const char * find_toplevel_char(const char *s, char c)
static struct demangle_component * unqualified_name_from_comp(struct demangle_component *comp)
static std::unique_ptr< demangle_parse_info > mangled_name_to_comp(const char *mangled_name, int options, void **memory, gdb::unique_xmalloc_ptr< char > *demangled_p)
static void add_symbol_overload_list_adl_namespace(struct type *type, const char *func_name, std::vector< symbol * > *overload_list)
static void add_symbol_overload_list_namespace(const char *func_name, const char *the_namespace, std::vector< symbol * > *overload_list)
gdb::unique_xmalloc_ptr< char > cp_canonicalize_string_no_typedefs(const char *string)
symbol_name_matcher_ftype * cp_get_symbol_name_matcher(const lookup_name_info &lookup_name)
static void replace_typedefs(struct demangle_parse_info *info, struct demangle_component *ret_comp, canonicalization_ftype *finder, void *data)
struct type * cp_lookup_rtti_type(const char *name, const struct block *block)
char * method_name_from_physname(const char *physname)
void add_symbol_overload_list_adl(gdb::array_view< type * > arg_types, const char *func_name, std::vector< symbol * > *overload_list)
unsigned int cp_find_first_component(const char *name)
void _initialize_cp_support()
static void first_component_command(const char *arg, int from_tty)
unsigned int cp_entire_prefix_len(const char *name)
static bool replace_typedefs_template(struct demangle_parse_info *info, string_file &buf, struct demangle_component *tmpl, struct demangle_component *repl, canonicalization_ftype *finder, void *data)
gdb::unique_xmalloc_ptr< char > cp_canonicalize_string(const char *string)
char * cp_class_name_from_physname(const char *physname)
unsigned int cp_search_name_hash(const char *search_name)
static void add_symbol_overload_list_block(const char *name, const struct block *block, std::vector< symbol * > *overload_list)
gdb::unique_xmalloc_ptr< char > cp_remove_params_if_any(const char *demangled_name, bool completion_mode)
struct std::vector< symbol * > make_symbol_overload_list(const char *func_name, const char *the_namespace)
static void replace_typedefs_qualified_name(struct demangle_parse_info *info, struct demangle_component *ret_comp, canonicalization_ftype *finder, void *data)
static void check_cv_qualifiers(struct demangle_component *ret_comp)
static gdb::unique_xmalloc_ptr< char > cp_remove_params_1(const char *demangled_name, bool require_params)
static char * copy_string_to_obstack(struct obstack *obstack, const char *string, long *len)
static void overload_list_add_symbol(struct symbol *sym, const char *oload_name, std::vector< symbol * > *overload_list)
struct cmd_list_element * maint_cplus_cmd_list
static struct demangle_component * gdb_cplus_demangle_v3_components(const char *mangled, int options, void **mem)
static void demangled_name_complaint(const char *name)
const char *() canonicalization_ftype(struct type *, void *)
struct value * parse_and_eval(const char *exp)
const struct block * get_selected_block(CORE_ADDR *addr_in_block)
void gdbarch_iterate_over_objfiles_in_search_order(struct gdbarch *gdbarch, iterate_over_objfiles_in_search_order_cb_ftype cb, struct objfile *current_objfile)
struct type * check_typedef(struct type *type)
#define TYPE_BASECLASS(thistype, index)
#define BASETYPE_VIA_PUBLIC(thistype, index)
#define TYPE_N_BASECLASSES(thistype)
const struct language_defn * language_def(enum language lang)
#define CHECK_INCOMPL(LANG, NAME, EXPECTED)
static void scan(growable_macro_buffer *dest, shared_macro_buffer *src, struct macro_name_list *no_loop, const macro_scope &scope)
#define SYMBOL_HASH_NEXT(hash, c)
#define prefix(a, b, R, do)
struct program_space * current_program_space
void run_on_main_thread(std::function< void()> &&func)
const block * superblock() const
void set_match(const char *m, const char *m_for_lcd=NULL)
completion_match_for_lcd match_for_lcd
const std::string & lookup_name() const
const char * natural_name() const
enum language language() const
const char * linkage_name() const
virtual void print_type(struct type *type, const char *varstring, struct ui_file *stream, int show, int level, const struct type_print_options *flags) const =0
struct gdbarch * arch() const
objfiles_range objfiles()
address_class aclass() const
struct type * type() const
struct type * target_type() const
bool is_pointer_or_reference() const
const char * name() const
struct using_direct * next
struct block_symbol lookup_symbol(const char *name, const struct block *block, domain_enum domain, struct field_of_this_result *is_a_field_of_this)
bool() symbol_name_matcher_ftype(const char *symbol_search_name, const lookup_name_info &lookup_name, completion_match_result *comp_match_res)
const struct type_print_options type_print_raw_options
void demangler_warning(const char *file, int line, const char *string,...)
int can_dump_core(enum resource_limit_kind limit_kind)
int strncmp_iw_with_mode(const char *string1, const char *string2, size_t string2_len, strncmp_iw_mode mode, enum language language, completion_match_for_lcd *match_for_lcd, bool ignore_template_params)
void gdb_printf(struct ui_file *stream, const char *format,...)
void warn_cant_dump_core(const char *reason)