251 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLDB_SOURCE_PLUGINS_LANGUAGE_CPLUSPLUS_CPLUSPLUSLANGUAGE_H10#define LLDB_SOURCE_PLUGINS_LANGUAGE_CPLUSPLUS_CPLUSPLUSLANGUAGE_H11 12#include <set>13#include <vector>14 15#include "llvm/ADT/StringRef.h"16 17#include "Plugins/Language/ClangCommon/ClangHighlighter.h"18#include "lldb/Target/Language.h"19#include "lldb/Utility/ConstString.h"20#include "lldb/lldb-private.h"21 22namespace lldb_private {23 24class CPlusPlusLanguage : public Language {25 ClangHighlighter m_highlighter;26 27public:28 class CxxMethodName : public Language::MethodName {29 public:30 CxxMethodName(ConstString s) : Language::MethodName(s) {}31 32 bool ContainsPath(llvm::StringRef path);33 34 private:35 /// Returns the Basename of this method without a template parameter36 /// 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 64 lldb::LanguageType GetLanguageType() const override {65 return lldb::eLanguageTypeC_plus_plus;66 }67 68 llvm::StringRef GetUserEntryPointName() const override { return "main"; }69 70 std::unique_ptr<TypeScavenger> GetTypeScavenger() override;71 lldb::TypeCategoryImplSP GetFormatters() override;72 73 HardcodedFormatters::HardcodedSummaryFinder GetHardcodedSummaries() override;74 75 HardcodedFormatters::HardcodedSyntheticFinder76 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 Functions87 static void Initialize();88 89 static void Terminate();90 91 static lldb_private::Language *CreateInstance(lldb::LanguageType language);92 93 static llvm::StringRef GetPluginNameStatic() { return "cplusplus"; }94 95 bool SymbolNameFitsToLanguage(const Mangled &mangled) const override;96 97 bool DemangledNameContainsPath(llvm::StringRef path,98 ConstString demangled) const override;99 100 ConstString101 GetDemangledFunctionNameWithoutArguments(Mangled mangled) const override;102 103 bool GetFunctionDisplayName(const SymbolContext &sc,104 const ExecutionContext *exe_ctx,105 FunctionNameRepresentation representation,106 Stream &s) override;107 108 bool HandleFrameFormatVariable(const SymbolContext &sc,109 const ExecutionContext *exe_ctx,110 FormatEntity::Entry::Type type,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 matching146 // (as opposed to147 // 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 identifier150 // (e.g. A::B::C) it will return true,151 // and identifier will be the identifier (C and C respectively) and the152 // context will be "" and "A::B" respectively.153 // If the name fails the heuristic matching for a qualified or unqualified154 // C/C++ identifier, then it will return false155 // and identifier and context will be unchanged.156 157 static bool ExtractContextAndIdentifier(llvm::StringRef name,158 llvm::StringRef &context,159 llvm::StringRef &identifier);160 161 std::vector<ConstString>162 GenerateAlternateFunctionManglings(const ConstString mangled) const override;163 164 ConstString FindBestAlternateFunctionMangledName(165 const Mangled mangled, const SymbolContext &sym_ctx) const override;166 167 /// Substitutes Itanium type encoding substrings given by \c subst_from168 /// 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 verifiction172 /// 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 substitutions182 /// have been made, returns an empty \c ConstString (even if the string183 /// already contained the substitutions). If an error occurred, this function184 /// 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_from192 /// 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 is197 /// 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 substitutions207 /// have been made, returns an empty \c ConstString (even if the string208 /// already contained the substitutions). If an error occurred, this function209 /// 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_name217 /// with potential aliases.j218 ///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/D2223 /// variants. This function will try to replace occurrences of C1/D1 with224 /// 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 substitutions230 /// have been made, returns an empty \c ConstString (even if the string231 /// already contained the substitutions). If an error occurred, this function232 /// 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 239 FormatEntity::Entry GetFunctionNameFormat() const override;240 241 // PluginInterface protocol242 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }243 244private:245 static void DebuggerInitialize(Debugger &);246};247 248} // namespace lldb_private249 250#endif // LLDB_SOURCE_PLUGINS_LANGUAGE_CPLUSPLUS_CPLUSPLUSLANGUAGE_H251