Index: lldb/include/lldb/Symbol/LineTable.h =================================================================== --- lldb/include/lldb/Symbol/LineTable.h +++ lldb/include/lldb/Symbol/LineTable.h @@ -78,6 +78,12 @@ // Insert a sequence of entries into this line table. void InsertSequence(LineSequence *sequence); + /// Replace the current line table with entries found in \a sequences. + /// + /// \param[in] sequences + /// Unsorted list of line sequences. + void ReplaceLineTableWithSequences(std::vector &sequences); + /// Dump all line entries in this line table to the stream \a s. /// /// \param[in] s @@ -259,6 +265,7 @@ public: LessThanBinaryPredicate(LineTable *line_table); bool operator()(const LineTable::Entry &, const LineTable::Entry &) const; + bool operator()(LineSequence*, LineSequence*) const; protected: LineTable *m_line_table; Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp =================================================================== --- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -1018,17 +1018,20 @@ std::unique_ptr line_table_up = std::make_unique(&comp_unit); LineSequence *sequence = line_table_up->CreateLineSequenceContainer(); + std::vector sequences; for (auto &row : line_table->Rows) { line_table_up->AppendLineEntryToSequence( sequence, row.Address.Address, row.Line, row.Column, row.File, row.IsStmt, row.BasicBlock, row.PrologueEnd, row.EpilogueBegin, row.EndSequence); if (row.EndSequence) { - line_table_up->InsertSequence(sequence); + sequences.push_back(sequence); sequence = line_table_up->CreateLineSequenceContainer(); } } + line_table_up->ReplaceLineTableWithSequences(sequences); + if (SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile()) { // We have an object file that has a line table with addresses that are not // linked. We need to link the line table and convert the addresses that Index: lldb/source/Symbol/LineTable.cpp =================================================================== --- lldb/source/Symbol/LineTable.cpp +++ lldb/source/Symbol/LineTable.cpp @@ -130,6 +130,17 @@ m_entries.insert(pos, seq->m_entries.begin(), seq->m_entries.end()); } +void LineTable::ReplaceLineTableWithSequences(std::vector &sequences) { + m_entries.clear(); + LineTable::Entry::LessThanBinaryPredicate less_than_bp(this); + std::sort(sequences.begin(), sequences.end(), less_than_bp); + for (auto *sequence : sequences) { + LineSequenceImpl *seq = reinterpret_cast(sequence); + m_entries.insert(m_entries.end(), seq->m_entries.begin(), + seq->m_entries.end()); + } +} + LineTable::Entry::LessThanBinaryPredicate::LessThanBinaryPredicate( LineTable *line_table) : m_line_table(line_table) {} @@ -154,6 +165,13 @@ #undef LT_COMPARE } +bool LineTable::Entry::LessThanBinaryPredicate:: +operator()(LineSequence *sequence_a, LineSequence *sequence_b) const { + LineSequenceImpl *seq_a = reinterpret_cast(sequence_a); + LineSequenceImpl *seq_b = reinterpret_cast(sequence_b); + return (*this)(seq_a->m_entries.front(), seq_b->m_entries.front()); +} + uint32_t LineTable::GetSize() const { return m_entries.size(); } bool LineTable::GetLineEntryAtIndex(uint32_t idx, LineEntry &line_entry) {