1 //===-- RichManglingContext.h -----------------------------------*- C++ -*-===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #ifndef LLDB_CORE_RICHMANGLINGCONTEXT_H 10 #define LLDB_CORE_RICHMANGLINGCONTEXT_H 11 12 #include "lldb/lldb-forward.h" 13 #include "lldb/lldb-private.h" 14 15 #include "lldb/Target/Language.h" 16 #include "lldb/Utility/ConstString.h" 17 18 #include "llvm/ADT/Any.h" 19 #include "llvm/ADT/SmallString.h" 20 #include "llvm/Demangle/Demangle.h" 21 22 namespace lldb_private { 23 24 /// Uniform wrapper for access to rich mangling information from different 25 /// providers. See Mangled::DemangleWithRichManglingInfo() 26 class RichManglingContext { 27 public: RichManglingContext()28 RichManglingContext() { 29 m_ipd_buf = static_cast<char *>(std::malloc(m_ipd_buf_size)); 30 m_ipd_buf[0] = '\0'; 31 } 32 33 ~RichManglingContext(); 34 35 /// Use the ItaniumPartialDemangler to obtain rich mangling information from 36 /// the given mangled name. 37 bool FromItaniumName(ConstString mangled); 38 39 /// Use the legacy language parser implementation to obtain rich mangling 40 /// information from the given demangled name. 41 bool FromCxxMethodName(ConstString demangled); 42 43 /// If this symbol describes a constructor or destructor. 44 bool IsCtorOrDtor() const; 45 46 /// Get the base name of a function. This doesn't include trailing template 47 /// arguments, ie "a::b<int>" gives "b". 48 llvm::StringRef ParseFunctionBaseName(); 49 50 /// Get the context name for a function. For "a::b::c", this function returns 51 /// "a::b". 52 llvm::StringRef ParseFunctionDeclContextName(); 53 54 /// Get the entire demangled name. 55 llvm::StringRef ParseFullName(); 56 57 private: 58 enum InfoProvider { None, ItaniumPartialDemangler, PluginCxxLanguage }; 59 60 /// Selects the rich mangling info provider. 61 InfoProvider m_provider = None; 62 63 /// Members for ItaniumPartialDemangler 64 llvm::ItaniumPartialDemangler m_ipd; 65 /// Note: m_ipd_buf is a raw pointer due to being resized by realloc via 66 /// ItaniumPartialDemangler. It should be managed with malloc/free, not 67 /// new/delete. 68 char *m_ipd_buf; 69 size_t m_ipd_buf_size = 2048; 70 71 std::unique_ptr<Language::MethodName> m_cxx_method_parser; 72 73 /// Clean up memory when using PluginCxxLanguage 74 void ResetCxxMethodParser(); 75 76 /// Clean up memory and set a new info provider for this instance. 77 void ResetProvider(InfoProvider new_provider); 78 79 /// Uniform handling of string buffers for ItaniumPartialDemangler. 80 llvm::StringRef processIPDStrResult(char *ipd_res, size_t res_len); 81 }; 82 83 } // namespace lldb_private 84 85 #endif 86