diff options
Diffstat (limited to 'Source/JavaScriptCore/debugger')
-rw-r--r-- | Source/JavaScriptCore/debugger/Debugger.cpp | 119 | ||||
-rw-r--r-- | Source/JavaScriptCore/debugger/Debugger.h | 65 | ||||
-rw-r--r-- | Source/JavaScriptCore/debugger/DebuggerActivation.cpp | 104 | ||||
-rw-r--r-- | Source/JavaScriptCore/debugger/DebuggerActivation.h | 66 | ||||
-rw-r--r-- | Source/JavaScriptCore/debugger/DebuggerCallFrame.cpp | 106 | ||||
-rw-r--r-- | Source/JavaScriptCore/debugger/DebuggerCallFrame.h | 67 |
6 files changed, 527 insertions, 0 deletions
diff --git a/Source/JavaScriptCore/debugger/Debugger.cpp b/Source/JavaScriptCore/debugger/Debugger.cpp new file mode 100644 index 0000000..6b24c5a --- /dev/null +++ b/Source/JavaScriptCore/debugger/Debugger.cpp @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) + * Copyright (C) 2001 Peter Kelly (pmk@post.com) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#include "config.h" +#include "Debugger.h" + +#include "CollectorHeapIterator.h" +#include "Error.h" +#include "Interpreter.h" +#include "JSFunction.h" +#include "JSGlobalObject.h" +#include "Parser.h" +#include "Protect.h" + +namespace JSC { + +Debugger::~Debugger() +{ + HashSet<JSGlobalObject*>::iterator end = m_globalObjects.end(); + for (HashSet<JSGlobalObject*>::iterator it = m_globalObjects.begin(); it != end; ++it) + (*it)->setDebugger(0); +} + +void Debugger::attach(JSGlobalObject* globalObject) +{ + ASSERT(!globalObject->debugger()); + globalObject->setDebugger(this); + m_globalObjects.add(globalObject); +} + +void Debugger::detach(JSGlobalObject* globalObject) +{ + ASSERT(m_globalObjects.contains(globalObject)); + m_globalObjects.remove(globalObject); + globalObject->setDebugger(0); +} + +void Debugger::recompileAllJSFunctions(JSGlobalData* globalData) +{ + // If JavaScript is running, it's not safe to recompile, since we'll end + // up throwing away code that is live on the stack. + ASSERT(!globalData->dynamicGlobalObject); + if (globalData->dynamicGlobalObject) + return; + + typedef HashSet<FunctionExecutable*> FunctionExecutableSet; + typedef HashMap<SourceProvider*, ExecState*> SourceProviderMap; + + FunctionExecutableSet functionExecutables; + SourceProviderMap sourceProviders; + + LiveObjectIterator it = globalData->heap.primaryHeapBegin(); + LiveObjectIterator heapEnd = globalData->heap.primaryHeapEnd(); + for ( ; it != heapEnd; ++it) { + if (!(*it)->inherits(&JSFunction::info)) + continue; + + JSFunction* function = asFunction(*it); + if (function->executable()->isHostFunction()) + continue; + + FunctionExecutable* executable = function->jsExecutable(); + + // Check if the function is already in the set - if so, + // we've already retranslated it, nothing to do here. + if (!functionExecutables.add(executable).second) + continue; + + ExecState* exec = function->scope().globalObject()->JSGlobalObject::globalExec(); + executable->discardCode(); + if (function->scope().globalObject()->debugger() == this) + sourceProviders.add(executable->source().provider(), exec); + } + + // Call sourceParsed() after reparsing all functions because it will execute + // JavaScript in the inspector. + SourceProviderMap::const_iterator end = sourceProviders.end(); + for (SourceProviderMap::const_iterator iter = sourceProviders.begin(); iter != end; ++iter) + sourceParsed(iter->second, SourceCode(iter->first), -1, UString()); +} + +JSValue evaluateInGlobalCallFrame(const UString& script, JSValue& exception, JSGlobalObject* globalObject) +{ + CallFrame* globalCallFrame = globalObject->globalExec(); + + RefPtr<EvalExecutable> eval = EvalExecutable::create(globalCallFrame, makeSource(script), false); + JSObject* error = eval->compile(globalCallFrame, globalCallFrame->scopeChain()); + if (error) + return error; + + JSGlobalData& globalData = globalObject->globalData(); + JSValue result = globalData.interpreter->execute(eval.get(), globalCallFrame, globalObject, globalCallFrame->scopeChain()); + if (globalData.exception) { + exception = globalData.exception; + globalData.exception = JSValue(); + } + ASSERT(result); + return result; +} + +} // namespace JSC diff --git a/Source/JavaScriptCore/debugger/Debugger.h b/Source/JavaScriptCore/debugger/Debugger.h new file mode 100644 index 0000000..3b9bec4 --- /dev/null +++ b/Source/JavaScriptCore/debugger/Debugger.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 1999-2001 Harri Porten (porten@kde.org) + * Copyright (C) 2001 Peter Kelly (pmk@post.com) + * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef Debugger_h +#define Debugger_h + +#include <wtf/HashSet.h> + +namespace JSC { + + class DebuggerCallFrame; + class ExecState; + class JSGlobalData; + class JSGlobalObject; + class JSValue; + class SourceCode; + class UString; + + class Debugger { + public: + virtual ~Debugger(); + + void attach(JSGlobalObject*); + virtual void detach(JSGlobalObject*); + + virtual void sourceParsed(ExecState*, const SourceCode&, int errorLineNumber, const UString& errorMessage) = 0; + virtual void exception(const DebuggerCallFrame&, intptr_t sourceID, int lineNumber, bool hasHandler) = 0; + virtual void atStatement(const DebuggerCallFrame&, intptr_t sourceID, int lineNumber) = 0; + virtual void callEvent(const DebuggerCallFrame&, intptr_t sourceID, int lineNumber) = 0; + virtual void returnEvent(const DebuggerCallFrame&, intptr_t sourceID, int lineNumber) = 0; + + virtual void willExecuteProgram(const DebuggerCallFrame&, intptr_t sourceID, int lineNumber) = 0; + virtual void didExecuteProgram(const DebuggerCallFrame&, intptr_t sourceID, int lineNumber) = 0; + virtual void didReachBreakpoint(const DebuggerCallFrame&, intptr_t sourceID, int lineNumber) = 0; + + void recompileAllJSFunctions(JSGlobalData*); + + private: + HashSet<JSGlobalObject*> m_globalObjects; + }; + + // This function exists only for backwards compatibility with existing WebScriptDebugger clients. + JSValue evaluateInGlobalCallFrame(const UString&, JSValue& exception, JSGlobalObject*); + +} // namespace JSC + +#endif // Debugger_h diff --git a/Source/JavaScriptCore/debugger/DebuggerActivation.cpp b/Source/JavaScriptCore/debugger/DebuggerActivation.cpp new file mode 100644 index 0000000..0444d23 --- /dev/null +++ b/Source/JavaScriptCore/debugger/DebuggerActivation.cpp @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2008, 2009 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 "DebuggerActivation.h" + +#include "JSActivation.h" + +namespace JSC { + +DebuggerActivation::DebuggerActivation(JSObject* activation) + : JSObject(DebuggerActivation::createStructure(jsNull())) +{ + ASSERT(activation); + ASSERT(activation->isActivationObject()); + m_activation = static_cast<JSActivation*>(activation); +} + +void DebuggerActivation::markChildren(MarkStack& markStack) +{ + JSObject::markChildren(markStack); + + if (m_activation) + markStack.append(m_activation); +} + +UString DebuggerActivation::className() const +{ + return m_activation->className(); +} + +bool DebuggerActivation::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) +{ + return m_activation->getOwnPropertySlot(exec, propertyName, slot); +} + +void DebuggerActivation::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot) +{ + m_activation->put(exec, propertyName, value, slot); +} + +void DebuggerActivation::putWithAttributes(ExecState* exec, const Identifier& propertyName, JSValue value, unsigned attributes) +{ + m_activation->putWithAttributes(exec, propertyName, value, attributes); +} + +bool DebuggerActivation::deleteProperty(ExecState* exec, const Identifier& propertyName) +{ + return m_activation->deleteProperty(exec, propertyName); +} + +void DebuggerActivation::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode) +{ + m_activation->getPropertyNames(exec, propertyNames, mode); +} + +bool DebuggerActivation::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor) +{ + return m_activation->getOwnPropertyDescriptor(exec, propertyName, descriptor); +} + +void DebuggerActivation::defineGetter(ExecState* exec, const Identifier& propertyName, JSObject* getterFunction, unsigned attributes) +{ + m_activation->defineGetter(exec, propertyName, getterFunction, attributes); +} + +void DebuggerActivation::defineSetter(ExecState* exec, const Identifier& propertyName, JSObject* setterFunction, unsigned attributes) +{ + m_activation->defineSetter(exec, propertyName, setterFunction, attributes); +} + +JSValue DebuggerActivation::lookupGetter(ExecState* exec, const Identifier& propertyName) +{ + return m_activation->lookupGetter(exec, propertyName); +} + +JSValue DebuggerActivation::lookupSetter(ExecState* exec, const Identifier& propertyName) +{ + return m_activation->lookupSetter(exec, propertyName); +} + +} // namespace JSC diff --git a/Source/JavaScriptCore/debugger/DebuggerActivation.h b/Source/JavaScriptCore/debugger/DebuggerActivation.h new file mode 100644 index 0000000..3927017 --- /dev/null +++ b/Source/JavaScriptCore/debugger/DebuggerActivation.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2008, 2009 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 DebuggerActivation_h +#define DebuggerActivation_h + +#include "JSObject.h" + +namespace JSC { + + class JSActivation; + + class DebuggerActivation : public JSObject { + public: + DebuggerActivation(JSObject*); + + virtual void markChildren(MarkStack&); + virtual UString className() const; + virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&); + virtual void put(ExecState*, const Identifier& propertyName, JSValue, PutPropertySlot&); + virtual void putWithAttributes(ExecState*, const Identifier& propertyName, JSValue, unsigned attributes); + virtual bool deleteProperty(ExecState*, const Identifier& propertyName); + virtual void getOwnPropertyNames(ExecState*, PropertyNameArray&, EnumerationMode mode = ExcludeDontEnumProperties); + virtual bool getOwnPropertyDescriptor(ExecState*, const Identifier&, PropertyDescriptor&); + virtual void defineGetter(ExecState*, const Identifier& propertyName, JSObject* getterFunction, unsigned attributes); + virtual void defineSetter(ExecState*, const Identifier& propertyName, JSObject* setterFunction, unsigned attributes); + virtual JSValue lookupGetter(ExecState*, const Identifier& propertyName); + virtual JSValue lookupSetter(ExecState*, const Identifier& propertyName); + + static PassRefPtr<Structure> createStructure(JSValue prototype) + { + return Structure::create(prototype, TypeInfo(ObjectType, StructureFlags), AnonymousSlotCount); + } + + protected: + static const unsigned StructureFlags = OverridesGetOwnPropertySlot | OverridesMarkChildren | JSObject::StructureFlags; + + private: + JSActivation* m_activation; + }; + +} // namespace JSC + +#endif // DebuggerActivation_h diff --git a/Source/JavaScriptCore/debugger/DebuggerCallFrame.cpp b/Source/JavaScriptCore/debugger/DebuggerCallFrame.cpp new file mode 100644 index 0000000..ed673cb --- /dev/null +++ b/Source/JavaScriptCore/debugger/DebuggerCallFrame.cpp @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2008 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE 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 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 "DebuggerCallFrame.h" + +#include "JSFunction.h" +#include "CodeBlock.h" +#include "Interpreter.h" +#include "Parser.h" + +namespace JSC { + +const UString* DebuggerCallFrame::functionName() const +{ + if (!m_callFrame->codeBlock()) + return 0; + + if (!m_callFrame->callee()) + return 0; + + JSObject* function = m_callFrame->callee(); + if (!function || !function->inherits(&JSFunction::info)) + return 0; + return &asFunction(function)->name(m_callFrame); +} + +UString DebuggerCallFrame::calculatedFunctionName() const +{ + if (!m_callFrame->codeBlock()) + return UString(); + + JSObject* function = m_callFrame->callee(); + if (!function || !function->inherits(&JSFunction::info)) + return UString(); + + return asFunction(function)->calculatedDisplayName(m_callFrame); +} + +DebuggerCallFrame::Type DebuggerCallFrame::type() const +{ + if (m_callFrame->callee()) + return FunctionType; + + return ProgramType; +} + +JSObject* DebuggerCallFrame::thisObject() const +{ + CodeBlock* codeBlock = m_callFrame->codeBlock(); + if (!codeBlock) + return 0; + + JSValue thisValue = m_callFrame->uncheckedR(codeBlock->thisRegister()).jsValue(); + if (!thisValue.isObject()) + return 0; + + return asObject(thisValue); +} + +JSValue DebuggerCallFrame::evaluate(const UString& script, JSValue& exception) const +{ + if (!m_callFrame->codeBlock()) + return JSValue(); + + RefPtr<EvalExecutable> eval = EvalExecutable::create(m_callFrame, makeSource(script), m_callFrame->codeBlock()->isStrictMode()); + JSObject* error = eval->compile(m_callFrame, m_callFrame->scopeChain()); + if (error) + return error; + + JSGlobalData& globalData = m_callFrame->globalData(); + JSValue result = globalData.interpreter->execute(eval.get(), m_callFrame, thisObject(), m_callFrame->scopeChain()); + if (globalData.exception) { + exception = globalData.exception; + globalData.exception = JSValue(); + } + ASSERT(result); + return result; +} + +} // namespace JSC diff --git a/Source/JavaScriptCore/debugger/DebuggerCallFrame.h b/Source/JavaScriptCore/debugger/DebuggerCallFrame.h new file mode 100644 index 0000000..9d377ef --- /dev/null +++ b/Source/JavaScriptCore/debugger/DebuggerCallFrame.h @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2008 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. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE 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 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 DebuggerCallFrame_h +#define DebuggerCallFrame_h + +#include "CallFrame.h" + +namespace JSC { + + class DebuggerCallFrame { + public: + enum Type { ProgramType, FunctionType }; + + DebuggerCallFrame(CallFrame* callFrame) + : m_callFrame(callFrame) + { + } + + DebuggerCallFrame(CallFrame* callFrame, JSValue exception) + : m_callFrame(callFrame) + , m_exception(exception) + { + } + + JSGlobalObject* dynamicGlobalObject() const { return m_callFrame->dynamicGlobalObject(); } + const ScopeChainNode* scopeChain() const { return m_callFrame->scopeChain(); } + const UString* functionName() const; + UString calculatedFunctionName() const; + Type type() const; + JSObject* thisObject() const; + JSValue evaluate(const UString&, JSValue& exception) const; + JSValue exception() const { return m_exception; } + + private: + CallFrame* m_callFrame; + JSValue m_exception; + }; + +} // namespace JSC + +#endif // DebuggerCallFrame_h |