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#include <optional>
21
22namespace clang {
23class TagDecl;
24class DeclContext;
25class Decl;
26class QualType;
27class FunctionDecl;
28class NamespaceDecl;
29} // namespace clang
30
31namespace llvm {
32namespace codeview {
33class ProcSym;
34}
35} // namespace llvm
36
37namespace lldb_private {
38class ClangASTImporter;
39class ObjectFile;
40
41namespace npdb {
42class PdbIndex;
43struct VariableInfo;
44
45struct DeclStatus {
46 DeclStatus() = default;
48 : uid(uid), resolved(resolved) {}
50 bool resolved = false;
51};
52
54public:
55 // Constructors and Destructors
57
59
60 std::optional<lldb_private::CompilerDecl>
62 clang::DeclContext *GetOrCreateDeclContextForUid(PdbSymUid uid);
63 clang::DeclContext *GetParentDeclContext(PdbSymUid uid);
64
65 clang::FunctionDecl *GetOrCreateFunctionDecl(PdbCompilandSymId func_id);
66 clang::FunctionDecl *
68 clang::BlockDecl *GetOrCreateBlockDecl(PdbCompilandSymId block_id);
69 clang::VarDecl *GetOrCreateVariableDecl(PdbCompilandSymId scope_id,
70 PdbCompilandSymId var_id);
71 clang::VarDecl *GetOrCreateVariableDecl(PdbGlobalSymId var_id);
72 clang::TypedefNameDecl *GetOrCreateTypedefDecl(PdbGlobalSymId id);
73 void ParseDeclsForContext(clang::DeclContext &context);
74
75 clang::QualType GetBasicType(lldb::BasicType type);
76 clang::QualType GetOrCreateType(PdbTypeSymId type);
77
78 bool CompleteTagDecl(clang::TagDecl &tag);
79 bool CompleteType(clang::QualType qt);
80
81 CompilerDecl ToCompilerDecl(clang::Decl &decl);
82 CompilerType ToCompilerType(clang::QualType qt);
83 CompilerDeclContext ToCompilerDeclContext(clang::DeclContext &context);
84 clang::Decl *FromCompilerDecl(CompilerDecl decl);
85 clang::DeclContext *FromCompilerDeclContext(CompilerDeclContext context);
86
89
90 void Dump(Stream &stream);
91
92private:
93 clang::Decl *TryGetDecl(PdbSymUid uid) const;
94
95 using TypeIndex = llvm::codeview::TypeIndex;
96
97 clang::QualType
98 CreatePointerType(const llvm::codeview::PointerRecord &pointer);
99 clang::QualType
100 CreateModifierType(const llvm::codeview::ModifierRecord &modifier);
101 clang::QualType CreateArrayType(const llvm::codeview::ArrayRecord &array);
102 clang::QualType CreateRecordType(PdbTypeSymId id,
103 const llvm::codeview::TagRecord &record);
104 clang::QualType CreateEnumType(PdbTypeSymId id,
105 const llvm::codeview::EnumRecord &record);
106 clang::QualType
107 CreateFunctionType(TypeIndex args_type_idx, TypeIndex return_type_idx,
108 llvm::codeview::CallingConvention calling_convention);
109 clang::QualType CreateType(PdbTypeSymId type);
110
112 clang::FunctionDecl &function_decl,
113 uint32_t param_count);
115 clang::VarDecl *CreateVariableDecl(PdbSymUid uid,
116 llvm::codeview::CVSymbol sym,
117 clang::DeclContext &scope);
118 clang::NamespaceDecl *GetOrCreateNamespaceDecl(const char *name,
119 clang::DeclContext &context);
120 clang::FunctionDecl *CreateFunctionDeclFromId(PdbTypeSymId func_tid,
121 PdbCompilandSymId func_sid);
122 clang::FunctionDecl *
123 CreateFunctionDecl(PdbCompilandSymId func_id, llvm::StringRef func_name,
124 TypeIndex func_ti, CompilerType func_ct,
125 uint32_t param_count, clang::StorageClass func_storage,
126 bool is_inline, clang::DeclContext *parent);
127 void ParseNamespace(clang::DeclContext &parent);
128 void ParseAllTypes();
130 void ParseDeclsForSimpleContext(clang::DeclContext &context);
132
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
140
143 llvm::once_flag m_parse_all_types;
144 llvm::DenseMap<clang::Decl *, DeclStatus> m_decl_to_status;
145 llvm::DenseMap<lldb::user_id_t, clang::Decl *> m_uid_to_decl;
146 llvm::DenseMap<lldb::user_id_t, clang::QualType> m_uid_to_type;
147
148 // From class/struct's opaque_compiler_type_t to a set containing the pairs of
149 // method's name and CompilerType.
150 llvm::DenseMap<lldb::opaque_compiler_type_t,
151 llvm::SmallSet<std::pair<llvm::StringRef, CompilerType>, 8>>
153 llvm::DenseSet<clang::NamespaceDecl *> m_parsed_namespaces;
154};
155
156} // namespace npdb
157} // namespace lldb_private
158
159#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_PDBASTBUILDER_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.
Definition: CompilerDecl.h:28
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
A TypeSystem implementation based on Clang.
clang::QualType CreatePointerType(const llvm::codeview::PointerRecord &pointer)
bool CompleteTagDecl(clang::TagDecl &tag)
void ParseBlockChildren(PdbCompilandSymId block_id)
ClangASTImporter & GetClangASTImporter()
Definition: PdbAstBuilder.h:88
llvm::DenseMap< lldb::opaque_compiler_type_t, llvm::SmallSet< std::pair< llvm::StringRef, CompilerType >, 8 > > m_cxx_record_map
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)
lldb_private::CompilerDeclContext GetTranslationUnitDecl()
clang::QualType CreateModifierType(const llvm::codeview::ModifierRecord &modifier)
void ParseDeclsForSimpleContext(clang::DeclContext &context)
CompilerDecl ToCompilerDecl(clang::Decl &decl)
llvm::DenseMap< lldb::user_id_t, clang::QualType > m_uid_to_type
clang::QualType CreateFunctionType(TypeIndex args_type_idx, TypeIndex return_type_idx, llvm::codeview::CallingConvention calling_convention)
clang::DeclContext * GetParentDeclContext(PdbSymUid uid)
void ParseNamespace(clang::DeclContext &parent)
llvm::codeview::TypeIndex TypeIndex
Definition: PdbAstBuilder.h:95
CompilerDeclContext ToCompilerDeclContext(clang::DeclContext &context)
std::pair< clang::DeclContext *, std::string > CreateDeclInfoForUndecoratedName(llvm::StringRef uname)
clang::Decl * TryGetDecl(PdbSymUid uid) const
clang::DeclContext * FromCompilerDeclContext(CompilerDeclContext context)
clang::VarDecl * GetOrCreateVariableDecl(PdbCompilandSymId scope_id, PdbCompilandSymId var_id)
clang::Decl * GetOrCreateSymbolForId(PdbCompilandSymId id)
CompilerType ToCompilerType(clang::QualType qt)
clang::NamespaceDecl * GetOrCreateNamespaceDecl(const char *name, clang::DeclContext &context)
std::pair< clang::DeclContext *, std::string > CreateDeclInfoForType(const llvm::codeview::TagRecord &record, TypeIndex ti)
clang::QualType GetBasicType(lldb::BasicType type)
bool CompleteType(clang::QualType qt)
llvm::DenseSet< clang::NamespaceDecl * > m_parsed_namespaces
llvm::DenseMap< clang::Decl *, DeclStatus > m_decl_to_status
clang::DeclContext * GetOrCreateDeclContextForUid(PdbSymUid uid)
void ParseDeclsForContext(clang::DeclContext &context)
llvm::DenseMap< lldb::user_id_t, clang::Decl * > m_uid_to_decl
clang::BlockDecl * GetOrCreateBlockDecl(PdbCompilandSymId block_id)
clang::Decl * FromCompilerDecl(CompilerDecl decl)
clang::QualType CreateSimpleType(TypeIndex ti)
void CreateFunctionParameters(PdbCompilandSymId func_id, clang::FunctionDecl &function_decl, uint32_t param_count)
clang::FunctionDecl * GetOrCreateFunctionDecl(PdbCompilandSymId func_id)
clang::QualType CreateArrayType(const llvm::codeview::ArrayRecord &array)
clang::QualType CreateRecordType(PdbTypeSymId id, const llvm::codeview::TagRecord &record)
clang::FunctionDecl * CreateFunctionDeclFromId(PdbTypeSymId func_tid, PdbCompilandSymId func_sid)
llvm::once_flag m_parse_functions_and_non_local_vars
clang::VarDecl * CreateVariableDecl(PdbSymUid uid, llvm::codeview::CVSymbol sym, clang::DeclContext &scope)
clang::QualType GetOrCreateType(PdbTypeSymId type)
clang::QualType CreateEnumType(PdbTypeSymId id, const llvm::codeview::EnumRecord &record)
clang::FunctionDecl * GetOrCreateInlinedFunctionDecl(PdbCompilandSymId inlinesite_id)
std::optional< lldb_private::CompilerDecl > GetOrCreateDeclForUid(PdbSymUid uid)
clang::QualType CreateType(PdbTypeSymId type)
clang::TypedefNameDecl * GetOrCreateTypedefDecl(PdbGlobalSymId id)
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
Definition: Debugger.h:54
DeclStatus(lldb::user_id_t uid, bool resolved)
Definition: PdbAstBuilder.h:47