Title: [126228] trunk/Source/_javascript_Core
Revision
126228
Author
[email protected]
Date
2012-08-21 17:11:20 -0700 (Tue, 21 Aug 2012)

Log Message

Introducing the VMInspector for VM debugging use.
https://bugs.webkit.org/show_bug.cgi?id=94613.

Patch by Mark Lam <[email protected]> on 2012-08-21
Reviewed by Filip Pizlo.

Adding some utility functions for debugging the VM. This code is
presently #ifdef'd out by default.

* CMakeLists.txt:
* GNUmakefile.list.am:
* _javascript_Core.vcproj/_javascript_Core/_javascript_Core.vcproj:
* _javascript_Core.xcodeproj/project.pbxproj:
* interpreter/CallFrame.h:
(ExecState):
* interpreter/VMInspector.cpp: Added.
(JSC):
(JSC::VMInspector::getTypeName):
(JSC::VMInspector::dumpFrame0):
(JSC::VMInspector::dumpFrame):
(JSC::VMInspector::countFrames):
* interpreter/VMInspector.h: Added.
(JSC):
(VMInspector):

Modified Paths

Added Paths

Diff

Modified: trunk/Source/_javascript_Core/CMakeLists.txt (126227 => 126228)


--- trunk/Source/_javascript_Core/CMakeLists.txt	2012-08-22 00:07:56 UTC (rev 126227)
+++ trunk/Source/_javascript_Core/CMakeLists.txt	2012-08-22 00:11:20 UTC (rev 126228)
@@ -130,6 +130,7 @@
     interpreter/CallFrame.cpp
     interpreter/Interpreter.cpp
     interpreter/RegisterFile.cpp
+    interpreter/VMInspector.cpp
 
     jit/ExecutableAllocator.cpp
     jit/HostCallReturnValue.cpp

Modified: trunk/Source/_javascript_Core/ChangeLog (126227 => 126228)


--- trunk/Source/_javascript_Core/ChangeLog	2012-08-22 00:07:56 UTC (rev 126227)
+++ trunk/Source/_javascript_Core/ChangeLog	2012-08-22 00:11:20 UTC (rev 126228)
@@ -1,3 +1,29 @@
+2012-08-21  Mark Lam  <[email protected]>
+
+        Introducing the VMInspector for VM debugging use.
+        https://bugs.webkit.org/show_bug.cgi?id=94613.
+
+        Reviewed by Filip Pizlo.
+
+        Adding some utility functions for debugging the VM. This code is
+        presently #ifdef'd out by default.
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * _javascript_Core.vcproj/_javascript_Core/_javascript_Core.vcproj:
+        * _javascript_Core.xcodeproj/project.pbxproj:
+        * interpreter/CallFrame.h:
+        (ExecState):
+        * interpreter/VMInspector.cpp: Added.
+        (JSC):
+        (JSC::VMInspector::getTypeName):
+        (JSC::VMInspector::dumpFrame0):
+        (JSC::VMInspector::dumpFrame):
+        (JSC::VMInspector::countFrames):
+        * interpreter/VMInspector.h: Added.
+        (JSC):
+        (VMInspector):
+
 2012-08-21  Filip Pizlo  <[email protected]>
 
         A patchable GetById right after a watchpoint should have the appropriate nop padding

Modified: trunk/Source/_javascript_Core/GNUmakefile.list.am (126227 => 126228)


--- trunk/Source/_javascript_Core/GNUmakefile.list.am	2012-08-22 00:07:56 UTC (rev 126227)
+++ trunk/Source/_javascript_Core/GNUmakefile.list.am	2012-08-22 00:11:20 UTC (rev 126228)
@@ -362,6 +362,8 @@
 	Source/_javascript_Core/interpreter/RegisterFile.cpp \
 	Source/_javascript_Core/interpreter/RegisterFile.h \
 	Source/_javascript_Core/interpreter/Register.h \
+	Source/_javascript_Core/interpreter/VMInspector.cpp \
+	Source/_javascript_Core/interpreter/VMInspector.h \
 	Source/_javascript_Core/_javascript_CorePrefix.h \
 	Source/_javascript_Core/jit/CompactJITCodeMap.h \
 	Source/_javascript_Core/jit/ExecutableAllocator.cpp \

Modified: trunk/Source/_javascript_Core/_javascript_Core.vcproj/_javascript_Core/_javascript_Core.vcproj (126227 => 126228)


--- trunk/Source/_javascript_Core/_javascript_Core.vcproj/_javascript_Core/_javascript_Core.vcproj	2012-08-22 00:07:56 UTC (rev 126227)
+++ trunk/Source/_javascript_Core/_javascript_Core.vcproj/_javascript_Core/_javascript_Core.vcproj	2012-08-22 00:11:20 UTC (rev 126228)
@@ -2045,6 +2045,14 @@
 				RelativePath="..\..\interpreter\RegisterFile.h"
 				>
 			</File>
