• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "Timer.h"
33 #include <debugger/Debugger.h>
34 #include <wtf/HashMap.h>
35 #include <wtf/HashSet.h>
36 #include <wtf/RefPtr.h>
37 
38 namespace JSC {
39     class DebuggerCallFrame;
40 }
41 
42 namespace WebCore {
43 
44     class Frame;
45     class FrameView;
46     class Page;
47     class PageGroup;
48     class JavaScriptCallFrame;
49     class JavaScriptDebugListener;
50 
51     class JavaScriptDebugServer : JSC::Debugger {
52     public:
53         static JavaScriptDebugServer& shared();
54 
55         void addListener(JavaScriptDebugListener*);
56         void removeListener(JavaScriptDebugListener*);
57 
58         void addListener(JavaScriptDebugListener*, Page*);
59         void removeListener(JavaScriptDebugListener*, Page*);
60 
61         void addBreakpoint(intptr_t sourceID, unsigned lineNumber);
62         void removeBreakpoint(intptr_t sourceID, unsigned lineNumber);
63         bool hasBreakpoint(intptr_t sourceID, unsigned lineNumber) const;
64         void clearBreakpoints();
65 
pauseOnExceptions()66         bool pauseOnExceptions() const { return m_pauseOnExceptions; }
67         void setPauseOnExceptions(bool);
68 
69         void pauseProgram();
70         void continueProgram();
71         void stepIntoStatement();
72         void stepOverStatement();
73         void stepOutOfFunction();
74 
75         void recompileAllJSFunctionsSoon();
76         void recompileAllJSFunctions(Timer<JavaScriptDebugServer>* = 0);
77 
78         JavaScriptCallFrame* currentCallFrame();
79 
80         void pageCreated(Page*);
81 
82         typedef HashSet<JavaScriptDebugListener*> ListenerSet;
83         typedef void (JavaScriptDebugListener::*JavaScriptExecutionCallback)();
84 
85     private:
86         JavaScriptDebugServer();
87         ~JavaScriptDebugServer();
88 
hasListeners()89         bool hasListeners() const { return !m_listeners.isEmpty() || !m_pageListenersMap.isEmpty(); }
hasGlobalListeners()90         bool hasGlobalListeners() const { return !m_listeners.isEmpty(); }
91         bool hasListenersInterestedInPage(Page*);
92 
93         void setJavaScriptPaused(const PageGroup&, bool paused);
94         void setJavaScriptPaused(Page*, bool paused);
95         void setJavaScriptPaused(Frame*, bool paused);
96         void setJavaScriptPaused(FrameView*, bool paused);
97 
98         void dispatchFunctionToListeners(JavaScriptExecutionCallback, Page*);
99         void pauseIfNeeded(Page*);
100 
101         virtual void sourceParsed(JSC::ExecState*, const JSC::SourceCode&, int errorLine, const JSC::UString& errorMsg);
102         virtual void callEvent(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber);
103         virtual void atStatement(const JSC::DebuggerCallFrame&, intptr_t sourceID, int firstLine);
104         virtual void returnEvent(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber);
105         virtual void exception(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineNumber);
106         virtual void willExecuteProgram(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineno);
107         virtual void didExecuteProgram(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineno);
108         virtual void didReachBreakpoint(const JSC::DebuggerCallFrame&, intptr_t sourceID, int lineno);
109 
110         void didAddListener(Page*);
111         void didRemoveListener(Page*);
112         void didRemoveLastListener();
113 
114         typedef HashMap<Page*, ListenerSet*> PageListenersMap;
115         PageListenersMap m_pageListenersMap;
116         ListenerSet m_listeners;
117         bool m_callingListeners;
118         bool m_pauseOnExceptions;
119         bool m_pauseOnNextStatement;
120         bool m_paused;
121         bool m_doneProcessingDebuggerEvents;
122         JavaScriptCallFrame* m_pauseOnCallFrame;
123         RefPtr<JavaScriptCallFrame> m_currentCallFrame;
124         HashMap<intptr_t, HashSet<unsigned>*> m_breakpoints;
125         Timer<JavaScriptDebugServer> m_recompileTimer;
126     };
127 
128 } // namespace WebCore
129 
130 #endif // JavaScriptDebugServer_h
131