Introducing the VMInspector for VM debugging use.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Aug 2012 00:11:20 +0000 (00:11 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Aug 2012 00:11:20 +0000 (00:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=94613.

Patch by Mark Lam <mark.lam@apple.com> 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:
* JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
* JavaScriptCore.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):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@126228 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/CMakeLists.txt
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/GNUmakefile.list.am
Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/interpreter/CallFrame.h
Source/JavaScriptCore/interpreter/VMInspector.cpp [new file with mode: 0644]
Source/JavaScriptCore/interpreter/VMInspector.h [new file with mode: 0644]

index 317814a..9c18f5b 100644 (file)
@@ -130,6 +130,7 @@ SET(JavaScriptCore_SOURCES
     interpreter/CallFrame.cpp
     interpreter/Interpreter.cpp
     interpreter/RegisterFile.cpp
+    interpreter/VMInspector.cpp
 
     jit/ExecutableAllocator.cpp
     jit/HostCallReturnValue.cpp
index 1c2985f..ac3aae5 100644 (file)
@@ -1,3 +1,29 @@
+2012-08-21  Mark Lam  <mark.lam@apple.com>
+
+        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:
+        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
+        * JavaScriptCore.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  <fpizlo@apple.com>
 
         A patchable GetById right after a watchpoint should have the appropriate nop padding
index c504962..ed79e68 100644 (file)
@@ -362,6 +362,8 @@ javascriptcore_sources += \
        Source/JavaScriptCore/interpreter/RegisterFile.cpp \
        Source/JavaScriptCore/interpreter/RegisterFile.h \
        Source/JavaScriptCore/interpreter/Register.h \
+       Source/JavaScriptCore/interpreter/VMInspector.cpp \
+       Source/JavaScriptCore/interpreter/VMInspector.h \
        Source/JavaScriptCore/JavaScriptCorePrefix.h \
        Source/JavaScriptCore/jit/CompactJITCodeMap.h \
        Source/JavaScriptCore/jit/ExecutableAllocator.cpp \
index e91baa4..8695a75 100644 (file)
                                RelativePath="..\..\interpreter\RegisterFile.h"
                                >
                        </File>
+                       <File
+                               RelativePath="..\..\interpreter\VMInspector.cpp"
+                               >
+                       </File>
+                       <File
+                               RelativePath="..\..\interpreter\VMInspector.h"
+                               >
+                       </File>
                </Filter>
                <Filter
                        Name="bytecompiler"
index a41fb99..7dd87fe 100644 (file)
                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 */
                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 */
 
                1429D77A0ED20D7300B89619 /* interpreter */ = {
                        isa = PBXGroup;
                        children = (
+                               FE4A331D15BD2E07006F54F3 /* VMInspector.cpp */,
+                               FE4A331E15BD2E07006F54F3 /* VMInspector.h */,
                                0F55F0F114D1063600AC7649 /* AbstractPC.cpp */,
                                0F55F0F214D1063600AC7649 /* AbstractPC.h */,
                                A7F8690E0F9584A100558697 /* CachedCall.h */,
                                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 */,
                                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 */,
                        );
index 0488bb4..ea98f66 100644 (file)
@@ -272,6 +272,8 @@ namespace JSC  {
 #endif
         ExecState();
         ~ExecState();
+
+        friend class VMInspector;
     };
 
 } // namespace JSC
diff --git a/Source/JavaScriptCore/interpreter/VMInspector.cpp b/Source/JavaScriptCore/interpreter/VMInspector.cpp
new file mode 100644 (file)
index 0000000..34bf615
--- /dev/null
@@ -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)
diff --git a/Source/JavaScriptCore/interpreter/VMInspector.h b/Source/JavaScriptCore/interpreter/VMInspector.h
new file mode 100644 (file)
index 0000000..6806caf
--- /dev/null
@@ -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