Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Unified Diff: tools/ddbg.dart

Issue 10383164: Debugger wire protocol: setting breakpoints (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« lib/json/json.dart ('K') | « runtime/vm/debugger_api_impl_test.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/ddbg.dart
===================================================================
--- tools/ddbg.dart (revision 7627)
+++ tools/ddbg.dart (working copy)
@@ -20,10 +20,12 @@
void printHelp() {
print("""
q Quit debugger shell
+ bt Show backtrace
r Resume execution
s Single step
so Step over
si Step into
+ sbp <file> <line> Set breakpoint
ll List loaded libraries
ls <libname> List loaded scripts in library
""");
@@ -69,22 +71,34 @@
} else if (cmd == "so") {
var cmd = { "id": seqNum, "command": "stepOut" };
sendCmd(cmd).then((result) => handleGenericResponse(result));
+ } else if (cmd == "bt") {
+ var cmd = { "id": seqNum, "command": "getStackTrace" };
+ sendCmd(cmd).then((result) => handleStackTraceResponse(result));
} else if (cmd == "ll") {
var cmd = { "id": seqNum, "command": "getLibraryURLs" };
sendCmd(cmd).then((result) => handleGetLibraryResponse(result));
+ } else if (cmd == "sbp") {
+ if (args.length < 3) {
+ return;
+ }
+ var cmd = { "id": seqNum,
+ "command": "setBreakpoint",
+ "params": { "url": args[1], "line": Math.parseInt(args[2]) }};
+ sendCmd(cmd).then((result) => handleSetBpResponse(result));
} else if (cmd == "ls") {
if (args.length < 2) {
return;
}
- var cmd = { "id": seqNum, "command": "getScriptURLs",
- "param": { "library": args[1] }};
+ var cmd = { "id": seqNum,
+ "command": "getScriptURLs",
+ "params": { "library": args[1] }};
sendCmd(cmd).then((result) => handleGetScriptsResponse(result));
} else if (cmd == "q") {
quitShell();
} else if (cmd == "h") {
printHelp();
} else {
- print("Error: $cmd not understood");
+ print("command '$cmd' not understood, try h for help");
}
}
@@ -95,7 +109,7 @@
var urls = result["urls"];
assert(urls != null);
assert(urls is List);
- print("Loaded isolates:");
+ print("Loaded libraries:");
for (int i = 0; i < urls.length; i++) {
print(" $i ${urls[i]}");
}
@@ -115,6 +129,15 @@
}
+void handleSetBpResponse(response) {
+ var result = response["result"];
+ assert(result != null);
+ var id = result["breakpointId"];
+ assert(id != null);
+ print("Set BP $id");
+}
+
+
void handleGenericResponse(response) {
if (response["error"] != null) {
print("Error: ${response["error"]}");
@@ -122,10 +145,17 @@
}
-void printStackTrace(var trace) {
- if (trace == null) {
- return;
- }
+void handleStackTraceResponse(response) {
+ var result = response["result"];
+ assert(result != null);
+ var callFrames = result["callFrames"];
+ assert(callFrames != null);
+ printStackTrace(result);
+}
+
+
+void printStackTrace(trace) {
+ assert(trace != null);
var frames = trace["callFrames"];
if (frames is !List) {
print("unexpected type for frames parameter $frames");
@@ -141,12 +171,8 @@
}
-// TODO(hausner): Need to handle the case where we receive only a partial
-// message from the debugger, e.g. when the message is too big to fit in
-// one network packet.
-void processVmData(String s) {
- if (verbose) print("vm: $s");
- var msg = JSON.parse(s);
+void processVmMessage(String json) {
+ var msg = JSON.parse(json);
if (msg == null) {
return;
}
@@ -156,6 +182,13 @@
printStackTrace(msg["params"]);
return;
}
+ if (event == "breakpointResolved") {
+ var params = msg["params"];
+ assert(params != null);
+ print("BP ${params["breakpointId"]} resolved and "
+ "set at line ${params["line"]}.");
+ return;
+ }
if (msg["id"] != null) {
var id = msg["id"];
if (outstandingCommands.containsKey(id)) {
@@ -171,6 +204,34 @@
}
+// TODO(hausner): Need to handle the case where we receive only a partial
+// message from the debugger, e.g. when the message is too big to fit in
+// one network packet.
+void processVmData(String s) {
+ final printMessages = false;
+ int msg_len = JSON.length(s);
+ if (printMessages && msg_len == 0) {
+ print("vm sent illegal or partial json message '$s'");
+ quitShell();
+ return;
+ }
+ while (msg_len > 0 && msg_len <= s.length) {
+ if (msg_len == s.length) {
+ if (printMessages) { print("message: $s"); }
+ processVmMessage(s);
+ return;
+ }
+ if (printMessages) { print("at least one message: '$s'"); }
+ var msg = s.substring(0, msg_len);
+ if (printMessages) { print("first message: $msg"); }
+ processVmMessage(msg);
+ s = s.substring(msg_len);
+ msg_len = JSON.length(s);
+ }
+ if (printMessages) { print("leftover vm data '$s'"); }
+}
+
+
void main() {
outstandingCommands = new Map<int, Completer>();
vmSock = new Socket("127.0.0.1", 5858);
« lib/json/json.dart ('K') | « runtime/vm/debugger_api_impl_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698