Title: [163397] trunk/Source/_javascript_Core
Revision
163397
Author
[email protected]
Date
2014-02-04 13:27:19 -0800 (Tue, 04 Feb 2014)

Log Message

JSC needs to be able to parse DWARF debug_line info
https://bugs.webkit.org/show_bug.cgi?id=127394

Reviewed by Geoffrey Garen.

If we want to encode IR maps in the DWARF debug line info metadata generated by LLVM, 
we'll need to know how to decode the .debug_line DWARF section. This patch implements 
an interpreter for the .debug_line DWARF section in accordance with the version 3 spec 
published at http://www.dwarfstd.org.

* _javascript_Core.xcodeproj/project.pbxproj:
* ftl/FTLDWARFDebugLineInfo.cpp: Added.
(JSC::FTL::DebugLineInterpreter::DebugLineInterpreter):
(JSC::FTL::read):
(JSC::FTL::DebugLineInterpreter::parseULEB128):
(JSC::FTL::DebugLineInterpreter::parseSLEB128):
(JSC::FTL::DebugLineInterpreter::run):
(JSC::FTL::DebugLineInterpreter::parsePrologue):
(JSC::FTL::DebugLineInterpreter::parseIncludeDirectories):
(JSC::FTL::DebugLineInterpreter::parseFileEntries):
(JSC::FTL::DebugLineInterpreter::parseFileEntry):
(JSC::FTL::DebugLineInterpreter::interpretStatementProgram):
(JSC::FTL::DebugLineInterpreter::interpretOpcode):
(JSC::FTL::DebugLineInterpreter::printLineInfo):
(JSC::FTL::DebugLineInterpreter::resetInterpreterState):
* ftl/FTLDWARFDebugLineInfo.h: Added.
(JSC::FTL::DebugLineInterpreter::Prologue::Prologue):
* ftl/FTLValueRange.cpp: Random build fix for !ENABLE(FTL_JIT).

Modified Paths

Added Paths

Diff

Modified: trunk/Source/_javascript_Core/CMakeLists.txt (163396 => 163397)


--- trunk/Source/_javascript_Core/CMakeLists.txt	2014-02-04 20:28:49 UTC (rev 163396)
+++ trunk/Source/_javascript_Core/CMakeLists.txt	2014-02-04 21:27:19 UTC (rev 163397)
@@ -677,6 +677,7 @@
         ftl/FTLCapabilities.cpp
         ftl/FTLCommonValues.cpp
         ftl/FTLCompile.cpp
+        ftl/FTLDWARFDebugLineInfo.cpp
         ftl/FTLExitArgument.cpp
         ftl/FTLExitArgumentForOperand.cpp
         ftl/FTLExitThunkGenerator.cpp

Modified: trunk/Source/_javascript_Core/ChangeLog (163396 => 163397)


--- trunk/Source/_javascript_Core/ChangeLog	2014-02-04 20:28:49 UTC (rev 163396)
+++ trunk/Source/_javascript_Core/ChangeLog	2014-02-04 21:27:19 UTC (rev 163397)
@@ -1,3 +1,34 @@
+2014-01-21  Mark Hahnenberg  <[email protected]>
+
+        JSC needs to be able to parse DWARF debug_line info
+        https://bugs.webkit.org/show_bug.cgi?id=127394
+
+        Reviewed by Geoffrey Garen.
+
+        If we want to encode IR maps in the DWARF debug line info metadata generated by LLVM, 
+        we'll need to know how to decode the .debug_line DWARF section. This patch implements 
+        an interpreter for the .debug_line DWARF section in accordance with the version 3 spec 
+        published at http://www.dwarfstd.org.
+
+        * _javascript_Core.xcodeproj/project.pbxproj:
+        * ftl/FTLDWARFDebugLineInfo.cpp: Added.
+        (JSC::FTL::DebugLineInterpreter::DebugLineInterpreter):
+        (JSC::FTL::read):
+        (JSC::FTL::DebugLineInterpreter::parseULEB128):
+        (JSC::FTL::DebugLineInterpreter::parseSLEB128):
+        (JSC::FTL::DebugLineInterpreter::run):
+        (JSC::FTL::DebugLineInterpreter::parsePrologue):
+        (JSC::FTL::DebugLineInterpreter::parseIncludeDirectories):
+        (JSC::FTL::DebugLineInterpreter::parseFileEntries):
+        (JSC::FTL::DebugLineInterpreter::parseFileEntry):
+        (JSC::FTL::DebugLineInterpreter::interpretStatementProgram):
+        (JSC::FTL::DebugLineInterpreter::interpretOpcode):
+        (JSC::FTL::DebugLineInterpreter::printLineInfo):
+        (JSC::FTL::DebugLineInterpreter::resetInterpreterState):
+        * ftl/FTLDWARFDebugLineInfo.h: Added.
+        (JSC::FTL::DebugLineInterpreter::Prologue::Prologue):
+        * ftl/FTLValueRange.cpp: Random build fix for !ENABLE(FTL_JIT).
+
 2014-02-04  Anders Carlsson  <[email protected]>
 
         Rename String::getCharacters to String::characters
