diff options
author | sgjesse@google.com <sgjesse@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-29 11:07:40 +0000 |
---|---|---|
committer | sgjesse@google.com <sgjesse@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-29 11:07:40 +0000 |
commit | 88010e083e2d9c235120b7f8702fe82d7620b2e9 (patch) | |
tree | 985f6248f736dd86d27ab7733768ad8d2300bb1a /chrome/browser/debugger | |
parent | 466c8a51142090c6b475d72acd380ce72a10bfe9 (diff) | |
download | chromium_src-88010e083e2d9c235120b7f8702fe82d7620b2e9.zip chromium_src-88010e083e2d9c235120b7f8702fe82d7620b2e9.tar.gz chromium_src-88010e083e2d9c235120b7f8702fe82d7620b2e9.tar.bz2 |
Made changes to the JavaScript debugger in preparing for an upcoming
change in V8 where the implicit breaks currently issued when receiving
a command while running will be removed. To get in contact with the
V8 debugging interface and send messages V8 needs to be in the break
state. Getting V8 into the break state will be the responsebility of the
debugger using the V8 debugging interface.
Changed the messages between the renderer and the debugger. There are now
explicit messages for break and detach. Alse renamed the SendToDebugger
message to DebugCommand. There is now messages DebugAttach, DebugBreak,
DebugCommand and DebugDetach. The message DebugBreak has a force flag
to indicate whether the renderer should issue some JavaScript to help
the break along or whether it should just schedule a break to happen
whenever JavaScript executes.
Removed the artificial attach JSON response send by the renderer and
replaced that with an on debug attach call to the debugger shell. This
call is reouted to the on_attach function in the debugger JavScript code.
Changed the debugger to issue break requests whenever a suitable command,
e.g. setting a break point, is issued. In this case a flag is used to
track whether execution should be automatically resumed after the command
have been send to the V8 debugger interface. Changed the handling of the
plain break event to not force a break by executing additional JavaScript.
Thereby a plain break does not break JavaScript execution until code on
the tab beeing debugged is actually executed.
Set the command name explicitly on all commands.
Removed parseSimpleCommand as it was just used for the the continue command
for which an explicit parseContinueCommand has been added.
Removed the last_command field from DebugShell as it was not used.
Updated the debugger protocol test to reflect the removed attach event.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1526 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/debugger')
-rw-r--r-- | chrome/browser/debugger/debugger_node.cc | 8 | ||||
-rw-r--r-- | chrome/browser/debugger/debugger_shell.cc | 5 | ||||
-rw-r--r-- | chrome/browser/debugger/debugger_shell.h | 3 | ||||
-rw-r--r-- | chrome/browser/debugger/debugger_wrapper.cc | 5 | ||||
-rw-r--r-- | chrome/browser/debugger/debugger_wrapper.h | 1 | ||||
-rw-r--r-- | chrome/browser/debugger/resources/debugger_shell.js | 167 |
6 files changed, 131 insertions, 58 deletions
diff --git a/chrome/browser/debugger/debugger_node.cc b/chrome/browser/debugger/debugger_node.cc index 43de519..23b2cef 100644 --- a/chrome/browser/debugger/debugger_node.cc +++ b/chrome/browser/debugger/debugger_node.cc @@ -316,7 +316,7 @@ v8::Handle<v8::Value> TabNode::SendToDebugger(const v8::Arguments& args, v8::Handle<v8::Value> obj; obj = args[0]; DebuggerShell::ObjectToString(obj, &cmd); - host->SendToDebugger(cmd); + host->DebugCommand(cmd); } return v8::Undefined(); } @@ -340,7 +340,11 @@ v8::Handle<v8::Value> TabNode::Detach(const v8::Arguments& args, v8::Handle<v8::Value> TabNode::Break(const v8::Arguments& args, WebContents* web) { RenderViewHost* host = web->render_view_host(); - host->DebugBreak(); + bool force = false; + if (args.Length() >= 1) { + force = args[0]->BooleanValue(); + } + host->DebugBreak(force); return v8::Undefined(); } diff --git a/chrome/browser/debugger/debugger_shell.cc b/chrome/browser/debugger/debugger_shell.cc index b9b9aaa..eae5687 100644 --- a/chrome/browser/debugger/debugger_shell.cc +++ b/chrome/browser/debugger/debugger_shell.cc @@ -238,6 +238,11 @@ void DebuggerShell::DebugMessage(const std::wstring& msg) { } } +void DebuggerShell::OnDebugAttach() { + v8::HandleScope scope; + SubshellFunction("on_attach", 0, NULL); +} + void DebuggerShell::OnDebugDisconnect() { v8::HandleScope scope; SubshellFunction("on_disconnect", 0, NULL); diff --git a/chrome/browser/debugger/debugger_shell.h b/chrome/browser/debugger/debugger_shell.h index 8614746..31a51af 100644 --- a/chrome/browser/debugger/debugger_shell.h +++ b/chrome/browser/debugger/debugger_shell.h @@ -59,6 +59,9 @@ class DebuggerShell : public base::RefCountedThreadSafe<DebuggerShell> { void DebugMessage(const std::wstring& msg); // The renderer we're attached to is gone. + void OnDebugAttach(); + + // The renderer we're attached to is gone. void OnDebugDisconnect(); // SocketInputOutput callback methods diff --git a/chrome/browser/debugger/debugger_wrapper.cc b/chrome/browser/debugger/debugger_wrapper.cc index 847fab7..9b29903 100644 --- a/chrome/browser/debugger/debugger_wrapper.cc +++ b/chrome/browser/debugger/debugger_wrapper.cc @@ -32,6 +32,11 @@ void DebuggerWrapper::DebugMessage(const std::wstring& msg) { debugger_->DebugMessage(msg); } +void DebuggerWrapper::OnDebugAttach() { + if (debugger_.get()) + debugger_->OnDebugAttach(); +} + void DebuggerWrapper::OnDebugDisconnect() { if (debugger_.get()) debugger_->OnDebugDisconnect(); diff --git a/chrome/browser/debugger/debugger_wrapper.h b/chrome/browser/debugger/debugger_wrapper.h index ae4521a..2befe70 100644 --- a/chrome/browser/debugger/debugger_wrapper.h +++ b/chrome/browser/debugger/debugger_wrapper.h @@ -36,6 +36,7 @@ class DebuggerWrapper : public base::RefCountedThreadSafe<DebuggerWrapper> { void DebugMessage(const std::wstring& msg); + void OnDebugAttach(); void OnDebugDisconnect(); private: diff --git a/chrome/browser/debugger/resources/debugger_shell.js b/chrome/browser/debugger/resources/debugger_shell.js index ab89c0d..6c798b4 100644 --- a/chrome/browser/debugger/resources/debugger_shell.js +++ b/chrome/browser/debugger/resources/debugger_shell.js @@ -28,10 +28,10 @@ function DebugCommand(str) { str = argv.join(' '); if (DebugCommand.aliases[this.user_command]) this.user_command = DebugCommand.aliases[this.user_command]; - if (this.parseArgs_(str) == 1) - this.type = "request"; - if (this.command == undefined) - this.command = this.user_command; + if (this.parseArgs_(str) == 1) + this.type = "request"; + if (this.command == undefined) + this.command = this.user_command; }; // Mapping of some control characters to avoid the \uXXXX syntax for most @@ -211,16 +211,6 @@ DebugCommand.aliases = { }; /** - * Parses arguments to simple commands which have no arguments. - * @see DebugCommand.commands - * @param {string} str The arguments to be parsed. - * @return -1 for usage error, 1 for success - */ -DebugCommand.parseSimpleCommand_ = function(str) { - return str.length ? -1 : 1; -}; - -/** * Parses arguments to "args" and "locals" command, and initializes * the underlying DebugCommand (which is a frame request). * @see DebugCommand.commands @@ -361,8 +351,8 @@ DebugCommand.prototype.parseBreak_ = function(str) { } if (str.length == 0) { - this.type = "shell"; - return 0; + this.command = "break"; + return 1; } else { var parts = str.split(/\s+/); var condition = null; @@ -500,6 +490,22 @@ DebugCommand.responseClear_ = function(msg) { shell_.clearedBreakpoint(parseInt(msg.command.arguments.breakpoint)); } + +/** + * Parses arguments to "continue" command. See DebugCommand.commands below + * for syntax details. + * @see DebugCommand.commands + * @param {string} str The arguments to be parsed. + * @return -1 for usage error, 1 for success + */ +DebugCommand.prototype.parseContinueCommand_ = function(str) { + this.command = "continue"; + if (str.length > 0) { + return -1; + } + return 1; +} + /** * Parses arguments to "frame" command. See DebugCommand.commands below * for syntax details. @@ -742,8 +748,13 @@ DebugCommand.prototype.parseArgs_ = function(str) { } else { var ret = parse.call(this, str); if (ret > 0) { + // Command gererated a debugger request. this.type = "request"; + } else if (ret == 0) { + // Command handeled internally. + this.type = "handled"; } else if (ret < 0) { + // Command error. this.type = "handled"; DebugCommand.help(this.user_command); } @@ -809,7 +820,7 @@ DebugCommand.commands = { 'response': DebugCommand.responseClear_, 'usage': 'clear <breakpoint #>', 'while_running': true }, - 'continue': { 'parse': DebugCommand.parseSimpleCommand_, + 'continue': { 'parse': DebugCommand.prototype.parseContinueCommand_, 'usage': 'continue' }, 'frame': { 'parse': DebugCommand.prototype.parseFrame_, 'response': DebugCommand.responseFrame_, @@ -863,9 +874,15 @@ function DebugShell(tab) { this.running = true; this.current_command = undefined; this.pending_commands = []; + // The auto continue flag is used to indicate whether the JavaScript execution + // should automatically continue after a break event and the processing of + // pending commands. This is used to make it possible for the user to issue + // commands, e.g. setting break points, without making an explicit break. In + // this case the debugger will silently issue a forced break issue the command + // and silently continue afterwards. + this.auto_continue = false; this.debug = false; this.last_msg = undefined; - this.last_command = undefined; this.current_line = -1; this.current_pos = -1; this.current_frame = 0; @@ -896,32 +913,50 @@ DebugShell.prototype.set_running = function(running) { * @param cmd {DebugCommand} - command to execute */ DebugShell.prototype.process_command = function(cmd) { - if (this.current_command) { - this.pending_commands.push(cmd); - dprint("pending command: " + DebugCommand.toJSON(cmd)); - } else if (cmd.type == "shell") { - if (cmd.user_command == "break") { - if (this.running) { - this.tab.debugBreak(); - this.set_ready(false); - } else { - print(">>already paused"); - } + dprint("Running: " + (this.running ? "yes" : "no")); + + // The "break" commands needs to be handled seperatly + if (cmd.command == "break") { + if (this.running) { + // Schedule a break. + print("Stopping JavaScript execution..."); + this.tab.debugBreak(false); + } else { + print("JavaScript execution already stopped."); } - this.last_command = cmd; - } else if (cmd.type == "request") { - // If the page is running, then the debugger isn't listening to certain - // requests. + return; + } + + // If page is running an break needs to be issued. + if (this.running) { + // Some requests are not valid when the page is running. var cmd_info = DebugCommand.commands[cmd.user_command]; - if (this.running && !cmd_info['while_running']) { + if (!cmd_info['while_running']) { print(cmd.user_command + " can only be run while paused"); - } else { - this.current_command = cmd; - cmd.sendToDebugger(this.tab); - this.set_ready(false); + return; } + + // Add the command as pending before scheduling a break. + this.pending_commands.push(cmd); + dprint("pending command: " + cmd.toJSONProtocol()); + + // Schedule a forced break and enable auto continue. + this.tab.debugBreak(true); + this.auto_continue = true; + this.set_ready(false); + return; + } + + // If waiting for a response add command as pending otherwise send the + // command. + if (this.current_command) { + this.pending_commands.push(cmd); + dprint("pending command: " + cmd.toJSONProtocol()); + } else { + this.current_command = cmd; + cmd.sendToDebugger(this.tab); + this.set_ready(false); } - this.last_command = cmd; }; /** @@ -931,7 +966,6 @@ DebugShell.prototype.process_command = function(cmd) { DebugShell.prototype.event_break = function(msg) { this.current_frame = 0; this.set_running(false); - this.set_ready(true); if (msg.body) { var body = msg.body; this.current_script = body.script; @@ -941,6 +975,8 @@ DebugShell.prototype.event_break = function(msg) { var source = loc[1]; this.current_line = loc[2]; if (msg.body.breakpoints) { + // Always disable auto continue if a real break point is hit. + this.auto_continue = false; var breakpoints = msg.body.breakpoints; print("paused at breakpoint " + breakpoints.join(",") + ": " + location); @@ -954,14 +990,19 @@ DebugShell.prototype.event_break = function(msg) { if (location != this.last_break_location) { // We only print the location (function + script) when it changes, // so as we step, you only see the source line when you transition - // to a new script and/or function. - print(location); + // to a new script and/or function. Also if auto continue is enables + // don't print the break location. + if (!this.auto_continue) + print(location); } } - if (source) + // Print th current source line unless auto continue is enabled. + if (source && !this.auto_continue) print(source); this.last_break_location = location; } + if (!this.auto_continue) + this.set_ready(true); }; /** @@ -1037,7 +1078,8 @@ DebugShell.prototype.command = function(str) { if (str.length) { var cmd = new DebugCommand(str); cmd.from_user = true; - this.process_command(cmd); + if (cmd.type == "request") + this.process_command(cmd); } } else { print(">>not connected to a tab"); @@ -1064,15 +1106,6 @@ DebugShell.prototype.response = function(str) { this.event_break(msg); } else if (ev == "exception") { this.event_exception(msg); - } else if (ev == "attach") { - var title = this.tab.title; - if (!title) - title = "Untitled"; - print('attached to ' + title); - // on attach, we update our current script list - var cmd = new DebugCommand("scripts"); - cmd.from_user = false; - this.process_command(cmd); } } else if (msg.type == "response") { if (msg.request_seq != undefined) { @@ -1098,9 +1131,15 @@ DebugShell.prototype.response = function(str) { } } this.set_ready(true); - if (this.pending_commands.length) { - this.process_command(this.pending_commands.shift()); - } + } + + // Process next pending command if any. + if (this.pending_commands.length) { + this.process_command(this.pending_commands.shift()); + } else if (this.auto_continue) { + // If no more pending commands and auto continue is active issue a continue command. + this.auto_continue = false; + this.process_command(new DebugCommand("continue")); } }; @@ -1178,6 +1217,22 @@ DebugShell.prototype.exit = function() { /** * Called by the Chrome Shell when the tab that the shell is debugging + * have attached. + */ +DebugShell.prototype.on_attach = function() { + var title = this.tab.title; + if (!title) + title = "Untitled"; + print('attached to ' + title); + // on attach, we update our current script list + var cmd = new DebugCommand("scripts"); + cmd.from_user = false; + this.process_command(cmd); +}; + + +/** + * Called by the Chrome Shell when the tab that the shell is debugging * went away. */ DebugShell.prototype.on_disconnect = function() { |