LLDB  mainline
UdtRecordCompleter.h
Go to the documentation of this file.
1 //===-- UdtRecordCompleter.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_UDTRECORDCOMPLETER_H
10 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_UDTRECORDCOMPLETER_H
11 
12 #include "PdbAstBuilder.h"
13 #include "PdbSymUid.h"
15 #include "llvm/DebugInfo/CodeView/CVRecord.h"
16 #include "llvm/DebugInfo/CodeView/TypeRecord.h"
17 #include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h"
18 
19 namespace clang {
20 class CXXBaseSpecifier;
21 class QualType;
22 class TagDecl;
23 } // namespace clang
24 
25 namespace llvm {
26 namespace pdb {
27 class TpiStream;
28 class GlobalsStream;
29 }
30 } // namespace llvm
31 
32 namespace lldb_private {
33 class Type;
34 class CompilerType;
35 namespace npdb {
36 class PdbAstBuilder;
37 class PdbIndex;
38 
40  using IndexedBase =
41  std::pair<uint64_t, std::unique_ptr<clang::CXXBaseSpecifier>>;
42 
43  union UdtTagRecord {
45  llvm::codeview::UnionRecord ur;
46  llvm::codeview::ClassRecord cr;
47  llvm::codeview::EnumRecord er;
48  } m_cvr;
49 
52  clang::TagDecl &m_tag_decl;
55  std::vector<IndexedBase> m_bases;
57  llvm::DenseMap<clang::Decl *, DeclStatus> &m_decl_to_status;
58  llvm::DenseMap<lldb::opaque_compiler_type_t,
59  llvm::SmallSet<std::pair<llvm::StringRef, CompilerType>, 8>>
61 
62 public:
64  PdbTypeSymId id, CompilerType &derived_ct, clang::TagDecl &tag_decl,
65  PdbAstBuilder &ast_builder, PdbIndex &index,
66  llvm::DenseMap<clang::Decl *, DeclStatus> &decl_to_status,
67  llvm::DenseMap<lldb::opaque_compiler_type_t,
68  llvm::SmallSet<std::pair<llvm::StringRef, CompilerType>,
69  8>> &cxx_record_map);
70 
71 #define MEMBER_RECORD(EnumName, EnumVal, Name) \
72  llvm::Error visitKnownMember(llvm::codeview::CVMemberRecord &CVR, \
73  llvm::codeview::Name##Record &Record) override;
74 #define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
75 #include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
76 
77  struct Member;
78  using MemberUP = std::unique_ptr<Member>;
79 
80  struct Member {
81  enum Kind { Field, Struct, Union } kind;
82  // Following are only used for field.
83  llvm::StringRef name;
84  uint64_t bit_offset;
85  uint64_t bit_size;
86  clang::QualType qt;
89  // Following are Only used for struct or union.
90  uint64_t base_offset;
91  llvm::SmallVector<MemberUP, 1> fields;
92 
93  Member() = default;
95  : kind(kind), name(), bit_offset(0), bit_size(0), qt(),
97  Member(llvm::StringRef name, uint64_t bit_offset, uint64_t bit_size,
101  base_offset(0) {}
103  kind = Struct;
105  fields.push_back(std::make_unique<Member>(name, bit_offset, bit_size, qt,
107  name = llvm::StringRef();
108  qt = clang::QualType();
111  }
112  };
113 
114  struct Record {
115  // Top level record.
118  std::map<uint64_t, llvm::SmallVector<MemberUP, 1>> fields_map;
119  void CollectMember(llvm::StringRef name, uint64_t offset,
120  uint64_t field_size, clang::QualType qt,
121  lldb::AccessType access, uint64_t bitfield_width);
122  void ConstructRecord();
123  };
124  void complete();
125 
126 private:
128  clang::QualType AddBaseClassForTypeIndex(
129  llvm::codeview::TypeIndex ti, llvm::codeview::MemberAccess access,
130  llvm::Optional<uint64_t> vtable_idx = llvm::Optional<uint64_t>());
131  void AddMethod(llvm::StringRef name, llvm::codeview::TypeIndex type_idx,
132  llvm::codeview::MemberAccess access,
133  llvm::codeview::MethodOptions options,
134  llvm::codeview::MemberAttributes attrs);
135  void FinishRecord();
136  uint64_t AddMember(TypeSystemClang &clang, Member *field, uint64_t bit_offset,
137  CompilerType parent_ct,
138  ClangASTImporter::LayoutInfo &parent_layout,
139  clang::DeclContext *decl_ctx);
140 };
141 
142 } // namespace npdb
143 } // namespace lldb_private
144 
145 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_UDTRECORDCOMPLETER_H
lldb_private::npdb::PdbSymUidKind::Type
@ Type
lldb_private::npdb::UdtRecordCompleter::Record::fields_map
std::map< uint64_t, llvm::SmallVector< MemberUP, 1 > > fields_map
Definition: UdtRecordCompleter.h:118
lldb_private::npdb::UdtRecordCompleter::UdtTagRecord::er
llvm::codeview::EnumRecord er
Definition: UdtRecordCompleter.h:47
lldb_private::npdb::UdtRecordCompleter::Member
Definition: UdtRecordCompleter.h:80
llvm
Definition: Debugger.h:50
TypeVisitorCallbacks
lldb_private::npdb::PdbIndex
PdbIndex - Lazy access to the important parts of a PDB file.
Definition: PdbIndex.h:47
lldb_private::npdb::UdtRecordCompleter::UdtTagRecord::cr
llvm::codeview::ClassRecord cr
Definition: UdtRecordCompleter.h:46
lldb_private::npdb::UdtRecordCompleter::AddBaseClassForTypeIndex
clang::QualType AddBaseClassForTypeIndex(llvm::codeview::TypeIndex ti, llvm::codeview::MemberAccess access, llvm::Optional< uint64_t > vtable_idx=llvm::Optional< uint64_t >())
Definition: UdtRecordCompleter.cpp:67
lldb_private::ClangASTImporter::LayoutInfo
Definition: ClangASTImporter.h:66
lldb_private::npdb::UdtRecordCompleter::Member::Union
@ Union
Definition: UdtRecordCompleter.h:81
lldb_private::npdb::UdtRecordCompleter::Member::Field
@ Field
Definition: UdtRecordCompleter.h:81
lldb_private::npdb::UdtRecordCompleter::Member::Struct
@ Struct
Definition: UdtRecordCompleter.h:81
lldb_private::npdb::UdtRecordCompleter::Member::name
llvm::StringRef name
Definition: UdtRecordCompleter.h:83
lldb_private::npdb::UdtRecordCompleter::Member::qt
clang::QualType qt
Definition: UdtRecordCompleter.h:86
lldb_private::npdb::UdtRecordCompleter::Record::start_offset
uint64_t start_offset
Definition: UdtRecordCompleter.h:117
lldb_private::npdb::UdtRecordCompleter::IndexedBase
std::pair< uint64_t, std::unique_ptr< clang::CXXBaseSpecifier > > IndexedBase
Definition: UdtRecordCompleter.h:41
lldb_private::npdb::UdtRecordCompleter::UdtTagRecord::UdtTagRecord
UdtTagRecord()
Definition: UdtRecordCompleter.h:44
lldb_private::npdb::UdtRecordCompleter::Member::Member
Member(Kind kind)
Definition: UdtRecordCompleter.h:94
lldb_private::npdb::UdtRecordCompleter::complete
void complete()
Definition: UdtRecordCompleter.cpp:304
lldb_private::npdb::UdtRecordCompleter::Member::kind
enum lldb_private::npdb::UdtRecordCompleter::Member::Kind kind
lldb_private::npdb::UdtRecordCompleter::Member::ConvertToStruct
void ConvertToStruct()
Definition: UdtRecordCompleter.h:102
lldb_private::npdb::UdtRecordCompleter::m_ast_builder
PdbAstBuilder & m_ast_builder
Definition: UdtRecordCompleter.h:53
lldb_private::npdb::PdbTypeSymId
Definition: PdbSymUid.h:70
lldb_private::npdb::UdtRecordCompleter::UdtRecordCompleter
UdtRecordCompleter(PdbTypeSymId id, CompilerType &derived_ct, clang::TagDecl &tag_decl, PdbAstBuilder &ast_builder, PdbIndex &index, llvm::DenseMap< clang::Decl *, DeclStatus > &decl_to_status, llvm::DenseMap< lldb::opaque_compiler_type_t, llvm::SmallSet< std::pair< llvm::StringRef, CompilerType >, 8 >> &cxx_record_map)
Definition: UdtRecordCompleter.cpp:36
lldb_private::npdb::UdtRecordCompleter::UdtTagRecord
Definition: UdtRecordCompleter.h:43
lldb_private::npdb::UdtRecordCompleter::Member::fields
llvm::SmallVector< MemberUP, 1 > fields
Definition: UdtRecordCompleter.h:91
PdbAstBuilder.h
lldb_private::npdb::UdtRecordCompleter::Member::Kind
Kind
Definition: UdtRecordCompleter.h:81
lldb_private::npdb::UdtRecordCompleter::MemberUP
std::unique_ptr< Member > MemberUP
Definition: UdtRecordCompleter.h:78
lldb_private::npdb::UdtRecordCompleter::m_cvr
union lldb_private::npdb::UdtRecordCompleter::UdtTagRecord m_cvr
lldb::eAccessPublic
@ eAccessPublic
Definition: lldb-enumerations.h:510
lldb_private::npdb::UdtRecordCompleter::Member::bitfield_width
uint32_t bitfield_width
Definition: UdtRecordCompleter.h:88
lldb_private::npdb::UdtRecordCompleter::FinishRecord
void FinishRecord()
Definition: UdtRecordCompleter.cpp:400
lldb_private::npdb::UdtRecordCompleter::Member::bit_offset
uint64_t bit_offset
Definition: UdtRecordCompleter.h:84
uint32_t
lldb_private::npdb::UdtRecordCompleter::Record
Definition: UdtRecordCompleter.h:114
PdbSymUid.h
lldb_private::npdb::UdtRecordCompleter::Member::Member
Member(llvm::StringRef name, uint64_t bit_offset, uint64_t bit_size, clang::QualType qt, lldb::AccessType access, uint32_t bitfield_width)
Definition: UdtRecordCompleter.h:97
lldb_private::npdb::UdtRecordCompleter
Definition: UdtRecordCompleter.h:39
lldb_private::npdb::UdtRecordCompleter::Member::bit_size
uint64_t bit_size
Definition: UdtRecordCompleter.h:85
lldb_private::npdb::UdtRecordCompleter::Member::Member
Member()=default
lldb_private::npdb::UdtRecordCompleter::m_cxx_record_map
llvm::DenseMap< lldb::opaque_compiler_type_t, llvm::SmallSet< std::pair< llvm::StringRef, CompilerType >, 8 > > & m_cxx_record_map
Definition: UdtRecordCompleter.h:60
lldb_private::npdb::UdtRecordCompleter::m_record
Record m_record
Definition: UdtRecordCompleter.h:127
clang
Definition: ASTResultSynthesizer.h:15
lldb_private::npdb::UdtRecordCompleter::m_derived_ct
CompilerType & m_derived_ct
Definition: UdtRecordCompleter.h:51
lldb_private::CompilerType
Generic representation of a type in a programming language.
Definition: CompilerType.h:35
lldb_private::npdb::UdtRecordCompleter::m_id
PdbTypeSymId m_id
Definition: UdtRecordCompleter.h:50
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::npdb::UdtRecordCompleter::AddMember
uint64_t AddMember(TypeSystemClang &clang, Member *field, uint64_t bit_offset, CompilerType parent_ct, ClangASTImporter::LayoutInfo &parent_layout, clang::DeclContext *decl_ctx)
Definition: UdtRecordCompleter.cpp:339
lldb_private::npdb::UdtRecordCompleter::Record::CollectMember
void CollectMember(llvm::StringRef name, uint64_t offset, uint64_t field_size, clang::QualType qt, lldb::AccessType access, uint64_t bitfield_width)
Definition: UdtRecordCompleter.cpp:413
lldb_private::npdb::UdtRecordCompleter::m_tag_decl
clang::TagDecl & m_tag_decl
Definition: UdtRecordCompleter.h:52
lldb_private::npdb::UdtRecordCompleter::Member::access
lldb::AccessType access
Definition: UdtRecordCompleter.h:87
lldb_private::TypeSystemClang
A TypeSystem implementation based on Clang.
Definition: TypeSystemClang.h:105
ClangASTImporter.h
lldb_private::npdb::UdtRecordCompleter::m_decl_to_status
llvm::DenseMap< clang::Decl *, DeclStatus > & m_decl_to_status
Definition: UdtRecordCompleter.h:57
lldb_private::npdb::UdtRecordCompleter::Record::record
Member record
Definition: UdtRecordCompleter.h:116
lldb_private::npdb::UdtRecordCompleter::Member::base_offset
uint64_t base_offset
Definition: UdtRecordCompleter.h:90
lldb_private::npdb::UdtRecordCompleter::m_layout
ClangASTImporter::LayoutInfo m_layout
Definition: UdtRecordCompleter.h:56
lldb_private::npdb::UdtRecordCompleter::UdtTagRecord::ur
llvm::codeview::UnionRecord ur
Definition: UdtRecordCompleter.h:45
lldb
Definition: SBAddress.h:15
lldb_private::npdb::UdtRecordCompleter::Record::ConstructRecord
void ConstructRecord()
Definition: UdtRecordCompleter.cpp:422
lldb::AccessType
AccessType
Definition: lldb-enumerations.h:508
lldb::opaque_compiler_type_t
void * opaque_compiler_type_t
Definition: lldb-types.h:90
lldb_private::npdb::UdtRecordCompleter::AddMethod
void AddMethod(llvm::StringRef name, llvm::codeview::TypeIndex type_idx, llvm::codeview::MemberAccess access, llvm::codeview::MethodOptions options, llvm::codeview::MemberAttributes attrs)
Definition: UdtRecordCompleter.cpp:88
lldb_private::npdb::PdbAstBuilder
Definition: PdbAstBuilder.h:52
lldb_private::npdb::UdtRecordCompleter::m_index
PdbIndex & m_index
Definition: UdtRecordCompleter.h:54
UINT64_MAX
#define UINT64_MAX
Definition: lldb-defines.h:23
lldb_private::npdb::UdtRecordCompleter::m_bases
std::vector< IndexedBase > m_bases
Definition: UdtRecordCompleter.h:55