OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * @fileoverview Provides communication interface to remote v8 debugger. See | 6 * @fileoverview Provides communication interface to remote v8 debugger. See |
7 * protocol decription at http://code.google.com/p/v8/wiki/DebuggerProtocol | 7 * protocol decription at http://code.google.com/p/v8/wiki/DebuggerProtocol |
8 */ | 8 */ |
9 goog.provide('devtools.DebuggerAgent'); | 9 goog.provide('devtools.DebuggerAgent'); |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 this.requestNumberToBreakpointInfo_ = null; | 32 this.requestNumberToBreakpointInfo_ = null; |
33 | 33 |
34 /** | 34 /** |
35 * Information on current stack top frame. | 35 * Information on current stack top frame. |
36 * See JavaScriptCallFrame.idl. | 36 * See JavaScriptCallFrame.idl. |
37 * @type {?Object} | 37 * @type {?Object} |
38 */ | 38 */ |
39 this.currentCallFrame_ = null; | 39 this.currentCallFrame_ = null; |
40 | 40 |
41 /** | 41 /** |
| 42 * Whether to stop in the debugger on the exceptions. |
| 43 * @type {boolean} |
| 44 */ |
| 45 this.pauseOnExceptions_ = true; |
| 46 |
| 47 /** |
42 * Mapping: request sequence number->callback. | 48 * Mapping: request sequence number->callback. |
43 * @type {Object} | 49 * @type {Object} |
44 */ | 50 */ |
45 this.requestSeqToCallback_ = null; | 51 this.requestSeqToCallback_ = null; |
46 }; | 52 }; |
47 | 53 |
48 | 54 |
49 /** | 55 /** |
50 * Resets debugger agent to its initial state. | 56 * Resets debugger agent to its initial state. |
51 */ | 57 */ |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 * Tells the v8 debugger to continue execution after it has been stopped on a | 172 * Tells the v8 debugger to continue execution after it has been stopped on a |
167 * breakpoint or an exception. | 173 * breakpoint or an exception. |
168 */ | 174 */ |
169 devtools.DebuggerAgent.prototype.resumeExecution = function() { | 175 devtools.DebuggerAgent.prototype.resumeExecution = function() { |
170 var cmd = new devtools.DebugCommand('continue'); | 176 var cmd = new devtools.DebugCommand('continue'); |
171 devtools.DebuggerAgent.sendCommand_(cmd); | 177 devtools.DebuggerAgent.sendCommand_(cmd); |
172 }; | 178 }; |
173 | 179 |
174 | 180 |
175 /** | 181 /** |
| 182 * @return {boolean} True iff the debugger will pause execution on the |
| 183 * exceptions. |
| 184 */ |
| 185 devtools.DebuggerAgent.prototype.pauseOnExceptions = function() { |
| 186 return this.pauseOnExceptions_; |
| 187 }; |
| 188 |
| 189 |
| 190 /** |
| 191 * Tells whether to pause in the debugger on the exceptions or not. |
| 192 * @param {boolean} value True iff execution should be stopped in the debugger |
| 193 * on the exceptions. |
| 194 */ |
| 195 devtools.DebuggerAgent.prototype.setPauseOnExceptions = function(value) { |
| 196 this.pauseOnExceptions_ = value; |
| 197 }; |
| 198 |
| 199 |
| 200 /** |
176 * Current stack top frame. | 201 * Current stack top frame. |
177 * @return {Object} | 202 * @return {Object} |
178 */ | 203 */ |
179 devtools.DebuggerAgent.prototype.getCurrentCallFrame = function() { | 204 devtools.DebuggerAgent.prototype.getCurrentCallFrame = function() { |
180 return this.currentCallFrame_; | 205 return this.currentCallFrame_; |
181 }; | 206 }; |
182 | 207 |
183 | 208 |
184 /** | 209 /** |
185 * Sends 'evaluate' request to the debugger. | 210 * Sends 'evaluate' request to the debugger. |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
350 }; | 375 }; |
351 | 376 |
352 | 377 |
353 /** | 378 /** |
354 * @param {devtools.DebuggerMessage} msg | 379 * @param {devtools.DebuggerMessage} msg |
355 */ | 380 */ |
356 devtools.DebuggerAgent.prototype.handleExceptionEvent_ = function(msg) { | 381 devtools.DebuggerAgent.prototype.handleExceptionEvent_ = function(msg) { |
357 var body = msg.getBody(); | 382 var body = msg.getBody(); |
358 debugPrint('Uncaught exception in ' + body.script.name + ':' + | 383 debugPrint('Uncaught exception in ' + body.script.name + ':' + |
359 body.sourceLine + '\n' + body.sourceLineText); | 384 body.sourceLine + '\n' + body.sourceLineText); |
360 this.resumeExecution(); | 385 if (this.pauseOnExceptions_) { |
| 386 var body = msg.getBody(); |
| 387 |
| 388 var sourceId = -1; |
| 389 // The exception may happen in native code in which case there is no script. |
| 390 if (body.script) { |
| 391 sourceId = body.script.id; |
| 392 } |
| 393 |
| 394 var line = devtools.DebuggerAgent.v8ToWwebkitLineNumber_(body.sourceLine); |
| 395 |
| 396 this.currentCallFrame_ = { |
| 397 'sourceID': sourceId, |
| 398 'line': line, |
| 399 'script': body.script, |
| 400 'scopeChain': [], |
| 401 'thisObject': {} |
| 402 }; |
| 403 this.requestBacktrace_(); |
| 404 } else { |
| 405 this.resumeExecution(); |
| 406 } |
361 }; | 407 }; |
362 | 408 |
363 | 409 |
364 /** | 410 /** |
365 * @param {devtools.DebuggerMessage} msg | 411 * @param {devtools.DebuggerMessage} msg |
366 */ | 412 */ |
367 devtools.DebuggerAgent.prototype.handleScriptsResponse_ = function(msg) { | 413 devtools.DebuggerAgent.prototype.handleScriptsResponse_ = function(msg) { |
368 var scripts = msg.getBody(); | 414 var scripts = msg.getBody(); |
369 for (var i = 0; i < scripts.length; i++) { | 415 for (var i = 0; i < scripts.length; i++) { |
370 var script = scripts[i]; | 416 var script = scripts[i]; |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 | 565 |
520 | 566 |
521 /** | 567 /** |
522 * Returns user-friendly representation of the function call from the stack | 568 * Returns user-friendly representation of the function call from the stack |
523 * frame. | 569 * frame. |
524 * @param {Object} stackFrame Frame json object from 'backtrace' response. | 570 * @param {Object} stackFrame Frame json object from 'backtrace' response. |
525 * @return {!string} Function name with argument values. | 571 * @return {!string} Function name with argument values. |
526 */ | 572 */ |
527 devtools.DebuggerAgent.formatFunctionCall_ = function(stackFrame, msg) { | 573 devtools.DebuggerAgent.formatFunctionCall_ = function(stackFrame, msg) { |
528 var func = msg.lookup(stackFrame.func.ref); | 574 var func = msg.lookup(stackFrame.func.ref); |
529 var argv = []; | 575 if (func.name) { |
530 for (var j = 0; j < stackFrame.arguments.length; j++) { | 576 return func.name; |
531 var arg = stackFrame.arguments[j]; | 577 } else { |
532 var val = devtools.DebuggerAgent.formatObjectReference_(arg.value, msg); | 578 // TODO(yurys): support method name inference(F.m = function() {} should be |
533 argv.push(arg.name + ' = ' + val); | 579 // a function with name 'm') |
| 580 return '(anonymous function)'; |
534 } | 581 } |
535 return func.name + '(' + argv.join(', ') + ')'; | |
536 }; | 582 }; |
537 | 583 |
538 | 584 |
539 /** | 585 /** |
540 * Converts an object from the debugger response to the format understandable | 586 * Converts an object from the debugger response to the format understandable |
541 * by ScriptsPanel. | 587 * by ScriptsPanel. |
542 * @param {Object} object An object from the debugger protocol response. | 588 * @param {Object} object An object from the debugger protocol response. |
543 * @param {devtools.DebuggerMessage} msg Parsed debugger response. | 589 * @param {devtools.DebuggerMessage} msg Parsed debugger response. |
544 * @return {!Object} Object describing 'object' in the format expected by | 590 * @return {!Object} Object describing 'object' in the format expected by |
545 * ScriptsPanel and its panes. | 591 * ScriptsPanel and its panes. |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
977 | 1023 |
978 | 1024 |
979 /** | 1025 /** |
980 * @param {number} handle Object handle. | 1026 * @param {number} handle Object handle. |
981 * @return {?Object} Returns the object with the handle if it was sent in this | 1027 * @return {?Object} Returns the object with the handle if it was sent in this |
982 * message(some objects referenced by handles may be missing in the message). | 1028 * message(some objects referenced by handles may be missing in the message). |
983 */ | 1029 */ |
984 devtools.DebuggerMessage.prototype.lookup = function(handle) { | 1030 devtools.DebuggerMessage.prototype.lookup = function(handle) { |
985 return this.refs_[handle]; | 1031 return this.refs_[handle]; |
986 }; | 1032 }; |
OLD | NEW |