@@ -12,6 +43,40 @@
 
 2014-02-04  Mark Hahnenberg  <[email protected]>
 
+<<<<<<< .mine
+        JSC needs to be able to parse DWARF debug_line info
+        https://bugs.webkit.org/show_bug.cgi?id=127394
+
+        Reviewed by Geoffrey Garen.
+
+        If we want to encode IR maps in the DWARF debug line info metadata generated by LLVM, 
+        we'll need to know how to decode the .debug_line DWARF section. This patch implements 
+        an interpreter for the .debug_line DWARF section in accordance with the version 3 spec 
+        published at http://www.dwarfstd.org.
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * _javascript_Core.xcodeproj/project.pbxproj:
+        * ftl/FTLDWARFDebugLineInfo.cpp: Added.
+        (JSC::FTL::DebugLineInterpreter::DebugLineInterpreter):
+        (JSC::FTL::read):
+        (JSC::FTL::DebugLineInterpreter::parseULEB128):
+        (JSC::FTL::DebugLineInterpreter::parseSLEB128):
+        (JSC::FTL::DebugLineInterpreter::run):
+        (JSC::FTL::DebugLineInterpreter::parsePrologue):
+        (JSC::FTL::DebugLineInterpreter::parseIncludeDirectories):
+        (JSC::FTL::DebugLineInterpreter::parseFileEntries):
+        (JSC::FTL::DebugLineInterpreter::parseFileEntry):
+        (JSC::FTL::DebugLineInterpreter::interpretStatementProgram):
+        (JSC::FTL::DebugLineInterpreter::interpretOpcode):
+        (JSC::FTL::DebugLineInterpreter::printLineInfo):
+        (JSC::FTL::DebugLineInterpreter::resetInterpreterState):
+        * ftl/FTLDWARFDebugLineInfo.h: Added.
+        (JSC::FTL::DebugLineInterpreter::Prologue::Prologue):
+
+2014-02-04  Mark Hahnenberg  <[email protected]>
+
+=======
         ASSERT in speculateMachineInt on 32-bit platforms
         https://bugs.webkit.org/show_bug.cgi?id=128155
 
@@ -22,6 +87,7 @@
 
 2014-02-04  Mark Hahnenberg  <[email protected]>
 
+>>>>>>> .r163396
         GC timer should always do a FullCollection
         https://bugs.webkit.org/show_bug.cgi?id=128186
 

Modified: trunk/Source/_javascript_Core/GNUmakefile.list.am (163396 => 163397)


--- trunk/Source/_javascript_Core/GNUmakefile.list.am	2014-02-04 20:28:49 UTC (rev 163396)
+++ trunk/Source/_javascript_Core/GNUmakefile.list.am	2014-02-04 21:27:19 UTC (rev 163397)
@@ -449,6 +449,8 @@
 	Source/_javascript_Core/ftl/FTLCommonValues.h \
 	Source/_javascript_Core/ftl/FTLCompile.cpp \
 	Source/_javascript_Core/ftl/FTLCompile.h \
+	Source/_javascript_Core/ftl/FTLDWARFDebugLineInfo.cpp \
+	Source/_javascript_Core/ftl/FTLDWARFDebugLineInfo.h \
 	Source/_javascript_Core/ftl/FTLExitArgument.cpp \
 	Source/_javascript_Core/ftl/FTLExitArgumentForOperand.cpp \
 	Source/_javascript_Core/ftl/FTLExitArgumentForOperand.h \

Modified: trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj (163396 => 163397)


--- trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2014-02-04 20:28:49 UTC (rev 163396)
+++ trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2014-02-04 21:27:19 UTC (rev 163397)
@@ -747,6 +747,8 @@
 		2A6F462617E959CE00C45C98 /* HeapOperation.h in Headers */ = {isa = PBXBuildFile; fileRef = 2A6F462517E959CE00C45C98 /* HeapOperation.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		2A7A58EF1808A4C40020BDF7 /* DeferGC.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2A7A58EE1808A4C40020BDF7 /* DeferGC.cpp */; };
 		2AAD964A18569417001F93BE /* RecursiveAllocationScope.h in Headers */ = {isa = PBXBuildFile; fileRef = 2AAD964918569417001F93BE /* RecursiveAllocationScope.h */; };
+		2AC922BB18A16182003CE0FB /* FTLDWARFDebugLineInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2AC922B918A16182003CE0FB /* FTLDWARFDebugLineInfo.cpp */; };
+		2AC922BC18A16182003CE0FB /* FTLDWARFDebugLineInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 2AC922BA18A16182003CE0FB /* FTLDWARFDebugLineInfo.h */; };
 		2ACCF3DE185FE26B0083E2AD /* DFGStoreBarrierElisionPhase.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2ACCF3DC185FE26B0083E2AD /* DFGStoreBarrierElisionPhase.cpp */; };
 		2ACCF3DF185FE26B0083E2AD /* DFGStoreBarrierElisionPhase.h in Headers */ = {isa = PBXBuildFile; fileRef = 2ACCF3DD185FE26B0083E2AD /* DFGStoreBarrierElisionPhase.h */; };
 		2AD8932B17E3868F00668276 /* HeapIterationScope.h in Headers */ = {isa = PBXBuildFile; fileRef = 2AD8932917E3868F00668276 /* HeapIterationScope.h */; };
