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 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 22 namespace lldb_private { 23 24 class CPlusPlusLanguage : public Language { 25 ClangHighlighter m_highlighter; 26 27 public: 28 class MethodName { 29 public: MethodName()30 MethodName() 31 : m_full(), m_basename(), m_context(), m_arguments(), m_qualifiers(), 32 m_parsed(false), m_parse_error(false) {} 33 MethodName(ConstString s)34 MethodName(ConstString s) 35 : m_full(s), m_basename(), m_context(), m_arguments(), m_qualifiers(), 36 m_parsed(false), m_parse_error(false) {} 37 38 void Clear(); 39 IsValid()40 bool IsValid() { 41 if (!m_parsed) 42 Parse(); 43 if (m_parse_error) 44 return false; 45 return (bool)m_full; 46 } 47 GetFullName()48 ConstString GetFullName() const { return m_full; } 49 50 std::string GetScopeQualifiedName(); 51 52 llvm::StringRef GetBasename(); 53 54 llvm::StringRef GetContext(); 55 56 llvm::StringRef GetArguments(); 57 58 llvm::StringRef GetQualifiers(); 59 60 protected: 61 void Parse(); 62 bool TrySimplifiedParse(); 63 64 ConstString m_full; // Full name: 65 // "lldb::SBTarget::GetBreakpointAtIndex(unsigned int) 66 // const" 67 llvm::StringRef m_basename; // Basename: "GetBreakpointAtIndex" 68 llvm::StringRef m_context; // Decl context: "lldb::SBTarget" 69 llvm::StringRef m_arguments; // Arguments: "(unsigned int)" 70 llvm::StringRef m_qualifiers; // Qualifiers: "const" 71 bool m_parsed; 72 bool m_parse_error; 73 }; 74 75 CPlusPlusLanguage() = default; 76 77 ~CPlusPlusLanguage() override = default; 78 GetLanguageType()79 lldb::LanguageType GetLanguageType() const override { 80 return lldb::eLanguageTypeC_plus_plus; 81 } 82 83 std::unique_ptr<TypeScavenger> GetTypeScavenger() override; 84 lldb::TypeCategoryImplSP GetFormatters() override; 85 86 HardcodedFormatters::HardcodedSummaryFinder GetHardcodedSummaries() override; 87 88 HardcodedFormatters::HardcodedSyntheticFinder 89 GetHardcodedSynthetics() override; 90 91 bool IsNilReference(ValueObject &valobj) override; 92 GetNilReferenceSummaryString()93 llvm::StringRef GetNilReferenceSummaryString() override { return "nullptr"; } 94 95 bool IsSourceFile(llvm::StringRef file_path) const override; 96 GetHighlighter()97 const Highlighter *GetHighlighter() const override { return &m_highlighter; } 98 99 // Static Functions 100 static void Initialize(); 101 102 static void Terminate(); 103 104 static lldb_private::Language *CreateInstance(lldb::LanguageType language); 105 106 static lldb_private::ConstString GetPluginNameStatic(); 107 108 static bool IsCPPMangledName(llvm::StringRef name); 109 110 // Extract C++ context and identifier from a string using heuristic matching 111 // (as opposed to 112 // CPlusPlusLanguage::MethodName which has to have a fully qualified C++ name 113 // with parens and arguments. 114 // If the name is a lone C identifier (e.g. C) or a qualified C identifier 115 // (e.g. A::B::C) it will return true, 116 // and identifier will be the identifier (C and C respectively) and the 117 // context will be "" and "A::B" respectively. 118 // If the name fails the heuristic matching for a qualified or unqualified 119 // C/C++ identifier, then it will return false 120 // and identifier and context will be unchanged. 121 122 static bool ExtractContextAndIdentifier(const char *name, 123 llvm::StringRef &context, 124 llvm::StringRef &identifier); 125 126 // Given a mangled function name, calculates some alternative manglings since 127 // the compiler mangling may not line up with the symbol we are expecting 128 static uint32_t 129 FindAlternateFunctionManglings(const ConstString mangled, 130 std::set<ConstString> &candidates); 131 132 // PluginInterface protocol 133 ConstString GetPluginName() override; 134 135 uint32_t GetPluginVersion() override; 136 }; 137 138 } // namespace lldb_private 139 140 #endif // LLDB_SOURCE_PLUGINS_LANGUAGE_CPLUSPLUS_CPLUSPLUSLANGUAGE_H 141