aboutsummaryrefslogtreecommitdiff
path: root/gdb/symtab.h
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/symtab.h')
-rw-r--r--gdb/symtab.h39
1 files changed, 37 insertions, 2 deletions
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 9b1dbb4..a6bf655 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1637,8 +1637,43 @@ void iterate_over_symbols (const struct block *block, const char *name,
symbol_found_callback_ftype *callback,
void *data);
-struct cleanup *demangle_for_lookup (const char *name, enum language lang,
- const char **result_name);
+/* Storage type used by demangle_for_lookup. demangle_for_lookup
+ either returns a const char * pointer that points to either of the
+ fields of this type, or a pointer to the input NAME. This is done
+ this way because the underlying functions that demangle_for_lookup
+ calls either return a std::string (e.g., cp_canonicalize_string) or
+ a malloc'ed buffer (libiberty's demangled), and we want to avoid
+ unnecessary reallocation/string copying. */
+class demangle_result_storage
+{
+public:
+
+ /* Swap the std::string storage with STR, and return a pointer to
+ the beginning of the new string. */
+ const char *swap_string (std::string &str)
+ {
+ std::swap (m_string, str);
+ return m_string.c_str ();
+ }
+
+ /* Set the malloc storage to now point at PTR. Any previous malloc
+ storage is released. */
+ const char *set_malloc_ptr (char *ptr)
+ {
+ m_malloc.reset (ptr);
+ return ptr;
+ }
+
+private:
+
+ /* The storage. */
+ std::string m_string;
+ gdb::unique_xmalloc_ptr<char> m_malloc;
+};
+
+const char *
+ demangle_for_lookup (const char *name, enum language lang,
+ demangle_result_storage &storage);
struct symbol *allocate_symbol (struct objfile *);