LLDB  mainline
PdbAstBuilder.h
Go to the documentation of this file.
1 //===-- PdbAstBuilder.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_SYMBOLFILE_NATIVEPDB_PDBASTBUILDER_H
10 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_PDBASTBUILDER_H
11 
12 #include "llvm/ADT/DenseMap.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/Support/Threading.h"
15 
17 
18 #include "PdbIndex.h"
19 #include "PdbSymUid.h"
20 
21 namespace clang {
22 class TagDecl;
23 class DeclContext;
24 class Decl;
25 class QualType;
26 class FunctionDecl;
27 class NamespaceDecl;
28 } // namespace clang
29 
30 namespace llvm {
31 namespace codeview {
32 class ProcSym;
33 }
34 } // namespace llvm
35 
36 namespace lldb_private {
37 class ClangASTImporter;
38 class ObjectFile;
39 
40 namespace npdb {
41 class PdbIndex;
42 struct VariableInfo;
43 
44 struct DeclStatus {
45  DeclStatus() = default;
47  : uid(uid), resolved(resolved) {}
49  bool resolved = false;
50 };
51 
53 public:
54  // Constructors and Destructors
56 
58 
59  llvm::Optional<lldb_private::CompilerDecl>
61  clang::DeclContext *GetOrCreateDeclContextForUid(PdbSymUid uid);
62  clang::DeclContext *GetParentDeclContext(PdbSymUid uid);
63 
64  clang::FunctionDecl *GetOrCreateFunctionDecl(PdbCompilandSymId func_id);
65  clang::FunctionDecl *
67  clang::BlockDecl *GetOrCreateBlockDecl(PdbCompilandSymId block_id);
68  clang::VarDecl *GetOrCreateVariableDecl(PdbCompilandSymId scope_id,
69  PdbCompilandSymId var_id);
70  clang::VarDecl *GetOrCreateVariableDecl(PdbGlobalSymId var_id);
71  clang::TypedefNameDecl *GetOrCreateTypedefDecl(PdbGlobalSymId id);
72  void ParseDeclsForContext(clang::DeclContext &context);
73 
74  clang::QualType GetBasicType(lldb::BasicType type);
75  clang::QualType GetOrCreateType(PdbTypeSymId type);
76 
77  bool CompleteTagDecl(clang::TagDecl &tag);
78  bool CompleteType(clang::QualType qt);
79 
80  CompilerDecl ToCompilerDecl(clang::Decl &decl);
81  CompilerType ToCompilerType(clang::QualType qt);
82  CompilerDeclContext ToCompilerDeclContext(clang::DeclContext &context);
83  clang::Decl *FromCompilerDecl(CompilerDecl decl);
84  clang::DeclContext *FromCompilerDeclContext(CompilerDeclContext context);
85 
86  TypeSystemClang &clang() { return m_clang; }
88 
89  void Dump(Stream &stream);
90 
91 private:
92  clang::Decl *TryGetDecl(PdbSymUid uid) const;
93 
94  using TypeIndex = llvm::codeview::TypeIndex;
95 
96  clang::QualType
97  CreatePointerType(const llvm::codeview::PointerRecord &pointer);
98  clang::QualType
99  CreateModifierType(const llvm::codeview::ModifierRecord &modifier);
100  clang::QualType CreateArrayType(const llvm::codeview::ArrayRecord &array);
101  clang::QualType CreateRecordType(PdbTypeSymId id,
102  const llvm::codeview::TagRecord &record);
103  clang::QualType CreateEnumType(PdbTypeSymId id,
104  const llvm::codeview::EnumRecord &record);
105  clang::QualType
106  CreateFunctionType(TypeIndex args_type_idx, TypeIndex return_type_idx,
107  llvm::codeview::CallingConvention calling_convention);
108  clang::QualType CreateType(PdbTypeSymId type);
109 
111  clang::FunctionDecl &function_decl,
112  uint32_t param_count);
113  clang::Decl *GetOrCreateSymbolForId(PdbCompilandSymId id);
114  clang::VarDecl *CreateVariableDecl(PdbSymUid uid,
115  llvm::codeview::CVSymbol sym,
116  clang::DeclContext &scope);
117  clang::NamespaceDecl *GetOrCreateNamespaceDecl(const char *name,
118  clang::DeclContext &context);
119  clang::FunctionDecl *CreateFunctionDeclFromId(PdbTypeSymId func_tid,
120  PdbCompilandSymId func_sid);
121  clang::FunctionDecl *
122  CreateFunctionDecl(PdbCompilandSymId func_id, llvm::StringRef func_name,
123  TypeIndex func_ti, CompilerType func_ct,
124  uint32_t param_count, clang::StorageClass func_storage,
125  bool is_inline, clang::DeclContext *parent);
126  void ParseNamespace(clang::DeclContext &parent);
127  void ParseAllTypes();
129  void ParseDeclsForSimpleContext(clang::DeclContext &context);
130  void ParseBlockChildren(PdbCompilandSymId block_id);
131 
132  std::pair<clang::DeclContext *, std::string>
133  CreateDeclInfoForType(const llvm::codeview::TagRecord &record, TypeIndex ti);
134  std::pair<clang::DeclContext *, std::string>
135  CreateDeclInfoForUndecoratedName(llvm::StringRef uname);
136  clang::QualType CreateSimpleType(TypeIndex ti);
137 
139 
142  llvm::once_flag m_parse_all_types;
143  llvm::DenseMap<clang::Decl *, DeclStatus> m_decl_to_status;
144  llvm::DenseMap<lldb::user_id_t, clang::Decl *> m_uid_to_decl;
145  llvm::DenseMap<lldb::user_id_t, clang::QualType> m_uid_to_type;
146 
147  // From class/struct's opaque_compiler_type_t to a set containing the pairs of
148  // method's name and CompilerType.
149  llvm::DenseMap<lldb::opaque_compiler_type_t,
150  llvm::SmallSet<std::pair<llvm::StringRef, CompilerType>, 8>>
152  llvm::DenseSet<clang::NamespaceDecl *> m_parsed_namespaces;
153 };
154 
155 } // namespace npdb
156 } // namespace lldb_private
157 
158 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_PDBASTBUILDER_H
lldb_private::npdb::PdbAstBuilder::m_uid_to_decl
llvm::DenseMap< lldb::user_id_t, clang::Decl * > m_uid_to_decl
Definition: PdbAstBuilder.h:144
lldb_private::npdb::PdbAstBuilder::CreateEnumType
clang::QualType CreateEnumType(PdbTypeSymId id, const llvm::codeview::EnumRecord &record)
Definition: PdbAstBuilder.cpp:1139
llvm
Definition: Debugger.h:50
lldb_private::npdb::PdbAstBuilder::ToCompilerType
CompilerType ToCompilerType(clang::QualType qt)
Definition: PdbAstBuilder.cpp:1430
lldb_private::npdb::PdbAstBuilder::CreateDeclInfoForType
std::pair< clang::DeclContext *, std::string > CreateDeclInfoForType(const llvm::codeview::TagRecord &record, TypeIndex ti)
Definition: PdbAstBuilder.cpp:168
lldb_private::npdb::PdbAstBuilder::CreateVariableDecl
clang::VarDecl * CreateVariableDecl(PdbSymUid uid, llvm::codeview::CVSymbol sym, clang::DeclContext &scope)
Definition: PdbAstBuilder.cpp:667
lldb_private::npdb::PdbAstBuilder::m_importer
ClangASTImporter m_importer
Definition: PdbAstBuilder.h:140
lldb_private::npdb::PdbAstBuilder::CreateDeclInfoForUndecoratedName
std::pair< clang::DeclContext *, std::string > CreateDeclInfoForUndecoratedName(llvm::StringRef uname)
Definition: PdbAstBuilder.cpp:320
lldb_private::npdb::PdbAstBuilder::PdbAstBuilder
PdbAstBuilder(TypeSystemClang &clang)
Definition: PdbAstBuilder.cpp:161
lldb_private::npdb::PdbAstBuilder::GetOrCreateBlockDecl
clang::BlockDecl * GetOrCreateBlockDecl(PdbCompilandSymId block_id)
Definition: PdbAstBuilder.cpp:649
lldb_private::npdb::PdbAstBuilder::FromCompilerDeclContext
clang::DeclContext * FromCompilerDeclContext(CompilerDeclContext context)
Definition: PdbAstBuilder.cpp:1444
lldb_private::npdb::PdbCompilandSymId
Definition: PdbSymUid.h:44
lldb_private::npdb::PdbAstBuilder::CreateRecordType
clang::QualType CreateRecordType(PdbTypeSymId id, const llvm::codeview::TagRecord &record)
Definition: PdbAstBuilder.cpp:599
lldb_private::npdb::PdbAstBuilder::GetOrCreateNamespaceDecl
clang::NamespaceDecl * GetOrCreateNamespaceDecl(const char *name, clang::DeclContext &context)
Definition: PdbAstBuilder.cpp:641
lldb_private::npdb::PdbAstBuilder::clang
TypeSystemClang & clang()
Definition: PdbAstBuilder.h:86
lldb_private::npdb::PdbAstBuilder::GetOrCreateTypedefDecl
clang::TypedefNameDecl * GetOrCreateTypedefDecl(PdbGlobalSymId id)
Definition: PdbAstBuilder.cpp:715
lldb_private::npdb::PdbAstBuilder::CreateFunctionDeclFromId
clang::FunctionDecl * CreateFunctionDeclFromId(PdbTypeSymId func_tid, PdbCompilandSymId func_sid)
Definition: PdbAstBuilder.cpp:958
lldb_private::npdb::PdbAstBuilder::m_clang
TypeSystemClang & m_clang
Definition: PdbAstBuilder.h:138
lldb_private::npdb::PdbAstBuilder::GetTranslationUnitDecl
lldb_private::CompilerDeclContext GetTranslationUnitDecl()
Definition: PdbAstBuilder.cpp:163
lldb_private::npdb::PdbAstBuilder::GetParentDeclContext
clang::DeclContext * GetParentDeclContext(PdbSymUid uid)
Definition: PdbAstBuilder.cpp:356
lldb_private::CompilerDecl
Represents a generic declaration such as a function declaration.
Definition: CompilerDecl.h:28
lldb_private::npdb::PdbAstBuilder::m_parse_all_types
llvm::once_flag m_parse_all_types
Definition: PdbAstBuilder.h:142
lldb_private::npdb::PdbAstBuilder::GetOrCreateFunctionDecl
clang::FunctionDecl * GetOrCreateFunctionDecl(PdbCompilandSymId func_id)
Definition: PdbAstBuilder.cpp:1010
lldb_private::npdb::PdbAstBuilder::CreateFunctionParameters
void CreateFunctionParameters(PdbCompilandSymId func_id, clang::FunctionDecl &function_decl, uint32_t param_count)
Definition: PdbAstBuilder.cpp:1064
lldb_private::npdb::PdbAstBuilder::CreateType
clang::QualType CreateType(PdbTypeSymId type)
Definition: PdbAstBuilder.cpp:750
lldb_private::Stream
Definition: Stream.h:28
lldb::BasicType
BasicType
Basic types enumeration for the public API SBType::GetBasicType().
Definition: lldb-enumerations.h:748
lldb_private::npdb::PdbAstBuilder::ParseAllFunctionsAndNonLocalVars
void ParseAllFunctionsAndNonLocalVars()
Definition: PdbAstBuilder.cpp:1291
PdbIndex.h
lldb_private::npdb::DeclStatus
Definition: PdbAstBuilder.h:44
lldb_private::npdb::DeclStatus::DeclStatus
DeclStatus(lldb::user_id_t uid, bool resolved)
Definition: PdbAstBuilder.h:46
lldb_private::npdb::PdbAstBuilder::GetClangASTImporter
ClangASTImporter & GetClangASTImporter()
Definition: PdbAstBuilder.h:87
lldb_private::npdb::PdbGlobalSymId
Definition: PdbSymUid.h:57
lldb_private::npdb::PdbAstBuilder::GetBasicType
clang::QualType GetBasicType(lldb::BasicType type)
Definition: PdbAstBuilder.cpp:745
lldb_private::npdb::DeclStatus::resolved
bool resolved
Definition: PdbAstBuilder.h:49
lldb_private::npdb::PdbAstBuilder::FromCompilerDecl
clang::Decl * FromCompilerDecl(CompilerDecl decl)
Definition: PdbAstBuilder.cpp:1439
lldb_private::npdb::PdbAstBuilder::ToCompilerDeclContext
CompilerDeclContext ToCompilerDeclContext(clang::DeclContext &context)
Definition: PdbAstBuilder.cpp:1435
lldb_private::npdb::PdbAstBuilder::m_parsed_namespaces
llvm::DenseSet< clang::NamespaceDecl * > m_parsed_namespaces
Definition: PdbAstBuilder.h:152
lldb_private::npdb::PdbTypeSymId
Definition: PdbSymUid.h:70
lldb_private::npdb::PdbAstBuilder::TryGetDecl
clang::Decl * TryGetDecl(PdbSymUid uid) const
Definition: PdbAstBuilder.cpp:633
lldb_private::npdb::PdbAstBuilder::TypeIndex
llvm::codeview::TypeIndex TypeIndex
Definition: PdbAstBuilder.h:94
lldb_private::npdb::PdbAstBuilder::CompleteTagDecl
bool CompleteTagDecl(clang::TagDecl &tag)
Definition: PdbAstBuilder.cpp:433
lldb_private::npdb::PdbAstBuilder::Dump
void Dump(Stream &stream)
Definition: PdbAstBuilder.cpp:1448
lldb_private::npdb::PdbAstBuilder::CreateArrayType
clang::QualType CreateArrayType(const llvm::codeview::ArrayRecord &array)
Definition: PdbAstBuilder.cpp:1162
lldb_private::npdb::PdbAstBuilder::CompleteType
bool CompleteType(clang::QualType qt)
Definition: PdbAstBuilder.cpp:419
lldb_private::npdb::PdbAstBuilder::m_uid_to_type
llvm::DenseMap< lldb::user_id_t, clang::QualType > m_uid_to_type
Definition: PdbAstBuilder.h:145
lldb_private::CompilerDeclContext
Represents a generic declaration context in a program.
Definition: CompilerDeclContext.h:30
lldb_private::npdb::PdbAstBuilder::CreateSimpleType
clang::QualType CreateSimpleType(TypeIndex ti)
Definition: PdbAstBuilder.cpp:493
lldb_private::npdb::DeclStatus::DeclStatus
DeclStatus()=default
lldb_private::npdb::PdbAstBuilder::m_decl_to_status
llvm::DenseMap< clang::Decl *, DeclStatus > m_decl_to_status
Definition: PdbAstBuilder.h:143
lldb_private::npdb::PdbAstBuilder::CreatePointerType
clang::QualType CreatePointerType(const llvm::codeview::PointerRecord &pointer)
Definition: PdbAstBuilder.cpp:514
lldb_private::npdb::PdbAstBuilder::m_parse_functions_and_non_local_vars
llvm::once_flag m_parse_functions_and_non_local_vars
Definition: PdbAstBuilder.h:141
lldb_private::npdb::PdbAstBuilder::GetOrCreateInlinedFunctionDecl
clang::FunctionDecl * GetOrCreateInlinedFunctionDecl(PdbCompilandSymId inlinesite_id)
Definition: PdbAstBuilder.cpp:919
uint32_t
PdbSymUid.h
lldb_private::npdb::PdbAstBuilder::GetOrCreateDeclContextForUid
clang::DeclContext * GetOrCreateDeclContextForUid(PdbSymUid uid)
Definition: PdbAstBuilder.cpp:304
lldb_private::npdb::PdbAstBuilder::ParseDeclsForContext
void ParseDeclsForContext(clang::DeclContext &context)
Definition: PdbAstBuilder.cpp:1402
lldb_private::npdb::PdbAstBuilder::CreateModifierType
clang::QualType CreateModifierType(const llvm::codeview::ModifierRecord &modifier)
Definition: PdbAstBuilder.cpp:586
lldb_private::npdb::PdbAstBuilder::ParseAllTypes
void ParseAllTypes()
Definition: PdbAstBuilder.cpp:1273
lldb_private::ClangASTImporter
Manages and observes all Clang AST node importing in LLDB.
Definition: ClangASTImporter.h:64
lldb_private::npdb::PdbAstBuilder::ParseNamespace
void ParseNamespace(clang::DeclContext &parent)
Definition: PdbAstBuilder.cpp:1234
lldb_private::npdb::PdbAstBuilder::m_cxx_record_map
llvm::DenseMap< lldb::opaque_compiler_type_t, llvm::SmallSet< std::pair< llvm::StringRef, CompilerType >, 8 > > m_cxx_record_map
Definition: PdbAstBuilder.h:151
clang
Definition: ASTResultSynthesizer.h:15
lldb_private::npdb::PdbAstBuilder::GetOrCreateType
clang::QualType GetOrCreateType(PdbTypeSymId type)
Definition: PdbAstBuilder.cpp:804
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:35
lldb_private::npdb::PdbAstBuilder::CreateFunctionDecl
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)
Definition: PdbAstBuilder.cpp:848
lldb::user_id_t
uint64_t user_id_t
Definition: lldb-types.h:84
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::npdb::PdbAstBuilder::GetOrCreateDeclForUid
llvm::Optional< lldb_private::CompilerDecl > GetOrCreateDeclForUid(PdbSymUid uid)
Definition: PdbAstBuilder.cpp:275
lldb_private::npdb::PdbAstBuilder::ToCompilerDecl
CompilerDecl ToCompilerDecl(clang::Decl &decl)
Definition: PdbAstBuilder.cpp:1426
lldb_private::npdb::PdbAstBuilder::CreateFunctionType
clang::QualType CreateFunctionType(TypeIndex args_type_idx, TypeIndex return_type_idx, llvm::codeview::CallingConvention calling_convention)
Definition: PdbAstBuilder.cpp:1178
lldb_private::npdb::PdbAstBuilder::GetOrCreateVariableDecl
clang::VarDecl * GetOrCreateVariableDecl(PdbCompilandSymId scope_id, PdbCompilandSymId var_id)
Definition: PdbAstBuilder.cpp:686
lldb_private::TypeSystemClang
A TypeSystem implementation based on Clang.
Definition: TypeSystemClang.h:105
lldb_private::npdb::DeclStatus::uid
lldb::user_id_t uid
Definition: PdbAstBuilder.h:48
ClangASTImporter.h
lldb_private::npdb::PdbAstBuilder::ParseBlockChildren
void ParseBlockChildren(PdbCompilandSymId block_id)
Definition: PdbAstBuilder.cpp:1352
lldb_private::npdb::PdbSymUid
Definition: PdbSymUid.h:91
lldb_private::npdb::PdbAstBuilder::ParseDeclsForSimpleContext
void ParseDeclsForSimpleContext(clang::DeclContext &context)
Definition: PdbAstBuilder.cpp:1383
lldb_private::npdb::PdbAstBuilder::GetOrCreateSymbolForId
clang::Decl * GetOrCreateSymbolForId(PdbCompilandSymId id)
Definition: PdbAstBuilder.cpp:240
lldb::opaque_compiler_type_t
void * opaque_compiler_type_t
Definition: lldb-types.h:90
lldb_private::npdb::PdbAstBuilder
Definition: PdbAstBuilder.h:52