37 #include "safe-ctype.h"
39 #define d_left(dc) (dc)->u.s_binary.left
40 #define d_right(dc) (dc)->u.s_binary.right
56 const char *oload_name);
59 const char *the_namespace);
75 "std::istream",
"std::iostream",
"std::ostream",
"std::string"
80 struct demangle_component *ret_comp,
93 *len = strlen (
string);
94 return obstack_copy (obstack,
string, *len);
125 if (!ISIDST (
string[0]))
131 if (
string[0] ==
'u' && strcmp (&
string[1],
"nsigned") == 0)
133 else if (
string[0] ==
's' && strcmp (&
string[1],
"igned") == 0)
137 while (ISIDNUM (
string[1]))
140 if (
string[1] ==
'\0')
153 struct demangle_component *ret_comp,
163 name = (
char *) alloca (ret_comp->u.s_name.len + 1);
164 memcpy (name, ret_comp->u.s_name.s, ret_comp->u.s_name.len);
165 name[ret_comp->u.s_name.len] =
'\0';
192 const char *new_name = (*finder) (otype, data);
194 if (new_name != NULL)
196 ret_comp->u.s_name.s = new_name;
197 ret_comp->u.s_name.len = strlen (new_name);
230 struct type *last = otype;
300 ret_comp->u.s_name.s =
name;
301 ret_comp->u.s_name.len =
len;
317 struct demangle_component *ret_comp,
324 struct demangle_component *comp = ret_comp;
331 while (comp->type == DEMANGLE_COMPONENT_QUAL_NAME)
333 if (
d_left (comp)->
type == DEMANGLE_COMPONENT_NAME)
335 struct demangle_component newobj;
338 d_left (comp)->u.s_name.len);
340 newobj.type = DEMANGLE_COMPONENT_NAME;
341 newobj.u.s_name.s =
name;
342 newobj.u.s_name.len =
len;
364 d_left (ret_comp)->type = DEMANGLE_COMPONENT_NAME;
365 d_left (ret_comp)->u.s_name.s = s;
366 d_left (ret_comp)->u.s_name.len = slen;
397 if (comp->type == DEMANGLE_COMPONENT_NAME)
405 ret_comp->type = DEMANGLE_COMPONENT_NAME;
406 ret_comp->u.s_name.s =
name;
407 ret_comp->u.s_name.len =
len;
426 while (
d_left (ret_comp) != NULL
427 && (
d_left (ret_comp)->
type == DEMANGLE_COMPONENT_CONST
428 ||
d_left (ret_comp)->
type == DEMANGLE_COMPONENT_VOLATILE))
439 struct demangle_component *ret_comp,
446 && (ret_comp->type == DEMANGLE_COMPONENT_NAME
447 || ret_comp->type == DEMANGLE_COMPONENT_QUAL_NAME
448 || ret_comp->type == DEMANGLE_COMPONENT_TEMPLATE
449 || ret_comp->type == DEMANGLE_COMPONENT_BUILTIN_TYPE))
453 if (local_name != NULL)
455 struct symbol *sym = NULL;
472 const char *new_name = (*finder) (otype, data);
474 if (new_name != NULL)
476 ret_comp->type = DEMANGLE_COMPONENT_NAME;
477 ret_comp->u.s_name.s = new_name;
478 ret_comp->u.s_name.len = strlen (new_name);
485 switch (ret_comp->type)
487 case DEMANGLE_COMPONENT_ARGLIST:
491 case DEMANGLE_COMPONENT_FUNCTION_TYPE:
492 case DEMANGLE_COMPONENT_TEMPLATE:
493 case DEMANGLE_COMPONENT_TEMPLATE_ARGLIST:
494 case DEMANGLE_COMPONENT_TYPED_NAME:
499 case DEMANGLE_COMPONENT_NAME:
503 case DEMANGLE_COMPONENT_QUAL_NAME:
507 case DEMANGLE_COMPONENT_LOCAL_NAME:
508 case DEMANGLE_COMPONENT_CTOR:
509 case DEMANGLE_COMPONENT_ARRAY_TYPE:
510 case DEMANGLE_COMPONENT_PTRMEM_TYPE:
514 case DEMANGLE_COMPONENT_CONST:
515 case DEMANGLE_COMPONENT_RESTRICT:
516 case DEMANGLE_COMPONENT_VOLATILE:
517 case DEMANGLE_COMPONENT_VOLATILE_THIS:
518 case DEMANGLE_COMPONENT_CONST_THIS:
519 case DEMANGLE_COMPONENT_RESTRICT_THIS:
520 case DEMANGLE_COMPONENT_POINTER:
521 case DEMANGLE_COMPONENT_REFERENCE:
543 unsigned int estimated_len;
547 estimated_len = strlen (
string) * 2;
563 if (strcmp (
string, ret) == 0)
590 unsigned int estimated_len;
600 estimated_len = strlen (
string) * 2;
606 warning (
_(
"internal error: string \"%s\" failed to be canonicalized"),
611 if (strcmp (
string, ret) == 0)
628 void **memory,
char **demangled_p)
630 char *demangled_name;
635 if (mangled_name[0] ==
'_' && mangled_name[1] ==
'Z')
637 struct demangle_component *ret;
639 ret = cplus_demangle_v3_components (mangled_name,
653 if (demangled_name == NULL)
662 xfree (demangled_name);
666 *demangled_p = demangled_name;
675 void *storage = NULL;
676 char *demangled_name = NULL, *ret;
677 struct demangle_component *ret_comp, *prev_comp, *cur_comp;
682 &storage, &demangled_name);
687 ret_comp = info->
tree;
692 switch (ret_comp->type)
694 case DEMANGLE_COMPONENT_CONST:
695 case DEMANGLE_COMPONENT_RESTRICT:
696 case DEMANGLE_COMPONENT_VOLATILE:
697 case DEMANGLE_COMPONENT_CONST_THIS:
698 case DEMANGLE_COMPONENT_RESTRICT_THIS:
699 case DEMANGLE_COMPONENT_VOLATILE_THIS:
700 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
701 ret_comp =
d_left (ret_comp);
709 if (ret_comp->type == DEMANGLE_COMPONENT_TYPED_NAME)
710 ret_comp =
d_left (ret_comp);
714 if (ret_comp->type == DEMANGLE_COMPONENT_TEMPLATE)
715 ret_comp =
d_left (ret_comp);
724 switch (cur_comp->type)
726 case DEMANGLE_COMPONENT_QUAL_NAME:
727 case DEMANGLE_COMPONENT_LOCAL_NAME:
728 prev_comp = cur_comp;
731 case DEMANGLE_COMPONENT_TEMPLATE:
732 case DEMANGLE_COMPONENT_NAME:
733 case DEMANGLE_COMPONENT_CTOR:
734 case DEMANGLE_COMPONENT_DTOR:
735 case DEMANGLE_COMPONENT_OPERATOR:
736 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
746 if (cur_comp != NULL && prev_comp != NULL)
749 *prev_comp = *
d_left (prev_comp);
756 xfree (demangled_name);
766 static struct demangle_component *
769 struct demangle_component *ret_comp = comp, *last_template;
773 last_template = NULL;
775 switch (ret_comp->type)
777 case DEMANGLE_COMPONENT_QUAL_NAME:
778 case DEMANGLE_COMPONENT_LOCAL_NAME:
781 case DEMANGLE_COMPONENT_TYPED_NAME:
782 ret_comp =
d_left (ret_comp);
784 case DEMANGLE_COMPONENT_TEMPLATE:
786 last_template = ret_comp;
787 ret_comp =
d_left (ret_comp);
789 case DEMANGLE_COMPONENT_CONST:
790 case DEMANGLE_COMPONENT_RESTRICT:
791 case DEMANGLE_COMPONENT_VOLATILE:
792 case DEMANGLE_COMPONENT_CONST_THIS:
793 case DEMANGLE_COMPONENT_RESTRICT_THIS:
794 case DEMANGLE_COMPONENT_VOLATILE_THIS:
795 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
796 ret_comp =
d_left (ret_comp);
798 case DEMANGLE_COMPONENT_NAME:
799 case DEMANGLE_COMPONENT_CTOR:
800 case DEMANGLE_COMPONENT_DTOR:
801 case DEMANGLE_COMPONENT_OPERATOR:
802 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
812 d_left (last_template) = ret_comp;
813 return last_template;
824 void *storage = NULL;
825 char *demangled_name = NULL, *ret;
826 struct demangle_component *ret_comp;
830 &storage, &demangled_name);
837 if (ret_comp != NULL)
843 xfree (demangled_name);
858 struct demangle_component *ret_comp;
868 if (ret_comp != NULL)
883 struct demangle_component *ret_comp;
887 if (demangled_name == NULL)
895 ret_comp = info->
tree;
897 switch (ret_comp->type)
899 case DEMANGLE_COMPONENT_CONST:
900 case DEMANGLE_COMPONENT_RESTRICT:
901 case DEMANGLE_COMPONENT_VOLATILE:
902 case DEMANGLE_COMPONENT_CONST_THIS:
903 case DEMANGLE_COMPONENT_RESTRICT_THIS:
904 case DEMANGLE_COMPONENT_VOLATILE_THIS:
905 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
906 ret_comp =
d_left (ret_comp);
914 if (ret_comp->type == DEMANGLE_COMPONENT_TYPED_NAME)
976 #define LENGTH_OF_OPERATOR 8
981 unsigned int index = 0;
988 int operator_possible = 1;
1004 if (name[index] !=
':')
1007 return strlen (name);
1011 operator_possible = 1;
1020 if (name[index] !=
':')
1023 return strlen (name);
1027 operator_possible = 1;
1036 return strlen (name);
1043 if (operator_possible
1044 && strncmp (name + index,
"operator",
1048 while (ISSPACE(name[index]))
1050 switch (name[index])
1056 if (name[index + 1] ==
'<')
1063 if (name[index + 1] ==
'>')
1076 operator_possible = 0;
1088 operator_possible = 1;
1091 operator_possible = 0;
1104 "unexpected demangled name '%s'", name);
1117 unsigned int previous_len = 0;
1119 while (name[current_len] !=
'\0')
1122 previous_len = current_len;
1128 return previous_len;
1139 const char *oload_name)
1162 if (strcmp (sym_name, oload_name) != 0)
1175 sym_return_val = (
struct symbol **)
1178 sym_return_val[sym_return_val_index++] = sym;
1187 const char *the_namespace)
1195 sizeof (
struct symbol *));
1196 sym_return_val[0] = NULL;
1202 if (the_namespace[0] ==
'\0')
1206 char *concatenated_name
1207 = alloca (strlen (the_namespace) + 2 + strlen (func_name) + 1);
1208 strcpy (concatenated_name, the_namespace);
1209 strcat (concatenated_name,
"::");
1210 strcat (concatenated_name, func_name);
1211 name = concatenated_name;
1239 const char *the_namespace)
1244 if (the_namespace[0] ==
'\0')
1248 char *concatenated_name
1249 = alloca (strlen (the_namespace) + 2 + strlen (func_name) + 1);
1251 strcpy (concatenated_name, the_namespace);
1252 strcat (concatenated_name,
"::");
1253 strcat (concatenated_name, func_name);
1254 name = concatenated_name;
1274 const char *func_name)
1277 const char *type_name;
1293 if (type_name == NULL)
1298 if (prefix_len != 0)
1300 the_namespace = alloca (prefix_len + 1);
1301 strncpy (the_namespace, type_name, prefix_len);
1302 the_namespace[prefix_len] =
'\0';
1323 const char *func_name)
1329 for (i = 1; i <= nargs; i++)
1353 const char *the_namespace)
1367 current = current->
next)
1378 if (strcmp (the_namespace, current->
import_dest) == 0)
1408 const struct block *b, *surrounding_static_block = 0;
1442 if (b == surrounding_static_block)
1453 struct symbol * rtti_sym;
1454 struct type * rtti_type;
1460 if (rtti_sym == NULL)
1462 warning (
_(
"RTTI symbol not found for class '%s'"), name);
1468 warning (
_(
"RTTI symbol for class '%s' is not a type"), name);
1483 warning (
_(
"RTTI symbol for class '%s' is a namespace"), name);
1486 warning (
_(
"RTTI symbol for class '%s' has bad type"), name);
1493 #ifdef HAVE_WORKING_FORK
1531 char *result = NULL;
1532 int crash_signal = 0;
1534 #ifdef HAVE_WORKING_FORK
1535 #if defined (HAVE_SIGACTION) && defined (SA_RESTART)
1536 struct sigaction sa, old_sa;
1540 static int core_dump_allowed = -1;
1542 if (core_dump_allowed == -1)
1546 if (!core_dump_allowed)
1552 #if defined (HAVE_SIGACTION) && defined (SA_RESTART)
1554 sigemptyset (&sa.sa_mask);
1555 #ifdef HAVE_SIGALTSTACK
1556 sa.sa_flags = SA_ONSTACK;
1560 sigaction (SIGSEGV, &sa, &old_sa);
1569 if (crash_signal == 0)
1570 result = bfd_demangle (NULL, name, options);
1572 #ifdef HAVE_WORKING_FORK
1575 #if defined (HAVE_SIGACTION) && defined (SA_RESTART)
1576 sigaction (SIGSEGV, &old_sa, NULL);
1578 signal (SIGSEGV,
ofunc);
1581 if (crash_signal != 0)
1583 static int error_reported = 0;
1585 if (!error_reported)
1587 char *short_msg, *long_msg;
1590 short_msg =
xstrprintf (
_(
"unable to demangle '%s' "
1591 "(demangler failed with signal %d)"),
1592 name, crash_signal);
1595 long_msg =
xstrprintf (
"%s:%d: %s: %s", __FILE__, __LINE__,
1596 "demangler-warning", short_msg);
1601 if (core_dump_allowed)
1603 _(
"%s\nAttempting to dump core.\n"),
1629 "by the name of a command.\n"));
1631 "maintenance cplus ",
1649 prefix = alloca (len + 1);
1651 memcpy (prefix, arg, len);
1676 _(
"C++ maintenance commands."),
1677 &maint_cplus_cmd_list,
1678 "maintenance cplus ",
1687 _(
"Print the first class/namespace component of NAME."),
1688 &maint_cplus_cmd_list);
1691 _(
"Show the virtual function table for a C++ object.\n\
1692 Usage: info vtbl EXPRESSION\n\
1693 Evaluate EXPRESSION and display the virtual function table for the\n\
1694 resulting object."));
1696 #ifdef HAVE_WORKING_FORK
1699 Set whether to attempt to catch demangler crashes."),
_(
"\
1700 Show whether to attempt to catch demangler crashes."),
_(
"\
1701 If enabled GDB will attempt to catch demangler crashes and\n\
1702 display the offending symbol."),
void target_terminal_ours(void)
struct cmd_list_element * add_prefix_cmd(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc, struct cmd_list_element **prefixlist, const char *prefixname, int allow_unknown, struct cmd_list_element **list)
static void info_vtbl_command(char *arg, int from_tty)
static void reset_directive_searched(void *data)
static int cp_already_canonical(const char *string)
static void first_component_command(char *arg, int from_tty)
#define TYPE_N_BASECLASSES(thistype)
void cp_merge_demangle_parse_infos(struct demangle_parse_info *dest, struct demangle_component *target, struct demangle_parse_info *src)
static struct symbol ** sym_return_val
static const char *const ignore_typedefs[]
void fputs_unfiltered(const char *buf, struct ui_file *file)
#define LENGTH_OF_OPERATOR
static void demangled_name_complaint(const char *name)
void warning(const char *fmt,...)
#define TYPE_NAME(thistype)
static void maint_cplus_command(char *arg, int from_tty)
const struct block * block_global_block(const struct block *block)
char * cp_func_name(const char *full_name)
void ui_file_delete(struct ui_file *file)
struct ui_file * gdb_stdout
static int sym_return_val_index
#define SYMBOL_CLASS(symbol)
static int sym_return_val_size
struct demangle_component * tree
void type_print(struct type *type, const char *varstring, struct ui_file *stream, int show)
#define BLOCKVECTOR_BLOCK(blocklist, n)
struct cleanup * make_cleanup_cp_demangled_name_parse_free(struct demangle_parse_info *info)
static unsigned int cp_find_first_component_aux(const char *name, int permissive)
void demangler_warning(const char *file, int line, const char *string,...)
static void replace_typedefs(struct demangle_parse_info *info, struct demangle_component *ret_comp, canonicalization_ftype *finder, void *data)
struct cmd_list_element * maintenance_set_cmdlist
char * method_name_from_physname(const char *physname)
static void do_demangled_name_parse_free_cleanup(void *data)
struct demangle_info * info
char * cp_canonicalize_string_full(const char *string, canonicalization_ftype *finder, void *data)
struct symbol ** make_symbol_overload_list_adl(struct type **arg_types, int nargs, const char *func_name)
static void make_symbol_overload_list_qualified(const char *func_name)
char * gdb_demangle(const char *name, int options)
#define ALL_OBJFILES(obj)
struct type * check_typedef(struct type *type)
#define CATCH(EXCEPTION, MASK)
static SIGJMP_BUF gdb_demangle_jmp_buf
struct type * cp_lookup_rtti_type(const char *name, struct block *block)
#define SIGLONGJMP(buf, val)
void initialize_file_ftype(void)
char * cp_remove_params(const char *demangled_name)
struct symbol ** make_symbol_overload_list(const char *func_name, const char *the_namespace)
char * cp_canonicalize_string_no_typedefs(const char *string)
unsigned int cp_find_first_component(const char *name)
char * ui_file_obsavestring(struct ui_file *file, struct obstack *obstack, long *length)
void fprintf_unfiltered(struct ui_file *stream, const char *format,...)
struct cmd_list_element * add_cmd(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc, struct cmd_list_element **list)
const struct sym_fns * sf
void complaint(struct complaints **complaints, const char *fmt,...)
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
#define ALL_COMPUNITS(objfile, cu)
struct using_direct * block_using(const struct block *block)
struct demangle_parse_info * cp_demangled_name_to_comp(const char *demangled_name, const char **errmsg)
#define BLOCK_SUPERBLOCK(bl)
static struct demangle_component * unqualified_name_from_comp(struct demangle_component *comp)
struct cmd_list_element * add_info(const char *name, cmd_cfunc_ftype *fun, const char *doc)
#define SYMBOL_LINKAGE_NAME(symbol)
struct cmd_list_element * add_alias_cmd(const char *name, const char *oldname, enum command_class theclass, int abbrev_flag, struct cmd_list_element **list)
#define TYPE_BASECLASS(thistype, index)
char * xstrprintf(const char *format,...)
void(* expand_symtabs_for_function)(struct objfile *objfile, const char *func_name)
void printf_unfiltered(const char *format,...)
static void make_symbol_overload_list_namespace(const char *func_name, const char *the_namespace)
char * cp_canonicalize_string(const char *string)
struct ui_file * mem_fileopen(void)
char * cp_comp_to_string(struct demangle_component *result, int estimated_len)
struct using_direct * next
PTR xrealloc(PTR ptr, size_t size)
char * cp_class_name_from_physname(const char *physname)
static void check_cv_qualifiers(struct demangle_component *ret_comp)
struct demangle_parse_info * cp_new_demangle_parse_info(void)
struct block_namespace_info * the_namespace
#define COMPUNIT_BLOCKVECTOR(cust)
void help_list(struct cmd_list_element *list, const char *cmdtype, enum command_class theclass, struct ui_file *stream)
void discard_cleanups(struct cleanup *old_chain)
#define TYPE_TARGET_TYPE(thistype)
static void overload_list_add_symbol(struct symbol *sym, const char *oload_name)
static void make_symbol_overload_list_block(const char *name, const struct block *block)
const char *( canonicalization_ftype)(struct type *, void *)
const struct block * block_static_block(const struct block *block)
#define TYPE_CODE(thistype)
static struct demangle_parse_info * mangled_name_to_comp(const char *mangled_name, int options, void **memory, char **demangled_p)
struct ui_file * gdb_stderr
struct complaints * symfile_complaints
struct symbol * lookup_symbol(const char *name, const struct block *block, domain_enum domain, struct field_of_this_result *is_a_field_of_this)
void ui_file_write(struct ui_file *file, const char *buf, long length_buf)
static int inspect_type(struct demangle_parse_info *info, struct demangle_component *ret_comp, canonicalization_ftype *finder, void *data)
static int gdb_demangle_attempt_core_dump
#define TYPE_TAG_NAME(type)
void ui_file_rewind(struct ui_file *file)
const struct block * get_selected_block(CORE_ADDR *addr_in_block)
#define SYMBOL_NATURAL_NAME(symbol)
struct value * parse_and_eval(const char *exp)
#define BASETYPE_VIA_PUBLIC(thistype, index)
void cp_demangled_name_parse_free(struct demangle_parse_info *parse_info)
int can_dump_core(enum resource_limit_kind limit_kind)
#define SYMBOL_TYPE(symbol)
struct cmd_list_element * maintenancelist
void warn_cant_dump_core(const char *reason)
static int catch_demangler_crashes
void cplus_print_vtable(struct value *value)
#define ALL_BLOCK_SYMBOLS_WITH_NAME(block, name, iter, sym)
static void make_symbol_overload_list_adl_namespace(struct type *type, const char *func_name)
const struct quick_symbol_functions * qf
struct cmd_list_element * maintenance_show_cmdlist
unsigned int cp_entire_prefix_len(const char *name)
static void replace_typedefs_qualified_name(struct demangle_parse_info *info, struct demangle_component *ret_comp, canonicalization_ftype *finder, void *data)
static void make_symbol_overload_list_using(const char *func_name, const char *the_namespace)
static char * copy_string_to_obstack(struct obstack *obstack, const char *string, long *len)
void do_cleanups(struct cleanup *old_chain)
void add_setshow_boolean_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
initialize_file_ftype _initialize_cp_support
static void gdb_demangle_signal_handler(int signo)
const ULONGEST const LONGEST len