1 | // -*- c-basic-offset: 2 -*-
|
---|
2 | /*
|
---|
3 | * This file is part of the KDE libraries
|
---|
4 | * Copyright (C) 1999-2001 Harri Porten ([email protected])
|
---|
5 | * Copyright (C) 2001 Peter Kelly ([email protected])
|
---|
6 | *
|
---|
7 | * This library is free software; you can redistribute it and/or
|
---|
8 | * modify it under the terms of the GNU Lesser General Public
|
---|
9 | * License as published by the Free Software Foundation; either
|
---|
10 | * version 2 of the License, or (at your option) any later version.
|
---|
11 | *
|
---|
12 | * This library is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
15 | * Lesser General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU Lesser General Public
|
---|
18 | * License along with this library; if not, write to the Free Software
|
---|
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
20 | *
|
---|
21 | */
|
---|
22 |
|
---|
23 | #ifndef Debugger_h
|
---|
24 | #define Debugger_h
|
---|
25 |
|
---|
26 | #include <wtf/HashSet.h>
|
---|
27 | #include "protect.h"
|
---|
28 |
|
---|
29 | namespace KJS {
|
---|
30 |
|
---|
31 | class DebuggerCallFrame;
|
---|
32 | class ExecState;
|
---|
33 | class JSGlobalObject;
|
---|
34 | class JSObject;
|
---|
35 | class JSValue;
|
---|
36 | class ArgList;
|
---|
37 | class SourceProvider;
|
---|
38 | class UString;
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * @internal
|
---|
42 | *
|
---|
43 | * Provides an interface which receives notification about various
|
---|
44 | * script-execution related events such as statement execution and function
|
---|
45 | * calls.
|
---|
46 | */
|
---|
47 | class Debugger {
|
---|
48 | public:
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Creates a new debugger
|
---|
52 | */
|
---|
53 | Debugger();
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * Destroys the debugger. If the debugger is attached to any global objects,
|
---|
57 | * it is automatically detached.
|
---|
58 | */
|
---|
59 | virtual ~Debugger();
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * Attaches the debugger to specified global object. This will cause this
|
---|
63 | * object to receive notification of events during execution.
|
---|
64 | *
|
---|
65 | * If the global object is deleted, it will detach the debugger.
|
---|
66 | *
|
---|
67 | * Note: only one debugger can be attached to a global object at a time.
|
---|
68 | * Attaching another debugger to the same global object will cause the
|
---|
69 | * original debugger to be detached.
|
---|
70 | *
|
---|
71 | * @param The global object to attach to.
|
---|
72 | */
|
---|
73 | void attach(JSGlobalObject*);
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Detach the debugger from a global object.
|
---|
77 | *
|
---|
78 | * @param The global object to detach from.
|
---|
79 | */
|
---|
80 | void detach(JSGlobalObject*);
|
---|
81 |
|
---|
82 | /**
|
---|
83 | * Called to notify the debugger that some javascript source code has
|
---|
84 | * been parsed. For calls to Interpreter::evaluate(), this will be called
|
---|
85 | * with the supplied source code before any other code is parsed.
|
---|
86 | * Other situations in which this may be called include creation of a
|
---|
87 | * function using the Function() constructor, or the eval() function.
|
---|
88 | *
|
---|
89 | * The default implementation does nothing. Override this method if
|
---|
90 | * you want to process this event.
|
---|
91 | *
|
---|
92 | * @param exec The current execution state
|
---|
93 | * @param sourceId The ID of the source code (corresponds to the
|
---|
94 | * sourceId supplied in other functions such as atStatement()
|
---|
95 | * @param sourceURL Where the source code that was parsed came from
|
---|
96 | * @param source The source code that was parsed
|
---|
97 | * @param startingLineNumber The line number at which parsing started
|
---|
98 | * @param errorLine The line number at which parsing encountered an
|
---|
99 | * error, or -1 if the source code was valid and parsed successfully
|
---|
100 | * @param errorMsg The error description, or null if the source code
|
---|
101 | was valid and parsed successfully
|
---|
102 | */
|
---|
103 | virtual void sourceParsed(ExecState*, int sourceId, const UString& sourceURL,
|
---|
104 | const SourceProvider& source, int startingLineNumber, int errorLine, const UString& errorMsg) = 0;
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * Called when an exception is thrown during script execution.
|
---|
108 | *
|
---|
109 | * The default implementation does nothing. Override this method if
|
---|
110 | * you want to process this event.
|
---|
111 | *
|
---|
112 | * @param exec The current execution state
|
---|
113 | * @param sourceId The ID of the source code being executed
|
---|
114 | * @param lineno The line at which the error occurred
|
---|
115 | * @param exceptionObj The exception object
|
---|
116 | */
|
---|
117 | virtual void exception(const DebuggerCallFrame&, int sourceId, int lineno) = 0;
|
---|
118 |
|
---|
119 | /**
|
---|
120 | * Called when a line of the script is reached (before it is executed)
|
---|
121 | *
|
---|
122 | * The default implementation does nothing. Override this method if
|
---|
123 | * you want to process this event.
|
---|
124 | *
|
---|
125 | * @param exec The current execution state
|
---|
126 | * @param sourceId The ID of the source code being executed
|
---|
127 | * @param firstLine The starting line of the statement that is about to be
|
---|
128 | * executed
|
---|
129 | * @param lastLine The ending line of the statement that is about to be
|
---|
130 | * executed (usually the same as firstLine)
|
---|
131 | */
|
---|
132 | virtual void atStatement(const DebuggerCallFrame&, int sourceId, int lineno) = 0;
|
---|
133 | /**
|
---|
134 | * Called on each function call. Use together with @ref #returnEvent
|
---|
135 | * if you want to keep track of the call stack.
|
---|
136 | *
|
---|
137 | * Note: This only gets called for functions that are declared in ECMAScript
|
---|
138 | * source code or passed to eval(), not for internal KJS or
|
---|
139 | * application-supplied functions.
|
---|
140 | *
|
---|
141 | * The default implementation does nothing. Override this method if
|
---|
142 | * you want to process this event.
|
---|
143 | *
|
---|
144 | * @param exec The current execution state
|
---|
145 | * @param sourceId The ID of the source code being executed
|
---|
146 | * @param lineno The line that is about to be executed
|
---|
147 | */
|
---|
148 | virtual void callEvent(const DebuggerCallFrame&, int sourceId, int lineno) = 0;
|
---|
149 |
|
---|
150 | /**
|
---|
151 | * Called on each function exit. The function being returned from is that
|
---|
152 | * which was supplied in the last callEvent().
|
---|
153 | *
|
---|
154 | * Note: This only gets called for functions that are declared in ECMAScript
|
---|
155 | * source code or passed to eval(), not for internal KJS or
|
---|
156 | * application-supplied functions.
|
---|
157 | *
|
---|
158 | * The default implementation does nothing. Override this method if
|
---|
159 | * you want to process this event.
|
---|
160 | *
|
---|
161 | * @param exec The current execution state
|
---|
162 | * @param sourceId The ID of the source code being executed
|
---|
163 | * @param lineno The line that is about to be executed
|
---|
164 | */
|
---|
165 | virtual void returnEvent(const DebuggerCallFrame&, int sourceId, int lineno) = 0;
|
---|
166 |
|
---|
167 | virtual void willExecuteProgram(const DebuggerCallFrame&, int sourceId, int lineno) = 0;
|
---|
168 | virtual void didExecuteProgram(const DebuggerCallFrame&, int sourceId, int lineno) = 0;
|
---|
169 | virtual void didReachBreakpoint(const DebuggerCallFrame&, int sourceId, int lineno) = 0;
|
---|
170 |
|
---|
171 | private:
|
---|
172 | HashSet<JSGlobalObject*> m_globalObjects;
|
---|
173 | };
|
---|
174 |
|
---|
175 | } // namespace KJS
|
---|
176 |
|
---|
177 | #endif
|
---|