js/src/doc/Debugger/Debugger.md

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 # The Debugger Object
michael@0 2
michael@0 3 When called as a constructor, the `Debugger` object creates a new
michael@0 4 `Debugger` instance.
michael@0 5
michael@0 6 <code>new Debugger([<i>global</i>, ...])</code>
michael@0 7 : Create a debugger object, and apply its [`addDebuggee`][add] method to
michael@0 8 each of the given <i>global</i> objects to add them as the initial
michael@0 9 debuggees.
michael@0 10
michael@0 11 ## Accessor Properties of the Debugger Prototype Object
michael@0 12
michael@0 13 A `Debugger` instance inherits the following accessor properties from
michael@0 14 its prototype:
michael@0 15
michael@0 16 `enabled`
michael@0 17 : A boolean value indicating whether this `Debugger` instance's handlers,
michael@0 18 breakpoints, watchpoints, and the like are currently enabled. It is an
michael@0 19 accessor property with a getter and setter: assigning to it enables or
michael@0 20 disables this `Debugger` instance; reading it produces true if the
michael@0 21 instance is enabled, or false otherwise. This property is initially
michael@0 22 `true` in a freshly created `Debugger` instance.
michael@0 23
michael@0 24 This property gives debugger code a single point of control for
michael@0 25 disentangling itself from the debuggee, regardless of what sort of
michael@0 26 events or handlers or "points" we add to the interface.
michael@0 27
michael@0 28 `uncaughtExceptionHook`
michael@0 29 : Either `null` or a function that SpiderMonkey calls when a call to a
michael@0 30 debug event handler, breakpoint handler, watchpoint handler, or similar
michael@0 31 function throws some exception, which we refer to as
michael@0 32 <i>debugger-exception</i> here. Exceptions thrown in the debugger are
michael@0 33 not propagated to debuggee code; instead, SpiderMonkey calls this
michael@0 34 function, passing <i>debugger-exception</i> as its sole argument and
michael@0 35 the `Debugger` instance as the `this` value. This function should
michael@0 36 return a [resumption value][rv], which determines how the debuggee
michael@0 37 should continue.
michael@0 38
michael@0 39 If the uncaught exception hook itself throws an exception,
michael@0 40 <i>uncaught-hook-exception</i>, SpiderMonkey throws a new error object,
michael@0 41 <i>confess-to-debuggee-exception</i>, to the debuggee whose message
michael@0 42 blames the debugger, and includes textual descriptions of
michael@0 43 <i>uncaught-hook-exception</i> and the original
michael@0 44 <i>debugger-exception</i>.
michael@0 45
michael@0 46 If `uncaughtExceptionHook`'s value is `null`, SpiderMonkey throws an
michael@0 47 exception to the debuggee whose message blames the debugger, and
michael@0 48 includes a textual description of <i>debugger-exception</i>.
michael@0 49
michael@0 50 Assigning anything other than a callable value or `null` to this
michael@0 51 property throws a `TypeError` exception.
michael@0 52
michael@0 53 (This is not an ideal way to handle debugger bugs, but the hope here is
michael@0 54 that some sort of backstop, even if imperfect, will make life easier for
michael@0 55 debugger developers. For example, an uncaught exception hook may have
michael@0 56 access to browser-level features like the `alert` function, which this
michael@0 57 API's implementation does not, making it possible to present debugger
michael@0 58 errors to the developer in a way suited to the context.)
michael@0 59
michael@0 60
michael@0 61 ## Debugger Handler Functions
michael@0 62
michael@0 63 Each `Debugger` instance inherits accessor properties with which you can
michael@0 64 store handler functions for SpiderMonkey to call when given events occur
michael@0 65 in debuggee code.
michael@0 66
michael@0 67 When one of the events described below occurs in debuggee code, the engine
michael@0 68 pauses the debuggee and calls the corresponding debugging handler on each
michael@0 69 `Debugger` instance that is observing the debuggee. The handler functions
michael@0 70 receive the `Debugger` instance as their `this` value. Most handler
michael@0 71 functions can return a [resumption value][rv] indicating how the debuggee's
michael@0 72 execution should proceed.
michael@0 73
michael@0 74 On a new `Debugger` instance, each of these properties is initially
michael@0 75 `undefined`. Any value assigned to a debugging handler must be either a
michael@0 76 function or `undefined`; otherwise a `TypeError` is thrown.
michael@0 77
michael@0 78 Handler functions run in the same thread in which the event occurred.
michael@0 79 They run in the compartment to which they belong, not in a debuggee
michael@0 80 compartment.
michael@0 81
michael@0 82 <code>onNewScript(<i>script</i>, <i>global</i>)</code>
michael@0 83 : New code, represented by the [`Debugger.Script`][script] instance
michael@0 84 <i>script</i>, has been loaded in the scope of the debuggee global
michael@0 85 object <i>global</i>. <i>global</i> is a [`Debugger.Object`][object]
michael@0 86 instance whose referent is the global object.
michael@0 87
michael@0 88 This method's return value is ignored.
michael@0 89
michael@0 90 <code>onDebuggerStatement(<i>frame</i>)</code>
michael@0 91 : Debuggee code has executed a <i>debugger</i> statement in <i>frame</i>.
michael@0 92 This method should return a [resumption value][rv] specifying how the
michael@0 93 debuggee's execution should proceed.
michael@0 94
michael@0 95 <code>onEnterFrame(<i>frame</i>)</code>
michael@0 96 : The stack frame <i>frame</i> is about to begin executing code.
michael@0 97 (Naturally, <i>frame</i> is currently the youngest
michael@0 98 [visible frame][vf].) This method should return
michael@0 99 a [resumption value][rv] specifying how the debuggee's execution should
michael@0 100 proceed.
michael@0 101
michael@0 102 SpiderMonkey only calls `onEnterFrame` to report
michael@0 103 [visible][vf], non-`"debugger"` frames.
michael@0 104
michael@0 105 <code>onThrow(<i>frame</i>, <i>value</i>) <i>(future plan)</i></code>
michael@0 106 : The exception <i>value</i> is being thrown by <i>frame</i>, which is
michael@0 107 running debuggee code. This method should return a
michael@0 108 [resumption value][rv] specifying how the debuggee's execution should
michael@0 109 proceed. If it returns `undefined`, the exception is thrown as normal.
michael@0 110
michael@0 111 A call to the `onThrow` handler is typically followed by one or more
michael@0 112 calls to the `onExceptionUnwind` handler.
michael@0 113
michael@0 114 *(pending discussion)* If the debuggee executes
michael@0 115 `try { throw 0; } finally { f(); }` and `f()` executes without error,
michael@0 116 the `onThrow` handler is called only once. The debugger is not notified
michael@0 117 when the exception is set aside in order to execute the `finally` block,
michael@0 118 nor when it is restored after the `finally` block completes normally.
michael@0 119
michael@0 120 *(An alternative design here would be: onException(status, frame, value)
michael@0 121 where status is one of the strings "throw", "unwind", "catch",
michael@0 122 "finally", "rethrow". JS\_SaveExceptionState would trigger a "finally"
michael@0 123 event, JS\_RestoreExceptionState would trigger a "rethrow",
michael@0 124 JS\_ClearPendingException would trigger a "catch"; not sure what
michael@0 125 JS\_DropExceptionState or a return/throw from a finally block should
michael@0 126 do.)*
michael@0 127
michael@0 128 <code>onExceptionUnwind(<i>frame</i>, <i>value</i>)</code>
michael@0 129 : The exception <i>value</i> has been thrown, and has propagated to
michael@0 130 <i>frame</i>; <i>frame</i> is the youngest remaining stack frame, and is a
michael@0 131 debuggee frame. This method should return a [resumption value][rv]
michael@0 132 specifying how the debuggee's execution should proceed. If it returns
michael@0 133 `undefined`, the exception continues to propagate as normal: if control in
michael@0 134 `frame` is in a `try` block, control jumps to the corresponding `catch` or
michael@0 135 `finally` block; otherwise, <i>frame</i> is popped, and the exception
michael@0 136 propagates to <i>frame</i>'s caller.
michael@0 137
michael@0 138 When an exception's propagation causes control to enter a `finally`
michael@0 139 block, the exception is temporarily set aside. If the `finally` block
michael@0 140 finishes normally, the exception resumes propagation, and the debugger's
michael@0 141 `onExceptionUnwind` handler is called again, in the same frame. (The
michael@0 142 other possibility is for the `finally` block to exit due to a `return`,
michael@0 143 `continue`, or `break` statement, or a new exception. In those cases the
michael@0 144 old exception does not continue to propagate; it is discarded.)
michael@0 145
michael@0 146 <code>sourceHandler(<i>ASuffusionOfYellow</i>)</code>
michael@0 147 : This method is never called. If it is ever called, a contradiction has
michael@0 148 been proven, and the debugger is free to assume that everything is true.
michael@0 149
michael@0 150 <code>onError(<i>frame</i>, <i>report</i>)</code>
michael@0 151 : SpiderMonkey is about to report an error in <i>frame</i>. <i>Report</i>
michael@0 152 is an object describing the error, with the following properties:
michael@0 153
michael@0 154 `message`
michael@0 155 : The fully formatted error message.
michael@0 156
michael@0 157 `file`
michael@0 158 : If present, the source file name, URL, etc. (If this property is
michael@0 159 present, the <i>line</i> property will be too, and vice versa.)
michael@0 160
michael@0 161 `line`
michael@0 162 : If present, the source line number at which the error occurred.
michael@0 163
michael@0 164 `lineText`
michael@0 165 : If present, this is the source code of the offending line.
michael@0 166
michael@0 167 `offset`
michael@0 168 : The index of the character within lineText at which the error occurred.
michael@0 169
michael@0 170 `warning`
michael@0 171 : Present and true if this is a warning; absent otherwise.
michael@0 172
michael@0 173 `strict`
michael@0 174 : Present and true if this error or warning is due to the strict option
michael@0 175 (not to be confused with ES strict mode)
michael@0 176
michael@0 177 `exception`
michael@0 178 : Present and true if an exception will be thrown; absent otherwise.
michael@0 179
michael@0 180 `arguments`
michael@0 181 : An array of strings, representing the arguments substituted into the
michael@0 182 error message.
michael@0 183
michael@0 184 This method's return value is ignored.
michael@0 185
michael@0 186 `onNewGlobalObject(global)`
michael@0 187 : A new global object, <i>global</i>, has been created. The application
michael@0 188 embedding the JavaScript implementation may provide details about what
michael@0 189 kind of global it is via <code><i>global</i>.hostAnnotations</code>.
michael@0 190
michael@0 191 This handler method should return a [resumption value][rv] specifying how
michael@0 192 the debuggee's execution should proceed. However, note that a <code>{ return:
michael@0 193 <i>value</i> }</code> resumption value is treated like `undefined` ("continue
michael@0 194 normally"); <i>value</i> is ignored. (Allowing the handler to substitute
michael@0 195 its own value for the new global object doesn't seem useful.)
michael@0 196
michael@0 197 This handler method is only available to debuggers running in privileged
michael@0 198 code ("chrome", in Firefox). Most functions provided by this `Debugger`
michael@0 199 API observe activity in only those globals that are reachable by the
michael@0 200 API's user, thus imposing capability-based restrictions on a
michael@0 201 `Debugger`'s reach. However, the `onNewGlobalObject` method allows the
michael@0 202 API user to monitor all global object creation that occurs anywhere
michael@0 203 within the JavaScript system (the "JSRuntime", in SpiderMonkey terms),
michael@0 204 thereby escaping the capability-based limits. For this reason,
michael@0 205 `onNewGlobalObject` is only available to privileged code.
michael@0 206
michael@0 207
michael@0 208
michael@0 209 ## Function Properties of the Debugger Prototype Object
michael@0 210
michael@0 211 The functions described below may only be called with a `this` value
michael@0 212 referring to a `Debugger` instance; they may not be used as methods of
michael@0 213 other kinds of objects.
michael@0 214
michael@0 215 <code id="addDebuggee">addDebuggee(<i>global</i>)</code>
michael@0 216 : Add the global object designated by <i>global</i> to the set of global
michael@0 217 objects this `Debugger` instance is debugging. If the designated global
michael@0 218 is already a debuggee, this has no effect. Return this `Debugger`'s
michael@0 219 [`Debugger.Object`][object] instance referring to the designated global.
michael@0 220
michael@0 221 The value <i>global</i> may be any of the following:
michael@0 222
michael@0 223 * A global object.
michael@0 224
michael@0 225 * An HTML5 `WindowProxy` object (an "outer window", in Firefox
michael@0 226 terminology), which is treated as if the `Window` object of the
michael@0 227 browsing context's active document (the "inner window") were passed.
michael@0 228
michael@0 229 * A cross-compartment wrapper of an object; we apply the prior rules to
michael@0 230 the wrapped object.
michael@0 231
michael@0 232 * A [`Debugger.Object`][object] instance belonging to this `Debugger` instance;
michael@0 233 we apply the prior rules to the referent.
michael@0 234
michael@0 235 * Any other sort of value is treated as a `TypeError`. (Note that each
michael@0 236 rule is only applied once in the process of resolving a given
michael@0 237 <i>global</i> argument. Thus, for example, a [`Debugger.Object`][object]
michael@0 238 referring to a second [`Debugger.Object`][object] which refers to a global does
michael@0 239 not designate that global for the purposes of this function.)
michael@0 240
michael@0 241 The global designated by <i>global</i> must be in a different
michael@0 242 compartment than this `Debugger` instance itself. If adding the
michael@0 243 designated global's compartment would create a cycle of debugger and
michael@0 244 debuggee compartments, this method throws an error.
michael@0 245
michael@0 246 This method returns the [`Debugger.Object`][object] instance whose referent is
michael@0 247 the designated global object.
michael@0 248
michael@0 249 The `Debugger` instance does not hold a strong reference to its
michael@0 250 debuggee globals: if a debuggee global is not otherwise reachable, then
michael@0 251 it is dropped from the `Debugger`'s set of debuggees. (Naturally, the
michael@0 252 [`Debugger.Object`][object] instance this method returns does hold a strong
michael@0 253 reference to the added global.)
michael@0 254
michael@0 255 <code>removeDebuggee(<i>global</i>)</code>
michael@0 256 : Remove the global object designated by <i>global</i> from this
michael@0 257 `Debugger` instance's set of debuggees. Return `undefined`.
michael@0 258
michael@0 259 This method interprets <i>global</i> using the same rules that
michael@0 260 [`addDebuggee`][add] does.
michael@0 261
michael@0 262 <code>hasDebuggee(<i>global</i>)</code>
michael@0 263 : Return `true` if the global object designated by <i>global</i> is a
michael@0 264 debuggee of this `Debugger` instance.
michael@0 265
michael@0 266 This method interprets <i>global</i> using the same rules that
michael@0 267 [`addDebuggee`][add] does.
michael@0 268
michael@0 269 `getDebuggees()`
michael@0 270 : Return an array of distinct [`Debugger.Object`][object] instances whose referents
michael@0 271 are all the global objects this `Debugger` instance is debugging.
michael@0 272
michael@0 273 Since `Debugger` instances don't hold strong references to their
michael@0 274 debuggee globals, if a debuggee global is otherwise unreachable, it may
michael@0 275 be dropped at any moment from the array this method returns.
michael@0 276
michael@0 277 `getNewestFrame()`
michael@0 278 : Return a [`Debugger.Frame`][frame] instance referring to the youngest
michael@0 279 [visible frame][vf] currently on the calling thread's stack, or `null`
michael@0 280 if there are no visible frames on the stack.
michael@0 281
michael@0 282 <code>findSources([<i>query</i>]) <i>(not yet implemented)</i></code>
michael@0 283 : Return an array of all [`Debugger.Source`][source] instances matching
michael@0 284 <i>query</i>. Each source appears only once in the array. <i>Query</i>
michael@0 285 is an object whose properties restrict which sources are returned; a
michael@0 286 source must meet all the criteria given by <i>query</i> to be returned.
michael@0 287 If <i>query</i> is omitted, we return all sources of all debuggee
michael@0 288 scripts.
michael@0 289
michael@0 290 <i>Query</i> may have the following properties:
michael@0 291
michael@0 292 `url`
michael@0 293 : The source's `url` property must be equal to this value.
michael@0 294
michael@0 295 `global`
michael@0 296 : The source must have been evaluated in the scope of the given global
michael@0 297 object. If this property's value is a [`Debugger.Object`][object] instance
michael@0 298 belonging to this `Debugger` instance, then its referent is used. If the
michael@0 299 object is not a global object, then the global in whose scope it was
michael@0 300 allocated is used.
michael@0 301
michael@0 302 Note that the result may include sources that can no longer ever be
michael@0 303 used by the debuggee: say, eval code that has finished running, or
michael@0 304 source for unreachable functions. Whether such sources appear can be
michael@0 305 affected by the garbage collector's behavior, so this function's result
michael@0 306 is not entirely deterministic.
michael@0 307
michael@0 308 <code>findScripts([<i>query</i>])</code>
michael@0 309 : Return an array of [`Debugger.Script`][script] instances for all debuggee scripts
michael@0 310 matching <i>query</i>. Each instance appears only once in the array.
michael@0 311 <i>Query</i> is an object whose properties restrict which scripts are
michael@0 312 returned; a script must meet all the criteria given by <i>query</i> to
michael@0 313 be returned. If <i>query</i> is omitted, we return the [`Debugger.Script`][script]
michael@0 314 instances for all debuggee scripts.
michael@0 315
michael@0 316 <i>Query</i> may have the following properties:
michael@0 317
michael@0 318 `url`
michael@0 319 : The script's `url` property must be equal to this value.
michael@0 320
michael@0 321 `source` <i>(not yet implemented)</i>
michael@0 322 : The script's `source` property must be equal to this value.
michael@0 323
michael@0 324 `line`
michael@0 325 : The script must at least partially cover the given source line. If this
michael@0 326 property is present, the `url` property must be present as well.
michael@0 327
michael@0 328 `column`
michael@0 329 : The script must include given column on the line given by the `line`
michael@0 330 property. If this property is present, the `url` and `line` properties
michael@0 331 must both be present as well.
michael@0 332
michael@0 333 `innermost`
michael@0 334 : If this property is present and true, the script must be the innermost
michael@0 335 script covering the given source location; scripts of enclosing code are
michael@0 336 omitted.
michael@0 337
michael@0 338 `global`
michael@0 339 : The script must be in the scope of the given global object. If this
michael@0 340 property's value is a [`Debugger.Object`][object] instance belonging to this
michael@0 341 `Debugger` instance, then its referent is used. If the object is not a
michael@0 342 global object, then the global in whose scope it was allocated is used.
michael@0 343
michael@0 344 All properties of <i>query</i> are optional. Passing an empty object
michael@0 345 returns all debuggee code scripts.
michael@0 346
michael@0 347 Note that the result may include [`Debugger.Script`][script] instances for
michael@0 348 scripts that can no longer ever be used by the debuggee, say, those for
michael@0 349 eval code that has finished running, or unreachable functions. Whether
michael@0 350 such scripts appear can be affected by the garbage collector's
michael@0 351 behavior, so this function's behavior is not entirely deterministic.
michael@0 352
michael@0 353 <code>clearBreakpoint(<i>handler</i>)</code>
michael@0 354 : Remove all breakpoints set in this `Debugger` instance that use
michael@0 355 <i>handler</i> as their handler. Note that, if breakpoints using other
michael@0 356 handler objects are set at the same location(s) as <i>handler</i>, they
michael@0 357 remain in place.
michael@0 358
michael@0 359 `clearAllBreakpoints()`
michael@0 360 : Remove all breakpoints set using this `Debugger` instance.
michael@0 361
michael@0 362 `clearAllWatchpoints()` <i>(future plan)</i>
michael@0 363 : Clear all watchpoints owned by this `Debugger` instance.
michael@0 364
michael@0 365 `findAllGlobals()`
michael@0 366 : Return an array of [`Debugger.Object`][object] instances referring to all the
michael@0 367 global objects present in this JavaScript instance. The application may
michael@0 368 provide details about what kind of globals they are via the
michael@0 369 [`Debugger.Object`][object] instances' `hostAnnotations` accessors.
michael@0 370
michael@0 371 The results of this call can be affected in non-deterministic ways by
michael@0 372 the details of the JavaScript implementation. The array may include
michael@0 373 [`Debugger.Object`][object] instances referring to global objects that are not
michael@0 374 actually reachable by the debuggee or any other code in the system.
michael@0 375 (Naturally, once the function has returned, the array's
michael@0 376 [`Debugger.Object`][object] instances strongly reference the globals they refer
michael@0 377 to.)
michael@0 378
michael@0 379 This handler method is only available to debuggers running in privileged
michael@0 380 code ("chrome", in Firefox). Most functions provided by this `Debugger`
michael@0 381 API observe activity in only those globals that are reachable by the
michael@0 382 API's user, thus imposing capability-based restrictions on a
michael@0 383 `Debugger`'s reach. However, `findAllGlobals` allows the API user to
michael@0 384 find all global objects anywhere within the JavaScript system (the
michael@0 385 "JSRuntime", in SpiderMonkey terms), thereby escaping the
michael@0 386 capability-based limits. For this reason, `findAllGlobals` is only
michael@0 387 available to privileged code.
michael@0 388
michael@0 389 <code>makeGlobalObjectReference(<i>global</i>)</code>
michael@0 390 : Return the [`Debugger.Object`][object] whose referent is the global object
michael@0 391 designated by <i>global</i>, without adding the designated global as a
michael@0 392 debuggee. If <i>global</i> does not designate a global object, throw a
michael@0 393 `TypeError`. Determine which global is designated by <i>global</i>
michael@0 394 using the same rules as [`Debugger.prototype.addDebuggee`][add].
michael@0 395

mercurial