return *resultp;
}
-static char *
-ada_la_decode (const char *encoded, int options)
-{
- return xstrdup (ada_decode (encoded).c_str ());
-}
-
\f
/* Arrays */
}
/* See language.h. */
- bool sniff_from_mangled_name (const char *mangled,
- char **out) const override
+ bool sniff_from_mangled_name
+ (const char *mangled,
+ gdb::unique_xmalloc_ptr<char> *out) const override
{
std::string demangled = ada_decode (mangled);
/* See language.h. */
- char *demangle_symbol (const char *mangled, int options) const override
+ gdb::unique_xmalloc_ptr<char> demangle_symbol (const char *mangled,
+ int options) const override
{
- return ada_la_decode (mangled, options);
+ return make_unique_xstrdup (ada_decode (mangled).c_str ());
}
/* See language.h. */
}
/* See language.h. */
- bool sniff_from_mangled_name (const char *mangled,
- char **demangled) const override
+ bool sniff_from_mangled_name
+ (const char *mangled,
+ gdb::unique_xmalloc_ptr<char> *demangled) const override
{
*demangled = gdb_demangle (mangled, DMGL_PARAMS | DMGL_ANSI);
return *demangled != NULL;
/* See language.h. */
- char *demangle_symbol (const char *mangled, int options) const override
+ gdb::unique_xmalloc_ptr<char> demangle_symbol (const char *mangled,
+ int options) const override
{
return gdb_demangle (mangled, options);
}
form. Even the author of this function feels that writing little
parsers like this everywhere is stupid. */
-static char *
-remove_qualifiers (char *qid)
+static const char *
+remove_qualifiers (const char *qid)
{
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. */
char *parenstack = (char *) alloca (strlen (qid));
- char *scan;
- char *last = 0; /* The character after the rightmost
+ const char *scan;
+ const char *last = 0; /* The character after the rightmost
`::' token we've seen so far. */
for (scan = qid; *scan; scan++)
{
const char *mangled_name;
gdb::unique_xmalloc_ptr<char> mangled_name_holder;
- char *demangled_name;
const char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
int is_full_physname_constructor =
TYPE_FN_FIELD_CONSTRUCTOR (f, j)
else
mangled_name = TYPE_FN_FIELD_PHYSNAME (f, j);
- demangled_name =
- gdb_demangle (mangled_name,
- DMGL_ANSI | DMGL_PARAMS);
+ gdb::unique_xmalloc_ptr<char> demangled_name
+ = gdb_demangle (mangled_name,
+ DMGL_ANSI | DMGL_PARAMS);
if (demangled_name == NULL)
{
/* In some cases (for instance with the HP
}
else
{
- char *p;
- char *demangled_no_class
- = remove_qualifiers (demangled_name);
+ const char *p;
+ const char *demangled_no_class
+ = remove_qualifiers (demangled_name.get ());
/* Get rid of the `static' appended by the
demangler. */
if (p != NULL)
{
int length = p - demangled_no_class;
- char *demangled_no_static;
-
- demangled_no_static
- = (char *) xmalloc (length + 1);
- strncpy (demangled_no_static,
- demangled_no_class, length);
- *(demangled_no_static + length) = '\0';
- fputs_filtered (demangled_no_static, stream);
- xfree (demangled_no_static);
+ std::string demangled_no_static (demangled_no_class,
+ length);
+ fputs_filtered (demangled_no_static.c_str (), stream);
}
else
fputs_filtered (demangled_no_class, stream);
- xfree (demangled_name);
}
fprintf_filtered (stream, ";\n");
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 ();
}
/* 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)
/* A wrapper for bfd_demangle. */
-char *gdb_demangle (const char *name, int options);
+gdb::unique_xmalloc_ptr<char> gdb_demangle (const char *name, int options);
#endif /* CP_SUPPORT_H */
/* Implements the la_demangle language_defn routine for language D. */
-char *
+gdb::unique_xmalloc_ptr<char>
d_demangle (const char *symbol, int options)
{
return gdb_demangle (symbol, options | DMGL_DLANG);
}
/* See language.h. */
- bool sniff_from_mangled_name (const char *mangled,
- char **demangled) const override
+ bool sniff_from_mangled_name
+ (const char *mangled,
+ gdb::unique_xmalloc_ptr<char> *demangled) const override
{
*demangled = d_demangle (mangled, 0);
return *demangled != NULL;
/* See language.h. */
- char *demangle_symbol (const char *mangled, int options) const override
+ gdb::unique_xmalloc_ptr<char> demangle_symbol (const char *mangled,
+ int options) const override
{
return d_demangle (mangled, options);
}
extern const char *d_main_name (void);
-extern char *d_demangle (const char *mangled, int options);
+extern gdb::unique_xmalloc_ptr<char> d_demangle (const char *mangled,
+ int options);
extern const struct builtin_d_type *builtin_d_type (struct gdbarch *);
to look up their definition from their declaration so
the only disadvantage remains the minimal symbol variant
`long name(params)' does not have the proper inferior type. */
- demangled.reset (gdb_demangle (mangled,
- (DMGL_PARAMS | DMGL_ANSI
- | DMGL_RET_DROP)));
+ demangled = gdb_demangle (mangled, (DMGL_PARAMS | DMGL_ANSI
+ | DMGL_RET_DROP));
}
if (demangled)
canon = demangled.get ();
/* See language.h. */
- char *demangle_symbol (const char *mangled, int options) const override
+ gdb::unique_xmalloc_ptr<char> demangle_symbol (const char *mangled,
+ int options) const override
{
/* We could support demangling here to provide module namespaces
also for inferiors with only minimal symbol table (ELF symbols).
static void
demangle_command (const char *args, int from_tty)
{
- char *demangled;
const char *name;
const char *arg_start;
int processing_args = 1;
else
lang = current_language;
- demangled = language_demangle (lang, name, DMGL_ANSI | DMGL_PARAMS);
+ gdb::unique_xmalloc_ptr<char> demangled
+ = language_demangle (lang, name, DMGL_ANSI | DMGL_PARAMS);
if (demangled != NULL)
- {
- printf_filtered ("%s\n", demangled);
- xfree (demangled);
- }
+ printf_filtered ("%s\n", demangled.get ());
else
error (_("Can't demangle \"%s\""), name);
}
struct gdbarch *gdbarch = type->arch ();
struct fn_field *f;
char *mangled_name = gdb_mangle_name (type, method_id, signature_id);
- char *demangled_name = gdb_demangle (mangled_name,
- DMGL_PARAMS | DMGL_ANSI);
+ gdb::unique_xmalloc_ptr<char> demangled_name
+ = gdb_demangle (mangled_name, DMGL_PARAMS | DMGL_ANSI);
char *argtypetext, *p;
int depth = 0, argcount = 1;
struct field *argtypes;
/* Make sure we got back a function string that we can use. */
if (demangled_name)
- p = strchr (demangled_name, '(');
+ p = strchr (demangled_name.get (), '(');
else
p = NULL;
argtypes, argcount, p[-2] == '.');
mtype->set_is_stub (false);
TYPE_FN_FIELD_STUB (f, signature_id) = 0;
-
- xfree (demangled_name);
}
/* This is the external interface to check_stub_method, above. This
struct type *rtti_type;
CORE_ADDR vtbl;
struct bound_minimal_symbol minsym;
- char *demangled_name, *p;
+ char *p;
const char *linkage_name;
struct type *btype;
struct type *known_type_vptr_basetype;
return NULL;
/* If we just skip the prefix, we get screwed by namespaces. */
- demangled_name=gdb_demangle(linkage_name,DMGL_PARAMS|DMGL_ANSI);
- p = strchr (demangled_name, ' ');
+ gdb::unique_xmalloc_ptr<char> demangled_name
+ = gdb_demangle(linkage_name,DMGL_PARAMS|DMGL_ANSI);
+ p = strchr (demangled_name.get (), ' ');
if (p)
*p = '\0';
/* Lookup the type for the name. */
/* FIXME: chastain/2003-11-26: block=NULL is bogus. See pr gdb/1465. */
- rtti_type = cp_lookup_rtti_type (demangled_name, NULL);
+ rtti_type = cp_lookup_rtti_type (demangled_name.get (), NULL);
if (rtti_type == NULL)
return NULL;
possible paths to the method based on the adjustment. */
if (physname)
{
- char *demangled_name = gdb_demangle (physname,
- DMGL_ANSI | DMGL_PARAMS);
+ gdb::unique_xmalloc_ptr<char> demangled_name
+ = gdb_demangle (physname, DMGL_ANSI | DMGL_PARAMS);
fprintf_filtered (stream, "&virtual ");
if (demangled_name == NULL)
fputs_filtered (physname, stream);
else
- {
- fputs_filtered (demangled_name, stream);
- xfree (demangled_name);
- }
+ fputs_filtered (demangled_name.get (), stream);
return;
}
}
This demangler can't work in all situations,
thus not too much effort is currently put into it. */
-char *
+gdb::unique_xmalloc_ptr<char>
go_language::demangle_symbol (const char *mangled_name, int options) const
{
- struct obstack tempbuf;
- char *result;
- char *name_buf;
const char *package_name;
const char *object_name;
const char *method_type_package_name;
if (mangled_name == NULL)
return NULL;
- name_buf = unpack_mangled_go_symbol (mangled_name,
- &package_name, &object_name,
- &method_type_package_name,
- &method_type_object_name,
- &method_type_is_pointer);
+ gdb::unique_xmalloc_ptr<char> name_buf
+ (unpack_mangled_go_symbol (mangled_name,
+ &package_name, &object_name,
+ &method_type_package_name,
+ &method_type_object_name,
+ &method_type_is_pointer));
if (name_buf == NULL)
return NULL;
- obstack_init (&tempbuf);
+ auto_obstack tempbuf;
/* Print methods as they appear in "method expressions". */
if (method_type_package_name != NULL)
}
obstack_grow_str0 (&tempbuf, "");
- result = xstrdup ((const char *) obstack_finish (&tempbuf));
- obstack_free (&tempbuf, NULL);
- xfree (name_buf);
- return result;
+ return make_unique_xstrdup ((const char *) obstack_finish (&tempbuf));
}
/* Given a Go symbol, return its package or NULL if unknown.
/* See language.h. */
- bool sniff_from_mangled_name (const char *mangled,
- char **demangled) const override
+ bool sniff_from_mangled_name
+ (const char *mangled, gdb::unique_xmalloc_ptr<char> *demangled)
+ const override
{
*demangled = demangle_symbol (mangled, 0);
return *demangled != NULL;
/* See language.h. */
- char *demangle_symbol (const char *mangled, int options) const override;
+ gdb::unique_xmalloc_ptr<char> demangle_symbol (const char *mangled,
+ int options) const override;
/* See language.h. */
more flexible demangler for the languages that need it.
FIXME: Sometimes the demangler is invoked when we don't know the
language, so we can't use this everywhere. */
-char *
+gdb::unique_xmalloc_ptr<char>
language_demangle (const struct language_defn *current_language,
const char *mangled, int options)
{
/* See language.h. */
- char *demangle_symbol (const char *mangled, int options) const override
+ gdb::unique_xmalloc_ptr<char> demangle_symbol (const char *mangled,
+ int options) const override
{
/* The auto language just uses the C++ demangler. */
return gdb_demangle (mangled, options);
The resulting string should be of the form that will be
installed into a symbol. */
- virtual bool sniff_from_mangled_name (const char *mangled,
- char **demangled) const
+ virtual bool sniff_from_mangled_name
+ (const char *mangled, gdb::unique_xmalloc_ptr<char> *demangled) const
{
*demangled = nullptr;
return false;
}
/* Return demangled language symbol version of MANGLED, or NULL. */
- virtual char *demangle_symbol (const char *mangled, int options) const
+ virtual gdb::unique_xmalloc_ptr<char> demangle_symbol (const char *mangled,
+ int options) const
{
return nullptr;
}
extern CORE_ADDR skip_language_trampoline (struct frame_info *, CORE_ADDR pc);
/* Return demangled language symbol, or NULL. */
-extern char *language_demangle (const struct language_defn *current_language,
- const char *mangled, int options);
+extern gdb::unique_xmalloc_ptr<char> language_demangle
+ (const struct language_defn *current_language,
+ const char *mangled, int options);
/* Return information about whether TYPE should be passed
(and returned) by reference at the language level. */
if (!msym->name_set)
{
/* This will be freed later, by compute_and_set_names. */
- char *demangled_name
+ gdb::unique_xmalloc_ptr<char> demangled_name
= symbol_find_demangled_name (msym, msym->linkage_name ());
msym->set_demangled_name
- (demangled_name, &m_objfile->per_bfd->storage_obstack);
+ (demangled_name.release (),
+ &m_objfile->per_bfd->storage_obstack);
msym->name_set = 1;
}
/* This mangled_name_hash computation has to be outside of
}
/* See language.h. */
- bool sniff_from_mangled_name (const char *mangled,
- char **demangled) const override
+ bool sniff_from_mangled_name
+ (const char *mangled, gdb::unique_xmalloc_ptr<char> *demangled)
+ const override
{
*demangled = demangle_symbol (mangled, 0);
return *demangled != NULL;
/* See language.h. */
- char *demangle_symbol (const char *mangled, int options) const override;
+ gdb::unique_xmalloc_ptr<char> demangle_symbol (const char *mangled,
+ int options) const override;
/* See language.h. */
/* See declaration of objc_language::demangle_symbol above. */
-char *
+gdb::unique_xmalloc_ptr<char>
objc_language::demangle_symbol (const char *mangled, int options) const
{
char *demangled, *cp;
*cp++ = ']'; /* closing right brace */
*cp++ = 0; /* string terminator */
- return demangled;
+ return gdb::unique_xmalloc_ptr<char> (demangled);
}
else
return nullptr; /* Not an objc mangled name. */
/* See language.h. */
- bool sniff_from_mangled_name (const char *mangled,
- char **demangled) const override
+ bool sniff_from_mangled_name
+ (const char *mangled, gdb::unique_xmalloc_ptr<char> *demangled)
+ const override
{
*demangled = gdb_demangle (mangled, DMGL_PARAMS | DMGL_ANSI);
return *demangled != NULL;
/* See language.h. */
- char *demangle_symbol (const char *mangled, int options) const override
+ gdb::unique_xmalloc_ptr<char> demangle_symbol (const char *mangled,
+ int options) const override
{
return gdb_demangle (mangled, options);
}
/* See symtab.h */
-char *
+gdb::unique_xmalloc_ptr<char>
symbol_find_demangled_name (struct general_symbol_info *gsymbol,
const char *mangled)
{
- char *demangled = NULL;
+ gdb::unique_xmalloc_ptr<char> demangled;
int i;
if (gsymbol->language () == language_unknown)
linkage_name_copy = linkage_name;
if (demangled_name.get () == nullptr)
- demangled_name.reset
- (symbol_find_demangled_name (this, linkage_name_copy.data ()));
+ demangled_name
+ = symbol_find_demangled_name (this, linkage_name_copy.data ());
/* Suppose we have demangled_name==NULL, copy_name==0, and
linkage_name_copy==linkage_name. In this case, we already have the
lookup, so we can always binary search. */
if (lang == language_cplus)
{
- char *demangled_name = gdb_demangle (name, DMGL_ANSI | DMGL_PARAMS);
+ gdb::unique_xmalloc_ptr<char> demangled_name
+ = gdb_demangle (name, DMGL_ANSI | DMGL_PARAMS);
if (demangled_name != NULL)
- return storage.set_malloc_ptr (demangled_name);
+ return storage.set_malloc_ptr (std::move (demangled_name));
/* If we were given a non-mangled name, canonicalize it
according to the language (so far only for C++). */
}
else if (lang == language_d)
{
- char *demangled_name = d_demangle (name, 0);
+ gdb::unique_xmalloc_ptr<char> demangled_name = d_demangle (name, 0);
if (demangled_name != NULL)
- return storage.set_malloc_ptr (demangled_name);
+ return storage.set_malloc_ptr (std::move (demangled_name));
}
else if (lang == language_go)
{
- char *demangled_name
+ gdb::unique_xmalloc_ptr<char> demangled_name
= language_def (language_go)->demangle_symbol (name, 0);
if (demangled_name != NULL)
- return storage.set_malloc_ptr (demangled_name);
+ return storage.set_malloc_ptr (std::move (demangled_name));
}
return name;
then set the language appropriately. The returned name is allocated
by the demangler and should be xfree'd. */
-extern char *symbol_find_demangled_name (struct general_symbol_info *gsymbol,
- const char *mangled);
+extern gdb::unique_xmalloc_ptr<char> symbol_find_demangled_name
+ (struct general_symbol_info *gsymbol, const char *mangled);
/* Return true if NAME matches the "search" name of SYMBOL, according
to the symbol's language. */
fprintf_symbol_filtered (struct ui_file *stream, const char *name,
enum language lang, int arg_mode)
{
- char *demangled;
-
if (name != NULL)
{
/* If user wants to see raw output, no problem. */
}
else
{
- demangled = language_demangle (language_def (lang), name, arg_mode);
- fputs_filtered (demangled ? demangled : name, stream);
- if (demangled != NULL)
- {
- xfree (demangled);
- }
+ gdb::unique_xmalloc_ptr<char> demangled
+ = language_demangle (language_def (lang), name, arg_mode);
+ fputs_filtered (demangled ? demangled.get () : name, stream);
}
}
}