38#include "gdbsupport/gdb_setjmp.h"
39#include "gdbsupport/gdb-safe-ctype.h"
40#include "gdbsupport/selftest.h"
41#include "gdbsupport/gdb-sigmask.h"
47#define d_left(dc) (dc)->u.s_binary.left
48#define d_right(dc) (dc)->u.s_binary.right
60 const char *oload_name,
61 std::vector<symbol *> *overload_list);
64 (
const char *func_name,
const char *the_namespace,
65 std::vector<symbol *> *overload_list);
68 (
const char *func_name,
69 std::vector<symbol *> *overload_list);
77 struct demangle_component *ret_comp,
81static struct demangle_component *
83 int options,
void **mem);
94 *len = strlen (
string);
95 return (
char *) obstack_copy (obstack,
string, *len);
108 if (!ISIDST (
string[0]))
114 if (
string[0] ==
'u' && strcmp (&
string[1],
"nsigned") == 0)
116 else if (
string[0] ==
's' && strcmp (&
string[1],
"igned") == 0)
120 while (ISIDNUM (
string[1]))
123 if (
string[1] ==
'\0')
136 struct demangle_component *ret_comp,
145 name = (
char *) alloca (ret_comp->u.s_name.len + 1);
146 memcpy (
name, ret_comp->u.s_name.s, ret_comp->u.s_name.len);
147 name[ret_comp->u.s_name.len] =
'\0';
155 catch (
const gdb_exception &except)
166 const char *new_name = (*finder) (otype, data);
168 if (new_name != NULL)
170 ret_comp->u.s_name.s = new_name;
171 ret_comp->u.s_name.len = strlen (new_name);
179 if (otype->
code () == TYPE_CODE_TYPEDEF
180 || otype->
code () == TYPE_CODE_NAMESPACE)
185 std::unique_ptr<demangle_parse_info> i;
209 ||
type->
code () == TYPE_CODE_STRUCT
210 ||
type->
code () == TYPE_CODE_UNION));
213 struct type *last = otype;
218 == TYPE_CODE_TYPEDEF))
245 catch (
const gdb_exception_error &except)
251 name = obstack_strdup (&info->obstack, buf.
string ());
277 gdb::unique_xmalloc_ptr<char> canon
280 if (canon !=
nullptr)
286 ret_comp->u.s_name.s =
name;
287 ret_comp->u.s_name.len = len;
307 struct demangle_component *tmpl,
308 struct demangle_component *repl,
312 demangle_component *tmpl_arglist =
d_right (tmpl);
320 if (tmpl_str ==
nullptr)
325 buf.
puts (tmpl_str.get ());
327 repl->type = DEMANGLE_COMPONENT_NAME;
328 repl->u.s_name.s = obstack_strdup (&info->obstack, buf.
string ());
329 repl->u.s_name.len = buf.
size ();
339 struct demangle_component *ret_comp,
344 struct demangle_component *comp = ret_comp;
351 while (comp->type == DEMANGLE_COMPONENT_QUAL_NAME)
353 if (
d_left (comp)->
type == DEMANGLE_COMPONENT_TEMPLATE)
376 if (
d_left (comp)->
type == DEMANGLE_COMPONENT_NAME)
378 struct demangle_component newobj;
381 newobj.type = DEMANGLE_COMPONENT_NAME;
382 newobj.u.s_name.s = obstack_strdup (&info->obstack, buf.
string ());
383 newobj.u.s_name.len = buf.
size ();
394 gdb::unique_xmalloc_ptr<char> n
404 d_left (ret_comp)->type = DEMANGLE_COMPONENT_NAME;
405 d_left (ret_comp)->u.s_name.s = s;
406 d_left (ret_comp)->u.s_name.len = slen;
418 gdb::unique_xmalloc_ptr<char>
name
437 if (comp->type == DEMANGLE_COMPONENT_TEMPLATE)
445 else if (comp->type == DEMANGLE_COMPONENT_NAME)
447 buf.
write (comp->u.s_name.s, comp->u.s_name.len);
452 ret_comp->type = DEMANGLE_COMPONENT_NAME;
453 ret_comp->u.s_name.s = obstack_strdup (&info->obstack, buf.
string ());
454 ret_comp->u.s_name.len = buf.
size ();
471 while (
d_left (ret_comp) != NULL
472 && (
d_left (ret_comp)->
type == DEMANGLE_COMPONENT_CONST
473 ||
d_left (ret_comp)->
type == DEMANGLE_COMPONENT_VOLATILE))
484 struct demangle_component *ret_comp,
491 && (ret_comp->type == DEMANGLE_COMPONENT_NAME
492 || ret_comp->type == DEMANGLE_COMPONENT_QUAL_NAME
493 || ret_comp->type == DEMANGLE_COMPONENT_TEMPLATE
494 || ret_comp->type == DEMANGLE_COMPONENT_BUILTIN_TYPE))
496 gdb::unique_xmalloc_ptr<char> local_name
499 if (local_name != NULL)
501 struct symbol *sym = NULL;
509 catch (
const gdb_exception &except)
516 const char *new_name = (*finder) (otype, data);
518 if (new_name != NULL)
520 ret_comp->type = DEMANGLE_COMPONENT_NAME;
521 ret_comp->u.s_name.s = new_name;
522 ret_comp->u.s_name.len = strlen (new_name);
529 switch (ret_comp->type)
531 case DEMANGLE_COMPONENT_ARGLIST:
535 case DEMANGLE_COMPONENT_FUNCTION_TYPE:
536 case DEMANGLE_COMPONENT_TEMPLATE:
537 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
538 case DEMANGLE_COMPONENT_TYPED_NAME:
543 case DEMANGLE_COMPONENT_NAME:
547 case DEMANGLE_COMPONENT_QUAL_NAME:
551 case DEMANGLE_COMPONENT_LOCAL_NAME:
552 case DEMANGLE_COMPONENT_CTOR:
553 case DEMANGLE_COMPONENT_ARRAY_TYPE:
554 case DEMANGLE_COMPONENT_PTRMEM_TYPE:
558 case DEMANGLE_COMPONENT_CONST:
559 case DEMANGLE_COMPONENT_RESTRICT:
560 case DEMANGLE_COMPONENT_VOLATILE:
561 case DEMANGLE_COMPONENT_VOLATILE_THIS:
562 case DEMANGLE_COMPONENT_CONST_THIS:
563 case DEMANGLE_COMPONENT_RESTRICT_THIS:
564 case DEMANGLE_COMPONENT_POINTER:
565 case DEMANGLE_COMPONENT_REFERENCE:
566 case DEMANGLE_COMPONENT_RVALUE_REFERENCE:
582gdb::unique_xmalloc_ptr<char>
587 unsigned int estimated_len;
588 std::unique_ptr<demangle_parse_info> info;
590 estimated_len = strlen (
string) * 2;
604 if (strcmp (us.get (),
string) == 0)
616gdb::unique_xmalloc_ptr<char>
626gdb::unique_xmalloc_ptr<char>
629 std::unique_ptr<demangle_parse_info> info;
630 unsigned int estimated_len;
639 estimated_len = strlen (
string) * 2;
645 warning (_(
"internal error: string \"%s\" failed to be canonicalized"),
650 if (strcmp (us.get (),
string) == 0)
662static std::unique_ptr<demangle_parse_info>
665 gdb::unique_xmalloc_ptr<char> *demangled_p)
669 if (mangled_name[0] ==
'_' && mangled_name[1] ==
'Z')
671 struct demangle_component *ret;
677 auto info = gdb::make_unique<demangle_parse_info> ();
686 gdb::unique_xmalloc_ptr<char> demangled_name =
gdb_demangle (mangled_name,
688 if (demangled_name == NULL)
693 std::unique_ptr<demangle_parse_info> info
699 *demangled_p = std::move (demangled_name);
708 void *storage = NULL;
709 gdb::unique_xmalloc_ptr<char> demangled_name;
710 gdb::unique_xmalloc_ptr<char> ret;
711 struct demangle_component *ret_comp, *prev_comp, *cur_comp;
712 std::unique_ptr<demangle_parse_info> info;
716 &storage, &demangled_name);
721 ret_comp = info->tree;
726 switch (ret_comp->type)
728 case DEMANGLE_COMPONENT_CONST:
729 case DEMANGLE_COMPONENT_RESTRICT:
730 case DEMANGLE_COMPONENT_VOLATILE:
731 case DEMANGLE_COMPONENT_CONST_THIS:
732 case DEMANGLE_COMPONENT_RESTRICT_THIS:
733 case DEMANGLE_COMPONENT_VOLATILE_THIS:
734 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
735 ret_comp =
d_left (ret_comp);
743 if (ret_comp->type == DEMANGLE_COMPONENT_TYPED_NAME)
744 ret_comp =
d_left (ret_comp);
748 if (ret_comp->type == DEMANGLE_COMPONENT_TEMPLATE)
749 ret_comp =
d_left (ret_comp);
758 switch (cur_comp->type)
760 case DEMANGLE_COMPONENT_QUAL_NAME:
761 case DEMANGLE_COMPONENT_LOCAL_NAME:
762 prev_comp = cur_comp;
765 case DEMANGLE_COMPONENT_TEMPLATE:
766 case DEMANGLE_COMPONENT_NAME:
767 case DEMANGLE_COMPONENT_CTOR:
768 case DEMANGLE_COMPONENT_DTOR:
769 case DEMANGLE_COMPONENT_OPERATOR:
770 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
779 if (cur_comp != NULL && prev_comp != NULL)
782 *prev_comp = *
d_left (prev_comp);
789 return ret.release ();
797static struct demangle_component *
800 struct demangle_component *ret_comp = comp, *last_template;
804 last_template = NULL;
806 switch (ret_comp->type)
808 case DEMANGLE_COMPONENT_QUAL_NAME:
809 case DEMANGLE_COMPONENT_LOCAL_NAME:
812 case DEMANGLE_COMPONENT_TYPED_NAME:
813 ret_comp =
d_left (ret_comp);
815 case DEMANGLE_COMPONENT_TEMPLATE:
816 gdb_assert (last_template == NULL);
817 last_template = ret_comp;
818 ret_comp =
d_left (ret_comp);
820 case DEMANGLE_COMPONENT_CONST:
821 case DEMANGLE_COMPONENT_RESTRICT:
822 case DEMANGLE_COMPONENT_VOLATILE:
823 case DEMANGLE_COMPONENT_CONST_THIS:
824 case DEMANGLE_COMPONENT_RESTRICT_THIS:
825 case DEMANGLE_COMPONENT_VOLATILE_THIS:
826 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
827 ret_comp =
d_left (ret_comp);
829 case DEMANGLE_COMPONENT_NAME:
830 case DEMANGLE_COMPONENT_CTOR:
831 case DEMANGLE_COMPONENT_DTOR:
832 case DEMANGLE_COMPONENT_OPERATOR:
833 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
843 d_left (last_template) = ret_comp;
844 return last_template;
855 void *storage = NULL;
856 gdb::unique_xmalloc_ptr<char> demangled_name;
857 gdb::unique_xmalloc_ptr<char> ret;
858 struct demangle_component *ret_comp;
859 std::unique_ptr<demangle_parse_info> info;
862 &storage, &demangled_name);
868 if (ret_comp != NULL)
874 return ret.release ();
882gdb::unique_xmalloc_ptr<char>
885 gdb::unique_xmalloc_ptr<char> ret;
886 struct demangle_component *ret_comp;
887 std::unique_ptr<demangle_parse_info> info;
895 if (ret_comp != NULL)
907static gdb::unique_xmalloc_ptr<char>
911 struct demangle_component *ret_comp;
912 std::unique_ptr<demangle_parse_info> info;
913 gdb::unique_xmalloc_ptr<char> ret;
915 if (demangled_name == NULL)
923 ret_comp = info->tree;
925 switch (ret_comp->type)
927 case DEMANGLE_COMPONENT_CONST:
928 case DEMANGLE_COMPONENT_RESTRICT:
929 case DEMANGLE_COMPONENT_VOLATILE:
930 case DEMANGLE_COMPONENT_CONST_THIS:
931 case DEMANGLE_COMPONENT_RESTRICT_THIS:
932 case DEMANGLE_COMPONENT_VOLATILE_THIS:
933 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
934 ret_comp =
d_left (ret_comp);
942 if (ret_comp->type == DEMANGLE_COMPONENT_TYPED_NAME)
944 else if (!require_params
945 && (ret_comp->type == DEMANGLE_COMPONENT_NAME
946 || ret_comp->type == DEMANGLE_COMPONENT_QUAL_NAME
947 || ret_comp->type == DEMANGLE_COMPONENT_TEMPLATE))
958gdb::unique_xmalloc_ptr<char>
966gdb::unique_xmalloc_ptr<char>
972 if (demangled_name[0] ==
'\0' && completion_mode)
973 return make_unique_xstrdup (
"");
975 gdb::unique_xmalloc_ptr<char> without_params
978 if (without_params == NULL && completion_mode)
980 std::string copy = demangled_name;
982 while (!copy.empty ())
986 if (without_params != NULL)
991 return without_params;
1050 unsigned int index = 0;
1057 int operator_possible = 1;
1061 switch (
name[index])
1073 if (
name[index] !=
':')
1076 return strlen (
name);
1080 operator_possible = 1;
1089 if (
name[index] !=
':')
1092 return strlen (
name);
1096 operator_possible = 1;
1105 return strlen (
name);
1112 if (
name[index + 1] ==
':')
1117 if (operator_possible
1121 while (ISSPACE(
name[index]))
1123 switch (
name[index])
1131 if (
name[index + 1] ==
'<')
1138 if (
name[index + 1] ==
'>')
1151 operator_possible = 0;
1163 operator_possible = 1;
1166 operator_possible = 0;
1191 unsigned int previous_len = 0;
1193 while (
name[current_len] !=
'\0')
1195 gdb_assert (
name[current_len] ==
':');
1196 previous_len = current_len;
1202 return previous_len;
1213 const char *oload_name,
1214 std::vector<symbol *> *overload_list)
1218 if (sym->
type () == NULL)
1222 for (
symbol *listed_sym : *overload_list)
1223 if (strcmp (sym->
linkage_name (), listed_sym->linkage_name ()) == 0)
1227 gdb::unique_xmalloc_ptr<char> sym_name
1233 if (strcmp (sym_name.get (), oload_name) != 0)
1236 overload_list->push_back (sym);
1242struct std::vector<
symbol *>
1244 const char *the_namespace)
1247 std::vector<symbol *> overload_list;
1249 overload_list.reserve (100);
1253 if (the_namespace[0] ==
'\0')
1257 char *concatenated_name
1258 = (
char *) alloca (strlen (the_namespace) + 2 + strlen (func_name) + 1);
1259 strcpy (concatenated_name, the_namespace);
1260 strcat (concatenated_name,
"::");
1261 strcat (concatenated_name, func_name);
1262 name = concatenated_name;
1266 return overload_list;
1275 std::vector<symbol *> *overload_list)
1287 const char *the_namespace,
1288 std::vector<symbol *> *overload_list)
1293 if (the_namespace[0] ==
'\0')
1297 char *concatenated_name
1298 = (
char *) alloca (strlen (the_namespace) + 2 + strlen (func_name) + 1);
1300 strcpy (concatenated_name, the_namespace);
1301 strcat (concatenated_name,
"::");
1302 strcat (concatenated_name, func_name);
1303 name = concatenated_name;
1309 if (
block !=
nullptr)
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);
1459 surrounding_static_block = (surrounding_static_block ==
nullptr
1471 [func_name, surrounding_static_block, &overload_list]
1482 if (b == surrounding_static_block)
1489 }, current_objfile);
1497 struct symbol * rtti_sym;
1498 struct type * rtti_type;
1504 if (rtti_sym == NULL)
1506 warning (_(
"RTTI symbol not found for class '%s'"),
name);
1512 warning (_(
"RTTI symbol for class '%s' is not a type"),
name);
1518 switch (rtti_type->
code ())
1520 case TYPE_CODE_STRUCT:
1522 case TYPE_CODE_NAMESPACE:
1527 warning (_(
"RTTI symbol for class '%s' is a namespace"),
name);
1530 warning (_(
"RTTI symbol for class '%s' has bad type"),
name);
1537#ifdef HAVE_WORKING_FORK
1542static bool catch_demangler_crashes =
true;
1546static thread_local SIGJMP_BUF *gdb_demangle_jmp_buf;
1550static std::atomic<bool> gdb_demangle_attempt_core_dump;
1555gdb_demangle_signal_handler (
int signo)
1557 if (gdb_demangle_attempt_core_dump)
1562 gdb_demangle_attempt_core_dump =
false;
1565 SIGLONGJMP (*gdb_demangle_jmp_buf, signo);
1571report_failed_demangle (
const char *
name,
bool core_dump_allowed,
1574 static bool error_reported =
false;
1576 if (!error_reported)
1578 std::string short_msg
1579 = string_printf (_(
"unable to demangle '%s' "
1580 "(demangler failed with signal %d)"),
1581 name, crash_signal);
1583 std::string long_msg
1584 = string_printf (
"%s:%d: %s: %s", __FILE__, __LINE__,
1585 "demangler-warning", short_msg.c_str ());
1591 if (core_dump_allowed)
1593 _(
"%s\nAttempting to dump core.\n"),
1600 error_reported =
true;
1608gdb::unique_xmalloc_ptr<char>
1611 gdb::unique_xmalloc_ptr<char> result;
1612 int crash_signal = 0;
1614#ifdef HAVE_WORKING_FORK
1616 (catch_demangler_crashes
1617 ? gdb_demangle_signal_handler
1620 bool core_dump_allowed = gdb_demangle_attempt_core_dump;
1622 scoped_restore restore_jmp_buf
1623 = make_scoped_restore (&gdb_demangle_jmp_buf, &jmp_buf);
1624 if (catch_demangler_crashes)
1631#ifdef HAVE_SIGPROCMASK
1632 crash_signal = SIGSETJMP (*gdb_demangle_jmp_buf, 0);
1634 crash_signal = SIGSETJMP (*gdb_demangle_jmp_buf, 1);
1639 if (crash_signal == 0)
1640 result.reset (bfd_demangle (NULL,
name, options | DMGL_VERBOSE));
1642#ifdef HAVE_WORKING_FORK
1643 if (catch_demangler_crashes)
1645 if (crash_signal != 0)
1647#ifdef HAVE_SIGPROCMASK
1649 sigset_t segv_sig_set;
1650 sigemptyset (&segv_sig_set);
1651 sigaddset (&segv_sig_set, SIGSEGV);
1652 gdb_sigmask (SIG_UNBLOCK, &segv_sig_set, NULL);
1658 std::string copy =
name;
1660#
if __cplusplus >= 201402L
1661 =, copy = std::move (copy)
1667 report_failed_demangle (copy.c_str (), core_dump_allowed,
1683 struct demangle_component *tree,
1684 int estimated_length,
1685 size_t *p_allocated_size)
1687 return cplus_demangle_print (options | DMGL_VERBOSE, tree,
1688 estimated_length, p_allocated_size);
1694static struct demangle_component *
1696 int options,
void **mem)
1698 return cplus_demangle_v3_components (mangled, options | DMGL_VERBOSE, mem);
1708 if (startswith (search_name,
"::"))
1712 if (prefix_len != 0)
1713 search_name += prefix_len + 2;
1715 unsigned int hash = 0;
1716 for (
const char *
string = search_name; *
string !=
'\0'; ++string)
1718 string = skip_spaces (
string);
1725 && startswith (
string + 1,
"abi:")
1726 &&
string[5] !=
':')
1730 if (
string[0] ==
'<'
1731 &&
string[1] !=
'(' &&
string[1] !=
'<' &&
string[1] !=
'='
1732 &&
string[1] !=
' ' &&
string[1] !=
'\0')
1776 const char *lookup_name,
1777 size_t lookup_name_len,
1781 const char *sname = symbol_search_name;
1783 = (comp_match_res != NULL ? &comp_match_res->
match_for_lcd : NULL);
1785 gdb_assert (match_for_lcd ==
nullptr || match_for_lcd->
empty ());
1792 if (comp_match_res != NULL)
1815 comp_match_res->
set_match (symbol_search_name, sname);
1822 if (match_for_lcd !=
nullptr)
1823 match_for_lcd->
clear ();
1827 if (sname[len] ==
'\0')
1830 gdb_assert (sname[len] ==
':');
1846 = (comp_match_res != NULL ? &comp_match_res->
match_for_lcd : NULL);
1855 if (comp_match_res != NULL)
1856 comp_match_res->
set_match (symbol_search_name);
1880 mode, comp_match_res);
1898 gdb_assert_not_reached (
"");
1906test_cp_symbol_name_matches ()
1908#define CHECK_MATCH(SYMBOL, INPUT) \
1909 SELF_CHECK (cp_symbol_name_matches_1 (SYMBOL, \
1910 INPUT, sizeof (INPUT) - 1, \
1911 strncmp_iw_mode::MATCH_PARAMS, \
1914#define CHECK_NOT_MATCH(SYMBOL, INPUT) \
1915 SELF_CHECK (!cp_symbol_name_matches_1 (SYMBOL, \
1916 INPUT, sizeof (INPUT) - 1, \
1917 strncmp_iw_mode::MATCH_PARAMS, \
1922#define CHECK_MATCH_C(SYMBOL, INPUT) \
1925 CHECK_MATCH (SYMBOL, INPUT); \
1926 for (size_t i = 0; i < sizeof (INPUT) - 1; i++) \
1927 SELF_CHECK (cp_symbol_name_matches_1 (SYMBOL, INPUT, i, \
1928 strncmp_iw_mode::NORMAL, \
1934#define CHECK_NOT_MATCH_C(SYMBOL, INPUT) \
1937 CHECK_NOT_MATCH (SYMBOL, INPUT); \
1938 SELF_CHECK (!cp_symbol_name_matches_1 (SYMBOL, INPUT, \
1939 sizeof (INPUT) - 1, \
1940 strncmp_iw_mode::NORMAL, \
1945 CHECK_MATCH_C (
"function()",
"function");
1946 CHECK_MATCH_C (
"function(int)",
"function");
1949 CHECK_MATCH_C (
"function()",
"function ()");
1950 CHECK_MATCH_C (
"function ( )",
"function()");
1951 CHECK_MATCH_C (
"function ()",
"function( )");
1952 CHECK_MATCH_C (
"func(int)",
"func( int )");
1953 CHECK_MATCH_C (
"func(int)",
"func ( int ) ");
1954 CHECK_MATCH_C (
"func ( int )",
"func( int )");
1955 CHECK_MATCH_C (
"func ( int )",
"func ( int ) ");
1958 CHECK_NOT_MATCH (
"func",
"function");
1959 CHECK_NOT_MATCH (
"function",
"func");
1960 CHECK_NOT_MATCH (
"function()",
"func");
1964 CHECK_MATCH_C (
"function(int)",
"function(int)");
1965 CHECK_NOT_MATCH_C (
"function(int)",
"function()");
1968 CHECK_NOT_MATCH_C (
"function",
"func tion");
1969 CHECK_NOT_MATCH_C (
"func__tion",
"func_ _tion");
1970 CHECK_NOT_MATCH_C (
"func11tion",
"func1 1tion");
1974 CHECK_NOT_MATCH_C (
"func tion",
"function");
1975 CHECK_NOT_MATCH_C (
"func1 1tion",
"func11tion");
1976 CHECK_NOT_MATCH_C (
"func_ _tion",
"func__tion");
1979 CHECK_NOT_MATCH_C (
"func(param)",
"func(par am)");
1982 CHECK_NOT_MATCH_C (
"operator<<",
"opera tor<<");
1983 CHECK_NOT_MATCH_C (
"operator<<",
"operator< <");
1984 CHECK_NOT_MATCH_C (
"operator<<",
"operator < <");
1985 CHECK_NOT_MATCH_C (
"operator==",
"operator= =");
1986 CHECK_NOT_MATCH_C (
"operator==",
"operator = =");
1987 CHECK_MATCH_C (
"operator<<",
"operator <<");
1988 CHECK_MATCH_C (
"operator<<()",
"operator <<");
1989 CHECK_NOT_MATCH_C (
"operator<<()",
"operator<<(int)");
1990 CHECK_NOT_MATCH_C (
"operator<<(int)",
"operator<<()");
1991 CHECK_MATCH_C (
"operator==",
"operator ==");
1992 CHECK_MATCH_C (
"operator==()",
"operator ==");
1993 CHECK_MATCH_C (
"operator <<",
"operator<<");
1994 CHECK_MATCH_C (
"operator ==",
"operator==");
1995 CHECK_MATCH_C (
"operator bool",
"operator bool");
1996 CHECK_MATCH_C (
"operator bool ()",
"operator bool");
1997 CHECK_MATCH_C (
"operatorX<<",
"operatorX < <");
1998 CHECK_MATCH_C (
"Xoperator<<",
"Xoperator < <");
2000 CHECK_MATCH_C (
"operator()(int)",
"operator()(int)");
2001 CHECK_MATCH_C (
"operator()(int)",
"operator ( ) ( int )");
2002 CHECK_MATCH_C (
"operator()<long>(int)",
"operator ( ) < long > ( int )");
2004 CHECK_NOT_MATCH (
"operator()(int)",
"operator");
2008 CHECK_NOT_MATCH_C (
"operator/=()",
"operator ^=");
2010 CHECK_NOT_MATCH_C (
"operator>>",
"operator[]");
2012 CHECK_NOT_MATCH_C (
"operator>>()",
"operator[]()");
2014 CHECK_MATCH_C (
"base::operator char*()",
"base::operator char*()");
2015 CHECK_MATCH_C (
"base::operator char*()",
"base::operator char * ()");
2016 CHECK_MATCH_C (
"base::operator char**()",
"base::operator char * * ()");
2017 CHECK_MATCH (
"base::operator char**()",
"base::operator char * *");
2018 CHECK_MATCH_C (
"base::operator*()",
"base::operator*()");
2019 CHECK_NOT_MATCH_C (
"base::operator char*()",
"base::operatorc");
2020 CHECK_NOT_MATCH (
"base::operator char*()",
"base::operator char");
2021 CHECK_NOT_MATCH (
"base::operator char*()",
"base::operat");
2024 CHECK_NOT_MATCH_C (
"foo::bar",
"foo: :bar");
2025 CHECK_MATCH_C (
"foo::bar",
"foo :: bar");
2026 CHECK_MATCH_C (
"foo :: bar",
"foo::bar");
2028 CHECK_MATCH_C (
"abc::def::ghi()",
"abc::def::ghi()");
2029 CHECK_MATCH_C (
"abc::def::ghi ( )",
"abc::def::ghi()");
2030 CHECK_MATCH_C (
"abc::def::ghi()",
"abc::def::ghi ( )");
2031 CHECK_MATCH_C (
"function()",
"function()");
2032 CHECK_MATCH_C (
"bar::function()",
"bar::function()");
2037 CHECK_MATCH_C (
"foo::function()",
"function");
2038 CHECK_MATCH_C (
"foo::function(int)",
"function");
2039 CHECK_MATCH_C (
"foo::bar::function()",
"function");
2040 CHECK_MATCH_C (
"bar::function()",
"bar::function");
2041 CHECK_MATCH_C (
"foo::bar::function()",
"bar::function");
2042 CHECK_MATCH_C (
"foo::bar::function(int)",
"bar::function");
2045 CHECK_MATCH_C (
"foo::function()",
"function()");
2046 CHECK_MATCH_C (
"foo::bar::function()",
"function()");
2047 CHECK_MATCH_C (
"foo::function(int)",
"function(int)");
2048 CHECK_MATCH_C (
"foo::function()",
"foo::function()");
2049 CHECK_MATCH_C (
"foo::bar::function()",
"bar::function()");
2050 CHECK_MATCH_C (
"foo::bar::function(int)",
"bar::function(int)");
2051 CHECK_MATCH_C (
"bar::function()",
"bar::function()");
2053 CHECK_NOT_MATCH_C (
"foo::bar::function(int)",
"bar::function()");
2055 CHECK_MATCH_C (
"(anonymous namespace)::bar::function(int)",
2056 "bar::function(int)");
2057 CHECK_MATCH_C (
"foo::(anonymous namespace)::bar::function(int)",
2061 CHECK_NOT_MATCH_C (
"function()",
"bar::function");
2062 CHECK_NOT_MATCH_C (
"function()",
"bar::function()");
2065 CHECK_NOT_MATCH_C (
"foo::function()",
"::function");
2066 CHECK_NOT_MATCH_C (
"foo::function()",
"::function()");
2067 CHECK_NOT_MATCH_C (
"foo::function(int)",
"::function()");
2068 CHECK_NOT_MATCH_C (
"foo::function(int)",
"::function(int)");
2074 CHECK_MATCH_C (
"function[abi:foo]()",
"function");
2075 CHECK_MATCH_C (
"function[abi:foo](int)",
"function");
2076 CHECK_MATCH_C (
"function[abi:foo]()",
"function ()");
2077 CHECK_NOT_MATCH_C (
"function[abi:foo]()",
"function (int)");
2079 CHECK_MATCH_C (
"function[abi:foo]()",
"function[abi:foo]");
2080 CHECK_MATCH_C (
"function[abi:foo](int)",
"function[abi:foo]");
2081 CHECK_MATCH_C (
"function[abi:foo]()",
"function[abi:foo] ()");
2082 CHECK_MATCH_C (
"function[abi:foo][abi:bar]()",
"function");
2083 CHECK_MATCH_C (
"function[abi:foo][abi:bar](int)",
"function");
2084 CHECK_MATCH_C (
"function[abi:foo][abi:bar]()",
"function[abi:foo]");
2085 CHECK_MATCH_C (
"function[abi:foo][abi:bar](int)",
"function[abi:foo]");
2086 CHECK_MATCH_C (
"function[abi:foo][abi:bar]()",
"function[abi:foo] ()");
2087 CHECK_NOT_MATCH_C (
"function[abi:foo][abi:bar]()",
"function[abi:foo] (int)");
2089 CHECK_MATCH_C (
"function [abi:foo][abi:bar] ( )",
"function [abi:foo]");
2093 CHECK_NOT_MATCH_C (
"function()",
"function[abi:foo]()");
2094 CHECK_NOT_MATCH_C (
"function()",
"function[abi:foo]");
2101quote (
const char *str)
2104 return std::string (1,
'"') + str +
'"';
2115check_remove_params (
const char *file,
int line,
2116 const char *
name,
const char *expected,
2117 bool completion_mode)
2119 gdb::unique_xmalloc_ptr<char> result
2122 if ((expected == NULL) != (result == NULL)
2123 || (expected != NULL
2124 && strcmp (result.get (), expected) != 0))
2126 error (_(
"%s:%d: make-paramless self-test failed: (completion=%d) "
2127 "\"%s\" -> %s, expected %s"),
2128 file, line, completion_mode,
name,
2129 quote (result.get ()).c_str (), quote (expected).c_str ());
2136test_cp_remove_params ()
2140#define CHECK(NAME, EXPECTED) \
2143 check_remove_params (__FILE__, __LINE__, NAME, EXPECTED, false); \
2144 check_remove_params (__FILE__, __LINE__, NAME, EXPECTED, true); \
2151#define CHECK_INCOMPL(NAME, EXPECTED) \
2154 check_remove_params (__FILE__, __LINE__, NAME, NULL, false); \
2155 check_remove_params (__FILE__, __LINE__, NAME, EXPECTED, true); \
2159 CHECK (
"function()",
"function");
2161 CHECK (
"function() const",
"function");
2163 CHECK (
"(anonymous namespace)::A::B::C",
2164 "(anonymous namespace)::A::B::C");
2166 CHECK (
"A::(anonymous namespace)",
2167 "A::(anonymous namespace)");
2171 CHECK (
"A::foo<int>()",
2177 CHECK (
"A::foo<(anonymous namespace)::B>::func(int)",
2178 "A::foo<(anonymous namespace)::B>::func");
2181 "A::foo<(anonymous namespace)::B>::func");
2184 "A::foo<(anonymous namespace)::B>");
2187 "A::foo<(anonymous namespace)::B>");
2189 CHECK (
"A::foo<(anonymous namespace)::B>",
2190 "A::foo<(anonymous namespace)::B>");
2198 CHECK (
"A::foo<void(int)>::func(int)",
2199 "A::foo<void(int)>::func");
2230 prefix = (
char *) alloca (len + 1);
2232 memcpy (
prefix, arg, len);
2264 if (*
scan == quoted)
2266 else if (*
scan ==
'\\' && *(
scan + 1))
2269 else if (*
scan == c && ! quoted && depth == 0)
2271 else if (*
scan ==
'"' || *
scan ==
'\'')
2273 else if (*
scan ==
'(' || *
scan ==
'<')
2275 else if ((*
scan ==
')' || *
scan ==
'>') && depth > 0)
2277 else if (*
scan ==
'o' && !quoted && depth == 0)
2285 while (ISSPACE (*
scan))
2329 _(
"C++ maintenance commands."),
2338 _(
"Print the first class/namespace component of NAME."),
2342 _(
"Show the virtual function table for a C++ object.\n\
2343Usage: info vtbl EXPRESSION\n\
2344Evaluate EXPRESSION and display the virtual function table for the\n\
2345resulting object."));
2347#ifdef HAVE_WORKING_FORK
2349 &catch_demangler_crashes, _(
"\
2350Set whether to attempt to catch demangler crashes."), _(
"\
2351Show whether to attempt to catch demangler crashes."), _(
"\
2352If enabled GDB will attempt to catch demangler crashes and\n\
2353display the offending symbol."),
2363 selftests::register_test (
"cp_symbol_name_matches",
2364 selftests::test_cp_symbol_name_matches);
2365 selftests::register_test (
"cp_remove_params",
2366 selftests::test_cp_remove_params);
struct gdbarch * target_gdbarch(void)
iterator_range< block_iterator_wrapper > block_iterator_range
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, parser_flags flags)
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
const struct block * global_block() const
const struct block * static_block() const
struct objfile * objfile() const
struct using_direct * get_using() 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)