/* Helper routines for C++ support in GDB.
- Copyright (C) 2002-2021 Free Software Foundation, Inc.
+ Copyright (C) 2002-2022 Free Software Foundation, Inc.
Contributed by MontaVista Software.
name[ret_comp->u.s_name.len] = '\0';
/* Ignore any typedefs that should not be substituted. */
- for (int i = 0; i < ARRAY_SIZE (ignore_typedefs); ++i)
+ for (const char *ignorable : ignore_typedefs)
{
- if (strcmp (name, ignore_typedefs[i]) == 0)
+ if (strcmp (name, ignorable) == 0)
return 0;
}
if (sym != NULL)
{
- struct type *otype = SYMBOL_TYPE (sym);
+ struct type *otype = sym->type ();
if (finder != NULL)
{
if (sym != NULL)
{
- struct type *otype = SYMBOL_TYPE (sym);
+ struct type *otype = sym->type ();
const char *new_name = (*finder) (otype, data);
if (new_name != NULL)
static std::unique_ptr<demangle_parse_info>
mangled_name_to_comp (const char *mangled_name, int options,
- void **memory, char **demangled_p)
+ void **memory,
+ gdb::unique_xmalloc_ptr<char> *demangled_p)
{
- char *demangled_name;
-
/* If it looks like a v3 mangled name, then try to go directly
to trees. */
if (mangled_name[0] == '_' && mangled_name[1] == 'Z')
/* If it doesn't, or if that failed, then try to demangle the
name. */
- demangled_name = gdb_demangle (mangled_name, options);
+ gdb::unique_xmalloc_ptr<char> demangled_name = gdb_demangle (mangled_name,
+ options);
if (demangled_name == NULL)
return NULL;
/* If we could demangle the name, parse it to build the component
tree. */
std::unique_ptr<demangle_parse_info> info
- = cp_demangled_name_to_comp (demangled_name, NULL);
+ = cp_demangled_name_to_comp (demangled_name.get (), NULL);
if (info == NULL)
- {
- xfree (demangled_name);
- return NULL;
- }
+ return NULL;
- *demangled_p = demangled_name;
+ *demangled_p = std::move (demangled_name);
return info;
}
cp_class_name_from_physname (const char *physname)
{
void *storage = NULL;
- char *demangled_name = NULL;
+ gdb::unique_xmalloc_ptr<char> demangled_name;
gdb::unique_xmalloc_ptr<char> ret;
struct demangle_component *ret_comp, *prev_comp, *cur_comp;
std::unique_ptr<demangle_parse_info> info;
}
xfree (storage);
- xfree (demangled_name);
return ret.release ();
}
method_name_from_physname (const char *physname)
{
void *storage = NULL;
- char *demangled_name = NULL;
+ gdb::unique_xmalloc_ptr<char> demangled_name;
gdb::unique_xmalloc_ptr<char> ret;
struct demangle_component *ret_comp;
std::unique_ptr<demangle_parse_info> info;
ret = cp_comp_to_string (ret_comp, 10);
xfree (storage);
- xfree (demangled_name);
return ret.release ();
}
{
/* If there is no type information, we can't do anything, so
skip. */
- if (SYMBOL_TYPE (sym) == NULL)
+ if (sym->type () == NULL)
return;
/* skip any symbols that we've already considered. */
const char *type_name;
int i, prefix_len;
- while (type->code () == TYPE_CODE_PTR
- || TYPE_IS_REFERENCE (type)
+ while (type->is_pointer_or_reference ()
|| type->code () == TYPE_CODE_ARRAY
|| type->code () == TYPE_CODE_TYPEDEF)
{
for (block = get_selected_block (0);
block != NULL;
- block = BLOCK_SUPERBLOCK (block))
+ block = block->superblock ())
for (current = block_using (block);
current != NULL;
current = current->next)
add_symbol_overload_list_qualified (const char *func_name,
std::vector<symbol *> *overload_list)
{
- const struct block *b, *surrounding_static_block = 0;
+ const struct block *surrounding_static_block = 0;
/* Look through the partial symtabs for all symbols which begin by
matching FUNC_NAME. Make sure we read that symbol table in. */
/* Search upwards from currently selected frame (so that we can
complete on local vars. */
- for (b = get_selected_block (0); b != NULL; b = BLOCK_SUPERBLOCK (b))
+ for (const block *b = get_selected_block (0);
+ b != nullptr;
+ b = b->superblock ())
add_symbol_overload_list_block (func_name, b, overload_list);
surrounding_static_block = block_static_block (get_selected_block (0));
for (compunit_symtab *cust : objfile->compunits ())
{
QUIT;
- b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), GLOBAL_BLOCK);
+ const block *b = cust->blockvector ()->global_block ();
add_symbol_overload_list_block (func_name, b, overload_list);
}
}
for (compunit_symtab *cust : objfile->compunits ())
{
QUIT;
- b = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), STATIC_BLOCK);
+ const block *b = cust->blockvector ()->static_block ();
+
/* Don't do this block twice. */
if (b == surrounding_static_block)
continue;
+
add_symbol_overload_list_block (func_name, b, overload_list);
}
}
return NULL;
}
- if (SYMBOL_CLASS (rtti_sym) != LOC_TYPEDEF)
+ if (rtti_sym->aclass () != LOC_TYPEDEF)
{
warning (_("RTTI symbol for class '%s' is not a type"), name);
return NULL;
}
- rtti_type = check_typedef (SYMBOL_TYPE (rtti_sym));
+ rtti_type = check_typedef (rtti_sym->type ());
switch (rtti_type->code ())
{
begin_line ();
if (core_dump_allowed)
- fprintf_unfiltered (gdb_stderr,
- _("%s\nAttempting to dump core.\n"),
- long_msg.c_str ());
+ gdb_printf (gdb_stderr,
+ _("%s\nAttempting to dump core.\n"),
+ long_msg.c_str ());
else
warn_cant_dump_core (long_msg.c_str ());
/* A wrapper for bfd_demangle. */
-char *
+gdb::unique_xmalloc_ptr<char>
gdb_demangle (const char *name, int options)
{
- char *result = NULL;
+ gdb::unique_xmalloc_ptr<char> result;
int crash_signal = 0;
#ifdef HAVE_WORKING_FORK
#endif
if (crash_signal == 0)
- result = bfd_demangle (NULL, name, options);
+ result.reset (bfd_demangle (NULL, name, options));
#ifdef HAVE_WORKING_FORK
if (catch_demangler_crashes)
&& string[5] != ':')
break;
+ /* Ignore template parameter lists. */
+ if (string[0] == '<'
+ && string[1] != '(' && string[1] != '<' && string[1] != '='
+ && string[1] != ' ' && string[1] != '\0')
+ break;
+
hash = SYMBOL_HASH_NEXT (hash, *string);
}
return hash;
while (true)
{
if (strncmp_iw_with_mode (sname, lookup_name, lookup_name_len,
- mode, language_cplus, match_for_lcd) == 0)
+ mode, language_cplus, match_for_lcd, true) == 0)
{
if (comp_match_res != NULL)
{
memcpy (prefix, arg, len);
prefix[len] = '\0';
- printf_unfiltered ("%s\n", prefix);
+ gdb_printf ("%s\n", prefix);
}
/* Implement "info vtbl". */
cplus_print_vtable (value);
}
+/* See description in cp-support.h. */
+
+const char *
+find_toplevel_char (const char *s, char c)
+{
+ int quoted = 0; /* zero if we're not in quotes;
+ '"' if we're in a double-quoted string;
+ '\'' if we're in a single-quoted string. */
+ int depth = 0; /* Number of unclosed parens we've seen. */
+ const char *scan;
+
+ for (scan = s; *scan; scan++)
+ {
+ if (quoted)
+ {
+ if (*scan == quoted)
+ quoted = 0;
+ else if (*scan == '\\' && *(scan + 1))
+ scan++;
+ }
+ else if (*scan == c && ! quoted && depth == 0)
+ return scan;
+ else if (*scan == '"' || *scan == '\'')
+ quoted = *scan;
+ else if (*scan == '(' || *scan == '<')
+ depth++;
+ else if ((*scan == ')' || *scan == '>') && depth > 0)
+ depth--;
+ else if (*scan == 'o' && !quoted && depth == 0)
+ {
+ /* Handle C++ operator names. */
+ if (strncmp (scan, CP_OPERATOR_STR, CP_OPERATOR_LEN) == 0)
+ {
+ scan += CP_OPERATOR_LEN;
+ if (*scan == c)
+ return scan;
+ while (ISSPACE (*scan))
+ {
+ ++scan;
+ if (*scan == c)
+ return scan;
+ }
+ if (*scan == '\0')
+ break;
+
+ switch (*scan)
+ {
+ /* Skip over one less than the appropriate number of
+ characters: the for loop will skip over the last
+ one. */
+ case '<':
+ if (scan[1] == '<')
+ {
+ scan++;
+ if (*scan == c)
+ return scan;
+ }
+ break;
+ case '>':
+ if (scan[1] == '>')
+ {
+ scan++;
+ if (*scan == c)
+ return scan;
+ }
+ break;
+ }
+ }
+ }
+ }
+
+ return 0;
+}
+
void _initialize_cp_support ();
void
_initialize_cp_support ()