Commit 54231701 authored by sgjesse@chromium.org's avatar sgjesse@chromium.org

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
parent d7a61c27
...@@ -34,6 +34,11 @@ ...@@ -34,6 +34,11 @@
namespace v8 { namespace v8 {
void PrintPrompt() {
printf("dbg> ");
fflush(stdout);
}
void HandleDebugEvent(DebugEvent event, void HandleDebugEvent(DebugEvent event,
Handle<Object> exec_state, Handle<Object> exec_state,
...@@ -86,7 +91,7 @@ void HandleDebugEvent(DebugEvent event, ...@@ -86,7 +91,7 @@ void HandleDebugEvent(DebugEvent event,
bool running = false; bool running = false;
while (!running) { while (!running) {
char command[kBufferSize]; char command[kBufferSize];
printf("dbg> "); PrintPrompt();
char* str = fgets(command, kBufferSize, stdin); char* str = fgets(command, kBufferSize, stdin);
if (str == NULL) break; if (str == NULL) break;
...@@ -178,6 +183,7 @@ void RemoteDebugger::Run() { ...@@ -178,6 +183,7 @@ void RemoteDebugger::Run() {
// Start the keyboard thread. // Start the keyboard thread.
KeyboardThread keyboard(this); KeyboardThread keyboard(this);
keyboard.Start(); keyboard.Start();
PrintPrompt();
// Process events received from debugged VM and from the keyboard. // Process events received from debugged VM and from the keyboard.
bool terminate = false; bool terminate = false;
...@@ -265,6 +271,7 @@ void RemoteDebugger::HandleMessageReceived(char* message) { ...@@ -265,6 +271,7 @@ void RemoteDebugger::HandleMessageReceived(char* message) {
Shell::DebugMessageDetails(Handle<String>::Cast(String::New(message))); Shell::DebugMessageDetails(Handle<String>::Cast(String::New(message)));
if (try_catch.HasCaught()) { if (try_catch.HasCaught()) {
Shell::ReportException(&try_catch); Shell::ReportException(&try_catch);
PrintPrompt();
return; return;
} }
String::Utf8Value str(details->Get(String::New("text"))); String::Utf8Value str(details->Get(String::New("text")));
...@@ -277,7 +284,7 @@ void RemoteDebugger::HandleMessageReceived(char* message) { ...@@ -277,7 +284,7 @@ void RemoteDebugger::HandleMessageReceived(char* message) {
} else { } else {
printf("???\n"); printf("???\n");
} }
printf("dbg> "); PrintPrompt();
} }
...@@ -289,13 +296,17 @@ void RemoteDebugger::HandleKeyboardCommand(char* command) { ...@@ -289,13 +296,17 @@ void RemoteDebugger::HandleKeyboardCommand(char* command) {
Handle<Value> request = Handle<Value> request =
Shell::DebugCommandToJSONRequest(String::New(command)); Shell::DebugCommandToJSONRequest(String::New(command));
if (try_catch.HasCaught()) { 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; return;
} }
// If undefined is returned the command was handled internally and there is // If undefined is returned the command was handled internally and there is
// no JSON to send. // no JSON to send.
if (request->IsUndefined()) { if (request->IsUndefined()) {
PrintPrompt();
return; return;
} }
......
...@@ -102,7 +102,7 @@ bool CounterMap::Match(void* key1, void* key2) { ...@@ -102,7 +102,7 @@ bool CounterMap::Match(void* key1, void* key2) {
// Converts a V8 value to a C string. // 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 : "<string conversion failed>"; return *value ? *value : "<string conversion failed>";
} }
......
...@@ -117,6 +117,7 @@ class Shell: public i::AllStatic { ...@@ -117,6 +117,7 @@ class Shell: public i::AllStatic {
Handle<Value> name, Handle<Value> name,
bool print_result, bool print_result,
bool report_exceptions); bool report_exceptions);
static const char* ToCString(const v8::String::Utf8Value& value);
static void ReportException(TryCatch* try_catch); static void ReportException(TryCatch* try_catch);
static void Initialize(); static void Initialize();
static void OnExit(); static void OnExit();
......
...@@ -715,8 +715,6 @@ DebugRequest.prototype.scriptsCommandToJSONRequest_ = function(args) { ...@@ -715,8 +715,6 @@ DebugRequest.prototype.scriptsCommandToJSONRequest_ = function(args) {
// Create a JSON request for the break command. // Create a JSON request for the break command.
DebugRequest.prototype.breakCommandToJSONRequest_ = function(args) { DebugRequest.prototype.breakCommandToJSONRequest_ = function(args) {
// Build a evaluate request from the text command. // Build a evaluate request from the text command.
var request = this.createRequest('setbreakpoint');
// Process arguments if any. // Process arguments if any.
if (args && args.length > 0) { if (args && args.length > 0) {
var target = args; var target = args;
...@@ -726,6 +724,8 @@ DebugRequest.prototype.breakCommandToJSONRequest_ = function(args) { ...@@ -726,6 +724,8 @@ DebugRequest.prototype.breakCommandToJSONRequest_ = function(args) {
var condition; var condition;
var pos; var pos;
var request = this.createRequest('setbreakpoint');
// Check for breakpoint condition. // Check for breakpoint condition.
pos = args.indexOf(' '); pos = args.indexOf(' ');
if (pos > 0) { if (pos > 0) {
...@@ -763,7 +763,7 @@ DebugRequest.prototype.breakCommandToJSONRequest_ = function(args) { ...@@ -763,7 +763,7 @@ DebugRequest.prototype.breakCommandToJSONRequest_ = function(args) {
request.arguments.column = column; request.arguments.column = column;
request.arguments.condition = condition; request.arguments.condition = condition;
} else { } else {
throw new Error('Invalid break arguments.'); var request = this.createRequest('suspend');
} }
return request.toJSONProtocol(); return request.toJSONProtocol();
...@@ -817,6 +817,7 @@ DebugRequest.prototype.helpCommand_ = function(args) { ...@@ -817,6 +817,7 @@ DebugRequest.prototype.helpCommand_ = function(args) {
print('warning: arguments to \'help\' are ignored'); print('warning: arguments to \'help\' are ignored');
} }
print('break');
print('break location [condition]'); print('break location [condition]');
print(' break on named function: location is a function name'); print(' break on named function: location is a function name');
print(' break on function: location is #<id>#'); print(' break on function: location is #<id>#');
...@@ -931,6 +932,10 @@ function DebugResponseDetails(response) { ...@@ -931,6 +932,10 @@ function DebugResponseDetails(response) {
var body = response.body(); var body = response.body();
var result = ''; var result = '';
switch (response.command()) { switch (response.command()) {
case 'suspend':
details.text = 'stopped';
break;
case 'setbreakpoint': case 'setbreakpoint':
result = 'set breakpoint #'; result = 'set breakpoint #';
result += body.breakpoint; result += body.breakpoint;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment