summaryrefslogtreecommitdiffstats
path: root/lldb/source/Plugins
diff options
context:
space:
mode:
authorAleksandr Urakov <aleksandr.urakov@jetbrains.com>2019-02-12 08:17:11 +0000
committerAleksandr Urakov <aleksandr.urakov@jetbrains.com>2019-02-12 08:17:11 +0000
commiteaa0ad672e3935d79c00c8c181329e4f0630945b (patch)
treeb7e1d6e09e23dd5ab6a55a28e789f3d1d0b34206 /lldb/source/Plugins
parentca524b19c1524b7e43fee229d690384fd2bea27e (diff)
downloadbcm5719-llvm-eaa0ad672e3935d79c00c8c181329e4f0630945b.tar.gz
bcm5719-llvm-eaa0ad672e3935d79c00c8c181329e4f0630945b.zip
[NativePDB] Process virtual bases in the correct order
Summary: This patch makes virtual bases to be added in the correct order to the bases list. It is important because `VTableContext` (`MicrosoftVTableContext` in our case) uses then the order of virtual bases in the list to restore the virtual table indexes. These indexes are used then to resolve the layout of the virtual bases. We haven't enough information about offsets of virtual bases regarding to the object (moreover, in a common case we can't rely on such information, see the example here: https://reviews.llvm.org/D53506#1272306 ), but there should be enough information to restore the layout of the virtual bases from the indexes in runtime. After D53506 this information is used whenever possible, so there should be no problems with virtual bases' fields reading. Reviewers: zturner, rnk, stella.stamenova Subscribers: abidh, teemperor, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D56904 llvm-svn: 353806
Diffstat (limited to 'lldb/source/Plugins')
-rw-r--r--lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp29
-rw-r--r--lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.h10
2 files changed, 28 insertions, 11 deletions
diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp b/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp
index 37be3bc9cdf..ba5c14b9603 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.cpp
@@ -50,7 +50,8 @@ UdtRecordCompleter::UdtRecordCompleter(PdbTypeSymId id,
}
clang::QualType UdtRecordCompleter::AddBaseClassForTypeIndex(
- llvm::codeview::TypeIndex ti, llvm::codeview::MemberAccess access) {
+ llvm::codeview::TypeIndex ti, llvm::codeview::MemberAccess access,
+ llvm::Optional<uint64_t> vtable_idx) {
PdbTypeSymId type_id(ti);
clang::QualType qt = m_ast_builder.GetOrCreateType(type_id);
@@ -58,10 +59,13 @@ clang::QualType UdtRecordCompleter::AddBaseClassForTypeIndex(
std::unique_ptr<clang::CXXBaseSpecifier> base_spec =
m_ast_builder.clang().CreateBaseClassSpecifier(
- qt.getAsOpaquePtr(), TranslateMemberAccess(access), false,
- udt_cvt.kind() == LF_CLASS);
+ qt.getAsOpaquePtr(), TranslateMemberAccess(access),
+ vtable_idx.hasValue(), udt_cvt.kind() == LF_CLASS);
lldbassert(base_spec);
- m_bases.push_back(std::move(base_spec));
+
+ m_bases.push_back(
+ std::make_pair(vtable_idx.getValueOr(0), std::move(base_spec)));
+
return qt;
}
@@ -98,9 +102,8 @@ Error UdtRecordCompleter::visitKnownMember(CVMemberRecord &cvr,
Error UdtRecordCompleter::visitKnownMember(CVMemberRecord &cvr,
VirtualBaseClassRecord &base) {
- AddBaseClassForTypeIndex(base.BaseType, base.getAccess());
+ AddBaseClassForTypeIndex(base.BaseType, base.getAccess(), base.VTableIndex);
- // FIXME: Handle virtual base offsets.
return Error::success();
}
@@ -209,9 +212,19 @@ Error UdtRecordCompleter::visitKnownMember(CVMemberRecord &cvr,
}
void UdtRecordCompleter::complete() {
+ // Ensure the correct order for virtual bases.
+ std::stable_sort(m_bases.begin(), m_bases.end(),
+ [](const IndexedBase &lhs, const IndexedBase &rhs) {
+ return lhs.first < rhs.first;
+ });
+
+ std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> bases;
+ bases.reserve(m_bases.size());
+ for (auto &ib : m_bases)
+ bases.push_back(std::move(ib.second));
+
ClangASTContext &clang = m_ast_builder.clang();
- clang.TransferBaseClasses(m_derived_ct.GetOpaqueQualType(),
- std::move(m_bases));
+ clang.TransferBaseClasses(m_derived_ct.GetOpaqueQualType(), std::move(bases));
clang.AddMethodOverridesForCXXRecordType(m_derived_ct.GetOpaqueQualType());
ClangASTContext::BuildIndirectFields(m_derived_ct);
diff --git a/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.h b/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.h
index 43015f9e25b..b11e813c122 100644
--- a/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.h
+++ b/lldb/source/Plugins/SymbolFile/NativePDB/UdtRecordCompleter.h
@@ -35,6 +35,9 @@ namespace npdb {
class PdbAstBuilder;
class UdtRecordCompleter : public llvm::codeview::TypeVisitorCallbacks {
+ using IndexedBase =
+ std::pair<uint64_t, std::unique_ptr<clang::CXXBaseSpecifier>>;
+
union UdtTagRecord {
UdtTagRecord() {}
llvm::codeview::UnionRecord ur;
@@ -47,7 +50,7 @@ class UdtRecordCompleter : public llvm::codeview::TypeVisitorCallbacks {
clang::TagDecl &m_tag_decl;
PdbAstBuilder &m_ast_builder;
llvm::pdb::TpiStream &m_tpi;
- std::vector<std::unique_ptr<clang::CXXBaseSpecifier>> m_bases;
+ std::vector<IndexedBase> m_bases;
ClangASTImporter::LayoutInfo m_layout;
public:
@@ -64,8 +67,9 @@ public:
void complete();
private:
- clang::QualType AddBaseClassForTypeIndex(llvm::codeview::TypeIndex ti,
- llvm::codeview::MemberAccess access);
+ clang::QualType AddBaseClassForTypeIndex(
+ llvm::codeview::TypeIndex ti, llvm::codeview::MemberAccess access,
+ llvm::Optional<uint64_t> vtable_idx = llvm::Optional<uint64_t>());
void AddMethod(llvm::StringRef name, llvm::codeview::TypeIndex type_idx,
llvm::codeview::MemberAccess access,
llvm::codeview::MethodOptions options,
OpenPOWER on IntegriCloud