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
71
73 GetHardcodedSynthetics() override;
74
75 bool IsNilReference(ValueObject &valobj) override;
76
77 llvm::StringRef GetNilReferenceSummaryString() override { return "nullptr"; }
78
79 bool IsSourceFile(llvm::StringRef file_path) const override;
80
81 // Static Functions
82 static void Initialize();
83
84 static void Terminate();
85
87
88 static llvm::StringRef GetPluginNameStatic() { return "cplusplus"; }
89
90 bool SymbolNameFitsToLanguage(const Mangled &mangled) const override;
91
92 bool HandlesManglingScheme(Mangled::ManglingScheme scheme) const override;
93
94 DemangledName DemangleSymbol(ConstString mangled,
96 const DemangleOptions &options) const override;
97
98 std::unique_ptr<MangledNameParser>
100
101 bool DemangledNameContainsPath(llvm::StringRef path,
102 ConstString demangled) const override;
103
106
108 const ExecutionContext *exe_ctx,
109 FunctionNameRepresentation representation,
110 Stream &s) override;
111
113 const ExecutionContext *exe_ctx,
115 Stream &s) override;
116
117 static bool IsCPPMangledName(llvm::StringRef name);
118
119 static llvm::StringRef GetDemangledBasename(llvm::StringRef demangled,
120 const DemangledNameInfo &info);
121
122 static llvm::Expected<llvm::StringRef>
123 GetDemangledTemplateArguments(llvm::StringRef demangled,
124 const DemangledNameInfo &info);
125
126 static llvm::Expected<llvm::StringRef>
127 GetDemangledReturnTypeLHS(llvm::StringRef demangled,
128 const DemangledNameInfo &info);
129
130 static llvm::Expected<llvm::StringRef>
131 GetDemangledFunctionQualifiers(llvm::StringRef demangled,
132 const DemangledNameInfo &info);
133
134 static llvm::Expected<llvm::StringRef>
135 GetDemangledScope(llvm::StringRef demangled, const DemangledNameInfo &info);
136
137 static llvm::Expected<llvm::StringRef>
138 GetDemangledReturnTypeRHS(llvm::StringRef demangled,
139 const DemangledNameInfo &info);
140
141 static llvm::Expected<llvm::StringRef>
142 GetDemangledFunctionArguments(llvm::StringRef demangled,
143 const DemangledNameInfo &info);
144
145 static llvm::Expected<llvm::StringRef>
146 GetDemangledFunctionSuffix(llvm::StringRef demangled,
147 const DemangledNameInfo &info);
148
149 // Extract C++ context and identifier from a string using heuristic matching
150 // (as opposed to
151 // CPlusPlusLanguage::CxxMethodName which has to have a fully qualified C++
152 // name with parens and arguments.
153 // If the name is a lone C identifier (e.g. C) or a qualified C identifier
154 // (e.g. A::B::C) it will return true,
155 // and identifier will be the identifier (C and C respectively) and the
156 // context will be "" and "A::B" respectively.
157 // If the name fails the heuristic matching for a qualified or unqualified
158 // C/C++ identifier, then it will return false
159 // and identifier and context will be unchanged.
160
161 static bool ExtractContextAndIdentifier(llvm::StringRef name,
162 llvm::StringRef &context,
163 llvm::StringRef &identifier);
164
165 std::vector<ConstString>
166 GenerateAlternateFunctionManglings(const ConstString mangled) const override;
167
169 const Mangled mangled, const SymbolContext &sym_ctx) const override;
170
171 /// Substitutes Itanium type encoding substrings given by \c subst_from
172 /// in \c mangled_name with \c subst_to.
173 ///
174 /// This function will only replace Itanium type encodings (i.e., <type>
175 /// productions in the Itanium ABI mangling grammar). However, no verifiction
176 /// is done on whether \c subst_from or \c subst_to is a valid type encoding.
177 ///
178 /// \param[in] mangled_name Mangled name to perform the substitutions in.
179 /// This function only supports Itanium ABI mangling.
180 ///
181 /// \param[in] subst_from The substring to substitute.
182 ///
183 /// \param[in] subst_to The substring to insert.
184 ///
185 /// \returns The mangled string with substitutions. If no substitutions
186 /// have been made, returns an empty \c ConstString (even if the string
187 /// already contained the substitutions). If an error occurred, this function
188 /// returns the error.
189 ///
190 static llvm::Expected<ConstString>
191 SubstituteType_ItaniumMangle(llvm::StringRef mangled_name,
192 llvm::StringRef subst_from,
193 llvm::StringRef subst_to);
194
195 /// Substitutes Itanium structor encoding substrings given by \c subst_from
196 /// in \c mangled_name with \c subst_to.
197 ///
198 /// This function will only replace Itanium structor encodings (i.e.,
199 /// <ctor-dtor-name> productions in the Itanium ABI mangling grammar).
200 /// However, no verifiction is done on whether \c subst_from or \c subst_to is
201 /// a valid structor encoding.
202 ///
203 /// \param[in] mangled_name Mangled name to perform the substitutions in.
204 /// This function only supports Itanium ABI mangling.
205 ///
206 /// \param[in] subst_from The substring to substitute.
207 ///
208 /// \param[in] subst_to The substring to insert.
209 ///
210 /// \returns The mangled string with substitutions. If no substitutions
211 /// have been made, returns an empty \c ConstString (even if the string
212 /// already contained the substitutions). If an error occurred, this function
213 /// returns the error.
214 ///
215 static llvm::Expected<ConstString>
216 SubstituteStructor_ItaniumMangle(llvm::StringRef mangled_name,
217 llvm::StringRef subst_from,
218 llvm::StringRef subst_to);
219
220 /// Tries replacing Itanium structor encoding substrings in \c mangled_name
221 /// with potential aliases.j
222 ///
223 /// This function will only replace Itanium structor encodings (i.e.,
224 /// <ctor-dtor-name> productions in the Itanium ABI mangling grammar).
225 ///
226 /// E.g., on some platforms, the C1/D1 variants are aliased to the C2/D2
227 /// variants. This function will try to replace occurrences of C1/D1 with
228 /// C2/D2.
229 ///
230 /// \param[in] mangled_name Mangled name to perform the substitutions in.
231 /// This function only supports Itanium ABI mangling.
232 ///
233 /// \returns The mangled string with substitutions. If no substitutions
234 /// have been made, returns an empty \c ConstString (even if the string
235 /// already contained the substitutions). If an error occurred, this function
236 /// returns the error.
237 ///
238 static llvm::Expected<ConstString>
239 SubstituteStructorAliases_ItaniumMangle(llvm::StringRef mangled_name);
240
241 llvm::StringRef GetInstanceName() override { return "this"; }
242
244
245 // PluginInterface protocol
246 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
247
248private:
249 static void DebuggerInitialize(Debugger &);
250};
251
252} // namespace lldb_private
253
254#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 handles,...
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)
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 handles.
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
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.
bool HandlesManglingScheme(Mangled::ManglingScheme scheme) const override
Returns true if this language handles the names mangled with scheme.
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
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:103
"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: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.