Index: tools/ddbg.dart |
=================================================================== |
--- tools/ddbg.dart (revision 21113) |
+++ tools/ddbg.dart (working copy) |
@@ -19,7 +19,8 @@ |
int seqNum = 0; |
int isolate_id = -1; |
-bool verbose = false; |
+final verbose = false; |
+final printMessages = false; |
// The current stack trace, while the VM is paused. It's a list |
// of activation frames. |
@@ -463,14 +464,32 @@ |
} |
} |
+bool haveGarbageVmData() { |
+ if (vmData == null || vmData.length == 0) return false; |
+ var i = 0, char = " "; |
+ while (i < vmData.length) { |
+ char = vmData[i]; |
+ if (char != " " && char != "\n" && char != "\r" && char != "\t") break; |
+ i++; |
+ } |
+ if (i >= vmData.length) { |
+ return false; |
+ } else { |
+ return char != "{"; |
+ } |
+} |
+ |
void processVmData(String data) { |
- final printMessages = false; |
if (vmData == null || vmData.length == 0) { |
vmData = data; |
} else { |
vmData = vmData + data; |
} |
+ if (haveGarbageVmData()) { |
+ print("Error: have garbage data from VM: '$vmData'"); |
+ return; |
+ } |
int msg_len = jsonObjectLength(vmData); |
if (printMessages && msg_len == 0) { |
print("have partial or illegal json message" |
@@ -487,8 +506,13 @@ |
if (printMessages) { print("at least one message: '$vmData'"); } |
var msg = vmData.substring(0, msg_len); |
if (printMessages) { print("first message: $msg"); } |
+ vmData = vmData.substring(msg_len); |
+ if (haveGarbageVmData()) { |
+ print("Error: garbage data after previous message: '$vmData'"); |
+ print("Previous message was: '$msg'"); |
+ return; |
+ } |
processVmMessage(msg); |
- vmData = vmData.substring(msg_len); |
msg_len = jsonObjectLength(vmData); |
} |
if (printMessages) { print("leftover vm data '$vmData'"); } |