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
19#include "lldb/lldb-private.h"
20
21namespace lldb_private {
22
24public:
26 public:
27 CxxMethodName(std::string s) : Language::MethodName(std::move(s)) {}
28
29 bool ContainsPath(llvm::StringRef path);
30
31 private:
32 /// Returns the Basename of this method without a template parameter
33 /// list, if any.
34 ///
35 // Examples:
36 //
37 // +--------------------------------+---------+
38 // | MethodName | Returns |
39 // +--------------------------------+---------+
40 // | void func() | func |
41 // | void func<int>() | func |
42 // | void func<std::vector<int>>() | func |
43 // +--------------------------------+---------+
44 llvm::StringRef GetBasenameNoTemplateParameters();
45
46 protected:
47 void Parse() override;
48 bool TrySimplifiedParse();
49 };
50
51 CPlusPlusLanguage() = default;
52
53 ~CPlusPlusLanguage() override = default;
54
55 virtual std::unique_ptr<Language::MethodName>
56 GetMethodName(llvm::StringRef name) const override;
57
58 std::pair<lldb::FunctionNameType, std::optional<ConstString>>
59 GetFunctionNameInfo(ConstString name) const override;
60
64
65 llvm::StringRef GetUserEntryPointName() const override { return "main"; }
66
67 std::unique_ptr<TypeScavenger> GetTypeScavenger() override;
69
70 std::vector<lldb::LanguageType>
71 GetFormatterLanguages(lldb::LanguageType language) const override;
72
73 bool IsCategoryApplicable(lldb::LanguageType category_language,
74 lldb::LanguageType valobj_language) const override;
75
76 std::unique_ptr<OptionGroupLanguageExpression>
77 CreateExpressionOptions() override;
78
80
82 GetHardcodedSynthetics() override;
83
84 bool IsNilReference(ValueObject &valobj) override;
85
86 llvm::StringRef GetNilReferenceSummaryString() override { return "nullptr"; }
87
88 bool IsSourceFile(llvm::StringRef file_path) const override;
89
90 // Static Functions
91 static void Initialize();
92
93 static void Terminate();
94
96
97 static llvm::StringRef GetPluginNameStatic() { return "cplusplus"; }
98
99 bool SymbolNameFitsToLanguage(const Mangled &mangled) const override;
100
101 DemangledName DemangleSymbol(ConstString mangled,
103 const DemangleOptions &options) const override;
104
105 std::unique_ptr<MangledNameParser>
107
108 bool DemangledNameContainsPath(llvm::StringRef path,
109 ConstString demangled) const override;
110
113
115 const ExecutionContext *exe_ctx,
116 FunctionNameRepresentation representation,
117 Stream &s) override;
118
120 const ExecutionContext *exe_ctx,
122 Stream &s) override;
123
124 static bool IsCPPMangledName(llvm::StringRef name);
125
126 static llvm::StringRef GetDemangledBasename(llvm::StringRef demangled,
127 const DemangledNameInfo &info);
128
129 static llvm::Expected<llvm::StringRef>
130 GetDemangledTemplateArguments(llvm::StringRef demangled,
131 const DemangledNameInfo &info);
132
133 static llvm::Expected<llvm::StringRef>
134 GetDemangledReturnTypeLHS(llvm::StringRef demangled,
135 const DemangledNameInfo &info);
136
137 static llvm::Expected<llvm::StringRef>
138 GetDemangledFunctionQualifiers(llvm::StringRef demangled,
139 const DemangledNameInfo &info);
140
141 static llvm::Expected<llvm::StringRef>
142 GetDemangledScope(llvm::StringRef demangled, const DemangledNameInfo &info);
143
144 static llvm::Expected<llvm::StringRef>
145 GetDemangledReturnTypeRHS(llvm::StringRef demangled,
146 const DemangledNameInfo &info);
147
148 static llvm::Expected<llvm::StringRef>
149 GetDemangledFunctionArguments(llvm::StringRef demangled,
150 const DemangledNameInfo &info);
151
152 static llvm::Expected<llvm::StringRef>
153 GetDemangledFunctionSuffix(llvm::StringRef demangled,
154 const DemangledNameInfo &info);
155
156 // Extract C++ context and identifier from a string using heuristic matching
157 // (as opposed to
158 // CPlusPlusLanguage::CxxMethodName which has to have a fully qualified C++
159 // name with parens and arguments.
160 // If the name is a lone C identifier (e.g. C) or a qualified C identifier
161 // (e.g. A::B::C) it will return true,
162 // and identifier will be the identifier (C and C respectively) and the
163 // context will be "" and "A::B" respectively.
164 // If the name fails the heuristic matching for a qualified or unqualified
165 // C/C++ identifier, then it will return false
166 // and identifier and context will be unchanged.
167
168 static bool ExtractContextAndIdentifier(llvm::StringRef name,
169 llvm::StringRef &context,
170 llvm::StringRef &identifier);
171
172 std::vector<ConstString>
173 GenerateAlternateFunctionManglings(const ConstString mangled) const override;
174
176 const Mangled mangled, const SymbolContext &sym_ctx) const override;
177
178 /// Substitutes Itanium type encoding substrings given by \c subst_from
179 /// in \c mangled_name with \c subst_to.
180 ///
181 /// This function will only replace Itanium type encodings (i.e., <type>
182 /// productions in the Itanium ABI mangling grammar). However, no verifiction
183 /// is done on whether \c subst_from or \c subst_to is a valid type encoding.
184 ///
185 /// \param[in] mangled_name Mangled name to perform the substitutions in.
186 /// This function only supports Itanium ABI mangling.
187 ///
188 /// \param[in] subst_from The substring to substitute.
189 ///
190 /// \param[in] subst_to The substring to insert.
191 ///
192 /// \returns The mangled string with substitutions. If no substitutions
193 /// have been made, returns an empty \c ConstString (even if the string
194 /// already contained the substitutions). If an error occurred, this function
195 /// returns the error.
196 ///
197 static llvm::Expected<ConstString>
198 SubstituteType_ItaniumMangle(llvm::StringRef mangled_name,
199 llvm::StringRef subst_from,
200 llvm::StringRef subst_to);
201
202 /// Substitutes Itanium structor encoding substrings given by \c subst_from
203 /// in \c mangled_name with \c subst_to.
204 ///
205 /// This function will only replace Itanium structor encodings (i.e.,
206 /// <ctor-dtor-name> productions in the Itanium ABI mangling grammar).
207 /// However, no verifiction is done on whether \c subst_from or \c subst_to is
208 /// a valid structor encoding.
209 ///
210 /// \param[in] mangled_name Mangled name to perform the substitutions in.
211 /// This function only supports Itanium ABI mangling.
212 ///
213 /// \param[in] subst_from The substring to substitute.
214 ///
215 /// \param[in] subst_to The substring to insert.
216 ///
217 /// \returns The mangled string with substitutions. If no substitutions
218 /// have been made, returns an empty \c ConstString (even if the string
219 /// already contained the substitutions). If an error occurred, this function
220 /// returns the error.
221 ///
222 static llvm::Expected<ConstString>
223 SubstituteStructor_ItaniumMangle(llvm::StringRef mangled_name,
224 llvm::StringRef subst_from,
225 llvm::StringRef subst_to);
226
227 /// Tries replacing Itanium structor encoding substrings in \c mangled_name
228 /// with potential aliases.j
229 ///
230 /// This function will only replace Itanium structor encodings (i.e.,
231 /// <ctor-dtor-name> productions in the Itanium ABI mangling grammar).
232 ///
233 /// E.g., on some platforms, the C1/D1 variants are aliased to the C2/D2
234 /// variants. This function will try to replace occurrences of C1/D1 with
235 /// C2/D2.
236 ///
237 /// \param[in] mangled_name Mangled name to perform the substitutions in.
238 /// This function only supports Itanium ABI mangling.
239 ///
240 /// \returns The mangled string with substitutions. If no substitutions
241 /// have been made, returns an empty \c ConstString (even if the string
242 /// already contained the substitutions). If an error occurred, this function
243 /// returns the error.
244 ///
245 static llvm::Expected<ConstString>
246 SubstituteStructorAliases_ItaniumMangle(llvm::StringRef mangled_name);
247
248 llvm::StringRef GetInstanceName() override { return "this"; }
249
251
252 std::string GetVersionInfo() const override;
253
254 // PluginInterface protocol
255 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
256
257private:
258 static void DebuggerInitialize(Debugger &);
259};
260
261} // namespace lldb_private
262
263#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
llvm::StringRef GetInstanceName() override
ConstString GetDemangledFunctionNameWithoutArguments(Mangled mangled) const override
std::unique_ptr< MangledNameParser > CreateMangledNameParser(Mangled::ManglingScheme scheme) const override
Returns a parser for the names mangled with scheme, a scheme that this language registered,...
llvm::StringRef GetNilReferenceSummaryString() override
Returns the summary string for ValueObjects for which IsNilReference() is true.
static bool ExtractContextAndIdentifier(llvm::StringRef name, llvm::StringRef &context, llvm::StringRef &identifier)
lldb::TypeCategoryImplSP GetFormatters() override
static llvm::StringRef GetPluginNameStatic()
FormatEntity::Entry GetFunctionNameFormat() const override
HardcodedFormatters::HardcodedSyntheticFinder GetHardcodedSynthetics() override
lldb::LanguageType GetLanguageType() const override
static llvm::StringRef GetDemangledBasename(llvm::StringRef demangled, const DemangledNameInfo &info)
std::string GetVersionInfo() const override
Returns text to append to LLDB's version string, such as the revisions of compilers embedded in this ...
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
DemangledName DemangleSymbol(ConstString mangled, Mangled::ManglingScheme scheme, const DemangleOptions &options) const override
Demangle mangled, a name mangled with scheme, a scheme that this language registered with Mangled::Re...
bool SymbolNameFitsToLanguage(const Mangled &mangled) const override
Returns true iff the given symbol name is compatible with the mangling scheme of this language.
llvm::StringRef GetUserEntryPointName() const override
std::unique_ptr< OptionGroupLanguageExpression > CreateExpressionOptions() override
Returns the options that this language adds to the commands that evaluate expressions,...
static llvm::Expected< llvm::StringRef > GetDemangledFunctionArguments(llvm::StringRef demangled, const DemangledNameInfo &info)
static bool IsCPPMangledName(llvm::StringRef name)
~CPlusPlusLanguage() override=default
std::vector< lldb::LanguageType > GetFormatterLanguages(lldb::LanguageType language) const override
Returns the languages whose formatters apply to values of language, in the order in which to consult ...
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....
bool HandleFrameFormatVariable(const SymbolContext &sc, const ExecutionContext *exe_ctx, FormatEntity::Entry::Type type, Stream &s) override
bool IsCategoryApplicable(lldb::LanguageType category_language, lldb::LanguageType valobj_language) const override
Returns whether the formatters in a category for category_language, one of the languages of this plug...
static void DebuggerInitialize(Debugger &)
virtual std::unique_ptr< Language::MethodName > GetMethodName(llvm::StringRef name) const override
A uniqued constant string class.
Definition ConstString.h:40
A class to manage flag bits.
Definition Debugger.h:106
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
HardcodedFormatterFinders< SyntheticChildren > HardcodedSyntheticFinder
HardcodedFormatterFinders< TypeSummaryImpl > HardcodedSummaryFinder
A class that handles mangled names.
Definition Mangled.h:36
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.