Skip to content

Commit 39f1335

Browse files
Unnar Freyr Erlendssonlabath
Unnar Freyr Erlendsson
authored andcommitted
Make SymbolFileDWARF::ParseLineTable use std::sort instead of insertion sort
Summary: Motivation: When setting breakpoints in certain projects line sequences are frequently being inserted out of order. Rather than inserting sequences one at a time into a sorted line table, store all the line sequences as we're building them up and sort and flatten afterwards. Reviewers: jdoerfert, labath Reviewed By: labath Subscribers: teemperor, labath, mgrang, JDevlieghere, lldb-commits Tags: #lldb Differential Revision: https://reviews.llvm.org/D72909
1 parent b7af1bf commit 39f1335

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

lldb/include/lldb/Symbol/LineTable.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ class LineTable {
4242
/// The compile unit to which this line table belongs.
4343
LineTable(CompileUnit *comp_unit);
4444

45+
/// Construct with entries found in \a sequences.
46+
///
47+
/// \param[in] sequences
48+
/// Unsorted list of line sequences.
49+
LineTable(CompileUnit *comp_unit, std::vector<LineSequence *> &sequences);
50+
4551
/// Destructor.
4652
~LineTable();
4753

@@ -64,11 +70,11 @@ class LineTable {
6470
bool is_epilogue_begin, bool is_terminal_entry);
6571

6672
// Used to instantiate the LineSequence helper class
67-
LineSequence *CreateLineSequenceContainer();
73+
static LineSequence *CreateLineSequenceContainer();
6874

6975
// Append an entry to a caller-provided collection that will later be
7076
// inserted in this line table.
71-
void AppendLineEntryToSequence(LineSequence *sequence, lldb::addr_t file_addr,
77+
static void AppendLineEntryToSequence(LineSequence *sequence, lldb::addr_t file_addr,
7278
uint32_t line, uint16_t column,
7379
uint16_t file_idx, bool is_start_of_statement,
7480
bool is_start_of_basic_block,
@@ -259,6 +265,7 @@ class LineTable {
259265
public:
260266
LessThanBinaryPredicate(LineTable *line_table);
261267
bool operator()(const LineTable::Entry &, const LineTable::Entry &) const;
268+
bool operator()(const LineSequence*, const LineSequence*) const;
262269

263270
protected:
264271
LineTable *m_line_table;

lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,20 +1007,22 @@ bool SymbolFileDWARF::ParseLineTable(CompileUnit &comp_unit) {
10071007
// FIXME: Rather than parsing the whole line table and then copying it over
10081008
// into LLDB, we should explore using a callback to populate the line table
10091009
// while we parse to reduce memory usage.
1010-
std::unique_ptr<LineTable> line_table_up =
1011-
std::make_unique<LineTable>(&comp_unit);
1012-
LineSequence *sequence = line_table_up->CreateLineSequenceContainer();
1010+
LineSequence *sequence = LineTable::CreateLineSequenceContainer();
1011+
std::vector<LineSequence *> sequences;
10131012
for (auto &row : line_table->Rows) {
1014-
line_table_up->AppendLineEntryToSequence(
1013+
LineTable::AppendLineEntryToSequence(
10151014
sequence, row.Address.Address, row.Line, row.Column, row.File,
10161015
row.IsStmt, row.BasicBlock, row.PrologueEnd, row.EpilogueBegin,
10171016
row.EndSequence);
10181017
if (row.EndSequence) {
1019-
line_table_up->InsertSequence(sequence);
1020-
sequence = line_table_up->CreateLineSequenceContainer();
1018+
sequences.push_back(sequence);
1019+
sequence = LineTable::CreateLineSequenceContainer();
10211020
}
10221021
}
10231022

1023+
std::unique_ptr<LineTable> line_table_up =
1024+
std::make_unique<LineTable>(&comp_unit, sequences);
1025+
10241026
if (SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile()) {
10251027
// We have an object file that has a line table with addresses that are not
10261028
// linked. We need to link the line table and convert the addresses that

lldb/source/Symbol/LineTable.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ using namespace lldb_private;
2121
LineTable::LineTable(CompileUnit *comp_unit)
2222
: m_comp_unit(comp_unit), m_entries() {}
2323

24+
LineTable::LineTable(CompileUnit *comp_unit, std::vector<LineSequence *> &sequences)
25+
: m_comp_unit(comp_unit), m_entries() {
26+
LineTable::Entry::LessThanBinaryPredicate less_than_bp(this);
27+
std::sort(sequences.begin(), sequences.end(), less_than_bp);
28+
for (auto *sequence : sequences) {
29+
LineSequenceImpl *seq = reinterpret_cast<LineSequenceImpl *>(sequence);
30+
m_entries.insert(m_entries.end(), seq->m_entries.begin(),
31+
seq->m_entries.end());
32+
}
33+
}
34+
2435
// Destructor
2536
LineTable::~LineTable() {}
2637

@@ -154,6 +165,13 @@ operator()(const LineTable::Entry &a, const LineTable::Entry &b) const {
154165
#undef LT_COMPARE
155166
}
156167

168+
bool LineTable::Entry::LessThanBinaryPredicate::
169+
operator()(const LineSequence *sequence_a, const LineSequence *sequence_b) const {
170+
auto *seq_a = static_cast<const LineSequenceImpl *>(sequence_a);
171+
auto *seq_b = static_cast<const LineSequenceImpl *>(sequence_b);
172+
return (*this)(seq_a->m_entries.front(), seq_b->m_entries.front());
173+
}
174+
157175
uint32_t LineTable::GetSize() const { return m_entries.size(); }
158176

159177
bool LineTable::GetLineEntryAtIndex(uint32_t idx, LineEntry &line_entry) {

0 commit comments

Comments
 (0)