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 {
39class ObjectFile;
40
41namespace npdb {
42class PdbIndex;
43struct VariableInfo;
44
52
54public:
55 // Constructors and Destructors
57
59
60 std::optional<lldb_private::CompilerDecl>
63 clang::DeclContext *GetOrCreateClangDeclContextForUid(PdbSymUid uid);
65 clang::DeclContext *GetParentClangDeclContext(PdbSymUid uid);
66
67 clang::FunctionDecl *GetOrCreateFunctionDecl(PdbCompilandSymId func_id);
68 clang::FunctionDecl *
70 clang::BlockDecl *GetOrCreateBlockDecl(PdbCompilandSymId block_id);
71 clang::VarDecl *GetOrCreateVariableDecl(PdbCompilandSymId scope_id,
72 PdbCompilandSymId var_id);
73 clang::VarDecl *GetOrCreateVariableDecl(PdbGlobalSymId var_id);
74 clang::TypedefNameDecl *GetOrCreateTypedefDecl(PdbGlobalSymId id);
76
77 clang::QualType GetBasicType(lldb::BasicType type);
78 clang::QualType GetOrCreateClangType(PdbTypeSymId type);
80
81 bool CompleteTagDecl(clang::TagDecl &tag);
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
93
94 void Dump(Stream &stream, llvm::StringRef filter, bool show_color);
95
98 llvm::StringRef name);
99
100private:
101 clang::Decl *TryGetDecl(PdbSymUid uid) const;
102
103 using TypeIndex = llvm::codeview::TypeIndex;
104
105 clang::QualType
106 CreatePointerType(const llvm::codeview::PointerRecord &pointer);
107 clang::QualType
108 CreateModifierType(const llvm::codeview::ModifierRecord &modifier);
109 clang::QualType CreateArrayType(const llvm::codeview::ArrayRecord &array);
110 clang::QualType CreateRecordType(PdbTypeSymId id,
111 const llvm::codeview::TagRecord &record);
112 clang::QualType CreateEnumType(PdbTypeSymId id,
113 const llvm::codeview::EnumRecord &record);
114 clang::QualType
115 CreateFunctionType(TypeIndex args_type_idx, TypeIndex return_type_idx,
116 llvm::codeview::CallingConvention calling_convention);
117 clang::QualType CreateType(PdbTypeSymId type);
118
120 clang::FunctionDecl &function_decl,
121 uint32_t param_count);
123 clang::VarDecl *CreateVariableDecl(PdbSymUid uid,
124 llvm::codeview::CVSymbol sym,
125 clang::DeclContext &scope);
126 clang::NamespaceDecl *GetOrCreateNamespaceDecl(const char *name,
127 clang::DeclContext &context);
128 clang::FunctionDecl *CreateFunctionDeclFromId(PdbTypeSymId func_tid,
129 PdbCompilandSymId func_sid);
130 clang::FunctionDecl *
131 CreateFunctionDecl(PdbCompilandSymId func_id, llvm::StringRef func_name,
132 TypeIndex func_ti, CompilerType func_ct,
133 uint32_t param_count, clang::StorageClass func_storage,
134 bool is_inline, clang::DeclContext *parent);
135 void ParseNamespace(clang::DeclContext &parent);
136 void ParseAllTypes();
138 void ParseDeclsForSimpleContext(clang::DeclContext &context);
140
141 std::pair<clang::DeclContext *, std::string>
142 CreateDeclInfoForType(const llvm::codeview::TagRecord &record, TypeIndex ti);
143 std::pair<clang::DeclContext *, std::string>
144 CreateDeclInfoForUndecoratedName(llvm::StringRef uname);
145 clang::QualType CreateSimpleType(TypeIndex ti);
146
148
151 llvm::once_flag m_parse_all_types;
152 llvm::DenseMap<clang::Decl *, DeclStatus> m_decl_to_status;
153 llvm::DenseMap<lldb::user_id_t, clang::Decl *> m_uid_to_decl;
154 llvm::DenseMap<lldb::user_id_t, clang::QualType> m_uid_to_type;
155
156 // From class/struct's opaque_compiler_type_t to a set containing the pairs of
157 // method's name and CompilerType.
158 llvm::DenseMap<lldb::opaque_compiler_type_t,
159 llvm::SmallSet<std::pair<llvm::StringRef, CompilerType>, 8>>
161
162 using NamespaceSet = llvm::DenseSet<clang::NamespaceDecl *>;
163
164 // These namespaces are fully parsed
166
167 // We know about these namespaces, but they might not be completely parsed yet
169 llvm::DenseMap<clang::DeclContext *, NamespaceSet> m_parent_to_namespaces;
170};
171
172} // namespace npdb
173} // namespace lldb_private
174
175#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.
Generic representation of a type in a programming language.
A plug-in interface definition class for object file parsers.
Definition ObjectFile.h:46
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)
clang::QualType FromCompilerType(CompilerType ct)
void ParseBlockChildren(PdbCompilandSymId block_id)
ClangASTImporter & GetClangASTImporter()
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()
lldb_private::CompilerDeclContext GetParentDeclContext(PdbSymUid uid)
CompilerDecl ToCompilerDecl(clang::Decl *decl)
clang::QualType CreateModifierType(const llvm::codeview::ModifierRecord &modifier)
CompilerType GetOrCreateType(PdbTypeSymId type)
void ParseDeclsForSimpleContext(clang::DeclContext &context)
void ParseDeclsForContext(lldb_private::CompilerDeclContext context)
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)
void Dump(Stream &stream, llvm::StringRef filter, bool show_color)
void ParseNamespace(clang::DeclContext &parent)
llvm::codeview::TypeIndex TypeIndex
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)
PdbAstBuilder(TypeSystemClang &clang)
std::pair< clang::DeclContext *, std::string > CreateDeclInfoForType(const llvm::codeview::TagRecord &record, TypeIndex ti)
clang::QualType GetBasicType(lldb::BasicType type)
llvm::DenseMap< clang::Decl *, DeclStatus > m_decl_to_status
CompilerDeclContext ToCompilerDeclContext(clang::DeclContext *context)
clang::DeclContext * GetOrCreateClangDeclContextForUid(PdbSymUid uid)
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 GetOrCreateClangType(PdbTypeSymId type)
clang::QualType CreateRecordType(PdbTypeSymId id, const llvm::codeview::TagRecord &record)
clang::FunctionDecl * CreateFunctionDeclFromId(PdbTypeSymId func_tid, PdbCompilandSymId func_sid)
lldb_private::CompilerDeclContext GetOrCreateDeclContextForUid(PdbSymUid uid)
llvm::once_flag m_parse_functions_and_non_local_vars
clang::VarDecl * CreateVariableDecl(PdbSymUid uid, llvm::codeview::CVSymbol sym, clang::DeclContext &scope)
clang::QualType CreateEnumType(PdbTypeSymId id, const llvm::codeview::EnumRecord &record)
clang::FunctionDecl * GetOrCreateInlinedFunctionDecl(PdbCompilandSymId inlinesite_id)
clang::DeclContext * GetParentClangDeclContext(PdbSymUid uid)
std::optional< lldb_private::CompilerDecl > GetOrCreateDeclForUid(PdbSymUid uid)
llvm::DenseSet< clang::NamespaceDecl * > NamespaceSet
lldb_private::CompilerDeclContext FindNamespaceDecl(lldb_private::CompilerDeclContext parent_ctx, llvm::StringRef name)
clang::QualType CreateType(PdbTypeSymId type)
clang::TypedefNameDecl * GetOrCreateTypedefDecl(PdbGlobalSymId id)
llvm::DenseMap< clang::DeclContext *, NamespaceSet > m_parent_to_namespaces
PdbIndex - Lazy access to the important parts of a PDB file.
Definition PdbIndex.h:47
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)