1 //===-- UdtRecordCompleter.h ------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_UDTRECORDCOMPLETER_H
10 #define LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_UDTRECORDCOMPLETER_H
12 #include "PdbAstBuilder.h"
13 #include "PdbSymUid.h"
14 #include "Plugins/ExpressionParser/Clang/ClangASTImporter.h"
15 #include "llvm/DebugInfo/CodeView/CVRecord.h"
16 #include "llvm/DebugInfo/CodeView/TypeRecord.h"
17 #include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h"
21 class CXXBaseSpecifier
;
33 namespace lldb_private
{
40 class UdtRecordCompleter
: public llvm::codeview::TypeVisitorCallbacks
{
42 std::pair
<uint64_t, std::unique_ptr
<clang::CXXBaseSpecifier
>>;
46 llvm::codeview::UnionRecord ur
;
47 llvm::codeview::ClassRecord cr
;
48 llvm::codeview::EnumRecord er
;
52 CompilerType
&m_derived_ct
;
53 clang::TagDecl
&m_tag_decl
;
54 PdbAstBuilder
&m_ast_builder
;
56 std::vector
<IndexedBase
> m_bases
;
57 ClangASTImporter::LayoutInfo m_layout
;
58 llvm::DenseMap
<clang::Decl
*, DeclStatus
> &m_decl_to_status
;
59 llvm::DenseMap
<lldb::opaque_compiler_type_t
,
60 llvm::SmallSet
<std::pair
<llvm::StringRef
, CompilerType
>, 8>>
65 PdbTypeSymId id
, CompilerType
&derived_ct
, clang::TagDecl
&tag_decl
,
66 PdbAstBuilder
&ast_builder
, PdbIndex
&index
,
67 llvm::DenseMap
<clang::Decl
*, DeclStatus
> &decl_to_status
,
68 llvm::DenseMap
<lldb::opaque_compiler_type_t
,
69 llvm::SmallSet
<std::pair
<llvm::StringRef
, CompilerType
>,
72 #define MEMBER_RECORD(EnumName, EnumVal, Name) \
73 llvm::Error visitKnownMember(llvm::codeview::CVMemberRecord &CVR, \
74 llvm::codeview::Name##Record &Record) override;
75 #define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
76 #include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
79 using MemberUP
= std::unique_ptr
<Member
>;
82 enum Kind
{ Field
, Struct
, Union
} kind
;
83 // Following are only used for field.
88 lldb::AccessType access
;
89 uint32_t bitfield_width
;
90 // Following are Only used for struct or union.
92 llvm::SmallVector
<MemberUP
, 1> fields
;
96 : kind(kind
), name(), bit_offset(0), bit_size(0), qt(),
97 access(lldb::eAccessPublic
), bitfield_width(0), base_offset(0) {}
98 Member(llvm::StringRef name
, uint64_t bit_offset
, uint64_t bit_size
,
99 clang::QualType qt
, lldb::AccessType access
, uint32_t bitfield_width
)
100 : kind(Field
), name(name
), bit_offset(bit_offset
), bit_size(bit_size
),
101 qt(qt
), access(access
), bitfield_width(bitfield_width
),
103 void ConvertToStruct() {
105 base_offset
= bit_offset
;
106 fields
.push_back(std::make_unique
<Member
>(name
, bit_offset
, bit_size
, qt
,
107 access
, bitfield_width
));
108 name
= llvm::StringRef();
109 qt
= clang::QualType();
110 access
= lldb::eAccessPublic
;
111 bit_offset
= bit_size
= bitfield_width
= 0;
118 uint64_t start_offset
= UINT64_MAX
;
119 std::map
<uint64_t, llvm::SmallVector
<MemberUP
, 1>> fields_map
;
120 void CollectMember(llvm::StringRef name
, uint64_t offset
,
121 uint64_t field_size
, clang::QualType qt
,
122 lldb::AccessType access
, uint64_t bitfield_width
);
123 void ConstructRecord();
129 clang::QualType
AddBaseClassForTypeIndex(
130 llvm::codeview::TypeIndex ti
, llvm::codeview::MemberAccess access
,
131 std::optional
<uint64_t> vtable_idx
= std::optional
<uint64_t>());
132 void AddMethod(llvm::StringRef name
, llvm::codeview::TypeIndex type_idx
,
133 llvm::codeview::MemberAccess access
,
134 llvm::codeview::MethodOptions options
,
135 llvm::codeview::MemberAttributes attrs
);
137 uint64_t AddMember(TypeSystemClang
&clang
, Member
*field
, uint64_t bit_offset
,
138 CompilerType parent_ct
,
139 ClangASTImporter::LayoutInfo
&parent_layout
,
140 clang::DeclContext
*decl_ctx
);
144 } // namespace lldb_private
146 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_UDTRECORDCOMPLETER_H