@@ -2131,6 +2133,8 @@
 		2A6F462517E959CE00C45C98 /* HeapOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HeapOperation.h; sourceTree = "<group>"; };
 		2A7A58EE1808A4C40020BDF7 /* DeferGC.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DeferGC.cpp; sourceTree = "<group>"; };
 		2AAD964918569417001F93BE /* RecursiveAllocationScope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RecursiveAllocationScope.h; sourceTree = "<group>"; };
+		2AC922B918A16182003CE0FB /* FTLDWARFDebugLineInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = FTLDWARFDebugLineInfo.cpp; path = ftl/FTLDWARFDebugLineInfo.cpp; sourceTree = "<group>"; };
+		2AC922BA18A16182003CE0FB /* FTLDWARFDebugLineInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FTLDWARFDebugLineInfo.h; path = ftl/FTLDWARFDebugLineInfo.h; sourceTree = "<group>"; };
 		2ACCF3DC185FE26B0083E2AD /* DFGStoreBarrierElisionPhase.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DFGStoreBarrierElisionPhase.cpp; path = dfg/DFGStoreBarrierElisionPhase.cpp; sourceTree = "<group>"; };
 		2ACCF3DD185FE26B0083E2AD /* DFGStoreBarrierElisionPhase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DFGStoreBarrierElisionPhase.h; path = dfg/DFGStoreBarrierElisionPhase.h; sourceTree = "<group>"; };
 		2AD8932917E3868F00668276 /* HeapIterationScope.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HeapIterationScope.h; sourceTree = "<group>"; };
@@ -3048,6 +3052,8 @@
 		0FEA09FC1705137F00BB722C /* ftl */ = {
 			isa = PBXGroup;
 			children = (
+				2AC922B918A16182003CE0FB /* FTLDWARFDebugLineInfo.cpp */,
+				2AC922BA18A16182003CE0FB /* FTLDWARFDebugLineInfo.h */,
 				0FDB2CC7173DA51E007B3C1B /* FTLAbbreviatedTypes.h */,
 				0FEA09FD170513DB00BB722C /* FTLAbbreviations.h */,
 				0FEA0A171708B00700BB722C /* FTLAbstractHeap.cpp */,
@@ -5267,6 +5273,7 @@
 				0FB7F39D15ED8E4600F167B2 /* Reject.h in Headers */,
 				0F24E55117EE274900ABB217 /* Repatch.h in Headers */,
 				86D3B3C410159D7F002865E7 /* RepatchBuffer.h in Headers */,
+				2AC922BC18A16182003CE0FB /* FTLDWARFDebugLineInfo.h in Headers */,
 				A513E5B8185B8BD3007E95AD /* InjectedScript.h in Headers */,
 				869EBCB70E8C6D4A008722CC /* ResultType.h in Headers */,
 				C22B31B9140577D700DB475A /* SamplingCounter.h in Headers */,
@@ -6034,6 +6041,7 @@
 				0F24E55517F0B71C00ABB217 /* InlineCallFrameSet.cpp in Sources */,
 				A78853F917972629001440E4 /* IntendedStructureChain.cpp in Sources */,
 				147F39CF107EC37600427A48 /* InternalFunction.cpp in Sources */,
+				2AC922BB18A16182003CE0FB /* FTLDWARFDebugLineInfo.cpp in Sources */,
 				2ACCF3DE185FE26B0083E2AD /* DFGStoreBarrierElisionPhase.cpp in Sources */,
 				1429D7D40ED2128200B89619 /* Interpreter.cpp in Sources */,
 				1429D92F0ED22D7000B89619 /* JIT.cpp in Sources */,

Added: trunk/Source/_javascript_Core/ftl/FTLDWARFDebugLineInfo.cpp (0 => 163397)


--- trunk/Source/_javascript_Core/ftl/FTLDWARFDebugLineInfo.cpp	                        (rev 0)
+++ trunk/Source/_javascript_Core/ftl/FTLDWARFDebugLineInfo.cpp	2014-02-04 21:27:19 UTC (rev 163397)
@@ -0,0 +1,332 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "FTLDWARFDebugLineInfo.h"
+
+#include <wtf/DataLog.h>
+
+namespace JSC { namespace FTL {
+
+DebugLineInterpreter::DebugLineInterpreter(const char* program)
+    : m_program(program)
+    , m_logResults(false)
+{
+    resetInterpreterState();
+}
+
+template <typename T> inline T read(const char*& program)
+{
+    T result = *reinterpret_cast<const T*>(program);
+    program += sizeof(T);
+    return result;
+}
+
+uint32_t DebugLineInterpreter::parseULEB128(const char*& offset)
+{
+    uint32_t result = 0;
+    uint8_t byte;
+    unsigned shiftAmount = 0;
+    do {
+        byte = read<uint8_t>(offset);
+        result |= (byte & ~0x80) << shiftAmount;
+        shiftAmount += 7;
+    } while (byte & 0x80);
+    return result;
+}
+
+int32_t DebugLineInterpreter::parseSLEB128(const char*& offset)
+{
+    int32_t result = 0;
+    uint8_t byte;
+    unsigned shiftAmount = 0;
+    do {
+        byte = read<uint8_t>(offset);
+        result |= (byte & ~0x80) << shiftAmount;
+        shiftAmount += 7;
+    } while (byte & 0x80);
+    
+    // If the sign bit (in this case, the second MSB) on the last byte is set we need to zero extend.
+    if (byte & 0x40)
+        result |= -(1 << shiftAmount);
+    return result;
+}
+
+void DebugLineInterpreter::run()
+{
+    parsePrologue();
+    interpretStatementProgram();
+    if (m_logResults)
+        printLineInfo();
+}
+
+void DebugLineInterpreter::parsePrologue()
+{
+    const char* currentProgramOffset = m_program;
+    m_prologue.totalLength = read<uint32_t>(currentProgramOffset);
+    if (m_prologue.totalLength == 0xffffffff) {
+        // This is 64-bit DWARF format.
+        m_prologue.format = SixtyFourBit;
+        m_prologue.totalLength = read<uint64_t>(currentProgramOffset);
+    } else
+        m_prologue.format = ThirtyTwoBit;
+    m_prologue.version = read<uint16_t>(currentProgramOffset);
+    
+    if (m_prologue.format == ThirtyTwoBit)
+        m_prologue.prologueLength = read<uint32_t>(currentProgramOffset);
+    else
+        m_prologue.prologueLength = read<uint64_t>(currentProgramOffset);
+    const char* afterLengthOffset = currentProgramOffset;
+    
+    m_prologue.minimumInstructionLength = read<uint8_t>(currentProgramOffset);
+    m_prologue.defaultIsStatement = read<uint8_t>(currentProgramOffset);
+    m_prologue.lineBase = read<int8_t>(currentProgramOffset);
+    m_prologue.lineRange = read<uint8_t>(currentProgramOffset);
+    m_prologue.opcodeBase = read<uint8_t>(currentProgramOffset);
+    for (unsigned i = 1; i < m_prologue.opcodeBase; ++i)
+        m_prologue.standardOpcodeLengths.append(read<uint8_t>(currentProgramOffset));
+    parseIncludeDirectories(currentProgramOffset);
+    parseFileEntries(currentProgramOffset);
+    
+    m_program = afterLengthOffset + m_prologue.prologueLength;
+
+    if (!m_logResults)
+        return;
+
+    dataLog("\nPrologue:\n");
+    dataLog("totalLength = ", m_prologue.totalLength, "\n");
+    dataLog("version = ", m_prologue.version, "\n");
+    dataLog("prologueLength = ", m_prologue.prologueLength, "\n");
+    dataLog("minimumInstructionLength = ", m_prologue.minimumInstructionLength, "\n");
+    dataLog("defaultIsStatement = ", m_prologue.defaultIsStatement, "\n");
+    dataLog("lineBase = ", m_prologue.lineBase, "\n");
+    dataLog("lineRange = ", m_prologue.lineRange, "\n");
+    dataLog("opcodeBase = ", m_prologue.opcodeBase, "\n");
+    
+    dataLog("\nStandard Opcode Lengths:\n");
+    for (unsigned i = 1; i < m_prologue.opcodeBase; ++i)
+        dataLog("standardOpcodeLengths[", i - 1, "] = ", m_prologue.standardOpcodeLengths[i - 1], "\n");
+    
+    dataLog("\nInclude Directories:\n");
+    for (unsigned i = 0; i < m_prologue.includeDirectories.size(); ++i)
+        dataLog("includeDirectories[", i, "] = ", m_prologue.includeDirectories[i], "\n");
+    
+    dataLog("\nFiles:\n");
+    for (unsigned i = 0; i < m_prologue.fileEntries.size(); ++i) {
+        FileEntry& entry = m_prologue.fileEntries[i];
+        dataLog("fileEntries[", i, "] = {name: \"", entry.name, "\", dir_index: ", entry.directoryIndex, ", last_modified: ", entry.lastModified, ", size: ", entry.size, "}\n");
+    }
+}
+
+void DebugLineInterpreter::parseIncludeDirectories(const char*& offset)
+{
+    size_t length = 0;
+    while ((length = strlen(offset))) {
+        m_prologue.includeDirectories.append(offset);
+        offset += length + 1;
+    }
+    
+    // Extra increment to get past the last null byte.
+    offset += 1;
+}
+
+void DebugLineInterpreter::parseFileEntries(const char*& offset)
+{
+    while (true) {
+        DebugLineInterpreter::FileEntry nextEntry;
+        if (!parseFileEntry(offset, nextEntry))
+            break;
+        m_prologue.fileEntries.append(nextEntry);
+    }
+}
+
+bool DebugLineInterpreter::parseFileEntry(const char*& offset, FileEntry& entry)
+{
+    size_t length = strlen(offset);
+    if (!length) {
+        offset += 1;
+        return false;
+    }
+    entry.name = offset;
+    offset += length + 1;
+    entry.directoryIndex = parseULEB128(offset);
+    entry.lastModified = parseULEB128(offset);
+    entry.size = parseULEB128(offset);
+    
+    return true;
+}
+
+void DebugLineInterpreter::interpretStatementProgram()
+{
+    const char* currentProgramOffset = m_program;
+    bool keepGoing = true;
+    do {
+        keepGoing = interpretOpcode(currentProgramOffset);
+    } while (keepGoing);
+}
+
+bool DebugLineInterpreter::interpretOpcode(const char*& offset)
+{
+    uint8_t nextOpcode = read<uint8_t>(offset);
+    switch (nextOpcode) {
+    case ExtendedOpcodes: {
+        uint32_t length = parseULEB128(offset);
+        if (!length)
+            return false;
+        uint8_t extendedOpcode = read<uint8_t>(offset);
+        switch (extendedOpcode) {
+        case DW_LNE_end_sequence: {
+            m_currentState.endSequence = true;
+            m_lineInfoMatrix.append(m_currentState);
+            resetInterpreterState();
+            break;
+        }
+        case DW_LNE_set_address: {
+            m_currentState.address = read<size_t>(offset);
+            break;
+        }
+        case DW_LNE_define_file: {
+            fprintf(stderr, "Unimplemented extended opcode DW_LNE_define_file.\n");
+            RELEASE_ASSERT_NOT_REACHED();
+            break;
+        }
+        default: {
+            fprintf(stderr, "Unknown extended opcode.\n");
+            RELEASE_ASSERT_NOT_REACHED();
+            break;
+        }
+        }
+        break;
+    }
+        /* Standard opcodes */
+    case DW_LNS_copy: {
+        m_lineInfoMatrix.append(m_currentState);
+        m_currentState.isBasicBlock = false;
+        m_currentState.prologueEnd = false;
+        m_currentState.epilogueBegin = false;
+        break;
+    }
+    case DW_LNS_advance_pc: {
+        uint32_t advance = parseULEB128(offset);
+        m_currentState.address += advance * m_prologue.minimumInstructionLength;
+        break;
+    }
+    case DW_LNS_advance_line: {
+        int32_t advance = parseSLEB128(offset);
+        m_currentState.line += advance;
+        break;
+    }
+    case DW_LNS_set_file: {
+        uint32_t fileIndex = parseULEB128(offset);
+        m_currentState.file = fileIndex;
+        break;
+    }
+    case DW_LNS_set_column: {
+        m_currentState.column = parseULEB128(offset);
+        break;
+    }
+    case DW_LNS_negate_stmt: {
+        m_currentState.isStatement = !m_currentState.isStatement;
+        break;
+    }
+    case DW_LNS_set_basic_block: {
+        m_currentState.isBasicBlock = true;
+        break;
+    }
+    case DW_LNS_const_add_pc: {
+        uint8_t adjustedOpcode = nextOpcode - m_prologue.opcodeBase;
+        uint32_t addressIncrement = (adjustedOpcode / m_prologue.lineRange) * m_prologue.minimumInstructionLength;
+        m_currentState.address += addressIncrement;
+        break;
+    }
+    case DW_LNS_fixed_advance_pc: {
+        uint16_t advance = read<uint16_t>(offset);
+        m_currentState.address += advance;
+        break;
+    }
+    case DW_LNS_set_prologue_end: {
+        m_currentState.prologueEnd = true;
+        break;
+    }
+    case DW_LNS_set_epilogue_begin: {
+        m_currentState.epilogueBegin = true;
+        break;
+    }
+    case DW_LNS_set_isa: {
+        m_currentState.isa = parseULEB128(offset);
+        break;
+    }
+        /* Special opcodes */
+    default: {
+        uint8_t adjustedOpcode = nextOpcode - m_prologue.opcodeBase;
+        uint32_t addressIncrement = (adjustedOpcode / m_prologue.lineRange) * m_prologue.minimumInstructionLength;
+        int32_t lineIncrement = m_prologue.lineBase + (adjustedOpcode % m_prologue.lineRange);
+        m_currentState.address += addressIncrement;
+        m_currentState.line += lineIncrement;
+        m_lineInfoMatrix.append(m_currentState);
+        m_currentState.isBasicBlock = false;
+        m_currentState.prologueEnd = false;
+        m_currentState.epilogueBegin = false;
+        break;
+    }
+    }
+    return true;
+}
+
+void DebugLineInterpreter::printLineInfo()
+{
+    dataLog("\nLine Info Matrix:\n");
+    for (unsigned i = 0; i < m_lineInfoMatrix.size(); ++i)
+        printLineInfo(m_lineInfoMatrix[i]);
+    dataLog("\n");
+}
+
+void DebugLineInterpreter::printLineInfo(LineInfo& info)
+{
+    dataLogF("address: %p", reinterpret_cast<void*>(info.address));
+    dataLog("  file: ", info.file, "  line: ", info.line, "  column: ", info.column, "  isa: ", info.isa, "  ");
+    dataLog("  statement?: ", info.isStatement);
+    dataLog("  basic block?: ", info.isBasicBlock);
+    dataLog("  end sequence?: ", info.endSequence);
+    dataLog("  prologue end?: ", info.prologueEnd);
+    dataLog("  epilogue begin?: ", info.epilogueBegin);
+    dataLog("\n");
+}
+
+void DebugLineInterpreter::resetInterpreterState()
+{
+    m_currentState.address = 0;
+    m_currentState.file = 1;
+    m_currentState.line = 1;
+    m_currentState.column = 0;
+    m_currentState.isa = 0;
+    m_currentState.isStatement = false;
+    m_currentState.isBasicBlock = false;
+    m_currentState.endSequence = false;
+    m_currentState.prologueEnd = false;
+    m_currentState.epilogueBegin = false;
+}
+
+} } // namespace JSC::FTL

Added: trunk/Source/_javascript_Core/ftl/FTLDWARFDebugLineInfo.h (0 => 163397)


--- trunk/Source/_javascript_Core/ftl/FTLDWARFDebugLineInfo.h	                        (rev 0)
+++ trunk/Source/_javascript_Core/ftl/FTLDWARFDebugLineInfo.h	2014-02-04 21:27:19 UTC (rev 163397)
@@ -0,0 +1,138 @@
+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef FTLDWARFDebugLineInfo_h
+#define FTLDWARFDebugLineInfo_h
+
+#include <wtf/Vector.h>
+#include <wtf/text/WTFString.h>
+
+namespace JSC { namespace FTL {
+
+class DebugLineInterpreter {
+public:
+    DebugLineInterpreter(const char* program);
+
+    void run();
+
+private:
+    struct FileEntry {
+        String name;
+        uint32_t directoryIndex;
+        uint32_t lastModified;
+        uint32_t size;
+    };
+
+    void resetInterpreterState();
+    void interpretStatementProgram();
+    bool interpretOpcode(const char*&);
+    void parsePrologue();
+    void parseIncludeDirectories(const char*&);
+    void parseFileEntries(const char*&);
+    bool parseFileEntry(const char*&, DebugLineInterpreter::FileEntry&);
+    uint32_t parseULEB128(const char*&);
+    int32_t parseSLEB128(const char*&);
+
+    const char* m_program;
+    bool m_logResults;
+
+    struct LineInfo {
+        size_t address;
+        uint32_t file;
+        uint32_t line;
+        uint32_t column;
+        uint32_t isa;
+        bool isStatement;
+        bool isBasicBlock;
+        bool endSequence;
+        bool prologueEnd;
+        bool epilogueBegin;
+    };
+    
+    void printLineInfo(LineInfo&);
+    void printLineInfo();
+
+    LineInfo m_currentState;
+    Vector<LineInfo> m_lineInfoMatrix;
+
+    enum DwarfFormat {
+        SixtyFourBit,
+        ThirtyTwoBit
+    };
+
+    struct Prologue {
+        Prologue()
+            : totalLength(0)
+            , format(ThirtyTwoBit)
+            , version(0)
+            , prologueLength(0)
+            , minimumInstructionLength(0)
+            , defaultIsStatement(0)
+            , lineBase(0)
+            , lineRange(0)
+            , opcodeBase(0)
+        {
+        }
+
+        uint32_t totalLength;
+        DwarfFormat format;
+        uint16_t version;
+        size_t prologueLength;
+        uint8_t minimumInstructionLength;
+        uint8_t defaultIsStatement;
+        int8_t lineBase;
+        uint8_t lineRange;
+        uint8_t opcodeBase;
+        Vector<uint8_t> standardOpcodeLengths;
+        Vector<String> includeDirectories;
+        Vector<FileEntry> fileEntries;
+    } m_prologue;
+
+    enum ExtendedOpcode {
+        DW_LNE_end_sequence = 0x1,
+        DW_LNE_set_address  = 0x2,
+        DW_LNE_define_file  = 0x3
+    };
+
+    enum StandardOpcode {
+        ExtendedOpcodes             = 0x0,
+        DW_LNS_copy                 = 0x1,
+        DW_LNS_advance_pc           = 0x2,
+        DW_LNS_advance_line         = 0x3,
+        DW_LNS_set_file             = 0x4,
+        DW_LNS_set_column           = 0x5,
+        DW_LNS_negate_stmt          = 0x6,
+        DW_LNS_set_basic_block      = 0x7,
+        DW_LNS_const_add_pc         = 0x8,
+        DW_LNS_fixed_advance_pc     = 0x9,
+        DW_LNS_set_prologue_end     = 0xa,
+        DW_LNS_set_epilogue_begin   = 0xb,
+        DW_LNS_set_isa              = 0xc
+    };
+};
+
+} } // namespace JSC::FTL
+    
+#endif // FTLDWARFDebugLineInfo_h
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to