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
57public:
59 PdbTypeSymId id, CompilerType &derived_ct, clang::TagDecl &tag_decl,
60 PdbAstBuilderClang &ast_builder, PdbIndex &index,
61 llvm::DenseMap<clang::Decl *, DeclStatus> &decl_to_status,
62 llvm::DenseMap<lldb::opaque_compiler_type_t,
63 llvm::SmallSet<std::pair<llvm::StringRef, CompilerType>,
64 8>> &cxx_record_map);
65
66#define MEMBER_RECORD(EnumName, EnumVal, Name) \
67 llvm::Error visitKnownMember(llvm::codeview::CVMemberRecord &CVR, \
68 llvm::codeview::Name##Record &Record) override;
69#define MEMBER_RECORD_ALIAS(EnumName, EnumVal, Name, AliasName)
70#include "llvm/DebugInfo/CodeView/CodeViewTypes.def"
71
72 struct Member;
73 using MemberUP = std::unique_ptr<Member>;
74
75 struct Member {
77 // Following are only used for field.
78 llvm::StringRef name;
79 uint64_t bit_offset;
80 uint64_t bit_size;
81 clang::QualType qt;
84 // Following are Only used for struct or union.
85 uint64_t base_offset;
86 llvm::SmallVector<MemberUP, 1> fields;
87
88 Member() = default;
90 : kind(kind), name(), bit_offset(0), bit_size(0), qt(),
91 access(lldb::eAccessPublic), bitfield_width(0), base_offset(0) {}
92 Member(llvm::StringRef name, uint64_t bit_offset, uint64_t bit_size,
93 clang::QualType qt, lldb::AccessType access, uint32_t bitfield_width)
96 base_offset(0) {}
98 kind = Struct;
100 fields.push_back(std::make_unique<Member>(name, bit_offset, bit_size, qt,
102 name = llvm::StringRef();
103 qt = clang::QualType();
106 }
107 };
108
109 struct Record {
110 // Top level record.
113 std::map<uint64_t, llvm::SmallVector<MemberUP, 1>> fields_map;
114 void CollectMember(llvm::StringRef name, uint64_t offset,
115 uint64_t field_size, clang::QualType qt,
116 lldb::AccessType access, uint64_t bitfield_width);
117 void ConstructRecord();
118 };
119 void complete();
120
121private:
123 clang::QualType AddBaseClassForTypeIndex(
124 llvm::codeview::TypeIndex ti, llvm::codeview::MemberAccess access,
125 std::optional<uint64_t> vtable_idx = std::optional<uint64_t>());
126 void AddMethod(llvm::StringRef name, llvm::codeview::TypeIndex type_idx,
127 llvm::codeview::MemberAccess access,
128 llvm::codeview::MethodOptions options,
129 llvm::codeview::MemberAttributes attrs);
130 void FinishRecord();
131 uint64_t AddMember(TypeSystemClang &clang, Member *field, uint64_t bit_offset,
132 CompilerType parent_ct,
133 ClangASTImporter::LayoutInfo &parent_layout,
134 clang::DeclContext *decl_ctx);
135};
136
137} // namespace npdb
138} // namespace lldb_private
139
140#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
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 >())
void AddMethod(llvm::StringRef name, llvm::codeview::TypeIndex type_idx, llvm::codeview::MemberAccess access, 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:89
Member(llvm::StringRef name, uint64_t bit_offset, uint64_t bit_size, clang::QualType qt, lldb::AccessType access, uint32_t bitfield_width)
enum lldb_private::npdb::UdtRecordCompleter::Member::Kind kind
void CollectMember(llvm::StringRef name, uint64_t offset, uint64_t field_size, clang::QualType qt, lldb::AccessType access, uint64_t bitfield_width)
std::map< uint64_t, llvm::SmallVector< MemberUP, 1 > > fields_map