LLDB mainline
CPlusPlusLanguage.h
Go to the documentation of this file.
1//===-- CPlusPlusLanguage.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_SOURCE_PLUGINS_LANGUAGE_CPLUSPLUS_CPLUSPLUSLANGUAGE_H
10#define LLDB_SOURCE_PLUGINS_LANGUAGE_CPLUSPLUS_CPLUSPLUSLANGUAGE_H
11
12#include <set>
13#include <vector>
14
15#include "llvm/ADT/StringRef.h"
16
20#include "lldb/lldb-private.h"
21
22namespace lldb_private {
23
26
27public:
29 public:
31
32 bool ContainsPath(llvm::StringRef path);
33
34 private:
35 /// Returns the Basename of this method without a template parameter
36 /// list, if any.
37 ///
38 // Examples:
39 //
40 // +--------------------------------+---------+
41 // | MethodName | Returns |
42 // +--------------------------------+---------+
43 // | void func() | func |
44 // | void func<int>() | func |
45 // | void func<std::vector<int>>() | func |
46 // +--------------------------------+---------+
47 llvm::StringRef GetBasenameNoTemplateParameters();
48
49 protected:
50 void Parse() override;
51 bool TrySimplifiedParse();
52 };
53
54 CPlusPlusLanguage() = default;
55
56 ~CPlusPlusLanguage() override = default;
57
58 virtual std::unique_ptr<Language::MethodName>
59 GetMethodName(ConstString name) const override;
60
61 std::pair<lldb::FunctionNameType, std::optional<ConstString>>
62 GetFunctionNameInfo(ConstString name) const override;
63
67
68 llvm::StringRef GetUserEntryPointName() const override { return "main"; }
69
70 std::unique_ptr<TypeScavenger> GetTypeScavenger() override;
72
74
76 GetHardcodedSynthetics() override;
77
78 bool IsNilReference(ValueObject &valobj) override;
79
80 llvm::StringRef GetNilReferenceSummaryString() override { return "nullptr"; }
81
82 bool IsSourceFile(llvm::StringRef file_path) const override;
83
84 const Highlighter *GetHighlighter() const override { return &m_highlighter; }
85
86 // Static Functions
87 static void Initialize();
88
89 static void Terminate();
90
92
93 static llvm::StringRef GetPluginNameStatic() { return "cplusplus"; }
94
95 bool SymbolNameFitsToLanguage(Mangled mangled) const override;
96
97 bool DemangledNameContainsPath(llvm::StringRef path,
98 ConstString demangled) const override;
99
102
104 const ExecutionContext *exe_ctx,
105 FunctionNameRepresentation representation,
106 Stream &s) override;
107
109 const ExecutionContext *exe_ctx,
111 Stream &s) override;
112
113 static bool IsCPPMangledName(llvm::StringRef name);
114
115 static llvm::StringRef GetDemangledBasename(llvm::StringRef demangled,
116 const DemangledNameInfo &info);
117
118 static llvm::Expected<llvm::StringRef>
119 GetDemangledTemplateArguments(llvm::StringRef demangled,
120 const DemangledNameInfo &info);
121
122 static llvm::Expected<llvm::StringRef>
123 GetDemangledReturnTypeLHS(llvm::StringRef demangled,
124 const DemangledNameInfo &info);
125
126 static llvm::Expected<llvm::StringRef>
127 GetDemangledFunctionQualifiers(llvm::StringRef demangled,
128 const DemangledNameInfo &info);
129
130 static llvm::Expected<llvm::StringRef>
131 GetDemangledScope(llvm::StringRef demangled, const DemangledNameInfo &info);
132
133 static llvm::Expected<llvm::StringRef>
134 GetDemangledReturnTypeRHS(llvm::StringRef demangled,
135 const DemangledNameInfo &info);
136
137 static llvm::Expected<llvm::StringRef>
138 GetDemangledFunctionArguments(llvm::StringRef demangled,
139 const DemangledNameInfo &info);
140
141 static llvm::Expected<llvm::StringRef>
142 GetDemangledFunctionSuffix(llvm::StringRef demangled,
143 const DemangledNameInfo &info);
144
145 // Extract C++ context and identifier from a string using heuristic matching
146 // (as opposed to
147 // CPlusPlusLanguage::CxxMethodName which has to have a fully qualified C++
148 // name with parens and arguments.
149 // If the name is a lone C identifier (e.g. C) or a qualified C identifier
150 // (e.g. A::B::C) it will return true,
151 // and identifier will be the identifier (C and C respectively) and the
152 // context will be "" and "A::B" respectively.
153 // If the name fails the heuristic matching for a qualified or unqualified
154 // C/C++ identifier, then it will return false
155 // and identifier and context will be unchanged.
156
157 static bool ExtractContextAndIdentifier(const char *name,
158 llvm::StringRef &context,
159 llvm::StringRef &identifier);
160
161 std::vector<ConstString>
162 GenerateAlternateFunctionManglings(const ConstString mangled) const override;
163
165 const Mangled mangled, const SymbolContext &sym_ctx) const override;
166
167 /// Substitutes Itanium type encoding substrings given by \c subst_from
168 /// in \c mangled_name with \c subst_to.
169 ///
170 /// This function will only replace Itanium type encodings (i.e., <type>
171 /// productions in the Itanium ABI mangling grammar). However, no verifiction
172 /// is done on whether \c subst_from or \c subst_to is a valid type encoding.
173 ///
174 /// \param[in] mangled_name Mangled name to perform the substitutions in.
175 /// This function only supports Itanium ABI mangling.
176 ///
177 /// \param[in] subst_from The substring to substitute.
178 ///
179 /// \param[in] subst_to The substring to insert.
180 ///
181 /// \returns The mangled string with substitutions. If no substitutions
182 /// have been made, returns an empty \c ConstString (even if the string
183 /// already contained the substitutions). If an error occurred, this function
184 /// returns the error.
185 ///
186 static llvm::Expected<ConstString>
187 SubstituteType_ItaniumMangle(llvm::StringRef mangled_name,
188 llvm::StringRef subst_from,
189 llvm::StringRef subst_to);
190
191 /// Substitutes Itanium structor encoding substrings given by \c subst_from
192 /// in \c mangled_name with \c subst_to.
193 ///
194 /// This function will only replace Itanium structor encodings (i.e.,
195 /// <ctor-dtor-name> productions in the Itanium ABI mangling grammar).
196 /// However, no verifiction is done on whether \c subst_from or \c subst_to is
197 /// a valid structor encoding.
198 ///
199 /// \param[in] mangled_name Mangled name to perform the substitutions in.
200 /// This function only supports Itanium ABI mangling.
201 ///
202 /// \param[in] subst_from The substring to substitute.
203 ///
204 /// \param[in] subst_to The substring to insert.
205 ///
206 /// \returns The mangled string with substitutions. If no substitutions
207 /// have been made, returns an empty \c ConstString (even if the string
208 /// already contained the substitutions). If an error occurred, this function
209 /// returns the error.
210 ///
211 static llvm::Expected<ConstString>
212 SubstituteStructor_ItaniumMangle(llvm::StringRef mangled_name,
213 llvm::StringRef subst_from,
214 llvm::StringRef subst_to);
215
216 /// Tries replacing Itanium structor encoding substrings in \c mangled_name
217 /// with potential aliases.j
218 ///
219 /// This function will only replace Itanium structor encodings (i.e.,
220 /// <ctor-dtor-name> productions in the Itanium ABI mangling grammar).
221 ///
222 /// E.g., on some platforms, the C1/D1 variants are aliased to the C2/D2
223 /// variants. This function will try to replace occurrences of C1/D1 with
224 /// C2/D2.
225 ///
226 /// \param[in] mangled_name Mangled name to perform the substitutions in.
227 /// This function only supports Itanium ABI mangling.
228 ///
229 /// \returns The mangled string with substitutions. If no substitutions
230 /// have been made, returns an empty \c ConstString (even if the string
231 /// already contained the substitutions). If an error occurred, this function
232 /// returns the error.
233 ///
234 static llvm::Expected<ConstString>
235 SubstituteStructorAliases_ItaniumMangle(llvm::StringRef mangled_name);
236
237 llvm::StringRef GetInstanceVariableName() override { return "this"; }
238
240
241 // PluginInterface protocol
242 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
243
244private:
245 static void DebuggerInitialize(Debugger &);
246};
247
248} // namespace lldb_private
249
250#endif // LLDB_SOURCE_PLUGINS_LANGUAGE_CPLUSPLUS_CPLUSPLUSLANGUAGE_H
llvm::StringRef GetBasenameNoTemplateParameters()
Returns the Basename of this method without a template parameter list, if any.
bool IsNilReference(ValueObject &valobj) override
static llvm::Expected< llvm::StringRef > GetDemangledFunctionQualifiers(llvm::StringRef demangled, const DemangledNameInfo &info)
static llvm::Expected< llvm::StringRef > GetDemangledReturnTypeLHS(llvm::StringRef demangled, const DemangledNameInfo &info)
static llvm::Expected< llvm::StringRef > GetDemangledTemplateArguments(llvm::StringRef demangled, const DemangledNameInfo &info)
bool IsSourceFile(llvm::StringRef file_path) const override
ConstString GetDemangledFunctionNameWithoutArguments(Mangled mangled) const override
llvm::StringRef GetNilReferenceSummaryString() override
Returns the summary string for ValueObjects for which IsNilReference() is true.
const Highlighter * GetHighlighter() const override
lldb::TypeCategoryImplSP GetFormatters() override
static llvm::StringRef GetPluginNameStatic()
FormatEntity::Entry GetFunctionNameFormat() const override
bool SymbolNameFitsToLanguage(Mangled mangled) const override
Returns true iff the given symbol name is compatible with the mangling scheme of this language.
HardcodedFormatters::HardcodedSyntheticFinder GetHardcodedSynthetics() override
lldb::LanguageType GetLanguageType() const override
static llvm::StringRef GetDemangledBasename(llvm::StringRef demangled, const DemangledNameInfo &info)
llvm::StringRef GetPluginName() override
std::vector< ConstString > GenerateAlternateFunctionManglings(const ConstString mangled) const override
static llvm::Expected< ConstString > SubstituteType_ItaniumMangle(llvm::StringRef mangled_name, llvm::StringRef subst_from, llvm::StringRef subst_to)
Substitutes Itanium type encoding substrings given by subst_from in mangled_name with subst_to.
bool GetFunctionDisplayName(const SymbolContext &sc, const ExecutionContext *exe_ctx, FunctionNameRepresentation representation, Stream &s) override
static llvm::Expected< llvm::StringRef > GetDemangledReturnTypeRHS(llvm::StringRef demangled, const DemangledNameInfo &info)
std::pair< lldb::FunctionNameType, std::optional< ConstString > > GetFunctionNameInfo(ConstString name) const override
bool DemangledNameContainsPath(llvm::StringRef path, ConstString demangled) const override
static llvm::Expected< llvm::StringRef > GetDemangledFunctionSuffix(llvm::StringRef demangled, const DemangledNameInfo &info)
ConstString FindBestAlternateFunctionMangledName(const Mangled mangled, const SymbolContext &sym_ctx) const override
llvm::StringRef GetUserEntryPointName() const override
static bool ExtractContextAndIdentifier(const char *name, llvm::StringRef &context, llvm::StringRef &identifier)
static llvm::Expected< llvm::StringRef > GetDemangledFunctionArguments(llvm::StringRef demangled, const DemangledNameInfo &info)
static bool IsCPPMangledName(llvm::StringRef name)
~CPlusPlusLanguage() override=default
static llvm::Expected< llvm::StringRef > GetDemangledScope(llvm::StringRef demangled, const DemangledNameInfo &info)
std::unique_ptr< TypeScavenger > GetTypeScavenger() override
static llvm::Expected< ConstString > SubstituteStructor_ItaniumMangle(llvm::StringRef mangled_name, llvm::StringRef subst_from, llvm::StringRef subst_to)
Substitutes Itanium structor encoding substrings given by subst_from in mangled_name with subst_to.
HardcodedFormatters::HardcodedSummaryFinder GetHardcodedSummaries() override
static lldb_private::Language * CreateInstance(lldb::LanguageType language)
static llvm::Expected< ConstString > SubstituteStructorAliases_ItaniumMangle(llvm::StringRef mangled_name)
Tries replacing Itanium structor encoding substrings in mangled_name with potential aliases....
virtual std::unique_ptr< Language::MethodName > GetMethodName(ConstString name) const override
bool HandleFrameFormatVariable(const SymbolContext &sc, const ExecutionContext *exe_ctx, FormatEntity::Entry::Type type, Stream &s) override
llvm::StringRef GetInstanceVariableName() override
static void DebuggerInitialize(Debugger &)
A uniqued constant string class.
Definition ConstString.h:40
A class to manage flag bits.
Definition Debugger.h:80
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
HardcodedFormatterFinders< SyntheticChildren > HardcodedSyntheticFinder
HardcodedFormatterFinders< TypeSummaryImpl > HardcodedSummaryFinder
Annotates source code with color attributes.
Definition Highlighter.h:91
A class that handles mangled names.
Definition Mangled.h:34
A stream class that can stream formatted output to a file.
Definition Stream.h:28
Defines a symbol context baton that can be handed other debug core functions.
A class that represents a running process on the host machine.
LanguageType
Programming language type.
@ eLanguageTypeC_plus_plus
ISO C++:1998.
std::shared_ptr< lldb_private::TypeCategoryImpl > TypeCategoryImplSP
Stores information about where certain portions of a demangled function name begin and end.