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#include <optional>
19
20namespace clang {
21class CXXBaseSpecifier;
22class QualType;
23class TagDecl;
24} // namespace clang
25
26namespace llvm {
27namespace pdb {
28class TpiStream;
29class GlobalsStream;
30}
31} // namespace llvm
32
33namespace lldb_private {
34class Type;
35class CompilerType;
36namespace npdb {
37class PdbAstBuilder;
38class PdbIndex;
39
42 std::pair<uint64_t, std::unique_ptr<clang::CXXBaseSpecifier>>;
43
46 llvm::codeview::UnionRecord ur;
47 llvm::codeview::ClassRecord cr;
48 llvm::codeview::EnumRecord er;
50
53 clang::TagDecl &m_tag_decl;
56 std::vector<IndexedBase> m_bases;
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>>
62
63public:
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>,
70 8>> &cxx_record_map);
71
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"
77
78 struct Member;
79 using MemberUP = std::unique_ptr<Member>;
80
81 struct Member {
83 // Following are only used for field.
84 llvm::StringRef name;
85 uint64_t bit_offset;
86 uint64_t bit_size;
87 clang::QualType qt;
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) {}
98 Member(llvm::StringRef name, uint64_t bit_offset, uint64_t bit_size,
99 clang::QualType qt, lldb::AccessType access, uint32_t bitfield_width)
102 base_offset(0) {}
104 kind = Struct;
106 fields.push_back(std::make_unique<Member>(name, bit_offset, bit_size, qt,
108 name = llvm::StringRef();
109 qt = clang::QualType();
112 }
113 };
114
115 struct Record {
116 // Top level record.
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();
124 };
125 void complete();
126
127private:
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);
136 void FinishRecord();
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);
141};
142
143} // namespace npdb
144} // namespace lldb_private
145
146#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_NATIVEPDB_UDTRECORDCOMPLETER_H
Generic representation of a type in a programming language.
Definition: CompilerType.h:36
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)
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)
union lldb_private::npdb::UdtRecordCompleter::UdtTagRecord m_cvr
#define UINT64_MAX
Definition: lldb-defines.h:23
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Definition: SBAddress.h:15
void * opaque_compiler_type_t
Definition: lldb-types.h:89
Definition: Debugger.h:54
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