Commit 3d8a5f1a authored by sgjesse@chromium.org's avatar sgjesse@chromium.org

Unify the handling of the event and response JSON in developer shell debugger.

Formatting of both debugger events and debugger responses are now unified into one function. This is mainly in preparation for the upcomming remote debugging support where having it a one function simplify things.
Review URL: http://codereview.chromium.org/27330

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1399 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 50e042df
......@@ -57,13 +57,17 @@ void HandleDebugEvent(DebugEvent event,
}
// Print the event details.
Handle<String> details =
Shell::DebugEventToText(Handle<String>::Cast(event_json));
if (details->Length() == 0) {
Handle<Object> details =
Shell::DebugMessageDetails(Handle<String>::Cast(event_json));
if (try_catch.HasCaught()) {
Shell::ReportException(&try_catch);
return;
}
String::Utf8Value str(details->Get(String::New("text")));
if (str.length() == 0) {
// Empty string is used to signal not to process this event.
return;
}
String::Utf8Value str(details);
printf("%s\n", *str);
// Get the debug command processor.
......@@ -123,7 +127,7 @@ void HandleDebugEvent(DebugEvent event,
Handle<String> response = Handle<String>::Cast(response_val);
// Convert the debugger response into text details and the running state.
Handle<Object> response_details = Shell::DebugResponseDetails(response);
Handle<Object> response_details = Shell::DebugMessageDetails(response);
if (try_catch.HasCaught()) {
Shell::ReportException(&try_catch);
continue;
......
......@@ -232,21 +232,14 @@ Handle<Array> Shell::GetCompletions(Handle<String> text, Handle<String> full) {
}
Handle<String> Shell::DebugEventToText(Handle<String> event) {
HandleScope handle_scope;
Handle<Object> Shell::DebugMessageDetails(Handle<String> message) {
Context::Scope context_scope(utility_context_);
Handle<Object> global = utility_context_->Global();
Handle<Value> fun = global->Get(String::New("DebugEventToText"));
TryCatch try_catch;
try_catch.SetVerbose(true);
Handle<Value> fun = global->Get(String::New("DebugMessageDetails"));
static const int kArgc = 1;
Handle<Value> argv[kArgc] = { event };
Handle<Value> argv[kArgc] = { message };
Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv);
if (try_catch.HasCaught()) {
return handle_scope.Close(try_catch.Exception()->ToString());
} else {
return handle_scope.Close(Handle<String>::Cast(val));
}
return Handle<Object>::Cast(val);
}
......@@ -261,17 +254,6 @@ Handle<Value> Shell::DebugCommandToJSONRequest(Handle<String> command) {
}
Handle<Object> Shell::DebugResponseDetails(Handle<String> response) {
Context::Scope context_scope(utility_context_);
Handle<Object> global = utility_context_->Global();
Handle<Value> fun = global->Get(String::New("DebugResponseDetails"));
static const int kArgc = 1;
Handle<Value> argv[kArgc] = { response };
Handle<Value> val = Handle<Function>::Cast(fun)->Call(global, kArgc, argv);
return Handle<Object>::Cast(val);
}
int32_t* Counter::Bind(const char* name) {
int i;
for (i = 0; i < kMaxNameSize - 1 && name[i]; i++)
......
......@@ -88,9 +88,8 @@ class Shell: public i::AllStatic {
static int Main(int argc, char* argv[]);
static Handle<Array> GetCompletions(Handle<String> text,
Handle<String> full);
static Handle<String> DebugEventToText(Handle<String> event);
static Handle<Object> DebugMessageDetails(Handle<String> message);
static Handle<Value> DebugCommandToJSONRequest(Handle<String> command);
static Handle<Object> DebugResponseDetails(Handle<String> response);
static Handle<Value> Print(const Arguments& args);
static Handle<Value> Quit(const Arguments& args);
......
......@@ -102,85 +102,98 @@ Debug.State = {
var trace_compile = false; // Tracing all compile events?
function DebugEventToText(event) {
// Process a debugger JSON message into a display text and a running status.
// This function returns an object with properties "text" and "running" holding
// this information.
function DebugMessageDetails(message) {
// Convert the JSON string to an object.
var response = new ProtocolPackage(event);
var response = new ProtocolPackage(message);
if (response.type() == 'event') {
return DebugEventDetails(response);
} else {
return DebugResponseDetails(response);
}
}
function DebugEventDetails(response) {
details = {text:'', running:false}
// Get the running state.
details.running = response.running();
// Build the text.
var body = response.body();
var details = '';
var result = '';
switch (response.event()) {
case 'break':
if (body.breakpoints) {
details += 'breakpoint';
result += 'breakpoint';
if (body.breakpoints.length > 1) {
details += 's';
result += 's';
}
details += ' #';
result += ' #';
for (var i = 0; i < body.breakpoints.length; i++) {
if (i > 0) {
details += ', #';
result += ', #';
}
details += body.breakpoints[i];
result += body.breakpoints[i];
}
} else {
details += 'break';
result += 'break';
}
details += ' in ';
details += body.invocationText;
details += ', ';
details += SourceInfo(body);
details += '\n';
details += SourceUnderline(body.sourceLineText, body.sourceColumn);
result += ' in ';
result += body.invocationText;
result += ', ';
result += SourceInfo(body);
result += '\n';
result += SourceUnderline(body.sourceLineText, body.sourceColumn);
Debug.State.currentSourceLine = body.sourceLine;
Debug.State.currentFrame = 0;
return details;
details.text = result;
break;
case 'exception':
if (body.uncaught) {
details += 'Uncaught: ';
result += 'Uncaught: ';
} else {
details += 'Exception: ';
result += 'Exception: ';
}
details += '"';
details += body.exception.text;
details += '"';
result += '"';
result += body.exception.text;
result += '"';
if (body.sourceLine >= 0) {
details += ', ';
details += SourceInfo(body);
details += '\n';
details += SourceUnderline(body.sourceLineText, body.sourceColumn);
result += ', ';
result += SourceInfo(body);
result += '\n';
result += SourceUnderline(body.sourceLineText, body.sourceColumn);
Debug.State.currentSourceLine = body.sourceLine;
Debug.State.currentFrame = 0;
} else {
details += ' (empty stack)';
result += ' (empty stack)';
Debug.State.currentSourceLine = -1;
Debug.State.currentFrame = kNoFrame;
}
return details;
details.text = result;
break;
case 'exception':
if (trace_compile) {
details = 'Source ' + body.script.name + ' compiled:\n'
} else {
return '';
}
case 'afterCompile':
if (trace_compile) {
details = 'Source ' + event.script().name() + ' compiled:\n'
result = 'Source ' + body.script.name + ' compiled:\n'
var source = body.script.source;
if (!(source[source.length - 1] == '\n')) {
details += source;
result += source;
} else {
details += source.substring(0, source.length - 1);
result += source.substring(0, source.length - 1);
}
return details;
} else {
return '';
}
details.text = result;
break;
default:
details.text = 'Unknown debug event ' + response.event();
}
return 'Unknown debug event ' + response.event();
return details;
};
......@@ -749,13 +762,10 @@ function formatObject_(value, include_properties) {
// Convert a JSON response to text for display in a text based debugger.
function DebugResponseDetails(json_response) {
function DebugResponseDetails(response) {
details = {text:'', running:false}
try {
// Convert the JSON string to an object.
var response = new ProtocolPackage(json_response);
if (!response.success()) {
details.text = response.message();
return details;
......
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