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 
18 #include "lldb/Target/Language.h"
20 #include "lldb/lldb-private.h"
21 
22 namespace lldb_private {
23 
24 class CPlusPlusLanguage : public Language {
26 
27 public:
28  class MethodName {
29  public:
32 
35  m_parsed(false), m_parse_error(false) {}
36 
37  void Clear();
38 
39  bool IsValid() {
40  if (!m_parsed)
41  Parse();
42  if (m_parse_error)
43  return false;
44  return (bool)m_full;
45  }
46 
47  ConstString GetFullName() const { return m_full; }
48 
50 
51  llvm::StringRef GetBasename();
52 
53  llvm::StringRef GetContext();
54 
55  llvm::StringRef GetArguments();
56 
57  llvm::StringRef GetQualifiers();
58 
59  bool ContainsPath(llvm::StringRef path);
60 
61  protected:
62  void Parse();
63  bool TrySimplifiedParse();
64 
65  ConstString m_full; // Full name:
66  // "lldb::SBTarget::GetBreakpointAtIndex(unsigned int)
67  // const"
68  llvm::StringRef m_basename; // Basename: "GetBreakpointAtIndex"
69  llvm::StringRef m_context; // Decl context: "lldb::SBTarget"
70  llvm::StringRef m_arguments; // Arguments: "(unsigned int)"
71  llvm::StringRef m_qualifiers; // Qualifiers: "const"
72  bool m_parsed = false;
73  bool m_parse_error = false;
74  };
75 
76  CPlusPlusLanguage() = default;
77 
78  ~CPlusPlusLanguage() override = default;
79 
82  }
83 
84  std::unique_ptr<TypeScavenger> GetTypeScavenger() override;
85  lldb::TypeCategoryImplSP GetFormatters() override;
86 
88 
90  GetHardcodedSynthetics() override;
91 
92  bool IsNilReference(ValueObject &valobj) override;
93 
94  llvm::StringRef GetNilReferenceSummaryString() override { return "nullptr"; }
95 
96  bool IsSourceFile(llvm::StringRef file_path) const override;
97 
98  const Highlighter *GetHighlighter() const override { return &m_highlighter; }
99 
100  // Static Functions
101  static void Initialize();
102 
103  static void Terminate();
104 
106 
107  static llvm::StringRef GetPluginNameStatic() { return "cplusplus"; }
108 
109  bool SymbolNameFitsToLanguage(Mangled mangled) const override;
110 
111  bool DemangledNameContainsPath(llvm::StringRef path,
112  ConstString demangled) const override;
113 
115  GetDemangledFunctionNameWithoutArguments(Mangled mangled) const override;
116 
117  static bool IsCPPMangledName(llvm::StringRef name);
118 
119  // Extract C++ context and identifier from a string using heuristic matching
120  // (as opposed to
121  // CPlusPlusLanguage::MethodName which has to have a fully qualified C++ name
122  // with parens and arguments.
123  // If the name is a lone C identifier (e.g. C) or a qualified C identifier
124  // (e.g. A::B::C) it will return true,
125  // and identifier will be the identifier (C and C respectively) and the
126  // context will be "" and "A::B" respectively.
127  // If the name fails the heuristic matching for a qualified or unqualified
128  // C/C++ identifier, then it will return false
129  // and identifier and context will be unchanged.
130 
131  static bool ExtractContextAndIdentifier(const char *name,
132  llvm::StringRef &context,
133  llvm::StringRef &identifier);
134 
135  std::vector<ConstString>
136  GenerateAlternateFunctionManglings(const ConstString mangled) const override;
137 
139  const Mangled mangled, const SymbolContext &sym_ctx) const override;
140 
141  // PluginInterface protocol
142  llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
143 };
144 
145 } // namespace lldb_private
146 
147 #endif // LLDB_SOURCE_PLUGINS_LANGUAGE_CPLUSPLUS_CPLUSPLUSLANGUAGE_H
lldb_private::CPlusPlusLanguage::CreateInstance
static lldb_private::Language * CreateInstance(lldb::LanguageType language)
Definition: CPlusPlusLanguage.cpp:97
lldb_private::CPlusPlusLanguage::GetFormatters
lldb::TypeCategoryImplSP GetFormatters() override
lldb_private::CPlusPlusLanguage::GetDemangledFunctionNameWithoutArguments
ConstString GetDemangledFunctionNameWithoutArguments(Mangled mangled) const override
Definition: CPlusPlusLanguage.cpp:66
lldb_private::CPlusPlusLanguage::SymbolNameFitsToLanguage
bool SymbolNameFitsToLanguage(Mangled mangled) const override
Returns true iff the given symbol name is compatible with the mangling scheme of this language.
Definition: CPlusPlusLanguage.cpp:61
lldb_private::CPlusPlusLanguage::MethodName::Clear
void Clear()
Definition: CPlusPlusLanguage.cpp:105
lldb_private::CPlusPlusLanguage::~CPlusPlusLanguage
~CPlusPlusLanguage() override=default
lldb_private::CPlusPlusLanguage::MethodName::m_full
ConstString m_full
Definition: CPlusPlusLanguage.h:65
lldb::LanguageType
LanguageType
Programming language type.
Definition: lldb-enumerations.h:436
lldb_private::CPlusPlusLanguage::MethodName::GetScopeQualifiedName
std::string GetScopeQualifiedName()
Definition: CPlusPlusLanguage.cpp:258
lldb_private::CPlusPlusLanguage::MethodName::GetBasename
llvm::StringRef GetBasename()
Definition: CPlusPlusLanguage.cpp:234
lldb_private::CPlusPlusLanguage::MethodName::GetContext
llvm::StringRef GetContext()
Definition: CPlusPlusLanguage.cpp:240
Language.h
lldb_private::CPlusPlusLanguage::MethodName::m_qualifiers
llvm::StringRef m_qualifiers
Definition: CPlusPlusLanguage.h:71
lldb_private::CPlusPlusLanguage::ExtractContextAndIdentifier
static bool ExtractContextAndIdentifier(const char *name, llvm::StringRef &context, llvm::StringRef &identifier)
Definition: CPlusPlusLanguage.cpp:324
lldb_private::CPlusPlusLanguage::MethodName::GetQualifiers
llvm::StringRef GetQualifiers()
Definition: CPlusPlusLanguage.cpp:252
lldb_private::CPlusPlusLanguage::MethodName::GetArguments
llvm::StringRef GetArguments()
Definition: CPlusPlusLanguage.cpp:246
lldb_private::SymbolContext
Definition: SymbolContext.h:33
lldb_private::CPlusPlusLanguage::MethodName::m_context
llvm::StringRef m_context
Definition: CPlusPlusLanguage.h:69
lldb_private::CPlusPlusLanguage::Terminate
static void Terminate()
Definition: CPlusPlusLanguage.cpp:57
lldb_private::Highlighter
Annotates source code with color attributes.
Definition: Highlighter.h:90
lldb_private::CPlusPlusLanguage::MethodName::ContainsPath
bool ContainsPath(llvm::StringRef path)
Definition: CPlusPlusLanguage.cpp:271
lldb_private::HardcodedFormatters::HardcodedSummaryFinder
HardcodedFormatterFinders< TypeSummaryImpl > HardcodedSummaryFinder
Definition: FormatClasses.h:40
lldb_private::CPlusPlusLanguage::CPlusPlusLanguage
CPlusPlusLanguage()=default
lldb_private::CPlusPlusLanguage::GetPluginName
llvm::StringRef GetPluginName() override
Definition: CPlusPlusLanguage.h:142
lldb_private::CPlusPlusLanguage::MethodName::GetFullName
ConstString GetFullName() const
Definition: CPlusPlusLanguage.h:47
lldb_private::CPlusPlusLanguage::GetTypeScavenger
std::unique_ptr< TypeScavenger > GetTypeScavenger() override
lldb_private::ConstString
Definition: ConstString.h:40
lldb_private::CPlusPlusLanguage::DemangledNameContainsPath
bool DemangledNameContainsPath(llvm::StringRef path, ConstString demangled) const override
Definition: CPlusPlusLanguage.cpp:318
lldb_private::CPlusPlusLanguage::m_highlighter
ClangHighlighter m_highlighter
Definition: CPlusPlusLanguage.h:25
ClangHighlighter.h
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::CPlusPlusLanguage::FindBestAlternateFunctionMangledName
ConstString FindBestAlternateFunctionMangledName(const Mangled mangled, const SymbolContext &sym_ctx) const override
Definition: CPlusPlusLanguage.cpp:513
lldb-private.h
lldb_private::CPlusPlusLanguage::GetPluginNameStatic
static llvm::StringRef GetPluginNameStatic()
Definition: CPlusPlusLanguage.h:107
lldb_private::CPlusPlusLanguage::MethodName::MethodName
MethodName()
Definition: CPlusPlusLanguage.h:30
lldb_private::CPlusPlusLanguage::GenerateAlternateFunctionManglings
std::vector< ConstString > GenerateAlternateFunctionManglings(const ConstString mangled) const override
Definition: CPlusPlusLanguage.cpp:459
lldb_private::ValueObject
ValueObject:
Definition: ValueObject.h:105
lldb_private::CPlusPlusLanguage::MethodName::TrySimplifiedParse
bool TrySimplifiedParse()
Definition: CPlusPlusLanguage.cpp:172
lldb_private::Language
Definition: Language.h:29
lldb_private::CPlusPlusLanguage::IsNilReference
bool IsNilReference(ValueObject &valobj) override
lldb_private::CPlusPlusLanguage::MethodName::MethodName
MethodName(ConstString s)
Definition: CPlusPlusLanguage.h:33
lldb_private::CPlusPlusLanguage::MethodName
Definition: CPlusPlusLanguage.h:28
lldb_private::CPlusPlusLanguage::GetHardcodedSynthetics
HardcodedFormatters::HardcodedSyntheticFinder GetHardcodedSynthetics() override
lldb_private::CPlusPlusLanguage::Initialize
static void Initialize()
Definition: CPlusPlusLanguage.cpp:52
lldb_private::CPlusPlusLanguage::MethodName::m_parsed
bool m_parsed
Definition: CPlusPlusLanguage.h:72
lldb_private::CPlusPlusLanguage::GetLanguageType
lldb::LanguageType GetLanguageType() const override
Definition: CPlusPlusLanguage.h:80
lldb_private::CPlusPlusLanguage::IsCPPMangledName
static bool IsCPPMangledName(llvm::StringRef name)
Definition: CPlusPlusLanguage.cpp:306
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::CPlusPlusLanguage::GetHighlighter
const Highlighter * GetHighlighter() const override
Definition: CPlusPlusLanguage.h:98
lldb_private::CPlusPlusLanguage
Definition: CPlusPlusLanguage.h:24
lldb_private::CPlusPlusLanguage::GetHardcodedSummaries
HardcodedFormatters::HardcodedSummaryFinder GetHardcodedSummaries() override
lldb_private::CPlusPlusLanguage::MethodName::m_arguments
llvm::StringRef m_arguments
Definition: CPlusPlusLanguage.h:70
lldb_private::ClangHighlighter
Definition: ClangHighlighter.h:19
ConstString.h
lldb_private::CPlusPlusLanguage::GetNilReferenceSummaryString
llvm::StringRef GetNilReferenceSummaryString() override
Returns the summary string for ValueObjects for which IsNilReference() is true.
Definition: CPlusPlusLanguage.h:94
lldb_private::CPlusPlusLanguage::MethodName::IsValid
bool IsValid()
Definition: CPlusPlusLanguage.h:39
lldb_private::CPlusPlusLanguage::IsSourceFile
bool IsSourceFile(llvm::StringRef file_path) const override
lldb_private::CPlusPlusLanguage::MethodName::Parse
void Parse()
Definition: CPlusPlusLanguage.cpp:214
lldb_private::CPlusPlusLanguage::MethodName::m_basename
llvm::StringRef m_basename
Definition: CPlusPlusLanguage.h:68
lldb_private::CPlusPlusLanguage::MethodName::m_parse_error
bool m_parse_error
Definition: CPlusPlusLanguage.h:73
lldb_private::HardcodedFormatters::HardcodedSyntheticFinder
HardcodedFormatterFinders< SyntheticChildren > HardcodedSyntheticFinder
Definition: FormatClasses.h:41
lldb::eLanguageTypeC_plus_plus
@ eLanguageTypeC_plus_plus
ISO C++:1998.
Definition: lldb-enumerations.h:441