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
namespace v8 {
+void PrintPrompt() {
+ printf("dbg> ");
+ fflush(stdout);
+}
+
void HandleDebugEvent(DebugEvent event,
Handle<Object> exec_state,
bool running = false;
while (!running) {
char command[kBufferSize];
- printf("dbg> ");
+ PrintPrompt();
char* str = fgets(command, kBufferSize, stdin);
if (str == NULL) break;
// Start the keyboard thread.
KeyboardThread keyboard(this);
keyboard.Start();
+ PrintPrompt();
// Process events received from debugged VM and from the keyboard.
bool terminate = false;
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")));
} else {
printf("???\n");
}
- printf("dbg> ");
+ PrintPrompt();
}
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;
}
// 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>";
}
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();
// 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;
var condition;
var pos;
+ var request = this.createRequest('setbreakpoint');
+
// Check for breakpoint condition.
pos = args.indexOf(' ');
if (pos > 0) {
request.arguments.column = column;
request.arguments.condition = condition;
} else {
- throw new Error('Invalid break arguments.');
+ var request = this.createRequest('suspend');
}
return request.toJSONProtocol();
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>#');
var body = response.body();
var result = '';
switch (response.command()) {
+ case 'suspend':
+ details.text = 'stopped';
+ break;
+
case 'setbreakpoint':
result = 'set breakpoint #';
result += body.breakpoint;