LLDB  mainline
RichManglingContext.h
Go to the documentation of this file.
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 
16 
17 #include "llvm/ADT/Any.h"
18 #include "llvm/ADT/SmallString.h"
19 #include "llvm/Demangle/Demangle.h"
20 
21 namespace lldb_private {
22 
23 /// Uniform wrapper for access to rich mangling information from different
24 /// providers. See Mangled::DemangleWithRichManglingInfo()
26 public:
28  m_ipd_buf = static_cast<char *>(std::malloc(m_ipd_buf_size));
29  m_ipd_buf[0] = '\0';
30  }
31 
33 
34  /// Use the ItaniumPartialDemangler to obtain rich mangling information from
35  /// the given mangled name.
36  bool FromItaniumName(ConstString mangled);
37 
38  /// Use the legacy language parser implementation to obtain rich mangling
39  /// information from the given demangled name.
40  bool FromCxxMethodName(ConstString demangled);
41 
42  /// If this symbol describes a constructor or destructor.
43  bool IsCtorOrDtor() const;
44 
45  /// Get the base name of a function. This doesn't include trailing template
46  /// arguments, ie "a::b<int>" gives "b". The result will overwrite the
47  /// internal buffer. It can be obtained via GetBufferRef().
48  void ParseFunctionBaseName();
49 
50  /// Get the context name for a function. For "a::b::c", this function returns
51  /// "a::b". The result will overwrite the internal buffer. It can be obtained
52  /// via GetBufferRef().
54 
55  /// Get the entire demangled name. The result will overwrite the internal
56  /// buffer. It can be obtained via GetBufferRef().
57  void ParseFullName();
58 
59  /// Obtain a StringRef to the internal buffer that holds the result of the
60  /// most recent ParseXy() operation. The next ParseXy() call invalidates it.
61  llvm::StringRef GetBufferRef() const {
62  assert(m_provider != None && "Initialize a provider first");
63  return m_buffer;
64  }
65 
66 private:
68 
69  /// Selects the rich mangling info provider.
71 
72  /// Reference to the buffer used for results of ParseXy() operations.
73  llvm::StringRef m_buffer;
74 
75  /// Members for ItaniumPartialDemangler
76  llvm::ItaniumPartialDemangler m_ipd;
77  /// Note: m_ipd_buf is a raw pointer due to being resized by realloc via
78  /// ItaniumPartialDemangler. It should be managed with malloc/free, not
79  /// new/delete.
80  char *m_ipd_buf;
81  size_t m_ipd_buf_size = 2048;
82 
83  /// Members for PluginCxxLanguage
84  /// Cannot forward declare inner class CPlusPlusLanguage::MethodName. The
85  /// respective header is in Plugins and including it from here causes cyclic
86  /// dependency. Instead keep a llvm::Any and cast it on-access in the cpp.
88 
89  /// Clean up memory when using PluginCxxLanguage
90  void ResetCxxMethodParser();
91 
92  /// Clean up memory and set a new info provider for this instance.
93  void ResetProvider(InfoProvider new_provider);
94 
95  /// Uniform handling of string buffers for ItaniumPartialDemangler.
96  void processIPDStrResult(char *ipd_res, size_t res_len);
97 
98  /// Cast the given parser to the given type. Ideally we would have a type
99  /// trait to deduce \a ParserT from a given InfoProvider, but unfortunately we
100  /// can't access CPlusPlusLanguage::MethodName from within the header.
101  template <class ParserT> static ParserT *get(llvm::Any parser) {
102  assert(parser.hasValue());
103  assert(llvm::any_isa<ParserT *>(parser));
104  return llvm::any_cast<ParserT *>(parser);
105  }
106 };
107 
108 } // namespace lldb_private
109 
110 #endif
lldb_private::RichManglingContext::None
@ None
Definition: RichManglingContext.h:67
lldb_private::RichManglingContext::FromCxxMethodName
bool FromCxxMethodName(ConstString demangled)
Use the legacy language parser implementation to obtain rich mangling information from the given dema...
Definition: RichManglingContext.cpp:63
lldb_private::RichManglingContext::IsCtorOrDtor
bool IsCtorOrDtor() const
If this symbol describes a constructor or destructor.
Definition: RichManglingContext.cpp:69
lldb_private::RichManglingContext::m_ipd_buf_size
size_t m_ipd_buf_size
Definition: RichManglingContext.h:81
lldb_private::RichManglingContext::InfoProvider
InfoProvider
Definition: RichManglingContext.h:67
lldb_private::RichManglingContext::ResetProvider
void ResetProvider(InfoProvider new_provider)
Clean up memory and set a new info provider for this instance.
Definition: RichManglingContext.cpp:37
lldb_private::RichManglingContext::ParseFunctionBaseName
void ParseFunctionBaseName()
Get the base name of a function.
Definition: RichManglingContext.cpp:115
lldb_private::RichManglingContext::ParseFunctionDeclContextName
void ParseFunctionDeclContextName()
Get the context name for a function.
Definition: RichManglingContext.cpp:133
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::RichManglingContext::RichManglingContext
RichManglingContext()
Definition: RichManglingContext.h:27
lldb_private::RichManglingContext::get
static ParserT * get(llvm::Any parser)
Cast the given parser to the given type.
Definition: RichManglingContext.h:101
lldb_private::RichManglingContext::m_cxx_method_parser
llvm::Any m_cxx_method_parser
Members for PluginCxxLanguage Cannot forward declare inner class CPlusPlusLanguage::MethodName.
Definition: RichManglingContext.h:87
lldb-private.h
lldb_private::RichManglingContext::m_provider
InfoProvider m_provider
Selects the rich mangling info provider.
Definition: RichManglingContext.h:70
lldb_private::RichManglingContext
Uniform wrapper for access to rich mangling information from different providers.
Definition: RichManglingContext.h:25
lldb_private::RichManglingContext::~RichManglingContext
~RichManglingContext()
Definition: RichManglingContext.cpp:22
lldb_private::RichManglingContext::m_buffer
llvm::StringRef m_buffer
Reference to the buffer used for results of ParseXy() operations.
Definition: RichManglingContext.h:73
lldb_private::RichManglingContext::ResetCxxMethodParser
void ResetCxxMethodParser()
Clean up memory when using PluginCxxLanguage.
Definition: RichManglingContext.cpp:27
lldb_private::RichManglingContext::GetBufferRef
llvm::StringRef GetBufferRef() const
Obtain a StringRef to the internal buffer that holds the result of the most recent ParseXy() operatio...
Definition: RichManglingContext.h:61
lldb_private::RichManglingContext::ParseFullName
void ParseFullName()
Get the entire demangled name.
Definition: RichManglingContext.cpp:151
lldb_private::RichManglingContext::FromItaniumName
bool FromItaniumName(ConstString mangled)
Use the ItaniumPartialDemangler to obtain rich mangling information from the given mangled name.
Definition: RichManglingContext.cpp:44
lldb_private::RichManglingContext::ItaniumPartialDemangler
@ ItaniumPartialDemangler
Definition: RichManglingContext.h:67
lldb-forward.h
lldb_private::RichManglingContext::m_ipd
llvm::ItaniumPartialDemangler m_ipd
Members for ItaniumPartialDemangler.
Definition: RichManglingContext.h:76
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::RichManglingContext::m_ipd_buf
char * m_ipd_buf
Note: m_ipd_buf is a raw pointer due to being resized by realloc via ItaniumPartialDemangler.
Definition: RichManglingContext.h:80
lldb_private::RichManglingContext::processIPDStrResult
void processIPDStrResult(char *ipd_res, size_t res_len)
Uniform handling of string buffers for ItaniumPartialDemangler.
Definition: RichManglingContext.cpp:86
ConstString.h
lldb_private::RichManglingContext::PluginCxxLanguage
@ PluginCxxLanguage
Definition: RichManglingContext.h:67