20#include "llvm/ADT/STLExtras.h"
21#include "llvm/DebugInfo/CodeView/SymbolDeserializer.h"
22#include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
23#include "llvm/DebugInfo/CodeView/TypeIndex.h"
24#include "llvm/DebugInfo/PDB/Native/GlobalsStream.h"
25#include "llvm/DebugInfo/PDB/Native/TpiStream.h"
26#include "llvm/DebugInfo/PDB/PDBTypes.h"
40 llvm::DenseMap<clang::Decl *, DeclStatus> &decl_to_status,
42 llvm::SmallSet<std::pair<llvm::StringRef, CompilerType>, 8>>
44 : m_id(
id), m_derived_ct(derived_ct), m_tag_decl(tag_decl),
45 m_ast_builder(ast_builder), m_index(index),
46 m_decl_to_status(decl_to_status), m_cxx_record_map(cxx_record_map) {
50 llvm::cantFail(TypeDeserializer::deserializeAs<EnumRecord>(cvt,
m_cvr.
er));
53 llvm::cantFail(TypeDeserializer::deserializeAs<UnionRecord>(cvt,
m_cvr.
ur));
59 llvm::cantFail(TypeDeserializer::deserializeAs<ClassRecord>(cvt,
m_cvr.
cr));
64 llvm_unreachable(
"unreachable!");
69 llvm::codeview::TypeIndex ti, llvm::codeview::MemberAccess access,
70 std::optional<uint64_t> vtable_idx) {
76 std::unique_ptr<clang::CXXBaseSpecifier> base_spec =
79 vtable_idx.has_value(), udt_cvt.kind() == LF_CLASS);
84 std::make_pair(vtable_idx.value_or(0), std::move(base_spec)));
90 MemberAccess access, MethodOptions options,
91 MemberAttributes attrs) {
92 clang::QualType method_qt =
94 if (method_qt.isNull())
102 if (iter->getSecond().contains({name, method_ct})) {
108 bool is_artificial = (options & MethodOptions::CompilerGenerated) ==
109 MethodOptions::CompilerGenerated;
111 derived_opaque_ty, name.data(),
nullptr, method_ct,
112 access_type, attrs.isVirtual(), attrs.isStatic(),
false,
false,
false,
118Error UdtRecordCompleter::visitKnownMember(CVMemberRecord &cvr,
119 BaseClassRecord &base) {
120 clang::QualType base_qt =
123 if (base_qt.isNull())
124 return llvm::Error::success();
129 auto offset = clang::CharUnits::fromQuantity(base.getBaseOffset());
132 return llvm::Error::success();
135Error UdtRecordCompleter::visitKnownMember(CVMemberRecord &cvr,
136 VirtualBaseClassRecord &base) {
139 return Error::success();
142Error UdtRecordCompleter::visitKnownMember(CVMemberRecord &cvr,
143 ListContinuationRecord &cont) {
144 return Error::success();
147Error UdtRecordCompleter::visitKnownMember(CVMemberRecord &cvr,
148 VFPtrRecord &vfptr) {
149 return Error::success();
152Error UdtRecordCompleter::visitKnownMember(
153 CVMemberRecord &cvr, StaticDataMemberRecord &static_data_member) {
154 clang::QualType member_type =
156 if (member_type.isNull())
157 return llvm::Error::success();
164 m_derived_ct, static_data_member.Name, member_ct, access);
169 std::string qual_name = decl->getQualifiedNameAsString();
174 for (
const auto &result : results) {
175 if (result.second.kind() == SymbolKind::S_CONSTANT) {
176 ConstantSym constant(SymbolRecordKind::ConstantSym);
177 cantFail(SymbolDeserializer::deserializeAs<ConstantSym>(result.second,
180 clang::QualType qual_type = decl->getType();
181 unsigned type_width = decl->getASTContext().getIntWidth(qual_type);
182 unsigned constant_width = constant.Value.getBitWidth();
184 if (qual_type->isIntegralOrEnumerationType()) {
185 if (type_width >= constant_width) {
187 decl, constant.Value.extOrTrunc(type_width));
190 "Class '{0}' has a member '{1}' of type '{2}' ({3} bits) "
191 "which resolves to a wider constant value ({4} bits). "
192 "Ignoring constant.",
194 member_ct.
GetTypeName(), type_width, constant_width);
198 switch (basic_type_enum) {
202 if (type_width == constant_width) {
205 ? llvm::APFloat(constant.Value.bitsToFloat())
206 : llvm::APFloat(constant.Value.bitsToDouble()));
207 decl->setConstexpr(
true);
211 "Class '{0}' has a member '{1}' of type '{2}' ({3} bits) "
212 "which resolves to a constant value of mismatched width "
213 "({4} bits). Ignoring constant.",
215 member_ct.
GetTypeName(), type_width, constant_width);
229 return Error::success();
232Error UdtRecordCompleter::visitKnownMember(CVMemberRecord &cvr,
233 NestedTypeRecord &nested) {
234 return Error::success();
237Error UdtRecordCompleter::visitKnownMember(CVMemberRecord &cvr,
238 DataMemberRecord &data_member) {
240 uint64_t offset = data_member.FieldOffset * 8;
241 uint32_t bitfield_width = 0;
243 TypeIndex ti(data_member.Type);
244 if (!ti.isSimple()) {
246 if (cvt.kind() == LF_BITFIELD) {
248 llvm::cantFail(TypeDeserializer::deserializeAs<BitFieldRecord>(cvt, bfr));
249 offset += bfr.BitOffset;
250 bitfield_width = bfr.BitSize;
256 if (member_qt.isNull())
257 return Error::success();
263 return Error::success();
266 return Error::success();
269Error UdtRecordCompleter::visitKnownMember(CVMemberRecord &cvr,
270 OneMethodRecord &one_method) {
271 AddMethod(one_method.Name, one_method.Type, one_method.getAccess(),
272 one_method.getOptions(), one_method.Attrs);
274 return Error::success();
277Error UdtRecordCompleter::visitKnownMember(CVMemberRecord &cvr,
278 OverloadedMethodRecord &overloaded) {
279 TypeIndex method_list_idx = overloaded.MethodList;
281 CVType method_list_type =
m_index.
tpi().getType(method_list_idx);
282 assert(method_list_type.kind() == LF_METHODLIST);
284 MethodOverloadListRecord method_list;
285 llvm::cantFail(TypeDeserializer::deserializeAs<MethodOverloadListRecord>(
286 method_list_type, method_list));
288 for (
const OneMethodRecord &method : method_list.Methods)
289 AddMethod(overloaded.Name, method.Type, method.getAccess(),
290 method.getOptions(), method.Attrs);
292 return Error::success();
295Error UdtRecordCompleter::visitKnownMember(CVMemberRecord &cvr,
296 EnumeratorRecord &enumerator) {
301 m_derived_ct, decl, name.str().c_str(), enumerator.Value);
302 return Error::success();
307 llvm::stable_sort(
m_bases, llvm::less_first());
309 std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> bases;
312 bases.push_back(std::move(ib.second));
318 for (
const auto &base_class : bases) {
319 clang::TypeSourceInfo *type_source_info =
320 base_class->getTypeSourceInfo();
321 if (type_source_info) {
323 clang.GetType(type_source_info->getType()));
334 if (
auto *record_decl = llvm::dyn_cast<clang::CXXRecordDecl>(&
m_tag_decl)) {
343 clang::DeclContext *parent_decl_ctx) {
345 clang.GetSymbolFile()->GetBackingSymbolFile());
346 clang::FieldDecl *field_decl =
nullptr;
347 uint64_t bit_size = 0;
348 switch (field->
kind) {
359 ? clang::TagTypeKind::Struct
360 : clang::TagTypeKind::Union;
369 clang::DeclContext *decl_ctx =
clang.GetDeclContextForType(record_ct);
370 for (
const auto &member : field->
fields) {
374 uint64_t member_bit_size =
AddMember(
clang, member.get(), member_offset,
375 record_ct, layout, decl_ctx);
377 bit_size = std::max(bit_size, member_offset + member_bit_size);
379 bit_size = std::max(bit_size, member_bit_size);
383 clang::RecordDecl *record_decl =
clang.GetAsRecordDecl(record_ct);
397 parent_layout.
field_offsets.insert({field_decl, bit_offset});
403 clang::DeclContext *decl_ctx =
415 llvm::StringRef name, uint64_t offset, uint64_t field_size,
417 fields_map[offset].push_back(std::make_unique<Member>(
418 name, offset, field_size, qt, access, bitfield_width));
442 std::map<uint64_t, std::vector<Member *>> end_offset_map;
443 for (
auto &pair : fields_map) {
444 uint64_t offset = pair.first;
445 auto &fields = pair.second;
448 if (offset > start_offset) {
453 auto iter = end_offset_map.lower_bound(offset);
454 if (iter == end_offset_map.end())
456 else if (iter->first > offset) {
457 if (iter == end_offset_map.begin())
461 if (iter->second.empty())
463 parent = iter->second.back();
464 iter->second.pop_back();
471 if (fields.size() == 1) {
472 uint64_t end_offset = offset + fields.back()->bit_size;
473 parent->
fields.push_back(std::move(fields.back()));
475 end_offset_map[end_offset].push_back(parent);
478 "If parent is union, it must be the top level record.");
479 end_offset_map[end_offset].push_back(parent->
fields.back().get());
484 parent = parent->
fields.back().get();
488 "If parent is union, it must be the top level record.");
490 for (
auto &field : fields) {
491 int64_t bit_size = field->bit_size;
492 parent->
fields.push_back(std::move(field));
493 end_offset_map[offset + bit_size].push_back(
494 parent->
fields.back().get());
#define LLDB_LOG(log,...)
The LLDB_LOG* macros defined below are the way to emit log messages.
void SetRecordLayout(clang::RecordDecl *decl, const LayoutInfo &layout)
Sets the layout for the given RecordDecl.
Generic representation of a type in a programming language.
lldb::BasicType GetBasicTypeEnumeration() const
bool IsCompleteType() const
lldb::opaque_compiler_type_t GetOpaqueQualType() const
ConstString GetTypeName(bool BaseOnly=false) const
A class that describes the declaration location of a lldb object.
A TypeSystem implementation based on Clang.
static clang::FieldDecl * AddFieldToRecordType(const CompilerType &type, llvm::StringRef name, const CompilerType &field_type, lldb::AccessType access, uint32_t bitfield_bit_size)
static void SetFloatingInitializerForVariable(clang::VarDecl *var, const llvm::APFloat &init_value)
Initializes a variable with a floating point value.
static void SetIntegerInitializerForVariable(clang::VarDecl *var, const llvm::APInt &init_value)
Initializes a variable with an integer value.
std::unique_ptr< clang::CXXBaseSpecifier > CreateBaseClassSpecifier(lldb::opaque_compiler_type_t type, lldb::AccessType access, bool is_virtual, bool base_of_class)
static void BuildIndirectFields(const CompilerType &type)
clang::CXXMethodDecl * AddMethodToCXXRecordType(lldb::opaque_compiler_type_t type, llvm::StringRef name, const char *mangled_name, const CompilerType &method_type, lldb::AccessType access, bool is_virtual, bool is_static, bool is_inline, bool is_explicit, bool is_attr_used, bool is_artificial)
clang::EnumConstantDecl * AddEnumerationValueToEnumerationType(const CompilerType &enum_type, const Declaration &decl, const char *name, int64_t enum_value, uint32_t enum_value_bit_size)
static clang::CXXRecordDecl * GetAsCXXRecordDecl(lldb::opaque_compiler_type_t type)
static bool CompleteTagDeclarationDefinition(const CompilerType &type)
static bool StartTagDeclarationDefinition(const CompilerType &type)
static clang::VarDecl * AddVariableToRecordType(const CompilerType &type, llvm::StringRef name, const CompilerType &var_type, lldb::AccessType access)
static void RequireCompleteType(CompilerType type)
Complete a type from debug info, or mark it as forcefully completed if there is no definition of the ...
ClangASTImporter & GetClangASTImporter()
CompilerType ToCompilerType(clang::QualType qt)
TypeSystemClang & clang()
clang::DeclContext * GetOrCreateDeclContextForUid(PdbSymUid uid)
clang::QualType GetOrCreateType(PdbTypeSymId type)
PdbIndex - Lazy access to the important parts of a PDB file.
llvm::pdb::GlobalsStream & globals()
llvm::pdb::SymbolStream & symrecords()
llvm::pdb::TpiStream & tpi()
lldb::user_id_t anonymous_id
std::vector< IndexedBase > m_bases
llvm::DenseMap< lldb::opaque_compiler_type_t, llvm::SmallSet< std::pair< llvm::StringRef, CompilerType >, 8 > > & m_cxx_record_map
ClangASTImporter::LayoutInfo m_layout
clang::TagDecl & m_tag_decl
CompilerType & m_derived_ct
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)
PdbAstBuilder & m_ast_builder
union lldb_private::npdb::UdtRecordCompleter::UdtTagRecord m_cvr
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)
llvm::StringRef DropNameScope(llvm::StringRef name)
lldb::AccessType TranslateMemberAccess(llvm::codeview::MemberAccess access)
size_t GetSizeOfType(PdbTypeSymId id, llvm::pdb::TpiStream &tpi)
A class that represents a running process on the host machine.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
void * opaque_compiler_type_t
BasicType
Basic types enumeration for the public API SBType::GetBasicType().
@ eLanguageTypeC_plus_plus
ISO C++:1998.
llvm::DenseMap< const clang::FieldDecl *, uint64_t > field_offsets
llvm::codeview::TypeIndex index
llvm::SmallVector< MemberUP, 1 > fields
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
llvm::codeview::EnumRecord er
llvm::codeview::ClassRecord cr
llvm::codeview::UnionRecord ur