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
15
16#include "llvm/ADT/DenseMap.h"
17#include "llvm/DebugInfo/CodeView/CVRecord.h"
18#include "llvm/Support/Threading.h"
19
20namespace clang {
21class TagDecl;
22class DeclContext;
23class Decl;
24class QualType;
25class FunctionDecl;
26class NamespaceDecl;
27class BlockDecl;
28class VarDecl;
29} // namespace clang
30
31namespace llvm {
32namespace codeview {
33class PointerRecord;
34class ModifierRecord;
35class ArrayRecord;
36class TagRecord;
37class EnumRecord;
38enum class CallingConvention : uint8_t;
39} // namespace codeview
40} // namespace llvm
41
42namespace lldb_private {
43namespace npdb {
44
52
54public:
56
60
61 void EnsureFunction(PdbCompilandSymId func_id) override;
62 void EnsureInlinedFunction(PdbCompilandSymId inlinesite_id) override;
63 void EnsureBlock(PdbCompilandSymId block_id) override;
65 PdbCompilandSymId var_id) override;
66 void EnsureVariable(PdbGlobalSymId var_id) override;
67
70 bool CompleteType(CompilerType ct) override;
71
72 void ParseDeclsForContext(CompilerDeclContext context) override;
73
75 llvm::StringRef name) override;
76
77 void Dump(Stream &stream, llvm::StringRef filter, bool show_color) override;
78
79 // Clang-specific
80 clang::QualType GetBasicType(lldb::BasicType type);
81 clang::QualType GetOrCreateClangType(PdbTypeSymId type);
82 clang::DeclContext *GetOrCreateClangDeclContextForUid(PdbSymUid uid);
83
84 CompilerDecl ToCompilerDecl(clang::Decl *decl);
85 CompilerType ToCompilerType(clang::QualType qt);
86 CompilerDeclContext ToCompilerDeclContext(clang::DeclContext *context);
87 clang::QualType FromCompilerType(CompilerType ct);
88 clang::Decl *FromCompilerDecl(CompilerDecl decl);
89 clang::DeclContext *FromCompilerDeclContext(CompilerDeclContext context);
90
91 bool CompleteTagDecl(clang::TagDecl &tag);
92
95
96private:
98 clang::DeclContext *GetParentClangDeclContext(PdbSymUid uid);
99
100 clang::Decl *TryGetDecl(PdbSymUid uid) const;
101
102 clang::FunctionDecl *GetOrCreateFunctionDecl(PdbCompilandSymId func_id);
103 clang::FunctionDecl *
105 clang::BlockDecl *GetOrCreateBlockDecl(PdbCompilandSymId block_id);
106 clang::VarDecl *GetOrCreateVariableDecl(PdbCompilandSymId scope_id,
107 PdbCompilandSymId var_id);
108 clang::VarDecl *GetOrCreateVariableDecl(PdbGlobalSymId var_id);
109
110 using TypeIndex = llvm::codeview::TypeIndex;
111
112 clang::QualType
113 CreatePointerType(const llvm::codeview::PointerRecord &pointer);
114 clang::QualType
115 CreateModifierType(const llvm::codeview::ModifierRecord &modifier);
116 clang::QualType CreateArrayType(const llvm::codeview::ArrayRecord &array);
117 clang::QualType CreateRecordType(PdbTypeSymId id,
118 const llvm::codeview::TagRecord &record);
119 clang::QualType CreateEnumType(PdbTypeSymId id,
120 const llvm::codeview::EnumRecord &record);
121 clang::QualType
122 CreateFunctionType(TypeIndex args_type_idx, TypeIndex return_type_idx,
123 llvm::codeview::CallingConvention calling_convention);
124 clang::QualType CreateType(PdbTypeSymId type);
125
127 clang::FunctionDecl &function_decl,
128 uint32_t param_count);
130 clang::VarDecl *CreateVariableDecl(PdbSymUid uid,
131 llvm::codeview::CVSymbol sym,
132 clang::DeclContext &scope);
133 clang::NamespaceDecl *GetOrCreateNamespaceDecl(const char *name,
134 clang::DeclContext &context);
135 clang::FunctionDecl *CreateFunctionDeclFromId(PdbTypeSymId func_tid,
136 PdbCompilandSymId func_sid);
137 clang::FunctionDecl *
138 CreateFunctionDecl(PdbCompilandSymId func_id, llvm::StringRef func_name,
139 TypeIndex func_ti, CompilerType func_ct,
140 uint32_t param_count, clang::StorageClass func_storage,
141 bool is_inline, clang::DeclContext *parent);
142 void ParseNamespace(clang::DeclContext &parent);
143 void ParseAllTypes();
145 void ParseDeclsForSimpleContext(clang::DeclContext &context);
147
148 std::pair<clang::DeclContext *, std::string>
149 CreateDeclInfoForType(const llvm::codeview::TagRecord &record, TypeIndex ti);
150 std::pair<clang::DeclContext *, std::string>
151 CreateDeclInfoForUndecoratedName(llvm::StringRef uname);
152 clang::QualType CreateSimpleType(TypeIndex ti);
153
155
158 llvm::once_flag m_parse_all_types;
159 llvm::DenseMap<clang::Decl *, DeclStatus> m_decl_to_status;
160 llvm::DenseMap<lldb::user_id_t, clang::Decl *> m_uid_to_decl;
161 llvm::DenseMap<lldb::user_id_t, clang::QualType> m_uid_to_type;
162
163 // From class/struct's opaque_compiler_type_t to a set containing the pairs of
164 // method's name and CompilerType.
165 llvm::DenseMap<lldb::opaque_compiler_type_t,
166 llvm::SmallSet<std::pair<llvm::StringRef, CompilerType>, 8>>
168
169 using NamespaceSet = llvm::DenseSet<clang::NamespaceDecl *>;
170
171 // These namespaces are fully parsed
173
174 // We know about these namespaces, but they might not be completely parsed yet
176 llvm::DenseMap<clang::DeclContext *, NamespaceSet> m_parent_to_namespaces;
177};
178
179} // namespace npdb
180} // namespace lldb_private
181
182#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 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::QualType CreateType(PdbTypeSymId type)
clang::QualType CreateFunctionType(TypeIndex args_type_idx, TypeIndex return_type_idx, llvm::codeview::CallingConvention calling_convention)
clang::QualType CreateArrayType(const llvm::codeview::ArrayRecord &array)
llvm::DenseMap< clang::Decl *, DeclStatus > m_decl_to_status
llvm::DenseMap< lldb::opaque_compiler_type_t, llvm::SmallSet< std::pair< llvm::StringRef, CompilerType >, 8 > > m_cxx_record_map
clang::FunctionDecl * CreateFunctionDeclFromId(PdbTypeSymId func_tid, PdbCompilandSymId func_sid)
CompilerType GetOrCreateType(PdbTypeSymId type) override
clang::QualType CreatePointerType(const llvm::codeview::PointerRecord &pointer)
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)
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
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
clang::QualType CreateRecordType(PdbTypeSymId id, const llvm::codeview::TagRecord &record)
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)
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:89
BasicType
Basic types enumeration for the public API SBType::GetBasicType().
uint64_t user_id_t
Definition lldb-types.h:82
DeclStatus(lldb::user_id_t uid, bool resolved)