Use unique_xmalloc_ptr<char> when demangling

I noticed that some methods in language_defn could use
unique_xmalloc_ptr<char> rather than a plain 'char *'.  This patch
implements this change, fixing up the fallout and changing
gdb_demangle to also return this type.  In one spot, std::string is
used to simplify some related code, and in another, an auto_obstack is
used to avoid manual management.

Regression tested on x86-64 Fedora 34.
This commit is contained in:
Tom Tromey
2021-10-04 08:44:22 -06:00
parent e133de4984
commit 3456e70c9d
23 changed files with 118 additions and 136 deletions

View File

@@ -189,7 +189,7 @@ gnuv2_value_rtti_type (struct value *v, int *full, LONGEST *top, int *using_enc)
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;
@@ -248,14 +248,15 @@ gnuv2_value_rtti_type (struct value *v, int *full, LONGEST *top, int *using_enc)
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;