Merge mozilla-central and tracemonkey. (a=blockers)
[mozilla-central.git] / js / src / jsdbgapi.h
blob992e16664490c166e55c569db416ece763764754
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 * vim: set ts=8 sw=4 et tw=99:
4 * ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License Version
8 * 1.1 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14 * for the specific language governing rights and limitations under the
15 * License.
17 * The Original Code is Mozilla Communicator client code, released
18 * March 31, 1998.
20 * The Initial Developer of the Original Code is
21 * Netscape Communications Corporation.
22 * Portions created by the Initial Developer are Copyright (C) 1998
23 * the Initial Developer. All Rights Reserved.
25 * Contributor(s):
27 * Alternatively, the contents of this file may be used under the terms of
28 * either of the GNU General Public License Version 2 or later (the "GPL"),
29 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
39 * ***** END LICENSE BLOCK ***** */
41 #ifndef jsdbgapi_h___
42 #define jsdbgapi_h___
44 * JS debugger API.
46 #include "jsapi.h"
47 #include "jsopcode.h"
48 #include "jsprvtd.h"
50 JS_BEGIN_EXTERN_C
53 * Currently, we only support runtime-wide debugging. In the future, we should
54 * be able to support compartment-wide debugging.
56 extern JS_PUBLIC_API(void)
57 JS_SetRuntimeDebugMode(JSRuntime *rt, JSBool debug);
60 * Debug mode is a compartment-wide mode that enables a debugger to attach
61 * to and interact with running methodjit-ed frames. In particular, it causes
62 * every function to be compiled as if an eval was present (so eval-in-frame)
63 * can work, and it ensures that functions can be re-JITed for other debug
64 * features. In general, it is not safe to interact with frames that were live
65 * before debug mode was enabled. For this reason, it is also not safe to
66 * enable debug mode while frames are live.
69 /* Get current state of debugging mode. */
70 extern JS_PUBLIC_API(JSBool)
71 JS_GetDebugMode(JSContext *cx);
74 * Turn on/off debugging mode for a single compartment. This must be
75 * called from the main thread and the compartment must be associated
76 * with the main thread.
78 JS_FRIEND_API(JSBool)
79 JS_SetDebugModeForCompartment(JSContext *cx, JSCompartment *comp, JSBool debug);
82 * Turn on/off debugging mode for a context's compartment.
84 JS_FRIEND_API(JSBool)
85 JS_SetDebugMode(JSContext *cx, JSBool debug);
87 /* Turn on single step mode. Requires debug mode. */
88 extern JS_FRIEND_API(JSBool)
89 js_SetSingleStepMode(JSContext *cx, JSScript *script, JSBool singleStep);
91 /* Turn on single step mode. */
92 extern JS_PUBLIC_API(JSBool)
93 JS_SetSingleStepMode(JSContext *cx, JSScript *script, JSBool singleStep);
96 * Unexported library-private helper used to unpatch all traps in a script.
97 * Returns script->code if script has no traps, else a JS_malloc'ed copy of
98 * script->code which the caller must JS_free, or null on JS_malloc OOM.
100 extern jsbytecode *
101 js_UntrapScriptCode(JSContext *cx, JSScript *script);
103 /* The closure argument will be marked. */
104 extern JS_PUBLIC_API(JSBool)
105 JS_SetTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
106 JSTrapHandler handler, jsval closure);
108 extern JS_PUBLIC_API(JSOp)
109 JS_GetTrapOpcode(JSContext *cx, JSScript *script, jsbytecode *pc);
111 extern JS_PUBLIC_API(void)
112 JS_ClearTrap(JSContext *cx, JSScript *script, jsbytecode *pc,
113 JSTrapHandler *handlerp, jsval *closurep);
115 extern JS_PUBLIC_API(void)
116 JS_ClearScriptTraps(JSContext *cx, JSScript *script);
118 extern JS_PUBLIC_API(void)
119 JS_ClearAllTraps(JSContext *cx);
121 extern JS_PUBLIC_API(JSTrapStatus)
122 JS_HandleTrap(JSContext *cx, JSScript *script, jsbytecode *pc, jsval *rval);
124 extern JS_PUBLIC_API(JSBool)
125 JS_SetInterrupt(JSRuntime *rt, JSInterruptHook handler, void *closure);
127 extern JS_PUBLIC_API(JSBool)
128 JS_ClearInterrupt(JSRuntime *rt, JSInterruptHook *handlerp, void **closurep);
130 /************************************************************************/
132 extern JS_PUBLIC_API(JSBool)
133 JS_SetWatchPoint(JSContext *cx, JSObject *obj, jsid id,
134 JSWatchPointHandler handler, JSObject *closure);
136 extern JS_PUBLIC_API(JSBool)
137 JS_ClearWatchPoint(JSContext *cx, JSObject *obj, jsid id,
138 JSWatchPointHandler *handlerp, JSObject **closurep);
140 extern JS_PUBLIC_API(JSBool)
141 JS_ClearWatchPointsForObject(JSContext *cx, JSObject *obj);
143 extern JS_PUBLIC_API(JSBool)
144 JS_ClearAllWatchPoints(JSContext *cx);
146 #ifdef JS_HAS_OBJ_WATCHPOINT
148 * Hide these non-API function prototypes by testing whether the internal
149 * header file "jsversion.h" has been included.
151 extern void
152 js_TraceWatchPoints(JSTracer *trc, JSObject *obj);
154 extern void
155 js_SweepWatchPoints(JSContext *cx);
157 #ifdef __cplusplus
159 extern JSBool
160 js_watch_set(JSContext *cx, JSObject *obj, jsid id, JSBool strict, js::Value *vp);
162 namespace js {
164 bool
165 IsWatchedProperty(JSContext *cx, const Shape *shape);
169 #endif
171 #endif /* JS_HAS_OBJ_WATCHPOINT */
173 /************************************************************************/
175 extern JS_PUBLIC_API(uintN)
176 JS_PCToLineNumber(JSContext *cx, JSScript *script, jsbytecode *pc);
178 extern JS_PUBLIC_API(jsbytecode *)
179 JS_LineNumberToPC(JSContext *cx, JSScript *script, uintN lineno);
181 extern JS_PUBLIC_API(jsbytecode *)
182 JS_EndPC(JSContext *cx, JSScript *script);
184 extern JS_PUBLIC_API(uintN)
185 JS_GetFunctionArgumentCount(JSContext *cx, JSFunction *fun);
187 extern JS_PUBLIC_API(JSBool)
188 JS_FunctionHasLocalNames(JSContext *cx, JSFunction *fun);
191 * N.B. The mark is in the context temp pool and thus the caller must take care
192 * to call JS_ReleaseFunctionLocalNameArray in a LIFO manner (wrt to any other
193 * call that may use the temp pool.
195 extern JS_PUBLIC_API(jsuword *)
196 JS_GetFunctionLocalNameArray(JSContext *cx, JSFunction *fun, void **markp);
198 extern JS_PUBLIC_API(JSAtom *)
199 JS_LocalNameToAtom(jsuword w);
201 extern JS_PUBLIC_API(JSString *)
202 JS_AtomKey(JSAtom *atom);
204 extern JS_PUBLIC_API(void)
205 JS_ReleaseFunctionLocalNameArray(JSContext *cx, void *mark);
207 extern JS_PUBLIC_API(JSScript *)
208 JS_GetFunctionScript(JSContext *cx, JSFunction *fun);
210 extern JS_PUBLIC_API(JSNative)
211 JS_GetFunctionNative(JSContext *cx, JSFunction *fun);
213 extern JS_PUBLIC_API(JSPrincipals *)
214 JS_GetScriptPrincipals(JSContext *cx, JSScript *script);
217 * Stack Frame Iterator
219 * Used to iterate through the JS stack frames to extract
220 * information from the frames.
223 extern JS_PUBLIC_API(JSStackFrame *)
224 JS_FrameIterator(JSContext *cx, JSStackFrame **iteratorp);
226 extern JS_PUBLIC_API(JSScript *)
227 JS_GetFrameScript(JSContext *cx, JSStackFrame *fp);
229 extern JS_PUBLIC_API(jsbytecode *)
230 JS_GetFramePC(JSContext *cx, JSStackFrame *fp);
233 * Get the closest scripted frame below fp. If fp is null, start from cx->fp.
235 extern JS_PUBLIC_API(JSStackFrame *)
236 JS_GetScriptedCaller(JSContext *cx, JSStackFrame *fp);
239 * Return a weak reference to fp's principals. A null return does not denote
240 * an error, it means there are no principals.
242 extern JSPrincipals *
243 js_StackFramePrincipals(JSContext *cx, JSStackFrame *fp);
245 JSPrincipals *
246 js_EvalFramePrincipals(JSContext *cx, JSObject *callee, JSStackFrame *caller);
248 extern JS_PUBLIC_API(void *)
249 JS_GetFrameAnnotation(JSContext *cx, JSStackFrame *fp);
251 extern JS_PUBLIC_API(void)
252 JS_SetFrameAnnotation(JSContext *cx, JSStackFrame *fp, void *annotation);
254 extern JS_PUBLIC_API(void *)
255 JS_GetFramePrincipalArray(JSContext *cx, JSStackFrame *fp);
257 extern JS_PUBLIC_API(JSBool)
258 JS_IsScriptFrame(JSContext *cx, JSStackFrame *fp);
260 /* this is deprecated, use JS_GetFrameScopeChain instead */
261 extern JS_PUBLIC_API(JSObject *)
262 JS_GetFrameObject(JSContext *cx, JSStackFrame *fp);
264 extern JS_PUBLIC_API(JSObject *)
265 JS_GetFrameScopeChain(JSContext *cx, JSStackFrame *fp);
267 extern JS_PUBLIC_API(JSObject *)
268 JS_GetFrameCallObject(JSContext *cx, JSStackFrame *fp);
270 extern JS_PUBLIC_API(JSBool)
271 JS_GetFrameThis(JSContext *cx, JSStackFrame *fp, jsval *thisv);
273 extern JS_PUBLIC_API(JSFunction *)
274 JS_GetFrameFunction(JSContext *cx, JSStackFrame *fp);
276 extern JS_PUBLIC_API(JSObject *)
277 JS_GetFrameFunctionObject(JSContext *cx, JSStackFrame *fp);
279 /* XXXrginda Initially published with typo */
280 #define JS_IsContructorFrame JS_IsConstructorFrame
281 extern JS_PUBLIC_API(JSBool)
282 JS_IsConstructorFrame(JSContext *cx, JSStackFrame *fp);
284 extern JS_PUBLIC_API(JSBool)
285 JS_IsDebuggerFrame(JSContext *cx, JSStackFrame *fp);
287 extern JS_PUBLIC_API(jsval)
288 JS_GetFrameReturnValue(JSContext *cx, JSStackFrame *fp);
290 extern JS_PUBLIC_API(void)
291 JS_SetFrameReturnValue(JSContext *cx, JSStackFrame *fp, jsval rval);
294 * Return fp's callee function object (fp->callee) if it has one. Note that
295 * this API cannot fail. A null return means "no callee": fp is a global or
296 * eval-from-global frame, not a call frame.
298 * This API began life as an infallible getter, but now it can return either:
300 * 1. An optimized closure that was compiled assuming the function could not
301 * escape and be called from sites the compiler could not see.
303 * 2. A "joined function object", an optimization whereby SpiderMonkey avoids
304 * creating fresh function objects for every evaluation of a function
305 * expression that is used only once by a consumer that either promises to
306 * clone later when asked for the value or that cannot leak the value.
308 * Because Mozilla's Gecko embedding of SpiderMonkey (and no doubt other
309 * embeddings) calls this API in potentially performance-sensitive ways (e.g.
310 * in nsContentUtils::GetDocumentFromCaller), we are leaving this API alone. It
311 * may now return an unwrapped non-escaping optimized closure, or a joined
312 * function object. Such optimized objects may work well if called from the
313 * correct context, never mutated or compared for identity, etc.
315 * However, if you really need to get the same callee object that JS code would
316 * see, which means undoing the optimizations, where an undo attempt can fail,
317 * then use JS_GetValidFrameCalleeObject.
319 extern JS_PUBLIC_API(JSObject *)
320 JS_GetFrameCalleeObject(JSContext *cx, JSStackFrame *fp);
323 * Return fp's callee function object after running the deferred closure
324 * cloning "method read barrier". This API can fail! If the frame has no
325 * callee, this API returns true with JSVAL_IS_VOID(*vp).
327 extern JS_PUBLIC_API(JSBool)
328 JS_GetValidFrameCalleeObject(JSContext *cx, JSStackFrame *fp, jsval *vp);
330 /************************************************************************/
332 extern JS_PUBLIC_API(const char *)
333 JS_GetScriptFilename(JSContext *cx, JSScript *script);
335 extern JS_PUBLIC_API(uintN)
336 JS_GetScriptBaseLineNumber(JSContext *cx, JSScript *script);
338 extern JS_PUBLIC_API(uintN)
339 JS_GetScriptLineExtent(JSContext *cx, JSScript *script);
341 extern JS_PUBLIC_API(JSVersion)
342 JS_GetScriptVersion(JSContext *cx, JSScript *script);
344 /************************************************************************/
347 * Hook setters for script creation and destruction, see jsprvtd.h for the
348 * typedefs. These macros provide binary compatibility and newer, shorter
349 * synonyms.
351 #define JS_SetNewScriptHook JS_SetNewScriptHookProc
352 #define JS_SetDestroyScriptHook JS_SetDestroyScriptHookProc
354 extern JS_PUBLIC_API(void)
355 JS_SetNewScriptHook(JSRuntime *rt, JSNewScriptHook hook, void *callerdata);
357 extern JS_PUBLIC_API(void)
358 JS_SetDestroyScriptHook(JSRuntime *rt, JSDestroyScriptHook hook,
359 void *callerdata);
361 /************************************************************************/
363 extern JS_PUBLIC_API(JSBool)
364 JS_EvaluateUCInStackFrame(JSContext *cx, JSStackFrame *fp,
365 const jschar *chars, uintN length,
366 const char *filename, uintN lineno,
367 jsval *rval);
369 extern JS_PUBLIC_API(JSBool)
370 JS_EvaluateInStackFrame(JSContext *cx, JSStackFrame *fp,
371 const char *bytes, uintN length,
372 const char *filename, uintN lineno,
373 jsval *rval);
375 /************************************************************************/
377 typedef struct JSPropertyDesc {
378 jsval id; /* primary id, atomized string, or int */
379 jsval value; /* property value */
380 uint8 flags; /* flags, see below */
381 uint8 spare; /* unused */
382 uint16 slot; /* argument/variable slot */
383 jsval alias; /* alias id if JSPD_ALIAS flag */
384 } JSPropertyDesc;
386 #define JSPD_ENUMERATE 0x01 /* visible to for/in loop */
387 #define JSPD_READONLY 0x02 /* assignment is error */
388 #define JSPD_PERMANENT 0x04 /* property cannot be deleted */
389 #define JSPD_ALIAS 0x08 /* property has an alias id */
390 #define JSPD_ARGUMENT 0x10 /* argument to function */
391 #define JSPD_VARIABLE 0x20 /* local variable in function */
392 #define JSPD_EXCEPTION 0x40 /* exception occurred fetching the property, */
393 /* value is exception */
394 #define JSPD_ERROR 0x80 /* native getter returned JS_FALSE without */
395 /* throwing an exception */
397 typedef struct JSPropertyDescArray {
398 uint32 length; /* number of elements in array */
399 JSPropertyDesc *array; /* alloc'd by Get, freed by Put */
400 } JSPropertyDescArray;
402 typedef struct JSScopeProperty JSScopeProperty;
404 extern JS_PUBLIC_API(JSScopeProperty *)
405 JS_PropertyIterator(JSObject *obj, JSScopeProperty **iteratorp);
407 extern JS_PUBLIC_API(JSBool)
408 JS_GetPropertyDesc(JSContext *cx, JSObject *obj, JSScopeProperty *shape,
409 JSPropertyDesc *pd);
411 extern JS_PUBLIC_API(JSBool)
412 JS_GetPropertyDescArray(JSContext *cx, JSObject *obj, JSPropertyDescArray *pda);
414 extern JS_PUBLIC_API(void)
415 JS_PutPropertyDescArray(JSContext *cx, JSPropertyDescArray *pda);
417 /************************************************************************/
419 extern JS_PUBLIC_API(JSBool)
420 JS_SetDebuggerHandler(JSRuntime *rt, JSDebuggerHandler hook, void *closure);
422 extern JS_PUBLIC_API(JSBool)
423 JS_SetSourceHandler(JSRuntime *rt, JSSourceHandler handler, void *closure);
425 extern JS_PUBLIC_API(JSBool)
426 JS_SetExecuteHook(JSRuntime *rt, JSInterpreterHook hook, void *closure);
428 extern JS_PUBLIC_API(JSBool)
429 JS_SetCallHook(JSRuntime *rt, JSInterpreterHook hook, void *closure);
431 extern JS_PUBLIC_API(JSBool)
432 JS_SetThrowHook(JSRuntime *rt, JSThrowHook hook, void *closure);
434 extern JS_PUBLIC_API(JSBool)
435 JS_SetDebugErrorHook(JSRuntime *rt, JSDebugErrorHook hook, void *closure);
437 /************************************************************************/
439 extern JS_PUBLIC_API(size_t)
440 JS_GetObjectTotalSize(JSContext *cx, JSObject *obj);
442 extern JS_PUBLIC_API(size_t)
443 JS_GetFunctionTotalSize(JSContext *cx, JSFunction *fun);
445 extern JS_PUBLIC_API(size_t)
446 JS_GetScriptTotalSize(JSContext *cx, JSScript *script);
449 * Get the top-most running script on cx starting from fp, or from the top of
450 * cx's frame stack if fp is null, and return its script filename flags. If
451 * the script has a null filename member, return JSFILENAME_NULL.
453 extern JS_PUBLIC_API(uint32)
454 JS_GetTopScriptFilenameFlags(JSContext *cx, JSStackFrame *fp);
457 * Get the script filename flags for the script. If the script doesn't have a
458 * filename, return JSFILENAME_NULL.
460 extern JS_PUBLIC_API(uint32)
461 JS_GetScriptFilenameFlags(JSScript *script);
464 * Associate flags with a script filename prefix in rt, so that any subsequent
465 * script compilation will inherit those flags if the script's filename is the
466 * same as prefix, or if prefix is a substring of the script's filename.
468 * The API defines only one flag bit, JSFILENAME_SYSTEM, leaving the remaining
469 * 31 bits up to the API client to define. The union of all 32 bits must not
470 * be a legal combination, however, in order to preserve JSFILENAME_NULL as a
471 * unique value. API clients may depend on JSFILENAME_SYSTEM being a set bit
472 * in JSFILENAME_NULL -- a script with a null filename member is presumed to
473 * be a "system" script.
475 extern JS_PUBLIC_API(JSBool)
476 JS_FlagScriptFilenamePrefix(JSRuntime *rt, const char *prefix, uint32 flags);
478 #define JSFILENAME_NULL 0xffffffff /* null script filename */
479 #define JSFILENAME_SYSTEM 0x00000001 /* "system" script, see below */
480 #define JSFILENAME_PROTECTED 0x00000002 /* scripts need protection */
483 * Return true if obj is a "system" object, that is, one created by
484 * JS_NewSystemObject with the system flag set and not JS_NewObject.
486 * What "system" means is up to the API client, but it can be used to implement
487 * access control policies based on script filenames and their prefixes, using
488 * JS_FlagScriptFilenamePrefix and JS_GetTopScriptFilenameFlags.
490 extern JS_PUBLIC_API(JSBool)
491 JS_IsSystemObject(JSContext *cx, JSObject *obj);
494 * Mark an object as being a system object. This should be called immediately
495 * after allocating the object. A system object is an object for which
496 * JS_IsSystemObject returns true.
498 extern JS_PUBLIC_API(JSBool)
499 JS_MakeSystemObject(JSContext *cx, JSObject *obj);
501 /************************************************************************/
503 extern JS_PUBLIC_API(JSObject *)
504 JS_UnwrapObject(JSContext *cx, JSObject *obj);
506 /************************************************************************/
508 extern JS_FRIEND_API(void)
509 js_RevertVersion(JSContext *cx);
511 extern JS_PUBLIC_API(const JSDebugHooks *)
512 JS_GetGlobalDebugHooks(JSRuntime *rt);
514 extern JS_PUBLIC_API(JSDebugHooks *)
515 JS_SetContextDebugHooks(JSContext *cx, const JSDebugHooks *hooks);
517 /* Disable debug hooks for this context. */
518 extern JS_PUBLIC_API(JSDebugHooks *)
519 JS_ClearContextDebugHooks(JSContext *cx);
521 extern JS_PUBLIC_API(JSBool)
522 JS_StartProfiling();
524 extern JS_PUBLIC_API(void)
525 JS_StopProfiling();
527 extern JS_PUBLIC_API(JSBool)
528 JS_DefineProfilingFunctions(JSContext *cx, JSObject *obj);
530 #ifdef MOZ_CALLGRIND
532 extern JS_FRIEND_API(JSBool)
533 js_StopCallgrind(JSContext *cx, uintN argc, jsval *vp);
535 extern JS_FRIEND_API(JSBool)
536 js_StartCallgrind(JSContext *cx, uintN argc, jsval *vp);
538 extern JS_FRIEND_API(JSBool)
539 js_DumpCallgrind(JSContext *cx, uintN argc, jsval *vp);
541 #endif /* MOZ_CALLGRIND */
543 #ifdef MOZ_VTUNE
545 extern JS_FRIEND_API(JSBool)
546 js_StartVtune(JSContext *cx, uintN argc, jsval *vp);
548 extern JS_FRIEND_API(JSBool)
549 js_StopVtune(JSContext *cx, uintN argc, jsval *vp);
551 extern JS_FRIEND_API(JSBool)
552 js_PauseVtune(JSContext *cx, uintN argc, jsval *vp);
554 extern JS_FRIEND_API(JSBool)
555 js_ResumeVtune(JSContext *cx, uintN argc, jsval *vp);
557 #endif /* MOZ_VTUNE */
559 #ifdef MOZ_TRACEVIS
560 extern JS_FRIEND_API(JSBool)
561 js_InitEthogram(JSContext *cx, uintN argc, jsval *vp);
562 extern JS_FRIEND_API(JSBool)
563 js_ShutdownEthogram(JSContext *cx, uintN argc, jsval *vp);
564 #endif /* MOZ_TRACEVIS */
566 JS_END_EXTERN_C
568 #endif /* jsdbgapi_h___ */