DWARF: Remove accessors that parse the whole line table section in one go, this can...
authorBenjamin Kramer <benny.kra@googlemail.com>
Thu, 15 Sep 2011 20:43:18 +0000 (20:43 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Thu, 15 Sep 2011 20:43:18 +0000 (20:43 +0000)
The address size is specified by the compile unit associated with a line table, there is no global address size.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@139835 91177308-0d34-0410-b5e6-96231b3b80d8

lib/DebugInfo/DWARFContext.cpp
lib/DebugInfo/DWARFContext.h
lib/DebugInfo/DWARFDebugLine.cpp
lib/DebugInfo/DWARFDebugLine.h

index 184a8b595c596bb11c3805a3d1b6b03e5b0e0897..36c6d98ac6dcb3f4367de7846e0e830880ccac08 100644 (file)
@@ -77,15 +77,25 @@ const DWARFDebugAranges *DWARFContext::getDebugAranges() {
   return Aranges.get();
 }
 
-const DWARFDebugLine *DWARFContext::getDebugLine() {
-  if (Line)
-    return Line.get();
-
-  DataExtractor lineData(getLineSection(), isLittleEndian(), 0);
-
-  Line.reset(new DWARFDebugLine());
-  Line->parse(lineData);
-  return Line.get();
+const DWARFDebugLine::LineTable *
+DWARFContext::getLineTableForCompileUnit(DWARFCompileUnit *cu) {
+  if (!Line)
+    Line.reset(new DWARFDebugLine());
+
+  unsigned stmtOffset =
+    cu->getCompileUnitDIE()->getAttributeValueAsUnsigned(cu, DW_AT_stmt_list,
+                                                         -1U);
+  if (stmtOffset == -1U)
+    return 0; // No line table for this compile unit.
+
+  // See if the line table is cached.
+  if (const DWARFDebugLine::LineTable *lt = Line->getLineTable(stmtOffset))
+    return lt;
+
+  // We have to parse it first.
+  DataExtractor lineData(getLineSection(), isLittleEndian(),
+                         cu->getAddressByteSize());
+  return Line->getOrParseLineTable(lineData, stmtOffset);
 }
 
 void DWARFContext::parseCompileUnits() {
index ead169ea7e0b07ca95bed362dd240bc8f7d2f4c1..687e5facfe51e4d754dfce49b39da25399428fb5 100644 (file)
@@ -59,8 +59,9 @@ public:
   /// Get a pointer to the parsed DebugAranges object.
   const DWARFDebugAranges *getDebugAranges();
 
-  /// Get a pointer to the parsed DWARFDebugLine object.
-  const DWARFDebugLine *getDebugLine();
+  /// Get a pointer to a parsed line table corresponding to a compile unit.
+  const DWARFDebugLine::LineTable *
+  getLineTableForCompileUnit(DWARFCompileUnit *cu);
 
   bool isLittleEndian() const { return IsLittleEndian; }
 
index c2fb111ebcf7ef72ec69c3814ed06d3cf03583b7..941d8813d5540ab4dd75c2443a9980cf174231a0 100644 (file)
@@ -99,50 +99,12 @@ void DWARFDebugLine::State::appendRowToMatrix(uint32_t offset) {
   Row::postAppend();
 }
 
-void DWARFDebugLine::parse(const DataExtractor debug_line_data) {
-  LineTableMap.clear();
-  uint32_t offset = 0;
-  State state;
-  while (debug_line_data.isValidOffset(offset)) {
-    const uint32_t debug_line_offset = offset;
-
-    if (parseStatementTable(debug_line_data, &offset, state)) {
-      // Make sure we don't don't loop infinitely
-      if (offset <= debug_line_offset)
-        break;
-
-      LineTableMap[debug_line_offset] = state;
-      state.reset();
-    }
-    else
-      ++offset; // Try next byte in line table
-  }
-}
-
 DWARFDebugLine::DumpingState::~DumpingState() {}
 
 void DWARFDebugLine::DumpingState::finalize(uint32_t offset) {
   LineTable::dump(OS);
 }
 
-void DWARFDebugLine::dump(const DataExtractor debug_line_data, raw_ostream &OS){
-  uint32_t offset = 0;
-  DumpingState state(OS);
-    while (debug_line_data.isValidOffset(offset)) {
-    const uint32_t debug_line_offset = offset;
-
-    if (parseStatementTable(debug_line_data, &offset, state)) {
-      // Make sure we don't don't loop infinitely
-      if (offset <= debug_line_offset)
-        break;
-
-      state.reset();
-    }
-    else
-      ++offset; // Try next byte in line table
-  }
-}
-
 const DWARFDebugLine::LineTable *
 DWARFDebugLine::getLineTable(uint32_t offset) const {
   LineTableConstIter pos = LineTableMap.find(offset);
@@ -151,6 +113,20 @@ DWARFDebugLine::getLineTable(uint32_t offset) const {
   return 0;
 }
 
+const DWARFDebugLine::LineTable *
+DWARFDebugLine::getOrParseLineTable(DataExtractor debug_line_data,
+                                    uint32_t offset) {
+  LineTableIter pos = LineTableMap.find(offset);
+  if (pos == LineTableMap.end()) {
+    // Parse and cache the line table for at this offset.
+    State state;
+    if (!parseStatementTable(debug_line_data, &offset, state))
+      return 0;
+    pos->second = state;
+  }
+  return &pos->second;
+}
+
 bool
 DWARFDebugLine::parsePrologue(DataExtractor debug_line_data,
                               uint32_t *offset_ptr, Prologue *prologue) {
index e50c4a9e74daf478a93ae31536bff08e65ddbee3..bc6a70b1112040af6bbe444594d3131f99cebbb6 100644 (file)
@@ -147,7 +147,7 @@ public:
       DoneParsingLineTable = -1
     };
 
-    State() : row(0) {}
+    State() : row(StartParsingLineTable) {}
     virtual ~State();
 
     virtual void appendRowToMatrix(uint32_t offset);
@@ -173,15 +173,9 @@ public:
   static bool parseStatementTable(DataExtractor debug_line_data,
                                   uint32_t *offset_ptr, State &state);
 
-  /// Parse all information in the debug_line_data into an internal
-  /// representation.
-  void parse(DataExtractor debug_line_data);
-  void parseIfNeeded(DataExtractor debug_line_data) {
-    if (LineTableMap.empty())
-      parse(debug_line_data);
-  }
-  static void dump(DataExtractor debug_line_data, raw_ostream &OS);
   const LineTable *getLineTable(uint32_t offset) const;
+  const LineTable *getOrParseLineTable(DataExtractor debug_line_data,
+                                       uint32_t offset);
 
 private:
   typedef std::map<uint32_t, LineTable> LineTableMapTy;