diff options
author | Tom Tromey <tromey@adacore.com> | 2021-10-04 08:44:22 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2021-10-04 13:45:38 -0600 |
commit | 3456e70c9d69da8d62a0ea1f8c2e643648afc654 (patch) | |
tree | 7959a8dc460685d2e8e3197478eddb4430d48708 /gdb/go-lang.c | |
parent | e133de4984cef9acb32fd756c607aa2fa1d090fb (diff) | |
download | binutils-3456e70c9d69da8d62a0ea1f8c2e643648afc654.zip binutils-3456e70c9d69da8d62a0ea1f8c2e643648afc654.tar.gz binutils-3456e70c9d69da8d62a0ea1f8c2e643648afc654.tar.bz2 |
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.
Diffstat (limited to 'gdb/go-lang.c')
-rw-r--r-- | gdb/go-lang.c | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/gdb/go-lang.c b/gdb/go-lang.c index 72c5d88..75cd38d 100644 --- a/gdb/go-lang.c +++ b/gdb/go-lang.c @@ -333,12 +333,9 @@ unpack_mangled_go_symbol (const char *mangled_name, 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; @@ -348,15 +345,16 @@ go_language::demangle_symbol (const char *mangled_name, int options) const 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) @@ -380,10 +378,7 @@ go_language::demangle_symbol (const char *mangled_name, int options) const } 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. |