diff --git a/src/common/dwarf/dwarf2reader.cc b/src/common/dwarf/dwarf2reader.cc index bf6758d8..11854b4b 100644 --- a/src/common/dwarf/dwarf2reader.cc +++ b/src/common/dwarf/dwarf2reader.cc @@ -129,10 +129,13 @@ void CompilationUnit::ReadAbbrevs() { const uint64_t abbrev_length = iter->second.second - header_.abbrev_offset; #endif + uint64_t highest_number = 0; + while (1) { CompilationUnit::Abbrev abbrev; size_t len; const uint64_t number = reader_->ReadUnsignedLEB128(abbrevptr, &len); + highest_number = std::max(highest_number, number); if (number == 0) break; @@ -170,9 +173,17 @@ void CompilationUnit::ReadAbbrevs() { value); abbrev.attributes.push_back(abbrev_attr); } - assert(abbrev.number == abbrevs_->size()); abbrevs_->push_back(abbrev); } + + // Account of cases where entries are out of order. + std::sort(abbrevs_->begin(), abbrevs_->end(), + [](const CompilationUnit::Abbrev& lhs, const CompilationUnit::Abbrev& rhs) { + return lhs.number < rhs.number; + }); + + // Ensure that there are no missing sections. + assert(abbrevs_->size() == highest_number + 1); } // Skips a single DIE's attributes.