1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is mozilla.org code.
18 * The Initial Developer of the Original Code is
19 * Netscape Communications Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 1998
21 * the Initial Developer. All Rights Reserved.
24 * Robert Ginda, <rginda@netscape.com>
26 * Alternatively, the contents of this file may be used under the terms of
27 * either the GNU General Public License Version 2 or later (the "GPL"), or
28 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 * in which case the provisions of the GPL or the LGPL are applicable instead
30 * of those above. If you wish to allow use of your version of this file only
31 * under the terms of either the GPL or the LGPL, and not to allow others to
32 * use your version of this file under the terms of the MPL, indicate your
33 * decision by deleting the provisions above and replace them with the notice
34 * and other provisions required by the GPL or the LGPL. If you do not delete
35 * the provisions above, a recipient may use your version of this file under
36 * the terms of any one of the MPL, the GPL or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
40 #ifndef JSDSERVICE_H___
41 #define JSDSERVICE_H___
43 #include "jsdIDebuggerService.h"
49 // #if defined(DEBUG_rginda_l)
50 // # define DEBUG_verbose
53 struct LiveEphemeral
{
54 /* link in a chain of live values list */
64 /*******************************************************************************
65 * reflected jsd data structures
66 *******************************************************************************/
68 class jsdObject
: public jsdIObject
74 /* you'll normally use use FromPtr() instead of directly constructing one */
75 jsdObject (JSDContext
*aCx
, JSDObject
*aObject
) :
76 mCx(aCx
), mObject(aObject
)
80 static jsdIObject
*FromPtr (JSDContext
*aCx
,
86 jsdIObject
*rv
= new jsdObject (aCx
, aObject
);
92 jsdObject(); /* no implementation */
93 jsdObject(const jsdObject
&); /* no implementation */
100 class jsdProperty
: public jsdIProperty
105 NS_DECL_JSDIEPHEMERAL
107 jsdProperty (JSDContext
*aCx
, JSDProperty
*aProperty
);
108 virtual ~jsdProperty ();
110 static jsdIProperty
*FromPtr (JSDContext
*aCx
,
111 JSDProperty
*aProperty
)
116 jsdIProperty
*rv
= new jsdProperty (aCx
, aProperty
);
121 static void InvalidateAll();
124 jsdProperty(); /* no implementation */
125 jsdProperty(const jsdProperty
&); /* no implementation */
128 LiveEphemeral mLiveListEntry
;
130 JSDProperty
*mProperty
;
133 class jsdScript
: public jsdIScript
138 NS_DECL_JSDIEPHEMERAL
140 /* you'll normally use use FromPtr() instead of directly constructing one */
141 jsdScript (JSDContext
*aCx
, JSDScript
*aScript
);
142 virtual ~jsdScript();
144 static jsdIScript
*FromPtr (JSDContext
*aCx
, JSDScript
*aScript
)
149 void *data
= JSD_GetScriptPrivate (aScript
);
153 rv
= static_cast<jsdIScript
*>(data
);
155 rv
= new jsdScript (aCx
, aScript
);
156 NS_IF_ADDREF(rv
); /* addref for the SetScriptPrivate, released in
158 JSD_SetScriptPrivate (aScript
, static_cast<void *>(rv
));
161 NS_IF_ADDREF(rv
); /* addref for return value */
165 static void InvalidateAll();
168 static PRUint32 LastTag
;
170 jsdScript(); /* no implementation */
171 jsdScript (const jsdScript
&); /* no implementation */
172 PCMapEntry
* CreatePPLineMap();
173 PRUint32
PPPcToLine(PRUint32 aPC
);
174 PRUint32
PPLineToPc(PRUint32 aLine
);
180 nsCString
*mFileName
;
181 nsCString
*mFunctionName
;
182 PRUint32 mBaseLineNumber
, mLineExtent
;
183 PCMapEntry
*mPPLineMap
;
188 PRUint32
jsdScript::LastTag
= 0;
190 class jsdContext
: public jsdIContext
195 NS_DECL_JSDIEPHEMERAL
197 jsdContext (JSDContext
*aJSDCx
, JSContext
*aJSCx
, nsISupports
*aISCx
);
198 virtual ~jsdContext();
200 static void InvalidateAll();
201 static jsdIContext
*FromPtr (JSDContext
*aJSDCx
, JSContext
*aJSCx
);
203 static PRUint32 LastTag
;
205 jsdContext (); /* no implementation */
206 jsdContext (const jsdContext
&); /* no implementation */
209 LiveEphemeral mLiveListEntry
;
213 nsCOMPtr
<nsISupports
> mISCx
;
216 PRUint32
jsdContext::LastTag
= 0;
218 class jsdStackFrame
: public jsdIStackFrame
222 NS_DECL_JSDISTACKFRAME
223 NS_DECL_JSDIEPHEMERAL
225 /* you'll normally use use FromPtr() instead of directly constructing one */
226 jsdStackFrame (JSDContext
*aCx
, JSDThreadState
*aThreadState
,
227 JSDStackFrameInfo
*aStackFrameInfo
);
228 virtual ~jsdStackFrame();
230 static void InvalidateAll();
231 static jsdIStackFrame
* FromPtr (JSDContext
*aCx
,
232 JSDThreadState
*aThreadState
,
233 JSDStackFrameInfo
*aStackFrameInfo
);
236 jsdStackFrame(); /* no implementation */
237 jsdStackFrame(const jsdStackFrame
&); /* no implementation */
240 LiveEphemeral mLiveListEntry
;
242 JSDThreadState
*mThreadState
;
243 JSDStackFrameInfo
*mStackFrameInfo
;
246 class jsdValue
: public jsdIValue
251 NS_DECL_JSDIEPHEMERAL
253 /* you'll normally use use FromPtr() instead of directly constructing one */
254 jsdValue (JSDContext
*aCx
, JSDValue
*aValue
);
257 static jsdIValue
*FromPtr (JSDContext
*aCx
, JSDValue
*aValue
);
258 static void InvalidateAll();
261 jsdValue(); /* no implementation */
262 jsdValue (const jsdScript
&); /* no implementation */
265 LiveEphemeral mLiveListEntry
;
270 /******************************************************************************
272 ******************************************************************************/
274 class jsdService
: public jsdIDebuggerService
278 NS_DECL_JSDIDEBUGGERSERVICE
280 jsdService() : mInitAtStartup(triUnknown
), mOn(PR_FALSE
), mPauseLevel(0),
281 mNestedLoopLevel(0), mCx(0), mRuntime(0), mErrorHook(0),
282 mBreakpointHook(0), mDebugHook(0), mDebuggerHook(0),
283 mInterruptHook(0), mScriptHook(0), mThrowHook(0),
284 mTopLevelHook(0), mFunctionHook(0)
288 virtual ~jsdService();
290 static jsdService
*GetService ();
299 Tristate mInitAtStartup
;
301 PRUint32 mPauseLevel
;
302 PRUint32 mNestedLoopLevel
;
306 nsCOMPtr
<jsdIErrorHook
> mErrorHook
;
307 nsCOMPtr
<jsdIExecutionHook
> mBreakpointHook
;
308 nsCOMPtr
<jsdIExecutionHook
> mDebugHook
;
309 nsCOMPtr
<jsdIExecutionHook
> mDebuggerHook
;
310 nsCOMPtr
<jsdIExecutionHook
> mInterruptHook
;
311 nsCOMPtr
<jsdIScriptHook
> mScriptHook
;
312 nsCOMPtr
<jsdIExecutionHook
> mThrowHook
;
313 nsCOMPtr
<jsdICallHook
> mTopLevelHook
;
314 nsCOMPtr
<jsdICallHook
> mFunctionHook
;
318 #endif /* JSDSERVICE_H___ */
325 class jsdContext
: public jsdIContext
331 /* you'll normally use use FromPtr() instead of directly constructing one */
332 jsdContext (JSDContext
*aCx
) : mCx(aCx
)
334 printf ("++++++ jsdContext\n");
337 static jsdIContext
*FromPtr (JSDContext
*aCx
)
342 void *data
= JSD_GetContextPrivate (aCx
);
346 rv
= static_cast<jsdIContext
*>(data
);
348 rv
= new jsdContext (aCx
);
349 NS_IF_ADDREF(rv
); // addref for the SetContextPrivate
350 JSD_SetContextPrivate (aCx
, static_cast<void *>(rv
));
353 NS_IF_ADDREF(rv
); // addref for the return value
357 virtual ~jsdContext() { printf ("------ ~jsdContext\n"); }
359 jsdContext(); /* no implementation */
360 jsdContext(const jsdContext
&); /* no implementation */
365 class jsdThreadState
: public jsdIThreadState
369 NS_DECL_JSDITHREADSTATE
371 /* you'll normally use use FromPtr() instead of directly constructing one */
372 jsdThreadState (JSDContext
*aCx
, JSDThreadState
*aThreadState
) :
373 mCx(aCx
), mThreadState(aThreadState
)
377 /* XXX These things are only valid for a short period of time, they reflect
378 * state in the js engine that will go away after stepping past wherever
379 * we were stopped at when this was created. We could keep a list of every
380 * instance of this we've created, and "invalidate" them before we let the
381 * engine continue. The next time we need a threadstate, we can search the
382 * list to find an invalidated one, and just reuse it.
384 static jsdIThreadState
*FromPtr (JSDContext
*aCx
,
385 JSDThreadState
*aThreadState
)
390 jsdIThreadState
*rv
= new jsdThreadState (aCx
, aThreadState
);
396 jsdThreadState(); /* no implementation */
397 jsdThreadState(const jsdThreadState
&); /* no implementation */
400 JSDThreadState
*mThreadState
;