Index: lldb/include/lldb/Symbol/LineTable.h =================================================================== --- lldb/include/lldb/Symbol/LineTable.h +++ lldb/include/lldb/Symbol/LineTable.h @@ -42,6 +42,12 @@ /// The compile unit to which this line table belongs. LineTable(CompileUnit *comp_unit); + /// Construct with entries found in \a sequences. + /// + /// \param[in] sequences + /// Unsorted list of line sequences. + LineTable(CompileUnit *comp_unit, std::vector &sequences); + /// Destructor. ~LineTable(); @@ -64,11 +70,11 @@ bool is_epilogue_begin, bool is_terminal_entry); // Used to instantiate the LineSequence helper class - LineSequence *CreateLineSequenceContainer(); + static LineSequence *CreateLineSequenceContainer(); // Append an entry to a caller-provided collection that will later be // inserted in this line table. - void AppendLineEntryToSequence(LineSequence *sequence, lldb::addr_t file_addr, + static void AppendLineEntryToSequence(LineSequence *sequence, lldb::addr_t file_addr, uint32_t line, uint16_t column, uint16_t file_idx, bool is_start_of_statement, bool is_start_of_basic_block, @@ -259,6 +265,7 @@ public: LessThanBinaryPredicate(LineTable *line_table); bool operator()(const LineTable::Entry &, const LineTable::Entry &) const; + bool operator()(const LineSequence*, const 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 @@ -1015,20 +1015,22 @@ // FIXME: Rather than parsing the whole line table and then copying it over // into LLDB, we should explore using a callback to populate the line table // while we parse to reduce memory usage. - std::unique_ptr line_table_up = - std::make_unique(&comp_unit); - LineSequence *sequence = line_table_up->CreateLineSequenceContainer(); + LineSequence *sequence = LineTable::CreateLineSequenceContainer(); + std::vector sequences; for (auto &row : line_table->Rows) { - line_table_up->AppendLineEntryToSequence( + LineTable::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); - sequence = line_table_up->CreateLineSequenceContainer(); + sequences.push_back(sequence); + sequence = LineTable::CreateLineSequenceContainer(); } } + std::unique_ptr line_table_up = + std::make_unique(&comp_unit, 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 @@ -21,6 +21,17 @@ LineTable::LineTable(CompileUnit *comp_unit) : m_comp_unit(comp_unit), m_entries() {} +LineTable::LineTable(CompileUnit *comp_unit, std::vector &sequences) + : m_comp_unit(comp_unit), m_entries() { + 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()); + } +} + // Destructor LineTable::~LineTable() {} @@ -154,6 +165,13 @@ #undef LT_COMPARE } +bool LineTable::Entry::LessThanBinaryPredicate:: +operator()(const LineSequence *sequence_a, const LineSequence *sequence_b) const { + auto *seq_a = static_cast(sequence_a); + auto *seq_b = static_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) {