1 /* 2 * Copyright (C) 2008 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 14 * its contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29 #ifndef JavaScriptDebugServer_h 30 #define JavaScriptDebugServer_h 31 32 #if ENABLE(JAVASCRIPT_DEBUGGER) 33 34 #include "Timer.h" 35 #include <debugger/Debugger.h> 36 #include <wtf/HashMap.h> 37 #include <wtf/HashSet.h> 38 #include <wtf/RefPtr.h> 39 40 namespace JSC { 41 class DebuggerCallFrame; 42 class JSGlobalObject; 43 } 44 45 namespace WebCore { 46 47 class Frame; 48 class FrameView; 49 class Page; 50 class PageGroup; 51 class JavaScriptCallFrame; 52 class JavaScriptDebugListener; 53 54 class JavaScriptDebugServer : JSC::Debugger { 55 public: 56 static JavaScriptDebugServer& shared(); 57 58 void addListener(JavaScriptDebugListener*); 59 void removeListener(JavaScriptDebugListener*); 60 61 void addListener(JavaScriptDebugListener*, Page*); 62 void removeListener(JavaScriptDebugListener*, Page*); 63 64 void addBreakpoint(intptr_t sourceID, unsigned lineNumber); 65 void removeBreakpoint(intptr_t sourceID, unsigned lineNumber); 66 bool hasBreakpoint(intptr_t sourceID, unsigned lineNumber) const; 67 void clearBreakpoints(); 68 pauseOnExceptions()69 bool pauseOnExceptions() const { return m_pauseOnExceptions; } 70 void setPauseOnExceptions(bool); 71 72 void pauseProgram(); 73 void continueProgram(); 74 void stepIntoStatement(); 75 void stepOverStatement(); 76 void stepOutOfFunction(); 77 78 void recompileAllJSFunctionsSoon(); 79 void recompileAllJSFunctions(Timer<JavaScriptDebugServer>* = 0); 80 81 JavaScriptCallFrame* currentCallFrame(); 82 83 void pageCreated(Page*); 84 85 typedef HashSet<JavaScriptDebugListener*> ListenerSet; 86 typedef void (JavaScriptDebugListener::*JavaScriptExecutionCallback)(); 87 88 private: 89 JavaScriptDebugServer(); 90 ~JavaScriptDebugServer(); 91 hasListeners()92 bool hasListeners() const { return !m_listeners.isEmpty() || !m_pageListenersMap.isEmpty(); } hasGlobalListeners()93 bool hasGlobalListeners() const { return !m_listeners.isEmpty(); } 94 bool hasListenersInterestedInPage(Page*); 95 96 void setJavaScriptPaused(const PageGroup&, bool paused); 97 void setJavaScriptPaused(Page*, bool paused); 98 void setJavaScriptPaused(Frame*, bool paused); 99 void setJavaScriptPaused(FrameView*, bool paused); 100 101 void dispatchFunctionToListeners(JavaScriptExecutionCallback, Page*); 102 void pauseIfNeeded(Page*); 103 104 virtual void detach(JSC::JSGlobalObject*); 105 106 virtual void sourceParsed(JSC::ExecState*, const JSC::SourceCode&, int errorLine, const JSC::UString& errorMsg); 107 virtual void callEvent(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber); 108 virtual void atStatement(const JSC::DebuggerCallFrame&, intptr_t sourceID, int firstLine); 109 virtual void returnEvent(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber); 110 virtual void exception(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber); 111 virtual void willExecuteProgram(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineno); 112 virtual void didExecuteProgram(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineno); 113 virtual void didReachBreakpoint(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineno); 114 115 void didAddListener(Page*); 116 void didRemoveListener(Page*); 117 void didRemoveLastListener(); 118 119 typedef HashMap<Page*, ListenerSet*> PageListenersMap; 120 PageListenersMap m_pageListenersMap; 121 ListenerSet m_listeners; 122 bool m_callingListeners; 123 bool m_pauseOnExceptions; 124 bool m_pauseOnNextStatement; 125 bool m_paused; 126 bool m_doneProcessingDebuggerEvents; 127 JavaScriptCallFrame* m_pauseOnCallFrame; 128 RefPtr<JavaScriptCallFrame> m_currentCallFrame; 129 HashMap<intptr_t, HashSet<unsigned>*> m_breakpoints; 130 Timer<JavaScriptDebugServer> m_recompileTimer; 131 }; 132 133 } // namespace WebCore 134 135 #endif // ENABLE(JAVASCRIPT_DEBUGGER) 136 137 #endif // JavaScriptDebugServer_h 138