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 "PdbAstBuilderClang.h"
13#include "PdbSymUid.h"
14#include "PdbUtil.h"
16#include "llvm/DebugInfo/CodeView/CVRecord.h"
17#include "llvm/DebugInfo/CodeView/TypeRecord.h"
18#include "llvm/DebugInfo/CodeView/TypeVisitorCallbacks.h"
19#include <optional>
20
21namespace clang {
22class CXXBaseSpecifier;
23class QualType;
24class TagDecl;
25} // namespace clang
26
27namespace llvm {
28namespace pdb {
29class TpiStream;
30class GlobalsStream;
31}
32} // namespace llvm
33
34namespace lldb_private {
35class Type;
36class CompilerType;
37namespace npdb {
38class PdbIndex;
39
42 std::pair<uint64_t, std::unique_ptr<clang::CXXBaseSpecifier>>;
43
47 clang::TagDecl &m_tag_decl;
50 std::vector<IndexedBase> m_bases;
52 llvm::DenseMap<clang::Decl *, DeclStatus> &m_decl_to_status;
53 llvm::DenseMap<lldb::opaque_compiler_type_t,
54 llvm::SmallSet<std::pair<llvm::StringRef, CompilerType>, 8>>
56 /// Index of the current member.
57 uint32_t m_member_index = 0;
58
59public:
61 PdbTypeSymId id, CompilerType &derived_ct, clang::TagDecl &tag_decl,
62 PdbAstBuilderClang &ast_builder, PdbIndex &index,
63 llvm::DenseMap<clang::Decl *, DeclStatus> &decl_to_status,
64 llvm::DenseMap<lldb::opaque_compiler_type_t,
65 llvm::SmallSet<std::pair<llvm::StringRef, CompilerType>,
66 8>> &cxx_record_map);
67
68 llvm::Error visitMemberEnd(llvm::codeview::CVMemberRecord &Record) override;
69
70#define MEMBER_RECORD(EnumName, EnumVal, Name) \
71 llvm::Error visitKnownMember(llvm::codeview::CVMemberRecord &CVR, \
72 llvm::codeview::Name##Record &Record) override;
73#define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
74#include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
75
76 struct Member;
77 using MemberUP = std::unique_ptr<Member>;
78
79 struct Member {
81 // Following are only used for field.
82 llvm::StringRef name;
83 uint64_t bit_offset;
84 uint64_t bit_size;
85 clang::QualType qt;
88 /// Index of the member inside the LF_FIELDLIST.
89 uint32_t original_index = 0;
90 // Following are Only used for struct or union.
91 uint64_t base_offset;
92 llvm::SmallVector<MemberUP, 1> fields;
93
94 Member() = default;
96 : kind(kind), name(), bit_offset(0), bit_size(0), qt(),
97 access(lldb::eAccessPublic), bitfield_width(0), base_offset(0) {}
105 kind = Struct;
107 fields.push_back(std::make_unique<Member>(name, bit_offset, bit_size, qt,
110 name = llvm::StringRef();
111 qt = clang::QualType();
114 // Keep original_index.
115 }
116
118 };
119
120 struct Record {
121 // Top level record.
124 std::map<uint64_t, llvm::SmallVector<MemberUP, 1>> fields_map;
125 void CollectMember(llvm::StringRef name, uint64_t offset,
126 uint64_t field_size, clang::QualType qt,
127 lldb::AccessType access, uint64_t bitfield_width,
128 uint32_t member_index);
129 void ConstructRecord();
130 };
131 void complete();
132
133private:
135 clang::QualType AddBaseClassForTypeIndex(
136 llvm::codeview::TypeIndex ti, llvm::codeview::MemberAccess access,
137 std::optional<uint64_t> vtable_idx = std::optional<uint64_t>());
138 void AddMethod(llvm::StringRef name, llvm::codeview::TypeIndex type_idx,
139 llvm::codeview::MethodOptions options,
140 llvm::codeview::MemberAttributes attrs);
141 void FinishRecord();
142 uint64_t AddMember(TypeSystemClang &clang, Member *field, uint64_t bit_offset,
143 CompilerType parent_ct,
144 ClangASTImporter::LayoutInfo &parent_layout,
145 clang::DeclContext *decl_ctx);
146};
147
148} // namespace npdb
149} // namespace lldb_private
150
151#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_UDTRECORDCOMPLETER_H
Generic representation of a type in a programming language.
A TypeSystem implementation based on Clang.
PdbIndex - Lazy access to the important parts of a PDB file.
Definition PdbIndex.h:47
llvm::DenseMap< lldb::opaque_compiler_type_t, llvm::SmallSet< std::pair< llvm::StringRef, CompilerType >, 8 > > & m_cxx_record_map
llvm::Error visitMemberEnd(llvm::codeview::CVMemberRecord &Record) override
ClangASTImporter::LayoutInfo m_layout
std::pair< uint64_t, std::unique_ptr< clang::CXXBaseSpecifier > > IndexedBase
llvm::DenseMap< clang::Decl *, DeclStatus > & m_decl_to_status
uint64_t AddMember(TypeSystemClang &clang, Member *field, uint64_t bit_offset, CompilerType parent_ct, ClangASTImporter::LayoutInfo &parent_layout, clang::DeclContext *decl_ctx)
UdtRecordCompleter(PdbTypeSymId id, CompilerType &derived_ct, clang::TagDecl &tag_decl, PdbAstBuilderClang &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)
clang::QualType AddBaseClassForTypeIndex(llvm::codeview::TypeIndex ti, llvm::codeview::MemberAccess access, std::optional< uint64_t > vtable_idx=std::optional< uint64_t >())
uint32_t m_member_index
Index of the current member.
void AddMethod(llvm::StringRef name, llvm::codeview::TypeIndex type_idx, llvm::codeview::MethodOptions options, llvm::codeview::MemberAttributes attrs)
#define UINT64_MAX
A class that represents a running process on the host machine.
void * opaque_compiler_type_t
Definition lldb-types.h:91
Member(llvm::StringRef name, uint64_t bit_offset, uint64_t bit_size, clang::QualType qt, lldb::AccessType access, uint32_t bitfield_width, uint32_t original_index)
enum lldb_private::npdb::UdtRecordCompleter::Member::Kind kind
uint32_t original_index
Index of the member inside the LF_FIELDLIST.
std::map< uint64_t, llvm::SmallVector< MemberUP, 1 > > fields_map
void CollectMember(llvm::StringRef name, uint64_t offset, uint64_t field_size, clang::QualType qt, lldb::AccessType access, uint64_t bitfield_width, uint32_t member_index)