LLDB mainline
PdbAstBuilderClang.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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_SYMBOLFILE_NATIVEPDB_PDBASTBUILDERCLANG_H
10#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_PDBASTBUILDERCLANG_H
11
12#include "PdbAstBuilder.h"
13
16
17#include "llvm/ADT/DenseMap.h"
18#include "llvm/DebugInfo/CodeView/CVRecord.h"
19#include "llvm/Support/Threading.h"
20
21namespace clang {
22class TagDecl;
23class DeclContext;
24class Decl;
25class QualType;
26class FunctionDecl;
27class NamespaceDecl;
28class BlockDecl;
29class VarDecl;
30} // namespace clang
31
32namespace llvm {
33namespace codeview {
34class PointerRecord;
35class ModifierRecord;
36class ArrayRecord;
37class TagRecord;
38class EnumRecord;
39enum class CallingConvention : uint8_t;
40} // namespace codeview
41} // namespace llvm
42
43namespace lldb_private {
44namespace npdb {
45
53
54struct CVTagRecord;
55
57public:
59
63
64 void EnsureFunction(PdbCompilandSymId func_id) override;
65 void EnsureInlinedFunction(PdbCompilandSymId inlinesite_id) override;
66 void EnsureBlock(PdbCompilandSymId block_id) override;
68 PdbCompilandSymId var_id) override;
69 void EnsureVariable(PdbGlobalSymId var_id) override;
70
73 bool CompleteType(CompilerType ct) override;
74
75 void ParseDeclsForContext(CompilerDeclContext context) override;
76
78 llvm::StringRef name) override;
79
80 std::string GetQualifiedName(llvm::StringRef name) override;
81
82 void Dump(Stream &stream, llvm::StringRef filter, bool show_color) override;
83
84 // Clang-specific
85 clang::QualType GetBasicType(lldb::BasicType type);
86 clang::QualType GetOrCreateClangType(PdbTypeSymId type);
87 clang::DeclContext *GetOrCreateClangDeclContextForUid(PdbSymUid uid);
88
89 CompilerDecl ToCompilerDecl(clang::Decl *decl);
90 CompilerType ToCompilerType(clang::QualType qt);
91 CompilerDeclContext ToCompilerDeclContext(clang::DeclContext *context);
92 clang::QualType FromCompilerType(CompilerType ct);
93 clang::Decl *FromCompilerDecl(CompilerDecl decl);
94 clang::DeclContext *FromCompilerDeclContext(CompilerDeclContext context);
95
96 bool CompleteTagDecl(clang::TagDecl &tag);
97
99
100 /// Returns the method named \p name with type \p method_ct in the record
101 /// \p parent_ty, creating it if it doesn't exist yet.
102 clang::CXXMethodDecl *
104 llvm::StringRef name, llvm::StringRef asm_label,
105 const CompilerType &method_ct, bool is_virtual,
106 bool is_static, bool is_artificial);
107
109
110private:
112 clang::DeclContext *GetParentClangDeclContext(PdbSymUid uid);
113
114 clang::Decl *TryGetDecl(PdbSymUid uid) const;
115
116 clang::FunctionDecl *GetOrCreateFunctionDecl(PdbCompilandSymId func_id);
117 clang::FunctionDecl *
119 clang::BlockDecl *GetOrCreateBlockDecl(PdbCompilandSymId block_id);
120 clang::VarDecl *GetOrCreateVariableDecl(PdbCompilandSymId scope_id,
121 PdbCompilandSymId var_id);
122 clang::VarDecl *GetOrCreateVariableDecl(PdbGlobalSymId var_id);
123
124 using TypeIndex = llvm::codeview::TypeIndex;
125
126 clang::QualType
127 CreatePointerType(const llvm::codeview::PointerRecord &pointer);
128 clang::QualType
129 CreateModifierType(const llvm::codeview::ModifierRecord &modifier);
130 clang::QualType CreateArrayType(const llvm::codeview::ArrayRecord &array);
131 clang::QualType CreateRecordType(PdbTypeSymId id, const CVTagRecord &record);
132 clang::QualType CreateEnumType(PdbTypeSymId id,
133 const llvm::codeview::EnumRecord &record);
134 clang::QualType
135 CreateFunctionType(TypeIndex args_type_idx, TypeIndex return_type_idx,
136 llvm::codeview::CallingConvention calling_convention,
137 unsigned int type_quals);
138 clang::QualType CreateType(PdbTypeSymId type);
139
141 clang::FunctionDecl &function_decl,
142 uint32_t param_count);
144 clang::VarDecl *CreateVariableDecl(PdbSymUid uid,
145 llvm::codeview::CVSymbol sym,
146 clang::DeclContext &scope);
147 clang::NamespaceDecl *GetOrCreateNamespaceDecl(const char *name,
148 clang::DeclContext &context);
149 clang::FunctionDecl *CreateFunctionDeclFromId(PdbTypeSymId func_tid,
150 PdbCompilandSymId func_sid);
151 clang::FunctionDecl *
152 CreateFunctionDecl(PdbCompilandSymId func_id, llvm::StringRef func_name,
153 TypeIndex func_ti, CompilerType func_ct,
154 uint32_t param_count, clang::StorageClass func_storage,
155 bool is_inline, clang::DeclContext *parent);
156 void ParseNamespace(clang::DeclContext &parent);
157 void ParseAllTypes();
159 void ParseDeclsForSimpleContext(clang::DeclContext &context);
161
162 std::pair<clang::DeclContext *, std::string>
163 CreateDeclInfoForType(const llvm::codeview::TagRecord &record, TypeIndex ti);
164 std::pair<clang::DeclContext *, std::string>
165 CreateDeclInfoForUndecoratedName(llvm::StringRef uname);
166
167 clang::DeclContext *
169
170 clang::QualType CreateSimpleType(TypeIndex ti);
171
172 bool IsDynamicTagRecord(const CVTagRecord &tag);
173
175
178 llvm::once_flag m_parse_all_types;
179 llvm::DenseMap<clang::Decl *, DeclStatus> m_decl_to_status;
180 llvm::DenseMap<lldb::user_id_t, clang::Decl *> m_uid_to_decl;
181 llvm::DenseMap<lldb::user_id_t, clang::QualType> m_uid_to_type;
182
183 // From a class/struct's opaque_compiler_type_t, a method's name and the
184 // method's opaque_compiler_type_t to the method decl.
185 llvm::DenseMap<std::tuple<lldb::opaque_compiler_type_t, ConstString,
187 clang::CXXMethodDecl *>
189
190 using NamespaceSet = llvm::DenseSet<clang::NamespaceDecl *>;
191
192 // These namespaces are fully parsed
194
195 // We know about these namespaces, but they might not be completely parsed yet
197 llvm::DenseMap<clang::DeclContext *, NamespaceSet> m_parent_to_namespaces;
198};
199
200} // namespace npdb
201} // namespace lldb_private
202
203#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_PDBASTBUILDERCLANG_H
Manages and observes all Clang AST node importing in LLDB.
Represents a generic declaration context in a program.
Represents a generic declaration such as a function declaration.
Generic representation of a type in a programming language.
A uniqued constant string class.
Definition ConstString.h:40
A stream class that can stream formatted output to a file.
Definition Stream.h:28
A TypeSystem implementation based on Clang.
clang::Decl * GetOrCreateSymbolForId(PdbCompilandSymId id)
std::pair< clang::DeclContext *, std::string > CreateDeclInfoForType(const llvm::codeview::TagRecord &record, TypeIndex ti)
void ParseDeclsForSimpleContext(clang::DeclContext &context)
CompilerDeclContext ToCompilerDeclContext(clang::DeclContext *context)
clang::FunctionDecl * GetOrCreateInlinedFunctionDecl(PdbCompilandSymId inlinesite_id)
llvm::DenseMap< clang::DeclContext *, NamespaceSet > m_parent_to_namespaces
void CreateFunctionParameters(PdbCompilandSymId func_id, clang::FunctionDecl &function_decl, uint32_t param_count)
bool CompleteType(CompilerType ct) override
clang::QualType GetBasicType(lldb::BasicType type)
clang::Decl * TryGetDecl(PdbSymUid uid) const
clang::CXXMethodDecl * GetOrCreateMethodDecl(lldb::opaque_compiler_type_t parent_ty, llvm::StringRef name, llvm::StringRef asm_label, const CompilerType &method_ct, bool is_virtual, bool is_static, bool is_artificial)
Returns the method named name with type method_ct in the record parent_ty, creating it if it doesn't ...
clang::QualType CreateType(PdbTypeSymId type)
llvm::DenseMap< std::tuple< lldb::opaque_compiler_type_t, ConstString, lldb::opaque_compiler_type_t >, clang::CXXMethodDecl * > m_cxx_method_decls
clang::QualType CreateArrayType(const llvm::codeview::ArrayRecord &array)
llvm::DenseMap< clang::Decl *, DeclStatus > m_decl_to_status
clang::FunctionDecl * CreateFunctionDeclFromId(PdbTypeSymId func_tid, PdbCompilandSymId func_sid)
CompilerType GetOrCreateType(PdbTypeSymId type) override
clang::QualType CreatePointerType(const llvm::codeview::PointerRecord &pointer)
clang::QualType CreateFunctionType(TypeIndex args_type_idx, TypeIndex return_type_idx, llvm::codeview::CallingConvention calling_convention, unsigned int type_quals)
clang::DeclContext * GetOrCreateDeclContextForCompilandSymbol(PdbCompilandSymId uid)
clang::QualType CreateModifierType(const llvm::codeview::ModifierRecord &modifier)
std::pair< clang::DeclContext *, std::string > CreateDeclInfoForUndecoratedName(llvm::StringRef uname)
clang::FunctionDecl * GetOrCreateFunctionDecl(PdbCompilandSymId func_id)
clang::NamespaceDecl * GetOrCreateNamespaceDecl(const char *name, clang::DeclContext &context)
clang::QualType CreateRecordType(PdbTypeSymId id, const CVTagRecord &record)
void EnsureVariable(PdbCompilandSymId scope_id, PdbCompilandSymId var_id) override
clang::VarDecl * CreateVariableDecl(PdbSymUid uid, llvm::codeview::CVSymbol sym, clang::DeclContext &scope)
void ParseDeclsForContext(CompilerDeclContext context) override
CompilerDecl ToCompilerDecl(clang::Decl *decl)
void EnsureFunction(PdbCompilandSymId func_id) override
llvm::DenseMap< lldb::user_id_t, clang::QualType > m_uid_to_type
void EnsureBlock(PdbCompilandSymId block_id) override
llvm::DenseMap< lldb::user_id_t, clang::Decl * > m_uid_to_decl
CompilerDecl GetOrCreateDeclForUid(PdbSymUid uid) override
CompilerDeclContext FindNamespaceDecl(CompilerDeclContext parent_ctx, llvm::StringRef name) override
bool IsDynamicTagRecord(const CVTagRecord &tag)
void ParseNamespace(clang::DeclContext &parent)
llvm::DenseSet< clang::NamespaceDecl * > NamespaceSet
clang::VarDecl * GetOrCreateVariableDecl(PdbCompilandSymId scope_id, PdbCompilandSymId var_id)
clang::BlockDecl * GetOrCreateBlockDecl(PdbCompilandSymId block_id)
clang::QualType CreateSimpleType(TypeIndex ti)
clang::DeclContext * GetParentClangDeclContext(PdbSymUid uid)
clang::QualType FromCompilerType(CompilerType ct)
clang::QualType CreateEnumType(PdbTypeSymId id, const llvm::codeview::EnumRecord &record)
CompilerType GetOrCreateTypedefType(PdbGlobalSymId id) override
CompilerDeclContext GetParentDeclContext(PdbSymUid uid) override
clang::DeclContext * FromCompilerDeclContext(CompilerDeclContext context)
clang::FunctionDecl * CreateFunctionDecl(PdbCompilandSymId func_id, llvm::StringRef func_name, TypeIndex func_ti, CompilerType func_ct, uint32_t param_count, clang::StorageClass func_storage, bool is_inline, clang::DeclContext *parent)
CompilerDeclContext GetOrCreateDeclContextForUid(PdbSymUid uid) override
void EnsureInlinedFunction(PdbCompilandSymId inlinesite_id) override
CompilerType ToCompilerType(clang::QualType qt)
clang::QualType GetOrCreateClangType(PdbTypeSymId type)
void ParseBlockChildren(PdbCompilandSymId block_id)
void Dump(Stream &stream, llvm::StringRef filter, bool show_color) override
clang::Decl * FromCompilerDecl(CompilerDecl decl)
std::string GetQualifiedName(llvm::StringRef name) override
Convert a CodeView qualified name into the spelling used by the language of this AST (e....
clang::DeclContext * GetOrCreateClangDeclContextForUid(PdbSymUid uid)
A class that represents a running process on the host machine.
void * opaque_compiler_type_t
Definition lldb-types.h:91
BasicType
Basic types enumeration for the public API SBType::GetBasicType().
uint64_t user_id_t
Definition lldb-types.h:83
DeclStatus(lldb::user_id_t uid, bool resolved)