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
20#include "lldb/lldb-private.h"
21
22namespace lldb_private {
23
26
27public:
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
49 std::string GetScopeQualifiedName();
50
51 llvm::StringRef GetBasename();
52
53 llvm::StringRef GetContext();
54
55 llvm::StringRef GetArguments();
56
57 llvm::StringRef GetQualifiers();
58
59 /// Returns the methods return-type.
60 ///
61 /// Currently returns an empty llvm::StringRef
62 /// if the return-type is a function pointer.
63 llvm::StringRef GetReturnType();
64
65 bool ContainsPath(llvm::StringRef path);
66
67 private:
68 /// Returns the Basename of this method without a template parameter
69 /// list, if any.
70 ///
71 // Examples:
72 //
73 // +--------------------------------+---------+
74 // | MethodName | Returns |
75 // +--------------------------------+---------+
76 // | void func() | func |
77 // | void func<int>() | func |
78 // | void func<std::vector<int>>() | func |
79 // +--------------------------------+---------+
80 llvm::StringRef GetBasenameNoTemplateParameters();
81
82 protected:
83 void Parse();
84 bool TrySimplifiedParse();
85
86 ConstString m_full; // Full name:
87 // "size_t lldb::SBTarget::GetBreakpointAtIndex(unsigned
88 // int) const"
89 llvm::StringRef m_basename; // Basename: "GetBreakpointAtIndex"
90 llvm::StringRef m_context; // Decl context: "lldb::SBTarget"
91 llvm::StringRef m_arguments; // Arguments: "(unsigned int)"
92 llvm::StringRef m_qualifiers; // Qualifiers: "const"
93 llvm::StringRef m_return_type; // Return type: "size_t"
94 bool m_parsed = false;
95 bool m_parse_error = false;
96 };
97
98 CPlusPlusLanguage() = default;
99
100 ~CPlusPlusLanguage() override = default;
101
104 }
105
106 llvm::StringRef GetUserEntryPointName() const override { return "main"; }
107
108 std::unique_ptr<TypeScavenger> GetTypeScavenger() override;
110
112
114 GetHardcodedSynthetics() override;
115
116 bool IsNilReference(ValueObject &valobj) override;
117
118 llvm::StringRef GetNilReferenceSummaryString() override { return "nullptr"; }
119
120 bool IsSourceFile(llvm::StringRef file_path) const override;
121
122 const Highlighter *GetHighlighter() const override { return &m_highlighter; }
123
124 // Static Functions
125 static void Initialize();
126
127 static void Terminate();
128
130
131 static llvm::StringRef GetPluginNameStatic() { return "cplusplus"; }
132
133 bool SymbolNameFitsToLanguage(Mangled mangled) const override;
134
135 bool DemangledNameContainsPath(llvm::StringRef path,
136 ConstString demangled) const override;
137
140
142 const ExecutionContext *exe_ctx,
143 FunctionNameRepresentation representation,
144 Stream &s) override;
145
146 static bool IsCPPMangledName(llvm::StringRef name);
147
148 // Extract C++ context and identifier from a string using heuristic matching
149 // (as opposed to
150 // CPlusPlusLanguage::MethodName which has to have a fully qualified C++ name
151 // with parens and arguments.
152 // If the name is a lone C identifier (e.g. C) or a qualified C identifier
153 // (e.g. A::B::C) it will return true,
154 // and identifier will be the identifier (C and C respectively) and the
155 // context will be "" and "A::B" respectively.
156 // If the name fails the heuristic matching for a qualified or unqualified
157 // C/C++ identifier, then it will return false
158 // and identifier and context will be unchanged.
159
160 static bool ExtractContextAndIdentifier(const char *name,
161 llvm::StringRef &context,
162 llvm::StringRef &identifier);
163
164 std::vector<ConstString>
165 GenerateAlternateFunctionManglings(const ConstString mangled) const override;
166
168 const Mangled mangled, const SymbolContext &sym_ctx) const override;
169
170 llvm::StringRef GetInstanceVariableName() override { return "this"; }
171
172 // PluginInterface protocol
173 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
174};
175
176} // namespace lldb_private
177
178#endif // LLDB_SOURCE_PLUGINS_LANGUAGE_CPLUSPLUS_CPLUSPLUSLANGUAGE_H
llvm::StringRef GetReturnType()
Returns the methods return-type.
llvm::StringRef GetBasenameNoTemplateParameters()
Returns the Basename of this method without a template parameter list, if any.
bool GetFunctionDisplayName(const SymbolContext *sc, const ExecutionContext *exe_ctx, FunctionNameRepresentation representation, Stream &s) override
bool IsNilReference(ValueObject &valobj) override
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.
const Highlighter * GetHighlighter() const override
lldb::TypeCategoryImplSP GetFormatters() override
static llvm::StringRef GetPluginNameStatic()
bool SymbolNameFitsToLanguage(Mangled mangled) const override
Returns true iff the given symbol name is compatible with the mangling scheme of this language.
HardcodedFormatters::HardcodedSyntheticFinder GetHardcodedSynthetics() override
lldb::LanguageType GetLanguageType() const override
static bool IsCPPMangledName(llvm::StringRef name)
llvm::StringRef GetPluginName() override
std::vector< ConstString > GenerateAlternateFunctionManglings(const ConstString mangled) const override
bool DemangledNameContainsPath(llvm::StringRef path, ConstString demangled) const override
ConstString FindBestAlternateFunctionMangledName(const Mangled mangled, const SymbolContext &sym_ctx) const override
llvm::StringRef GetUserEntryPointName() const override
static bool ExtractContextAndIdentifier(const char *name, llvm::StringRef &context, llvm::StringRef &identifier)
~CPlusPlusLanguage() override=default
std::unique_ptr< TypeScavenger > GetTypeScavenger() override
HardcodedFormatters::HardcodedSummaryFinder GetHardcodedSummaries() override
static lldb_private::Language * CreateInstance(lldb::LanguageType language)
llvm::StringRef GetInstanceVariableName() override
A uniqued constant string class.
Definition: ConstString.h:40
"lldb/Target/ExecutionContext.h" A class that contains an execution context.
HardcodedFormatterFinders< SyntheticChildren > HardcodedSyntheticFinder
Definition: FormatClasses.h:42
HardcodedFormatterFinders< TypeSummaryImpl > HardcodedSummaryFinder
Definition: FormatClasses.h:41
Annotates source code with color attributes.
Definition: Highlighter.h:91
A class that handles mangled names.
Definition: Mangled.h:33
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.
Definition: SymbolContext.h:34
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
Definition: lldb-forward.h:454