Add Win32 support to llvm::llvm_execute_on_thread(). Thanks to Aaron Ballman!
[oota-llvm.git] / lib / DebugInfo / DWARFDebugLine.cpp
index 9db86c33fb5b083c2599de1ebf8f9955f9b36f09..d8200a0fd6be1ba4804f8cec955a6f773faaca1f 100644 (file)
@@ -91,54 +91,20 @@ void DWARFDebugLine::LineTable::dump(raw_ostream &OS) const {
   }
 }
 
+DWARFDebugLine::State::~State() {}
+
 void DWARFDebugLine::State::appendRowToMatrix(uint32_t offset) {
   ++row;  // Increase the row number.
   LineTable::appendRow(*this);
   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);
@@ -147,6 +113,22 @@ 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;
+    // FIXME: double lookup.
+    LineTableMap[offset] = state;
+    return &LineTableMap[offset];
+  }
+  return &pos->second;
+}
+
 bool
 DWARFDebugLine::parsePrologue(DataExtractor debug_line_data,
                               uint32_t *offset_ptr, Prologue *prologue) {
@@ -218,6 +200,8 @@ DWARFDebugLine::parseStatementTable(DataExtractor debug_line_data,
   const uint32_t end_offset = debug_line_offset + prologue->TotalLength +
                               sizeof(prologue->TotalLength);
 
+  state.reset();
+
   while (*offset_ptr < end_offset) {
     uint8_t opcode = debug_line_data.getU8(offset_ptr);
 
@@ -394,7 +378,7 @@ DWARFDebugLine::parseStatementTable(DataExtractor debug_line_data,
         // of such opcodes because they are specified in the prologue
         // as a multiple of LEB128 operands for each opcode.
         {
-          assert(opcode - 1 < prologue->StandardOpcodeLengths.size());
+          assert(opcode - 1U < prologue->StandardOpcodeLengths.size());
           uint8_t opcode_length = prologue->StandardOpcodeLengths[opcode - 1];
           for (uint8_t i=0; i<opcode_length; ++i)
             debug_line_data.getULEB128(offset_ptr);