Skip to content

Commit 367ecc6

Browse files
authored
[lldb] Renaissance LineTable sequences (llvm#127800)
LineSeqeunce is basically a vector, except that users aren't supposed to know that. This implements the same concept in a slightly simpler fashion.
1 parent 544a161 commit 367ecc6

File tree

7 files changed

+95
-143
lines changed

7 files changed

+95
-143
lines changed

lldb/include/lldb/Symbol/LineTable.h

Lines changed: 38 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,11 @@
2020

2121
namespace lldb_private {
2222

23-
/// \class LineSequence LineTable.h "lldb/Symbol/LineTable.h" An abstract base
24-
/// class used during symbol table creation.
25-
class LineSequence {
26-
public:
27-
LineSequence();
28-
29-
virtual ~LineSequence() = default;
30-
31-
virtual void Clear() = 0;
32-
33-
private:
34-
LineSequence(const LineSequence &) = delete;
35-
const LineSequence &operator=(const LineSequence &) = delete;
36-
};
37-
3823
/// \class LineTable LineTable.h "lldb/Symbol/LineTable.h"
3924
/// A line table class.
4025
class LineTable {
4126
public:
27+
class Sequence;
4228
/// Construct with compile unit.
4329
///
4430
/// \param[in] comp_unit
@@ -49,8 +35,7 @@ class LineTable {
4935
///
5036
/// \param[in] sequences
5137
/// Unsorted list of line sequences.
52-
LineTable(CompileUnit *comp_unit,
53-
std::vector<std::unique_ptr<LineSequence>> &&sequences);
38+
LineTable(CompileUnit *comp_unit, std::vector<Sequence> &&sequences);
5439

5540
/// Destructor.
5641
~LineTable();
@@ -73,20 +58,17 @@ class LineTable {
7358
bool is_start_of_basic_block, bool is_prologue_end,
7459
bool is_epilogue_begin, bool is_terminal_entry);
7560

76-
// Used to instantiate the LineSequence helper class
77-
static std::unique_ptr<LineSequence> CreateLineSequenceContainer();
78-
7961
// Append an entry to a caller-provided collection that will later be
8062
// inserted in this line table.
81-
static void AppendLineEntryToSequence(LineSequence *sequence, lldb::addr_t file_addr,
82-
uint32_t line, uint16_t column,
83-
uint16_t file_idx, bool is_start_of_statement,
84-
bool is_start_of_basic_block,
85-
bool is_prologue_end, bool is_epilogue_begin,
86-
bool is_terminal_entry);
63+
static void
64+
AppendLineEntryToSequence(Sequence &sequence, lldb::addr_t file_addr,
65+
uint32_t line, uint16_t column, uint16_t file_idx,
66+
bool is_start_of_statement,
67+
bool is_start_of_basic_block, bool is_prologue_end,
68+
bool is_epilogue_begin, bool is_terminal_entry);
8769

8870
// Insert a sequence of entries into this line table.
89-
void InsertSequence(LineSequence *sequence);
71+
void InsertSequence(Sequence sequence);
9072

9173
/// Dump all line entries in this line table to the stream \a s.
9274
///
@@ -274,17 +256,6 @@ class LineTable {
274256
return 0;
275257
}
276258

277-
class LessThanBinaryPredicate {
278-
public:
279-
LessThanBinaryPredicate(LineTable *line_table);
280-
bool operator()(const LineTable::Entry &, const LineTable::Entry &) const;
281-
bool operator()(const std::unique_ptr<LineSequence> &,
282-
const std::unique_ptr<LineSequence> &) const;
283-
284-
protected:
285-
LineTable *m_line_table;
286-
};
287-
288259
static bool EntryAddressLessThan(const Entry &lhs, const Entry &rhs) {
289260
return lhs.file_addr < rhs.file_addr;
290261
}
@@ -316,6 +287,35 @@ class LineTable {
316287
uint16_t file_idx = 0;
317288
};
318289

290+
class Sequence {
291+
public:
292+
Sequence() = default;
293+
// Moving clears moved-from object so it can be used anew. Copying is
294+
// generally an error. C++ doesn't guarantee that a moved-from vector is
295+
// empty(), so we clear it explicitly.
296+
Sequence(Sequence &&rhs) : m_entries(std::exchange(rhs.m_entries, {})) {}
297+
Sequence &operator=(Sequence &&rhs) {
298+
m_entries = std::exchange(rhs.m_entries, {});
299+
return *this;
300+
}
301+
Sequence(const Sequence &) = delete;
302+
Sequence &operator=(const Sequence &) = delete;
303+
304+
private:
305+
std::vector<Entry> m_entries;
306+
friend class LineTable;
307+
};
308+
309+
class LessThanBinaryPredicate {
310+
public:
311+
LessThanBinaryPredicate(LineTable *line_table) : m_line_table(line_table) {}
312+
bool operator()(const LineTable::Entry &, const LineTable::Entry &) const;
313+
bool operator()(const Sequence &, const Sequence &) const;
314+
315+
protected:
316+
LineTable *m_line_table;
317+
};
318+
319319
protected:
320320
struct EntrySearchInfo {
321321
LineTable *line_table;
@@ -334,19 +334,6 @@ class LineTable {
334334
entry_collection
335335
m_entries; ///< The collection of line entries in this line table.
336336

337-
// Helper class
338-
class LineSequenceImpl : public LineSequence {
339-
public:
340-
LineSequenceImpl() = default;
341-
342-
~LineSequenceImpl() override = default;
343-
344-
void Clear() override;
345-
346-
entry_collection
347-
m_entries; ///< The collection of line entries in this sequence.
348-
};
349-
350337
bool ConvertEntryAtIndexToLineEntry(uint32_t idx, LineEntry &line_entry);
351338

352339
private:

lldb/source/Plugins/SymbolFile/Breakpad/SymbolFileBreakpad.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -837,18 +837,16 @@ void SymbolFileBreakpad::ParseLineTableAndSupportFiles(CompileUnit &cu,
837837
"How did we create compile units without a base address?");
838838

839839
SupportFileMap map;
840-
std::vector<std::unique_ptr<LineSequence>> sequences;
841-
std::unique_ptr<LineSequence> line_seq_up =
842-
LineTable::CreateLineSequenceContainer();
840+
std::vector<LineTable::Sequence> sequences;
841+
LineTable::Sequence sequence;
843842
std::optional<addr_t> next_addr;
844843
auto finish_sequence = [&]() {
845844
LineTable::AppendLineEntryToSequence(
846-
line_seq_up.get(), *next_addr, /*line=*/0, /*column=*/0,
845+
sequence, *next_addr, /*line=*/0, /*column=*/0,
847846
/*file_idx=*/0, /*is_start_of_statement=*/false,
848847
/*is_start_of_basic_block=*/false, /*is_prologue_end=*/false,
849848
/*is_epilogue_begin=*/false, /*is_terminal_entry=*/true);
850-
sequences.push_back(std::move(line_seq_up));
851-
line_seq_up = LineTable::CreateLineSequenceContainer();
849+
sequences.push_back(std::move(sequence));
852850
};
853851

854852
LineIterator It(*m_objfile_sp, Record::Func, data.bookmark),
@@ -870,7 +868,7 @@ void SymbolFileBreakpad::ParseLineTableAndSupportFiles(CompileUnit &cu,
870868
finish_sequence();
871869
}
872870
LineTable::AppendLineEntryToSequence(
873-
line_seq_up.get(), record->Address, record->LineNum, /*column=*/0,
871+
sequence, record->Address, record->LineNum, /*column=*/0,
874872
map[record->FileNum], /*is_start_of_statement=*/true,
875873
/*is_start_of_basic_block=*/false, /*is_prologue_end=*/false,
876874
/*is_epilogue_begin=*/false, /*is_terminal_entry=*/false);

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,7 @@ bool SymbolFileDWARF::ParseLineTable(CompileUnit &comp_unit) {
12321232
// FIXME: Rather than parsing the whole line table and then copying it over
12331233
// into LLDB, we should explore using a callback to populate the line table
12341234
// while we parse to reduce memory usage.
1235-
std::vector<std::unique_ptr<LineSequence>> sequences;
1235+
std::vector<LineTable::Sequence> sequences;
12361236
// The Sequences view contains only valid line sequences. Don't iterate over
12371237
// the Rows directly.
12381238
for (const llvm::DWARFDebugLine::Sequence &seq : line_table->Sequences) {
@@ -1242,12 +1242,11 @@ bool SymbolFileDWARF::ParseLineTable(CompileUnit &comp_unit) {
12421242
// m_first_code_address declaration for more details on this.
12431243
if (seq.LowPC < m_first_code_address)
12441244
continue;
1245-
std::unique_ptr<LineSequence> sequence =
1246-
LineTable::CreateLineSequenceContainer();
1245+
LineTable::Sequence sequence;
12471246
for (unsigned idx = seq.FirstRowIndex; idx < seq.LastRowIndex; ++idx) {
12481247
const llvm::DWARFDebugLine::Row &row = line_table->Rows[idx];
12491248
LineTable::AppendLineEntryToSequence(
1250-
sequence.get(), row.Address.Address, row.Line, row.Column, row.File,
1249+
sequence, row.Address.Address, row.Line, row.Column, row.File,
12511250
row.IsStmt, row.BasicBlock, row.PrologueEnd, row.EpilogueBegin,
12521251
row.EndSequence);
12531252
}

lldb/source/Plugins/SymbolFile/NativePDB/SymbolFileNativePDB.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,18 +1310,17 @@ bool SymbolFileNativePDB::ParseLineTable(CompileUnit &comp_unit) {
13101310
cii->m_global_line_table.Clear();
13111311

13121312
// Add line entries in line_set to line_table.
1313-
auto line_table = std::make_unique<LineTable>(&comp_unit);
1314-
std::unique_ptr<LineSequence> sequence(
1315-
line_table->CreateLineSequenceContainer());
1313+
std::vector<LineTable::Sequence> sequence(1);
13161314
for (const auto &line_entry : line_set) {
1317-
line_table->AppendLineEntryToSequence(
1318-
sequence.get(), line_entry.file_addr, line_entry.line,
1315+
LineTable::AppendLineEntryToSequence(
1316+
sequence.back(), line_entry.file_addr, line_entry.line,
13191317
line_entry.column, line_entry.file_idx,
13201318
line_entry.is_start_of_statement, line_entry.is_start_of_basic_block,
13211319
line_entry.is_prologue_end, line_entry.is_epilogue_begin,
13221320
line_entry.is_terminal_entry);
13231321
}
1324-
line_table->InsertSequence(sequence.get());
1322+
auto line_table =
1323+
std::make_unique<LineTable>(&comp_unit, std::move(sequence));
13251324

13261325
if (line_table->GetSize() == 0)
13271326
return false;

lldb/source/Plugins/SymbolFile/PDB/SymbolFilePDB.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,11 +1761,10 @@ bool SymbolFilePDB::ParseCompileUnitLineTable(CompileUnit &comp_unit,
17611761
if (!files)
17621762
return false;
17631763

1764-
// For each source and header file, create a LineSequence for contributions
1765-
// to the compiland from that file, and add the sequence.
1764+
// For each source and header file, create a LineTable::Sequence for
1765+
// contributions to the compiland from that file, and add the sequence.
17661766
while (auto file = files->getNext()) {
1767-
std::unique_ptr<LineSequence> sequence(
1768-
line_table->CreateLineSequenceContainer());
1767+
LineTable::Sequence sequence;
17691768
auto lines = m_session_up->findLineNumbers(*compiland_up, *file);
17701769
if (!lines)
17711770
continue;
@@ -1794,12 +1793,11 @@ bool SymbolFilePDB::ParseCompileUnitLineTable(CompileUnit &comp_unit,
17941793
// of the previous entry's address range if the current entry resulted in
17951794
// a gap from the previous entry.
17961795
if (is_gap && ShouldAddLine(match_line, prev_line, prev_length)) {
1797-
line_table->AppendLineEntryToSequence(
1798-
sequence.get(), prev_addr + prev_length, prev_line, 0,
1799-
prev_source_idx, false, false, false, false, true);
1796+
line_table->AppendLineEntryToSequence(sequence, prev_addr + prev_length,
1797+
prev_line, 0, prev_source_idx,
1798+
false, false, false, false, true);
18001799

1801-
line_table->InsertSequence(sequence.get());
1802-
sequence = line_table->CreateLineSequenceContainer();
1800+
line_table->InsertSequence(std::move(sequence));
18031801
}
18041802

18051803
if (ShouldAddLine(match_line, lno, length)) {
@@ -1818,7 +1816,7 @@ bool SymbolFilePDB::ParseCompileUnitLineTable(CompileUnit &comp_unit,
18181816
is_epilogue = (addr == epilogue->getVirtualAddress());
18191817
}
18201818

1821-
line_table->AppendLineEntryToSequence(sequence.get(), addr, lno, col,
1819+
line_table->AppendLineEntryToSequence(sequence, addr, lno, col,
18221820
source_idx, is_statement, false,
18231821
is_prologue, is_epilogue, false);
18241822
}
@@ -1831,12 +1829,12 @@ bool SymbolFilePDB::ParseCompileUnitLineTable(CompileUnit &comp_unit,
18311829

18321830
if (entry_count > 0 && ShouldAddLine(match_line, prev_line, prev_length)) {
18331831
// The end is always a terminal entry, so insert it regardless.
1834-
line_table->AppendLineEntryToSequence(
1835-
sequence.get(), prev_addr + prev_length, prev_line, 0,
1836-
prev_source_idx, false, false, false, false, true);
1832+
line_table->AppendLineEntryToSequence(sequence, prev_addr + prev_length,
1833+
prev_line, 0, prev_source_idx,
1834+
false, false, false, false, true);
18371835
}
18381836

1839-
line_table->InsertSequence(sequence.get());
1837+
line_table->InsertSequence(std::move(sequence));
18401838
}
18411839

18421840
if (line_table->GetSize()) {

0 commit comments

Comments
 (0)