Index: lldb/include/lldb/Core/RichManglingContext.h =================================================================== --- lldb/include/lldb/Core/RichManglingContext.h +++ lldb/include/lldb/Core/RichManglingContext.h @@ -43,25 +43,15 @@ bool IsCtorOrDtor() const; /// Get the base name of a function. This doesn't include trailing template - /// arguments, ie "a::b" gives "b". The result will overwrite the - /// internal buffer. It can be obtained via GetBufferRef(). - void ParseFunctionBaseName(); + /// arguments, ie "a::b" gives "b". + llvm::StringRef ParseFunctionBaseName(); /// Get the context name for a function. For "a::b::c", this function returns - /// "a::b". The result will overwrite the internal buffer. It can be obtained - /// via GetBufferRef(). - void ParseFunctionDeclContextName(); - - /// Get the entire demangled name. The result will overwrite the internal - /// buffer. It can be obtained via GetBufferRef(). - void ParseFullName(); - - /// Obtain a StringRef to the internal buffer that holds the result of the - /// most recent ParseXy() operation. The next ParseXy() call invalidates it. - llvm::StringRef GetBufferRef() const { - assert(m_provider != None && "Initialize a provider first"); - return m_buffer; - } + /// "a::b". + llvm::StringRef ParseFunctionDeclContextName(); + + /// Get the entire demangled name. + llvm::StringRef ParseFullName(); private: enum InfoProvider { None, ItaniumPartialDemangler, PluginCxxLanguage }; @@ -69,9 +59,6 @@ /// Selects the rich mangling info provider. InfoProvider m_provider = None; - /// Reference to the buffer used for results of ParseXy() operations. - llvm::StringRef m_buffer; - /// Members for ItaniumPartialDemangler llvm::ItaniumPartialDemangler m_ipd; /// Note: m_ipd_buf is a raw pointer due to being resized by realloc via @@ -93,7 +80,7 @@ void ResetProvider(InfoProvider new_provider); /// Uniform handling of string buffers for ItaniumPartialDemangler. - void processIPDStrResult(char *ipd_res, size_t res_len); + llvm::StringRef processIPDStrResult(char *ipd_res, size_t res_len); /// Cast the given parser to the given type. Ideally we would have a type /// trait to deduce \a ParserT from a given InfoProvider, but unfortunately we Index: lldb/source/Core/Mangled.cpp =================================================================== --- lldb/source/Core/Mangled.cpp +++ lldb/source/Core/Mangled.cpp @@ -217,8 +217,7 @@ if (context.FromItaniumName(m_mangled)) { // If we got an info, we have a name. Copy to string pool and connect the // counterparts to accelerate later access in GetDemangledName(). - context.ParseFullName(); - m_demangled.SetStringWithMangledCounterpart(context.GetBufferRef(), + m_demangled.SetStringWithMangledCounterpart(context.ParseFullName(), m_mangled); return true; } else { Index: lldb/source/Core/RichManglingContext.cpp =================================================================== --- lldb/source/Core/RichManglingContext.cpp +++ lldb/source/Core/RichManglingContext.cpp @@ -80,15 +80,15 @@ llvm_unreachable("Fully covered switch above!"); } -void RichManglingContext::processIPDStrResult(char *ipd_res, size_t res_size) { +llvm::StringRef RichManglingContext::processIPDStrResult(char *ipd_res, + size_t res_size) { // Error case: Clear the buffer. if (LLVM_UNLIKELY(ipd_res == nullptr)) { assert(res_size == m_ipd_buf_size && "Failed IPD queries keep the original size in the N parameter"); m_ipd_buf[0] = '\0'; - m_buffer = llvm::StringRef(m_ipd_buf, 0); - return; + return llvm::StringRef(m_ipd_buf, 0); } // IPD's res_size includes null terminator. @@ -106,60 +106,54 @@ } // 99% case: Just remember the string length. - m_buffer = llvm::StringRef(m_ipd_buf, res_size - 1); + return llvm::StringRef(m_ipd_buf, res_size - 1); } -void RichManglingContext::ParseFunctionBaseName() { +llvm::StringRef RichManglingContext::ParseFunctionBaseName() { assert(m_provider != None && "Initialize a provider first"); switch (m_provider) { case ItaniumPartialDemangler: { auto n = m_ipd_buf_size; auto buf = m_ipd.getFunctionBaseName(m_ipd_buf, &n); - processIPDStrResult(buf, n); - return; + return processIPDStrResult(buf, n); } case PluginCxxLanguage: - m_buffer = - get(m_cxx_method_parser)->GetBasename(); - return; + return get(m_cxx_method_parser) + ->GetBasename(); case None: - return; + return {}; } } -void RichManglingContext::ParseFunctionDeclContextName() { +llvm::StringRef RichManglingContext::ParseFunctionDeclContextName() { assert(m_provider != None && "Initialize a provider first"); switch (m_provider) { case ItaniumPartialDemangler: { auto n = m_ipd_buf_size; auto buf = m_ipd.getFunctionDeclContextName(m_ipd_buf, &n); - processIPDStrResult(buf, n); - return; + return processIPDStrResult(buf, n); } case PluginCxxLanguage: - m_buffer = - get(m_cxx_method_parser)->GetContext(); - return; + return get(m_cxx_method_parser) + ->GetContext(); case None: - return; + return {}; } } -void RichManglingContext::ParseFullName() { +llvm::StringRef RichManglingContext::ParseFullName() { assert(m_provider != None && "Initialize a provider first"); switch (m_provider) { case ItaniumPartialDemangler: { auto n = m_ipd_buf_size; auto buf = m_ipd.finishDemangle(m_ipd_buf, &n); - processIPDStrResult(buf, n); - return; + return processIPDStrResult(buf, n); } case PluginCxxLanguage: - m_buffer = get(m_cxx_method_parser) - ->GetFullName() - .GetStringRef(); - return; + return get(m_cxx_method_parser) + ->GetFullName() + .GetStringRef(); case None: - return; + return {}; } } Index: lldb/source/Symbol/Symtab.cpp =================================================================== --- lldb/source/Symbol/Symtab.cpp +++ lldb/source/Symbol/Symtab.cpp @@ -383,16 +383,13 @@ std::vector> &backlog, RichManglingContext &rmc) { // Only register functions that have a base name. - rmc.ParseFunctionBaseName(); - llvm::StringRef base_name = rmc.GetBufferRef(); + llvm::StringRef base_name = rmc.ParseFunctionBaseName(); if (base_name.empty()) return; // The base name will be our entry's name. NameToIndexMap::Entry entry(ConstString(base_name), value); - - rmc.ParseFunctionDeclContextName(); - llvm::StringRef decl_context = rmc.GetBufferRef(); + llvm::StringRef decl_context = rmc.ParseFunctionDeclContextName(); // Register functions with no context. if (decl_context.empty()) {