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
This commit is contained in:
sgjesse@chromium.org 2010-04-16 12:19:47 +00:00
parent d7a61c279d
commit 5423170113
4 changed files with 25 additions and 8 deletions

View File

@ -34,6 +34,11 @@
namespace v8 {
void PrintPrompt() {
printf("dbg> ");
fflush(stdout);
}
void HandleDebugEvent(DebugEvent event,
Handle<Object> 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<Object> details =
Shell::DebugMessageDetails(Handle<String>::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<Value> 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;
}

View File

@ -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 : "<string conversion failed>";
}

View File

@ -117,6 +117,7 @@ class Shell: public i::AllStatic {
Handle<Value> 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();

View File

@ -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 #<id>#');
@ -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;