diff options
| author | Zachary Turner <zturner@google.com> | 2015-03-24 16:24:50 +0000 |
|---|---|---|
| committer | Zachary Turner <zturner@google.com> | 2015-03-24 16:24:50 +0000 |
| commit | 504f38da4e2c5ef76e7414f18fdafc71908876e9 (patch) | |
| tree | 3a2070d2784730fb1444072f52dc97b27ebbc98d /lldb/source/Plugins/SymbolFile/DWARF | |
| parent | 186d2cbd1d746493d03be6a535b91ee2354effd9 (diff) | |
| download | bcm5719-llvm-504f38da4e2c5ef76e7414f18fdafc71908876e9.tar.gz bcm5719-llvm-504f38da4e2c5ef76e7414f18fdafc71908876e9.zip | |
Fix record layout when synthesizing class types.
Prior to this patch, we would try to synthesize class types by
iterating over a DenseMap of FieldDecls and adding each one to
a CXXRecordDecl. Since a DenseMap doesn't provide a deterministic
ordering of the elements, this would not add the fields in
FieldOffset order, but rather in some random order determined by
the memory layout of the DenseMap.
This patch fixes the issue by changing DenseMaps to vectors. The
ability to lookup a value in the DenseMap was hardly being used,
and where it is sufficient to do a vector lookup.
Differential Revision: http://reviews.llvm.org/D8512
llvm-svn: 233090
Diffstat (limited to 'lldb/source/Plugins/SymbolFile/DWARF')
4 files changed, 66 insertions, 89 deletions
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp index 3323bded4f4..6984c86afd7 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -2073,8 +2073,9 @@ SymbolFileDWARF::ParseChildMembers GetClangASTContext().GetBuiltinTypeForEncodingAndBitSize(eEncodingSint, word_width), accessibility, anon_field_info.bit_size); - - layout_info.field_offsets.insert(std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset)); + + layout_info.field_offsets.push_back( + std::make_pair(unnamed_bitfield_decl, anon_field_info.bit_offset)); } } last_field_info = this_field_info; @@ -2124,9 +2125,8 @@ SymbolFileDWARF::ParseChildMembers bit_size); GetClangASTContext().SetMetadataAsUserID (field_decl, MakeUserID(die->GetOffset())); - - layout_info.field_offsets.insert(std::make_pair(field_decl, field_bit_offset)); + layout_info.field_offsets.push_back(std::make_pair(field_decl, field_bit_offset)); } else { @@ -2287,8 +2287,9 @@ SymbolFileDWARF::ParseChildMembers } else { - layout_info.base_offsets.insert(std::make_pair(base_class_clang_type.GetAsCXXRecordDecl(), - clang::CharUnits::fromQuantity(member_byte_offset))); + layout_info.base_offsets.push_back( + std::make_pair(base_class_clang_type.GetAsCXXRecordDecl(), + clang::CharUnits::fromQuantity(member_byte_offset))); } } } @@ -2669,43 +2670,36 @@ SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (ClangASTType &clang_type) static_cast<uint32_t>(layout_info.base_offsets.size()), static_cast<uint32_t>(layout_info.vbase_offsets.size())); - uint32_t idx; - { - llvm::DenseMap <const clang::FieldDecl *, uint64_t>::const_iterator pos, end = layout_info.field_offsets.end(); - for (idx = 0, pos = layout_info.field_offsets.begin(); pos != end; ++pos, ++idx) + for (const auto &entry : layout_info.field_offsets) { - GetObjectFile()->GetModule()->LogMessage (log, - "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = { bit_offset=%u, name='%s' }", - static_cast<void*>(clang_type.GetOpaqueQualType()), - idx, - static_cast<uint32_t>(pos->second), - pos->first->getNameAsString().c_str()); - } + GetObjectFile()->GetModule()->LogMessage( + log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) field[%u] = " + "{ bit_offset=%u, name='%s' }", + static_cast<void *>(clang_type.GetOpaqueQualType()), entry.first->getFieldIndex(), + static_cast<uint32_t>(entry.second), entry.first->getNameAsString().c_str()); } + uint32_t idx = 0; + for (const auto &entry : layout_info.base_offsets) { - llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator base_pos, base_end = layout_info.base_offsets.end(); - for (idx = 0, base_pos = layout_info.base_offsets.begin(); base_pos != base_end; ++base_pos, ++idx) - { - GetObjectFile()->GetModule()->LogMessage (log, - "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] = { byte_offset=%u, name='%s' }", - clang_type.GetOpaqueQualType(), - idx, - (uint32_t)base_pos->second.getQuantity(), - base_pos->first->getNameAsString().c_str()); + GetObjectFile()->GetModule()->LogMessage( + log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) base[%u] = { " + "byte_offset=%u, name='%s' }", + clang_type.GetOpaqueQualType(), idx, (uint32_t)entry.second.getQuantity(), + entry.first->getNameAsString().c_str()); + ++idx; } - } - { - llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits>::const_iterator vbase_pos, vbase_end = layout_info.vbase_offsets.end(); - for (idx = 0, vbase_pos = layout_info.vbase_offsets.begin(); vbase_pos != vbase_end; ++vbase_pos, ++idx) + + idx = 0; + for (const auto &entry : layout_info.vbase_offsets) { - GetObjectFile()->GetModule()->LogMessage (log, - "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) vbase[%u] = { byte_offset=%u, name='%s' }", - static_cast<void*>(clang_type.GetOpaqueQualType()), - idx, - static_cast<uint32_t>(vbase_pos->second.getQuantity()), - vbase_pos->first->getNameAsString().c_str()); - } + GetObjectFile()->GetModule()->LogMessage( + log, "SymbolFileDWARF::ResolveClangOpaqueTypeDefinition (clang_type = %p) vbase[%u] = " + "{ byte_offset=%u, name='%s' }", + static_cast<void *>(clang_type.GetOpaqueQualType()), idx, + static_cast<uint32_t>(entry.second.getQuantity()), + entry.first->getNameAsString().c_str()); + ++idx; } } m_record_decl_to_layout_map.insert(std::make_pair(record_decl, layout_info)); @@ -7918,27 +7912,22 @@ SymbolFileDWARF::FindExternalVisibleDeclsByName (void *baton, } } -bool -SymbolFileDWARF::LayoutRecordType (void *baton, - const clang::RecordDecl *record_decl, - uint64_t &size, - uint64_t &alignment, - llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, - llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, - llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) +bool +SymbolFileDWARF::LayoutRecordType(void *baton, const clang::RecordDecl *record_decl, uint64_t &size, + uint64_t &alignment, + std::vector<std::pair<const clang::FieldDecl *, uint64_t>> &field_offsets, + std::vector<std::pair<const clang::CXXRecordDecl *, clang::CharUnits>> &base_offsets, + std::vector<std::pair<const clang::CXXRecordDecl *, clang::CharUnits>> &vbase_offsets) { SymbolFileDWARF *symbol_file_dwarf = (SymbolFileDWARF *)baton; return symbol_file_dwarf->LayoutRecordType (record_decl, size, alignment, field_offsets, base_offsets, vbase_offsets); } - -bool -SymbolFileDWARF::LayoutRecordType (const clang::RecordDecl *record_decl, - uint64_t &bit_size, - uint64_t &alignment, - llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, - llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, - llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) +bool +SymbolFileDWARF::LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &bit_size, uint64_t &alignment, + std::vector<std::pair<const clang::FieldDecl *, uint64_t>> &field_offsets, + std::vector<std::pair<const clang::CXXRecordDecl *, clang::CharUnits>> &base_offsets, + std::vector<std::pair<const clang::CXXRecordDecl *, clang::CharUnits>> &vbase_offsets) { Log *log (LogChannelDWARF::GetLogIfAll(DWARF_LOG_DEBUG_INFO)); RecordDeclToLayoutMap::iterator pos = m_record_decl_to_layout_map.find (record_decl); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h index 5ebb60e1367..4551d6ef56b 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -151,22 +151,16 @@ public: clang::DeclarationName Name, llvm::SmallVectorImpl <clang::NamedDecl *> *results); - static bool - LayoutRecordType (void *baton, - const clang::RecordDecl *record_decl, - uint64_t &size, - uint64_t &alignment, - llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, - llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, - llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets); - - bool - LayoutRecordType (const clang::RecordDecl *record_decl, - uint64_t &size, - uint64_t &alignment, - llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, - llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, - llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets); + static bool + LayoutRecordType(void *baton, const clang::RecordDecl *record_decl, uint64_t &size, uint64_t &alignment, + std::vector<std::pair<const clang::FieldDecl *, uint64_t>> &FieldOffsets, + std::vector<std::pair<const clang::CXXRecordDecl *, clang::CharUnits>> &BaseOffsets, + std::vector<std::pair<const clang::CXXRecordDecl *, clang::CharUnits>> &VirtualBaseOffsets); + + bool LayoutRecordType(const clang::RecordDecl *record_decl, uint64_t &size, uint64_t &alignment, + std::vector<std::pair<const clang::FieldDecl *, uint64_t>> &FieldOffsets, + std::vector<std::pair<const clang::CXXRecordDecl *, clang::CharUnits>> &BaseOffsets, + std::vector<std::pair<const clang::CXXRecordDecl *, clang::CharUnits>> &VirtualBaseOffsets); struct LayoutInfo { @@ -180,9 +174,9 @@ public: } uint64_t bit_size; uint64_t alignment; - llvm::DenseMap <const clang::FieldDecl *, uint64_t> field_offsets; - llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> base_offsets; - llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> vbase_offsets; + std::vector<std::pair<const clang::FieldDecl *, uint64_t>> field_offsets; + std::vector<std::pair<const clang::CXXRecordDecl *, clang::CharUnits>> base_offsets; + std::vector<std::pair<const clang::CXXRecordDecl *, clang::CharUnits>> vbase_offsets; }; //------------------------------------------------------------------ // PluginInterface protocol diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp index e7c68595b6f..eeb3ef8242a 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.cpp @@ -1474,14 +1474,12 @@ SymbolFileDWARFDebugMap::CompleteObjCInterfaceDecl (void *baton, clang::ObjCInte } } -bool -SymbolFileDWARFDebugMap::LayoutRecordType (void *baton, - const clang::RecordDecl *record_decl, - uint64_t &size, - uint64_t &alignment, - llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, - llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, - llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets) +bool +SymbolFileDWARFDebugMap::LayoutRecordType( + void *baton, const clang::RecordDecl *record_decl, uint64_t &size, uint64_t &alignment, + std::vector<std::pair<const clang::FieldDecl *, uint64_t>> &field_offsets, + std::vector<std::pair<const clang::CXXRecordDecl *, clang::CharUnits>> &base_offsets, + std::vector<std::pair<const clang::CXXRecordDecl *, clang::CharUnits>> &vbase_offsets) { SymbolFileDWARFDebugMap *symbol_file_dwarf = (SymbolFileDWARFDebugMap *)baton; SymbolFileDWARF *oso_dwarf; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h index 1493292d4b9..cecd6396784 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARFDebugMap.h @@ -102,16 +102,12 @@ public: static void CompleteObjCInterfaceDecl (void *baton, clang::ObjCInterfaceDecl *); - - static bool - LayoutRecordType (void *baton, - const clang::RecordDecl *record_decl, - uint64_t &size, - uint64_t &alignment, - llvm::DenseMap <const clang::FieldDecl *, uint64_t> &field_offsets, - llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &base_offsets, - llvm::DenseMap <const clang::CXXRecordDecl *, clang::CharUnits> &vbase_offsets); + static bool + LayoutRecordType(void *baton, const clang::RecordDecl *record_decl, uint64_t &size, uint64_t &alignment, + std::vector<std::pair<const clang::FieldDecl *, uint64_t>> &FieldOffsets, + std::vector<std::pair<const clang::CXXRecordDecl *, clang::CharUnits>> &BaseOffsets, + std::vector<std::pair<const clang::CXXRecordDecl *, clang::CharUnits>> &VirtualBaseOffsets); //------------------------------------------------------------------ // PluginInterface protocol |

