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
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 parameter
36 /// 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::HardcodedSyntheticFinder
76 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 Functions
87 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(Mangled mangled) const override;
96
97 bool DemangledNameContainsPath(llvm::StringRef path,
98 ConstString demangled) const override;
99
100 ConstString
101 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 // Extract C++ context and identifier from a string using heuristic matching
116 // (as opposed to
117 // CPlusPlusLanguage::CxxMethodName which has to have a fully qualified C++
118 // name with parens and arguments.
119 // If the name is a lone C identifier (e.g. C) or a qualified C identifier
120 // (e.g. A::B::C) it will return true,
121 // and identifier will be the identifier (C and C respectively) and the
122 // context will be "" and "A::B" respectively.
123 // If the name fails the heuristic matching for a qualified or unqualified
124 // C/C++ identifier, then it will return false
125 // and identifier and context will be unchanged.
126
127 static bool ExtractContextAndIdentifier(const char *name,
128 llvm::StringRef &context,
129 llvm::StringRef &identifier);
130
131 std::vector<ConstString>
132 GenerateAlternateFunctionManglings(const ConstString mangled) const override;
133
134 ConstString FindBestAlternateFunctionMangledName(
135 const Mangled mangled, const SymbolContext &sym_ctx) const override;
136
137 llvm::StringRef GetInstanceVariableName() override { return "this"; }
138
139 FormatEntity::Entry GetFunctionNameFormat() const override;
140
141 // PluginInterface protocol
142 llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
143
144private:
145 static void DebuggerInitialize(Debugger &);
146};
147
148} // namespace lldb_private
149
150#endif // LLDB_SOURCE_PLUGINS_LANGUAGE_CPLUSPLUS_CPLUSPLUSLANGUAGE_H
151

source code of lldb/source/Plugins/Language/CPlusPlus/CPlusPlusLanguage.h