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