+			<File
+				RelativePath="..\..\interpreter\VMInspector.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\..\interpreter\VMInspector.h"
+				>
+			</File>
 		</Filter>
 		<Filter
 			Name="bytecompiler"

Modified: trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj (126227 => 126228)


--- trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2012-08-22 00:07:56 UTC (rev 126227)
+++ trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2012-08-22 00:11:20 UTC (rev 126228)
@@ -712,6 +712,8 @@
 		E49DC16B12EF293E00184A1F /* SourceProviderCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E49DC15512EF277200184A1F /* SourceProviderCache.cpp */; };
 		E49DC16C12EF294E00184A1F /* SourceProviderCache.h in Headers */ = {isa = PBXBuildFile; fileRef = E49DC15112EF272200184A1F /* SourceProviderCache.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		E49DC16D12EF295300184A1F /* SourceProviderCacheItem.h in Headers */ = {isa = PBXBuildFile; fileRef = E49DC14912EF261A00184A1F /* SourceProviderCacheItem.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		FE4A331F15BD2E07006F54F3 /* VMInspector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FE4A331D15BD2E07006F54F3 /* VMInspector.cpp */; };
+		FE4A332015BD2E07006F54F3 /* VMInspector.h in Headers */ = {isa = PBXBuildFile; fileRef = FE4A331E15BD2E07006F54F3 /* VMInspector.h */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
@@ -1503,6 +1505,8 @@
 		F692A8850255597D01FF60F7 /* UString.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UString.cpp; sourceTree = "<group>"; tabWidth = 8; };
 		F692A8860255597D01FF60F7 /* UString.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = UString.h; sourceTree = "<group>"; tabWidth = 8; };
 		F692A8870255597D01FF60F7 /* JSValue.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSValue.cpp; sourceTree = "<group>"; tabWidth = 8; };
+		FE4A331D15BD2E07006F54F3 /* VMInspector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = VMInspector.cpp; sourceTree = "<group>"; };
+		FE4A331E15BD2E07006F54F3 /* VMInspector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VMInspector.h; sourceTree = "<group>"; };
 		FEB63AA2159B9DA3008932A6 /* Comment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Comment.h; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
@@ -1705,6 +1709,8 @@
 		1429D77A0ED20D7300B89619 /* interpreter */ = {
 			isa = PBXGroup;
 			children = (
+				FE4A331D15BD2E07006F54F3 /* VMInspector.cpp */,
+				FE4A331E15BD2E07006F54F3 /* VMInspector.h */,
 				0F55F0F114D1063600AC7649 /* AbstractPC.cpp */,
 				0F55F0F214D1063600AC7649 /* AbstractPC.h */,
 				A7F8690E0F9584A100558697 /* CachedCall.h */,
@@ -2875,6 +2881,7 @@
 				0F766D3915AE4A1F008F363E /* StructureStubClearingWatchpoint.h in Headers */,
 				0F766D4415B2A3C0008F363E /* DFGRegisterSet.h in Headers */,
 				0F766D4615B3701F008F363E /* DFGScratchRegisterAllocator.h in Headers */,
+				FE4A332015BD2E07006F54F3 /* VMInspector.h in Headers */,
 				0F63943F15C75F19006A597C /* DFGStructureCheckHoistingPhase.h in Headers */,
 				0F63945515D07057006A597C /* ArrayProfile.h in Headers */,
 				0F63947815DCE34B006A597C /* DFGStructureAbstractValue.h in Headers */,
@@ -3475,6 +3482,7 @@
 				0F766D2F15A8DCE0008F363E /* GCAwareJITStubRoutine.cpp in Sources */,
 				0F766D3415AE2538008F363E /* JumpReplacementWatchpoint.cpp in Sources */,
 				0F766D3815AE4A1C008F363E /* StructureStubClearingWatchpoint.cpp in Sources */,
+				FE4A331F15BD2E07006F54F3 /* VMInspector.cpp in Sources */,
 				0F63944015C75F1D006A597C /* DFGStructureCheckHoistingPhase.cpp in Sources */,
 				0F63945415D07055006A597C /* ArrayProfile.cpp in Sources */,
 			);

Modified: trunk/Source/_javascript_Core/interpreter/CallFrame.h (126227 => 126228)


--- trunk/Source/_javascript_Core/interpreter/CallFrame.h	2012-08-22 00:07:56 UTC (rev 126227)
+++ trunk/Source/_javascript_Core/interpreter/CallFrame.h	2012-08-22 00:11:20 UTC (rev 126228)
@@ -272,6 +272,8 @@
 #endif
         ExecState();
         ~ExecState();
+
+        friend class VMInspector;
     };
 
 } // namespace JSC

Added: trunk/Source/_javascript_Core/interpreter/VMInspector.cpp (0 => 126228)


--- trunk/Source/_javascript_Core/interpreter/VMInspector.cpp	                        (rev 0)
+++ trunk/Source/_javascript_Core/interpreter/VMInspector.cpp	2012-08-22 00:11:20 UTC (rev 126228)
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2012 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. ``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
+ * 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 "VMInspector.h"
+
+#if ENABLE(VMINSPECTOR)
+
+namespace JSC {
+
+const char* VMInspector::getTypeName(JSValue value)
+{
+    if (value.isInt32())
+        return "<Int32>";
+    if (value.isBoolean())
+        return "<Boolean>";
+    if (value.isNull())
+        return "<Empty>";
+    if (value.isUndefined())
+        return "<Undefined>";
+    if (value.isCell())
+        return "<Cell>";
+    if (value.isEmpty())
+        return "<Empty>";
+    return "";
+}
+
+void VMInspector::dumpFrame0(CallFrame* frame)
+{
+    dumpFrame(frame, 0, 0, 0, 0);
+}
+
+void VMInspector::dumpFrame(CallFrame* frame, const char* prefix,
+                            const char* funcName, const char* file, int line)
+{
+    int frameCount = VMInspector::countFrames(frame);
+    if (frameCount < 0)
+        return;
+
+    Instruction* vPC = 0;
+    if (frame->codeBlock())
+        vPC = frame->currentVPC();
+
+    #define CAST reinterpret_cast
+
+    if (prefix)
+        printf("%s ", prefix);
+
+    printf("frame [%d] %p { cb %p:%s, retPC %p:%s, scope %p:%s, callee %p:%s, callerFrame %p:%s, argc %d, vPC %p }",
+           frameCount, frame,
+
+           CAST<void*>(frame[RegisterFile::CodeBlock].payload()),
+           getTypeName(frame[RegisterFile::CodeBlock].jsValue()),
+
+           CAST<void*>(frame[RegisterFile::ReturnPC].payload()),
+           getTypeName(frame[RegisterFile::ReturnPC].jsValue()),
+
+           CAST<void*>(frame[RegisterFile::ScopeChain].payload()),
+           getTypeName(frame[RegisterFile::ScopeChain].jsValue()),
+
+           CAST<void*>(frame[RegisterFile::Callee].payload()),
+           getTypeName(frame[RegisterFile::Callee].jsValue()),
+
+           CAST<void*>(frame[RegisterFile::CallerFrame].payload()),
+           getTypeName(frame[RegisterFile::CallerFrame].jsValue()),
+
+           frame[RegisterFile::ArgumentCount].payload(),
+           vPC);
+
+    if (funcName || file || (line >= 0)) {
+        printf(" @");
+        if (funcName)
+            printf(" %s", funcName);
+        if (file)
+            printf(" %s", file);
+        if (line >= 0)
+            printf(":%d", line);
+    }
+    printf("\n");
+}
+
+int VMInspector::countFrames(CallFrame* frame)
+{
+    int count = -1;
+    while (frame && !frame->hasHostCallFrameFlag()) {
+        count++;
+        frame = frame->callerFrame();
+    }
+    return count;
+}
+
+} // namespace JSC
+
+#endif // ENABLE(VMINSPECTOR)

Added: trunk/Source/_javascript_Core/interpreter/VMInspector.h (0 => 126228)


--- trunk/Source/_javascript_Core/interpreter/VMInspector.h	                        (rev 0)
+++ trunk/Source/_javascript_Core/interpreter/VMInspector.h	2012-08-22 00:11:20 UTC (rev 126228)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2012 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. ``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
+ * 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 VMInspector_h
+#define VMInspector_h
+
+#define ENABLE_VMINSPECTOR 0
+
+#if ENABLE(VMINSPECTOR)
+
+#include "CallFrame.h"
+#include "JSValue.h"
+
+namespace JSC {
+
+class VMInspector {
+public:    
+    static JS_EXPORT_PRIVATE const char* getTypeName(JSValue);
+    static JS_EXPORT_PRIVATE void dumpFrame0(CallFrame*);
+    static JS_EXPORT_PRIVATE void dumpFrame(CallFrame*, const char* prefix = 0, const char* funcName = 0, const char* file = 0, int line = -1);
+    static JS_EXPORT_PRIVATE int countFrames(CallFrame*);
+};
+
+} // namespace JSC
+
+#endif // ENABLE(VMINSPECTOR)
+
+#endif // VMInspector.h
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to