diff options
author | sgjesse@chromium.org <sgjesse@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-16 14:09:52 +0000 |
---|---|---|
committer | sgjesse@chromium.org <sgjesse@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-01-16 14:09:52 +0000 |
commit | 7fad4a4b9f751c438f4b0701e0f0b9052db00d5a (patch) | |
tree | 1a6d3ecbf00b5c38012556d97bb925dec9393e85 /chrome/browser/debugger/resources | |
parent | a5365fc742f781b26d3438d61a8eb38628020159 (diff) | |
download | chromium_src-7fad4a4b9f751c438f4b0701e0f0b9052db00d5a.zip chromium_src-7fad4a4b9f751c438f4b0701e0f0b9052db00d5a.tar.gz chromium_src-7fad4a4b9f751c438f4b0701e0f0b9052db00d5a.tar.bz2 |
Update the command line JavaScript debugger to support the changed debugger protocol in V8 0.4.8. All the debugger tests now pass.
Review URL: http://codereview.chromium.org/18149
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8174 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/debugger/resources')
-rw-r--r-- | chrome/browser/debugger/resources/debugger_shell.js | 205 |
1 files changed, 141 insertions, 64 deletions
diff --git a/chrome/browser/debugger/resources/debugger_shell.js b/chrome/browser/debugger/resources/debugger_shell.js index a3671c3..70114b0 100644 --- a/chrome/browser/debugger/resources/debugger_shell.js +++ b/chrome/browser/debugger/resources/debugger_shell.js @@ -324,10 +324,10 @@ DebugCommand.prototype.parsePrint_ = function(str) { /** * Handle the response to a "print" command and display output to user. * @see http://wiki/Main/V8Debugger - * @param {Object} msg - the V8 debugger response object + * @param {ProtocolPacket} evaluate_response - the V8 debugger response object */ -DebugCommand.responsePrint_ = function(msg) { - body = msg["body"]; +DebugCommand.responsePrint_ = function(evaluate_response) { + body = evaluate_response.body(); if (body['text'] != undefined) { print(body['text']); } else { @@ -401,11 +401,13 @@ DebugCommand.prototype.parseBreak_ = function(str) { /** * Handle the response to a "break" command and display output to user. * @see http://wiki/Main/V8Debugger - * @param {Object} msg - the V8 debugger response object + * @param {ResponsePacket} setbreakpoint_response - the V8 debugger response + * object */ -DebugCommand.responseBreak_ = function(msg) { +DebugCommand.responseBreak_ = function(setbreakpoint_response) { + var body = setbreakpoint_response.body(); var info = new BreakpointInfo( - parseInt(msg.body.breakpoint), + parseInt(body.breakpoint), msg.command.arguments.type, msg.command.arguments.target, msg.command.arguments.line, @@ -446,10 +448,10 @@ DebugCommand.responseBreak_ = function(msg) { /** * Handle the response to a "backtrace" command and display output to user. * @see http://wiki/Main/V8Debugger - * @param {Object} msg - the V8 debugger response object + * @param {ResponsePacket} backtrace_response - the V8 debugger response object */ -DebugCommand.responseBacktrace_ = function(msg) { - body = msg["body"]; +DebugCommand.responseBacktrace_ = function(backtrace_response) { + body = backtrace_response.body(); if (body && body.totalFrames) { print('Frames #' + body.fromFrame + ' to #' + (body.toFrame - 1) + ' of ' + body.totalFrames + ":"); @@ -484,9 +486,11 @@ DebugCommand.prototype.parseClearCommand_ = function(str) { /** * Handle the response to a "clear" command and display output to user. * @see http://wiki/Main/V8Debugger - * @param {Object} msg - the V8 debugger response object + * @param {ResponsePacket} clearbreakpoint_response - the V8 debugger response + * object */ -DebugCommand.responseClear_ = function(msg) { +DebugCommand.responseClear_ = function(clearbreakpoint_response) { + var body = clearbreakpoint_response.body(); shell_.clearedBreakpoint(parseInt(msg.command.arguments.breakpoint)); } @@ -527,26 +531,29 @@ DebugCommand.prototype.parseFrame_ = function(str) { /** * Handle the response to a "frame" command and display output to user. * @see http://wiki/Main/V8Debugger - * @param {Object} msg - the V8 debugger response object + * @param {ResponsePacket} frame_response - the V8 debugger response object */ -DebugCommand.responseFrame_ = function(msg) { - body = msg.body; - loc = DebugCommand.getSourceLocation(body.func.script, - body.sourceLineText, body.line, body.func.name); +DebugCommand.responseFrame_ = function(frame_response) { + var body = frame_response.body(); + var func = frame_response.lookup(body.func.ref); + loc = DebugCommand.getSourceLocation(func.script, + body.sourceLineText, body.line, func.name); print("#" + (body.index <= 9 ? '0' : '') + body.index + " " + loc[0]); print(loc[1]); shell_.current_frame = body.index; shell_.current_line = loc[2]; - shell_.current_script = body.func.script; + shell_.current_script = func.script; }; /** * Handle the response to a "args" command and display output to user. * @see http://wiki/Main/V8Debugger - * @param {Object} msg - the V8 debugger response object (for "frame" command) + * @param {ProtocolPacket} frame_response - the V8 debugger response object (for + * "frame" command) */ -DebugCommand.responseArgs_ = function(msg) { - DebugCommand.printVariables_(msg.body.arguments); +DebugCommand.responseArgs_ = function(frame_response) { + var body = frame_response.body(); + DebugCommand.printVariables_(body.arguments, frame_response); } /** @@ -554,14 +561,15 @@ DebugCommand.responseArgs_ = function(msg) { * @see http://wiki/Main/V8Debugger * @param {Object} msg - the V8 debugger response object (for "frame" command) */ -DebugCommand.responseLocals_ = function(msg) { - DebugCommand.printVariables_(msg.body.locals); +DebugCommand.responseLocals_ = function(frame_response) { + var body = frame_response.body(); + DebugCommand.printVariables_(body.locals, frame_response); } -DebugCommand.printVariables_ = function(variables) { +DebugCommand.printVariables_ = function(variables, protocol_packet) { for (var i = 0; i < variables.length; i++) { print(variables[i].name + " = " + - DebugCommand.toPreviewString_(variables[i].value)); + DebugCommand.toPreviewString_(protocol_packet.lookup(variables[i].value.ref))); } } @@ -588,10 +596,10 @@ DebugCommand.prototype.parseScripts_ = function(str) { /** * Handle the response to a "scripts" command and display output to user. * @see http://wiki/Main/V8Debugger - * @param {Object} msg - the V8 debugger response object + * @param {ResponsePacket} scripts_response - the V8 debugger response object */ -DebugCommand.responseScripts_ = function(msg) { - scripts = msg.body; +DebugCommand.responseScripts_ = function(scripts_response) { + scripts = scripts_response.body(); shell_.scripts = []; for (var i in scripts) { var script = scripts[i]; @@ -600,7 +608,7 @@ DebugCommand.responseScripts_ = function(msg) { shell_.scripts.push(script); // Print result if this response was the result of a user command. - if (msg.command.from_user) { + if (scripts_response.command.from_user) { var name = script.name; if (name) { if (script.lineOffset > 0) { @@ -670,10 +678,10 @@ DebugCommand.prototype.parseSource_ = function(str) { /** * Handle the response to a "source" command and display output to user. * @see http://wiki/Main/V8Debugger - * @param {Object} msg - the V8 debugger response object + * @param {ProtocolPacket} source_response - the V8 debugger response object */ -DebugCommand.responseSource_ = function(msg) { - var body = msg.body; +DebugCommand.responseSource_ = function(source_response) { + var body = source_response.body(); var from_line = parseInt(body.fromLine) + 1; var source = body.source; var lines = source.split('\n'); @@ -882,7 +890,6 @@ function DebugShell(tab) { // and silently continue afterwards. this.auto_continue = false; this.debug = false; - this.last_msg = undefined; this.current_line = -1; this.current_pos = -1; this.current_frame = 0; @@ -963,21 +970,21 @@ DebugShell.prototype.process_command = function(cmd) { * Handle a break event from the debugger. * @param msg {Object} - event protocol message to handle */ -DebugShell.prototype.event_break = function(msg) { +DebugShell.prototype.event_break = function(break_event) { this.current_frame = 0; this.set_running(false); - if (msg.body) { - var body = msg.body; + var body = break_event.body(); + if (body) { this.current_script = body.script; var loc = DebugCommand.getSourceLocation(body.script, body.sourceLineText, body.sourceLine, body.invocationText); var location = loc[0]; var source = loc[1]; this.current_line = loc[2]; - if (msg.body.breakpoints) { + if (body.breakpoints) { // Always disable auto continue if a real break point is hit. this.auto_continue = false; - var breakpoints = msg.body.breakpoints; + var breakpoints = body.breakpoints; print("paused at breakpoint " + breakpoints.join(",") + ": " + location); for (var i = 0; i < breakpoints.length; i++) @@ -1007,16 +1014,17 @@ DebugShell.prototype.event_break = function(msg) { /** * Handle an exception event from the debugger. - * @param msg {Object} - event protocol message to handle + * @param msg {ResponsePacket} - exception_event protocol message to handle */ -DebugShell.prototype.event_exception = function(msg) { +DebugShell.prototype.event_exception = function(exception_event) { this.set_running(false); this.set_ready(true); - if (msg.body) { - if (msg.body["uncaught"]) { - print("uncaught exception " + msg.body["exception"].text); + var body = exception_event.body(); + if (body) { + if (body["uncaught"]) { + print("uncaught exception " + body["exception"].text); } else { - print("paused at exception " + msg.body["exception"].text); + print("paused at exception " + body["exception"].text); } } }; @@ -1091,43 +1099,40 @@ DebugShell.prototype.command = function(str) { * received. */ DebugShell.prototype.response = function(str) { - var msg; + var response; try { dprint("received: " + str); - msg = eval('(' + str + ')'); - this.last_msg = msg; + response = new ProtocolPackage(str); } catch (error) { print(error.toString(), str); return; } - if (msg.type == "event") { - ev = msg["event"] + if (response.type() == "event") { + ev = response.event(); if (ev == "break") { - this.event_break(msg); + this.event_break(response); } else if (ev == "exception") { - this.event_exception(msg); + this.event_exception(response); } - } else if (msg.type == "response") { - if (msg.request_seq != undefined) { - if (!this.current_command || this.current_command.seq != msg.request_seq){ - throw("received response to unknown command " + DebugCommand.toJSON(msg)); + } else if (response.type() == "response") { + if (response.requestSeq() != undefined) { + if (!this.current_command || this.current_command.seq != response.requestSeq()){ + throw("received response to unknown command " + str); } } else { // TODO(erikkay): should we reject these when they happen? - print(">>no request_seq in response " + DebugCommand.toJSON(msg)); + print(">>no request_seq in response " + str); } var cmd = DebugCommand.commands[this.current_command.user_command] - msg.command = this.current_command; + response.command = this.current_command; this.current_command = null - if (msg.running != undefined) { - this.set_running(msg.running); - } - if (!msg['success']) { - print(msg['message']); + this.set_running(response.running()); + if (!response.success()) { + print(response.message()); } else { - var response = cmd['response']; - if (response != undefined) { - response.call(this, msg); + var handler = cmd['response']; + if (handler != undefined) { + handler.call(this, response); } } this.set_ready(true); @@ -1242,6 +1247,78 @@ DebugShell.prototype.on_disconnect = function() { /** + * Protocol packages send from the debugger. + * @param {string} json - raw protocol packet as JSON string. + * @constructor + */ +function ProtocolPackage(json) { + this.packet_ = eval('(' + json + ')'); + this.refs_ = []; + if (this.packet_.refs) { + for (var i = 0; i < this.packet_.refs.length; i++) { + this.refs_[this.packet_.refs[i].handle] = this.packet_.refs[i]; + } + } +} + + +/** + * Get the packet type. + * @return {String} the packet type + */ +ProtocolPackage.prototype.type = function() { + return this.packet_.type; +} + + +/** + * Get the packet event. + * @return {Object} the packet event + */ +ProtocolPackage.prototype.event = function() { + return this.packet_.event; +} + + +/** + * Get the packet request sequence. + * @return {number} the packet request sequence + */ +ProtocolPackage.prototype.requestSeq = function() { + return this.packet_.request_seq; +} + + +/** + * Get the packet request sequence. + * @return {number} the packet request sequence + */ +ProtocolPackage.prototype.running = function() { + return this.packet_.running ? true : false; +} + + +ProtocolPackage.prototype.success = function() { + return this.packet_.success ? true : false; +} + + +ProtocolPackage.prototype.message = function() { + return this.packet_.message; +} + + +ProtocolPackage.prototype.body = function() { + return this.packet_.body; +} + + +ProtocolPackage.prototype.lookup = function(handle) { + return this.refs_[handle]; +} + + +/** * Structure that holds the details about a breakpoint. * @constructor * |