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 
16 
17 #include "PdbIndex.h"
18 #include "PdbSymUid.h"
19 
20 namespace clang {
21 class TagDecl;
22 class DeclContext;
23 class Decl;
24 class QualType;
25 class FunctionDecl;
26 class NamespaceDecl;
27 } // namespace clang
28 
29 namespace llvm {
30 namespace codeview {
31 class ProcSym;
32 }
33 } // namespace llvm
34 
35 namespace lldb_private {
36 class ClangASTImporter;
37 class ObjectFile;
38 
39 namespace npdb {
40 class PdbIndex;
41 struct VariableInfo;
42 
43 struct DeclStatus {
44  DeclStatus() = default;
46  : uid(uid), resolved(resolved) {}
48  bool resolved = false;
49 };
50 
52 public:
53  // Constructors and Destructors
55 
57 
58  llvm::Optional<lldb_private::CompilerDecl>
60  clang::DeclContext *GetOrCreateDeclContextForUid(PdbSymUid uid);
61  clang::DeclContext *GetParentDeclContext(PdbSymUid uid);
62 
63  clang::FunctionDecl *GetOrCreateFunctionDecl(PdbCompilandSymId func_id);
64  clang::FunctionDecl *
66  clang::BlockDecl *GetOrCreateBlockDecl(PdbCompilandSymId block_id);
67  clang::VarDecl *GetOrCreateVariableDecl(PdbCompilandSymId scope_id,
68  PdbCompilandSymId var_id);
69  clang::VarDecl *GetOrCreateVariableDecl(PdbGlobalSymId var_id);
70  clang::TypedefNameDecl *GetOrCreateTypedefDecl(PdbGlobalSymId id);
71  void ParseDeclsForContext(clang::DeclContext &context);
72 
73  clang::QualType GetBasicType(lldb::BasicType type);
74  clang::QualType GetOrCreateType(PdbTypeSymId type);
75 
76  bool CompleteTagDecl(clang::TagDecl &tag);
77  bool CompleteType(clang::QualType qt);
78 
79  CompilerDecl ToCompilerDecl(clang::Decl &decl);
80  CompilerType ToCompilerType(clang::QualType qt);
81  CompilerDeclContext ToCompilerDeclContext(clang::DeclContext &context);
82  clang::Decl *FromCompilerDecl(CompilerDecl decl);
83  clang::DeclContext *FromCompilerDeclContext(CompilerDeclContext context);
84 
85  TypeSystemClang &clang() { return m_clang; }
87 
88  void Dump(Stream &stream);
89 
90 private:
91  clang::Decl *TryGetDecl(PdbSymUid uid) const;
92 
93  using TypeIndex = llvm::codeview::TypeIndex;
94 
95  clang::QualType
96  CreatePointerType(const llvm::codeview::PointerRecord &pointer);
97  clang::QualType
98  CreateModifierType(const llvm::codeview::ModifierRecord &modifier);
99  clang::QualType CreateArrayType(const llvm::codeview::ArrayRecord &array);
100  clang::QualType CreateRecordType(PdbTypeSymId id,
101  const llvm::codeview::TagRecord &record);
102  clang::QualType CreateEnumType(PdbTypeSymId id,
103  const llvm::codeview::EnumRecord &record);
104  clang::QualType
105  CreateFunctionType(TypeIndex args_type_idx, TypeIndex return_type_idx,
106  llvm::codeview::CallingConvention calling_convention);
107  clang::QualType CreateType(PdbTypeSymId type);
108 
110  clang::FunctionDecl &function_decl,
111  uint32_t param_count);
112  clang::Decl *GetOrCreateSymbolForId(PdbCompilandSymId id);
113  clang::VarDecl *CreateVariableDecl(PdbSymUid uid,
114  llvm::codeview::CVSymbol sym,
115  clang::DeclContext &scope);
116  clang::DeclContext *
117  GetParentDeclContextForSymbol(const llvm::codeview::CVSymbol &sym);
118 
119  clang::NamespaceDecl *GetOrCreateNamespaceDecl(const char *name,
120  clang::DeclContext &context);
121  clang::FunctionDecl *CreateFunctionDeclFromId(PdbTypeSymId func_tid,
122  PdbCompilandSymId func_sid);
123  clang::FunctionDecl *
124  CreateFunctionDecl(PdbCompilandSymId func_id, llvm::StringRef func_name,
125  TypeIndex func_ti, CompilerType func_ct,
126  uint32_t param_count, clang::StorageClass func_storage,
127  bool is_inline, clang::DeclContext *parent);
128  void ParseAllNamespacesPlusChildrenOf(llvm::Optional<llvm::StringRef> parent);
129  void ParseDeclsForSimpleContext(clang::DeclContext &context);
130  void ParseBlockChildren(PdbCompilandSymId block_id);
131 
132  void BuildParentMap();
133  std::pair<clang::DeclContext *, std::string>
134  CreateDeclInfoForType(const llvm::codeview::TagRecord &record, TypeIndex ti);
135  std::pair<clang::DeclContext *, std::string>
136  CreateDeclInfoForUndecoratedName(llvm::StringRef uname);
137  clang::QualType CreateSimpleType(TypeIndex ti);
138 
141 
143 
144  llvm::DenseMap<TypeIndex, TypeIndex> m_parent_types;
145  llvm::DenseMap<clang::Decl *, DeclStatus> m_decl_to_status;
146  llvm::DenseMap<lldb::user_id_t, clang::Decl *> m_uid_to_decl;
147  llvm::DenseMap<lldb::user_id_t, clang::QualType> m_uid_to_type;
148 
149  // From class/struct's opaque_compiler_type_t to a set containing the pairs of
150  // method's name and CompilerType.
151  llvm::DenseMap<lldb::opaque_compiler_type_t,
152  llvm::SmallSet<std::pair<llvm::StringRef, CompilerType>, 8>>
154 };
155 
156 } // namespace npdb
157 } // namespace lldb_private
158 
159 #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:146
lldb_private::npdb::PdbAstBuilder::CreateEnumType
clang::QualType CreateEnumType(PdbTypeSymId id, const llvm::codeview::EnumRecord &record)
Definition: PdbAstBuilder.cpp:1317
llvm
Definition: Debugger.h:50
lldb_private::npdb::PdbAstBuilder::ToCompilerType
CompilerType ToCompilerType(clang::QualType qt)
Definition: PdbAstBuilder.cpp:1564
lldb_private::npdb::PdbAstBuilder::CreateDeclInfoForType
std::pair< clang::DeclContext *, std::string > CreateDeclInfoForType(const llvm::codeview::TagRecord &record, TypeIndex ti)
Definition: PdbAstBuilder.cpp:275
lldb_private::npdb::PdbAstBuilder::BuildParentMap
void BuildParentMap()
Definition: PdbAstBuilder.cpp:331
lldb_private::npdb::PdbAstBuilder::CreateVariableDecl
clang::VarDecl * CreateVariableDecl(PdbSymUid uid, llvm::codeview::CVSymbol sym, clang::DeclContext &scope)
Definition: PdbAstBuilder.cpp:898
lldb_private::npdb::PdbAstBuilder::m_importer
ClangASTImporter m_importer
Definition: PdbAstBuilder.h:142
lldb_private::npdb::PdbAstBuilder::CreateDeclInfoForUndecoratedName
std::pair< clang::DeclContext *, std::string > CreateDeclInfoForUndecoratedName(llvm::StringRef uname)
Definition: PdbAstBuilder.cpp:567
lldb_private::npdb::PdbIndex
PdbIndex - Lazy access to the important parts of a PDB file.
Definition: PdbIndex.h:47
lldb_private::npdb::PdbAstBuilder::GetOrCreateBlockDecl
clang::BlockDecl * GetOrCreateBlockDecl(PdbCompilandSymId block_id)
Definition: PdbAstBuilder.cpp:880
lldb_private::npdb::PdbAstBuilder::FromCompilerDeclContext
clang::DeclContext * FromCompilerDeclContext(CompilerDeclContext context)
Definition: PdbAstBuilder.cpp:1578
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:833
lldb_private::npdb::PdbAstBuilder::GetOrCreateNamespaceDecl
clang::NamespaceDecl * GetOrCreateNamespaceDecl(const char *name, clang::DeclContext &context)
Definition: PdbAstBuilder.cpp:872
lldb_private::npdb::PdbAstBuilder::clang
TypeSystemClang & clang()
Definition: PdbAstBuilder.h:85
lldb_private::npdb::PdbAstBuilder::GetOrCreateTypedefDecl
clang::TypedefNameDecl * GetOrCreateTypedefDecl(PdbGlobalSymId id)
Definition: PdbAstBuilder.cpp:938
lldb_private::npdb::PdbAstBuilder::CreateFunctionDeclFromId
clang::FunctionDecl * CreateFunctionDeclFromId(PdbTypeSymId func_tid, PdbCompilandSymId func_sid)
Definition: PdbAstBuilder.cpp:1150
lldb_private::npdb::PdbAstBuilder::m_clang
TypeSystemClang & m_clang
Definition: PdbAstBuilder.h:140
lldb_private::npdb::PdbAstBuilder::GetTranslationUnitDecl
lldb_private::CompilerDeclContext GetTranslationUnitDecl()
Definition: PdbAstBuilder.cpp:270
lldb_private::npdb::PdbAstBuilder::GetParentDeclContext
clang::DeclContext * GetParentDeclContext(PdbSymUid uid)
Definition: PdbAstBuilder.cpp:642
lldb_private::CompilerDecl
Represents a generic declaration such as a function declaration.
Definition: CompilerDecl.h:28
lldb_private::npdb::PdbAstBuilder::GetOrCreateFunctionDecl
clang::FunctionDecl * GetOrCreateFunctionDecl(PdbCompilandSymId func_id)
Definition: PdbAstBuilder.cpp:1199
lldb_private::npdb::PdbAstBuilder::CreateFunctionParameters
void CreateFunctionParameters(PdbCompilandSymId func_id, clang::FunctionDecl &function_decl, uint32_t param_count)
Definition: PdbAstBuilder.cpp:1247
lldb_private::npdb::PdbAstBuilder::CreateType
clang::QualType CreateType(PdbTypeSymId type)
Definition: PdbAstBuilder.cpp:968
lldb_private::Stream
Definition: Stream.h:28
lldb::BasicType
BasicType
Basic types enumeration for the public API SBType::GetBasicType().
Definition: lldb-enumerations.h:741
PdbIndex.h
lldb_private::npdb::DeclStatus
Definition: PdbAstBuilder.h:43
lldb_private::npdb::DeclStatus::DeclStatus
DeclStatus(lldb::user_id_t uid, bool resolved)
Definition: PdbAstBuilder.h:45
lldb_private::npdb::PdbGlobalSymId
Definition: PdbSymUid.h:57
lldb_private::npdb::PdbAstBuilder::GetBasicType
clang::QualType GetBasicType(lldb::BasicType type)
Definition: PdbAstBuilder.cpp:963
lldb_private::npdb::DeclStatus::resolved
bool resolved
Definition: PdbAstBuilder.h:48
lldb_private::npdb::PdbAstBuilder::FromCompilerDecl
clang::Decl * FromCompilerDecl(CompilerDecl decl)
Definition: PdbAstBuilder.cpp:1573
lldb_private::npdb::PdbAstBuilder::ToCompilerDeclContext
CompilerDeclContext ToCompilerDeclContext(clang::DeclContext &context)
Definition: PdbAstBuilder.cpp:1569
lldb_private::npdb::PdbTypeSymId
Definition: PdbSymUid.h:70
lldb_private::npdb::PdbAstBuilder::TryGetDecl
clang::Decl * TryGetDecl(PdbSymUid uid) const
Definition: PdbAstBuilder.cpp:864
lldb_private::npdb::PdbAstBuilder::TypeIndex
llvm::codeview::TypeIndex TypeIndex
Definition: PdbAstBuilder.h:93
lldb_private::npdb::PdbAstBuilder::CompleteTagDecl
bool CompleteTagDecl(clang::TagDecl &tag)
Definition: PdbAstBuilder.cpp:710
lldb_private::npdb::PdbAstBuilder::Dump
void Dump(Stream &stream)
Definition: PdbAstBuilder.cpp:1582
lldb_private::npdb::PdbAstBuilder::CreateArrayType
clang::QualType CreateArrayType(const llvm::codeview::ArrayRecord &array)
Definition: PdbAstBuilder.cpp:1335
lldb_private::npdb::PdbAstBuilder::CompleteType
bool CompleteType(clang::QualType qt)
Definition: PdbAstBuilder.cpp:702
lldb_private::npdb::PdbAstBuilder::m_uid_to_type
llvm::DenseMap< lldb::user_id_t, clang::QualType > m_uid_to_type
Definition: PdbAstBuilder.h:147
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:764
lldb_private::npdb::DeclStatus::DeclStatus
DeclStatus()=default
lldb_private::npdb::PdbAstBuilder::GetParentDeclContextForSymbol
clang::DeclContext * GetParentDeclContextForSymbol(const llvm::codeview::CVSymbol &sym)
Definition: PdbAstBuilder.cpp:599
lldb_private::npdb::PdbAstBuilder::m_decl_to_status
llvm::DenseMap< clang::Decl *, DeclStatus > m_decl_to_status
Definition: PdbAstBuilder.h:145
lldb_private::npdb::PdbAstBuilder::CreatePointerType
clang::QualType CreatePointerType(const llvm::codeview::PointerRecord &pointer)
Definition: PdbAstBuilder.cpp:783
lldb_private::npdb::PdbAstBuilder::GetOrCreateInlinedFunctionDecl
clang::FunctionDecl * GetOrCreateInlinedFunctionDecl(PdbCompilandSymId inlinesite_id)
Definition: PdbAstBuilder.cpp:1116
lldb_private::npdb::PdbAstBuilder::importer
ClangASTImporter & importer()
Definition: PdbAstBuilder.h:86
uint32_t
PdbSymUid.h
lldb_private::npdb::PdbAstBuilder::GetOrCreateDeclContextForUid
clang::DeclContext * GetOrCreateDeclContextForUid(PdbSymUid uid)
Definition: PdbAstBuilder.cpp:551
lldb_private::npdb::PdbAstBuilder::ParseDeclsForContext
void ParseDeclsForContext(clang::DeclContext &context)
Definition: PdbAstBuilder.cpp:1535
lldb_private::npdb::PdbAstBuilder::CreateModifierType
clang::QualType CreateModifierType(const llvm::codeview::ModifierRecord &modifier)
Definition: PdbAstBuilder.cpp:820
lldb_private::npdb::PdbAstBuilder::ParseAllNamespacesPlusChildrenOf
void ParseAllNamespacesPlusChildrenOf(llvm::Optional< llvm::StringRef > parent)
Definition: PdbAstBuilder.cpp:1397
lldb_private::ClangASTImporter
Manages and observes all Clang AST node importing in LLDB.
Definition: ClangASTImporter.h:64
lldb_private::npdb::PdbAstBuilder::m_parent_types
llvm::DenseMap< TypeIndex, TypeIndex > m_parent_types
Definition: PdbAstBuilder.h:144
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:153
clang
Definition: ASTResultSynthesizer.h:15
lldb_private::npdb::PdbAstBuilder::GetOrCreateType
clang::QualType GetOrCreateType(PdbTypeSymId type)
Definition: PdbAstBuilder.cpp:1019
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:33
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:1052
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:524
lldb_private::npdb::PdbAstBuilder::ToCompilerDecl
CompilerDecl ToCompilerDecl(clang::Decl &decl)
Definition: PdbAstBuilder.cpp:1560
lldb_private::npdb::PdbAstBuilder::CreateFunctionType
clang::QualType CreateFunctionType(TypeIndex args_type_idx, TypeIndex return_type_idx, llvm::codeview::CallingConvention calling_convention)
Definition: PdbAstBuilder.cpp:1348
lldb_private::npdb::PdbAstBuilder::GetOrCreateVariableDecl
clang::VarDecl * GetOrCreateVariableDecl(PdbCompilandSymId scope_id, PdbCompilandSymId var_id)
Definition: PdbAstBuilder.cpp:915
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:47
ClangASTImporter.h
lldb_private::npdb::PdbAstBuilder::ParseBlockChildren
void ParseBlockChildren(PdbCompilandSymId block_id)
Definition: PdbAstBuilder.cpp:1488
lldb_private::npdb::PdbAstBuilder::m_index
PdbIndex & m_index
Definition: PdbAstBuilder.h:139
lldb_private::npdb::PdbSymUid
Definition: PdbSymUid.h:91
lldb_private::npdb::PdbAstBuilder::ParseDeclsForSimpleContext
void ParseDeclsForSimpleContext(clang::DeclContext &context)
Definition: PdbAstBuilder.cpp:1516
lldb_private::npdb::PdbAstBuilder::GetOrCreateSymbolForId
clang::Decl * GetOrCreateSymbolForId(PdbCompilandSymId id)
Definition: PdbAstBuilder.cpp:494
lldb::opaque_compiler_type_t
void * opaque_compiler_type_t
Definition: lldb-types.h:90
lldb_private::ObjectFile
Definition: ObjectFile.h:60
lldb_private::npdb::PdbAstBuilder
Definition: PdbAstBuilder.h:51
lldb_private::npdb::PdbAstBuilder::PdbAstBuilder
PdbAstBuilder(ObjectFile &obj, PdbIndex &index, TypeSystemClang &clang)
Definition: PdbAstBuilder.cpp:265