unnar updated this revision to Diff 238759.
unnar marked an inline comment as done.
unnar added a comment.
Herald added a reviewer: jdoerfert.

@labath

Can you take another look and see if this matches what you had in mind?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D72909/new/

https://reviews.llvm.org/D72909

Files:
  lldb/include/lldb/Symbol/LineTable.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Symbol/LineTable.cpp

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, llvm::MutableArrayRef<LineSequence *> 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<LineSequenceImpl *>(sequence);
+    m_entries.insert(m_entries.end(), seq->m_entries.begin(),
+      seq->m_entries.end());
+  }
+}
+
 // Destructor
 LineTable::~LineTable() {}
 
@@ -130,17 +141,6 @@
   m_entries.insert(pos, seq->m_entries.begin(), seq->m_entries.end());
 }
 
-void LineTable::ReplaceLineTableWithSequences(std::vector<LineSequence*> &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<LineSequenceImpl *>(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) {}
@@ -166,9 +166,9 @@
 }
 
 bool LineTable::Entry::LessThanBinaryPredicate::
-operator()(LineSequence *sequence_a, LineSequence *sequence_b) const {
-  LineSequenceImpl *seq_a = reinterpret_cast<LineSequenceImpl *>(sequence_a);
-  LineSequenceImpl *seq_b = reinterpret_cast<LineSequenceImpl *>(sequence_b);
+operator()(const LineSequence *sequence_a, const LineSequence *sequence_b) const {
+  auto *seq_a = static_cast<const LineSequenceImpl *>(sequence_a);
+  auto *seq_b = static_cast<const LineSequenceImpl *>(sequence_b);
   return (*this)(seq_a->m_entries.front(), seq_b->m_entries.front());
 }
 
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -1015,22 +1015,23 @@
   // 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<LineTable> line_table_up =
-      std::make_unique<LineTable>(&comp_unit);
-  LineSequence *sequence = line_table_up->CreateLineSequenceContainer();
-  std::vector<LineSequence*> sequences;
+  LineSequence *sequence = LineTable::CreateLineSequenceContainer();
+  std::vector<LineSequence *> 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) {
       sequences.push_back(sequence);
-      sequence = line_table_up->CreateLineSequenceContainer();
+      sequence = LineTable::CreateLineSequenceContainer();
     }
   }
 
-  line_table_up->ReplaceLineTableWithSequences(sequences);
+  std::unique_ptr<LineTable> line_table_up =
+      std::make_unique<LineTable>(&comp_unit,
+                                  llvm::MutableArrayRef<LineSequence *>(
+                                      sequences));
 
   if (SymbolFileDWARFDebugMap *debug_map_symfile = GetDebugMapSymfile()) {
     // We have an object file that has a line table with addresses that are not
Index: lldb/include/lldb/Symbol/LineTable.h
===================================================================
--- lldb/include/lldb/Symbol/LineTable.h
+++ lldb/include/lldb/Symbol/LineTable.h
@@ -42,6 +42,13 @@
   ///     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,
+            llvm::MutableArrayRef<LineSequence *> sequences);
+
   /// Destructor.
   ~LineTable();
 
@@ -64,11 +71,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,
@@ -78,12 +85,6 @@
   // 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<LineSequence*> &sequences);
-
   /// Dump all line entries in this line table to the stream \a s.
   ///
   /// \param[in] s
@@ -265,7 +266,7 @@
     public:
       LessThanBinaryPredicate(LineTable *line_table);
       bool operator()(const LineTable::Entry &, const LineTable::Entry &) const;
-      bool operator()(LineSequence*, LineSequence*) const;
+      bool operator()(const LineSequence*, const LineSequence*) const;
 
     protected:
       LineTable *m_line_table;
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to