From 54231701131954365d08bf40aa9240814eddd2dc Mon Sep 17 00:00:00 2001 From: "sgjesse@chromium.org" Date: Fri, 16 Apr 2010 12:19:47 +0000 Subject: [PATCH] Tweak D8 remote debugger When D8 is used as remote debugger the command 'break' (shorthand 'b') can be used to break JavaScript execution. Fixed the printing of the prompt 'dbg>' and printing of error messages. Review URL: http://codereview.chromium.org/1566049 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@4437 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/d8-debug.cc | 19 +++++++++++++++---- src/d8.cc | 2 +- src/d8.h | 1 + src/d8.js | 11 ++++++++--- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/d8-debug.cc b/src/d8-debug.cc index 4e0243a..5f3ed76 100644 --- a/src/d8-debug.cc +++ b/src/d8-debug.cc @@ -34,6 +34,11 @@ namespace v8 { +void PrintPrompt() { + printf("dbg> "); + fflush(stdout); +} + void HandleDebugEvent(DebugEvent event, Handle exec_state, @@ -86,7 +91,7 @@ void HandleDebugEvent(DebugEvent event, bool running = false; while (!running) { char command[kBufferSize]; - printf("dbg> "); + PrintPrompt(); char* str = fgets(command, kBufferSize, stdin); if (str == NULL) break; @@ -178,6 +183,7 @@ void RemoteDebugger::Run() { // Start the keyboard thread. KeyboardThread keyboard(this); keyboard.Start(); + PrintPrompt(); // Process events received from debugged VM and from the keyboard. bool terminate = false; @@ -264,7 +270,8 @@ void RemoteDebugger::HandleMessageReceived(char* message) { Handle details = Shell::DebugMessageDetails(Handle::Cast(String::New(message))); if (try_catch.HasCaught()) { - Shell::ReportException(&try_catch); + Shell::ReportException(&try_catch); + PrintPrompt(); return; } String::Utf8Value str(details->Get(String::New("text"))); @@ -277,7 +284,7 @@ void RemoteDebugger::HandleMessageReceived(char* message) { } else { printf("???\n"); } - printf("dbg> "); + PrintPrompt(); } @@ -289,13 +296,17 @@ void RemoteDebugger::HandleKeyboardCommand(char* command) { Handle request = Shell::DebugCommandToJSONRequest(String::New(command)); if (try_catch.HasCaught()) { - Shell::ReportException(&try_catch); + v8::String::Utf8Value exception(try_catch.Exception()); + const char* exception_string = Shell::ToCString(exception); + printf("%s\n", exception_string); + PrintPrompt(); return; } // If undefined is returned the command was handled internally and there is // no JSON to send. if (request->IsUndefined()) { + PrintPrompt(); return; } diff --git a/src/d8.cc b/src/d8.cc index 73cce46..531064f 100644 --- a/src/d8.cc +++ b/src/d8.cc @@ -102,7 +102,7 @@ bool CounterMap::Match(void* key1, void* key2) { // Converts a V8 value to a C string. -const char* ToCString(const v8::String::Utf8Value& value) { +const char* Shell::ToCString(const v8::String::Utf8Value& value) { return *value ? *value : ""; } diff --git a/src/d8.h b/src/d8.h index 9df291b..30f04c7 100644 --- a/src/d8.h +++ b/src/d8.h @@ -117,6 +117,7 @@ class Shell: public i::AllStatic { Handle name, bool print_result, bool report_exceptions); + static const char* ToCString(const v8::String::Utf8Value& value); static void ReportException(TryCatch* try_catch); static void Initialize(); static void OnExit(); diff --git a/src/d8.js b/src/d8.js index 369ab65..b9ff09c 100644 --- a/src/d8.js +++ b/src/d8.js @@ -715,8 +715,6 @@ DebugRequest.prototype.scriptsCommandToJSONRequest_ = function(args) { // Create a JSON request for the break command. DebugRequest.prototype.breakCommandToJSONRequest_ = function(args) { // Build a evaluate request from the text command. - var request = this.createRequest('setbreakpoint'); - // Process arguments if any. if (args && args.length > 0) { var target = args; @@ -726,6 +724,8 @@ DebugRequest.prototype.breakCommandToJSONRequest_ = function(args) { var condition; var pos; + var request = this.createRequest('setbreakpoint'); + // Check for breakpoint condition. pos = args.indexOf(' '); if (pos > 0) { @@ -763,7 +763,7 @@ DebugRequest.prototype.breakCommandToJSONRequest_ = function(args) { request.arguments.column = column; request.arguments.condition = condition; } else { - throw new Error('Invalid break arguments.'); + var request = this.createRequest('suspend'); } return request.toJSONProtocol(); @@ -817,6 +817,7 @@ DebugRequest.prototype.helpCommand_ = function(args) { print('warning: arguments to \'help\' are ignored'); } + print('break'); print('break location [condition]'); print(' break on named function: location is a function name'); print(' break on function: location is ##'); @@ -931,6 +932,10 @@ function DebugResponseDetails(response) { var body = response.body(); var result = ''; switch (response.command()) { + case 'suspend': + details.text = 'stopped'; + break; + case 'setbreakpoint': result = 'set breakpoint #'; result += body.breakpoint; -- 2.7.4