OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 // Library used by debugger wire protocol tests (standalone VM debugging). | 5 // Library used by debugger wire protocol tests (standalone VM debugging). |
6 | 6 |
7 library DartDebugger; | 7 library DartDebugger; |
8 | 8 |
9 import "dart:async"; | 9 import "dart:async"; |
10 import "dart:convert"; | 10 import "dart:convert"; |
11 import "dart:io"; | 11 import "dart:io"; |
12 import "dart:math"; | 12 import "dart:math"; |
13 import "dart:json" as JSON; | |
14 | 13 |
15 // Whether or not to print the debugger wire messages on the console. | 14 // Whether or not to print the debugger wire messages on the console. |
16 var verboseWire = false; | 15 var verboseWire = false; |
17 | 16 |
18 // Class to buffer wire protocol data from debug target and | 17 // Class to buffer wire protocol data from debug target and |
19 // break it down to individual json messages. | 18 // break it down to individual json messages. |
20 class JsonBuffer { | 19 class JsonBuffer { |
21 String buffer = null; | 20 String buffer = null; |
22 | 21 |
23 append(String s) { | 22 append(String s) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 return false; | 55 return false; |
57 } else { | 56 } else { |
58 return char != "{"; | 57 return char != "{"; |
59 } | 58 } |
60 } | 59 } |
61 | 60 |
62 // Returns the character length of the next json message in the | 61 // Returns the character length of the next json message in the |
63 // buffer, or 0 if there is only a partial message in the buffer. | 62 // buffer, or 0 if there is only a partial message in the buffer. |
64 // The object value must start with '{' and continues to the | 63 // The object value must start with '{' and continues to the |
65 // matching '}'. No attempt is made to otherwise validate the contents | 64 // matching '}'. No attempt is made to otherwise validate the contents |
66 // as JSON. If it is invalid, a later JSON.parse() will fail. | 65 // as JSON. If it is invalid, a later JSON.decode() will fail. |
67 int objectLength() { | 66 int objectLength() { |
68 int skipWhitespace(int index) { | 67 int skipWhitespace(int index) { |
69 while (index < buffer.length) { | 68 while (index < buffer.length) { |
70 String char = buffer[index]; | 69 String char = buffer[index]; |
71 if (char != " " && char != "\n" && char != "\r" && char != "\t") break; | 70 if (char != " " && char != "\n" && char != "\r" && char != "\t") break; |
72 index++; | 71 index++; |
73 } | 72 } |
74 return index; | 73 return index; |
75 } | 74 } |
76 int skipString(int index) { | 75 int skipString(int index) { |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
493 void handleMessages() { | 492 void handleMessages() { |
494 var msg = responses.getNextMessage(); | 493 var msg = responses.getNextMessage(); |
495 while (msg != null) { | 494 while (msg != null) { |
496 if (verboseWire) print("RECV: $msg"); | 495 if (verboseWire) print("RECV: $msg"); |
497 if (responses.haveGarbage()) { | 496 if (responses.haveGarbage()) { |
498 error("Error: leftover text after message: '${responses.buffer}'"); | 497 error("Error: leftover text after message: '${responses.buffer}'"); |
499 error("Previous message may be malformed, was: '$msg'"); | 498 error("Previous message may be malformed, was: '$msg'"); |
500 cleanup(); | 499 cleanup(); |
501 return; | 500 return; |
502 } | 501 } |
503 var msgObj = JSON.parse(msg); | 502 var msgObj = JSON.decode(msg); |
504 handleMessage(msgObj); | 503 handleMessage(msgObj); |
505 if (errorsDetected) { | 504 if (errorsDetected) { |
506 error("Error while handling script entry"); | 505 error("Error while handling script entry"); |
507 error("Message received from debug target: $msg"); | 506 error("Message received from debug target: $msg"); |
508 cleanup(); | 507 cleanup(); |
509 return; | 508 return; |
510 } | 509 } |
511 if (shutdownEventSeen) { | 510 if (shutdownEventSeen) { |
512 cleanup(); | 511 cleanup(); |
513 return; | 512 return; |
514 } | 513 } |
515 if (isPaused) sendNextCommand(); | 514 if (isPaused) sendNextCommand(); |
516 msg = responses.getNextMessage(); | 515 msg = responses.getNextMessage(); |
517 } | 516 } |
518 } | 517 } |
519 | 518 |
520 // Send a debugger command to the target VM. | 519 // Send a debugger command to the target VM. |
521 void sendMessage(Map<String,dynamic> msg) { | 520 void sendMessage(Map<String,dynamic> msg) { |
522 if (msg["id"] != null) { | 521 if (msg["id"] != null) { |
523 msg["id"] = seqNr; | 522 msg["id"] = seqNr; |
524 } | 523 } |
525 if (msg["params"] != null && msg["params"]["isolateId"] != null) { | 524 if (msg["params"] != null && msg["params"]["isolateId"] != null) { |
526 msg["params"]["isolateId"] = isolateId; | 525 msg["params"]["isolateId"] = isolateId; |
527 } | 526 } |
528 String jsonMsg = JSON.stringify(msg); | 527 String jsonMsg = JSON.encode(msg); |
529 if (verboseWire) print("SEND: $jsonMsg"); | 528 if (verboseWire) print("SEND: $jsonMsg"); |
530 socket.write(jsonMsg); | 529 socket.write(jsonMsg); |
531 } | 530 } |
532 | 531 |
533 bool get errorsDetected => errors.length > 0; | 532 bool get errorsDetected => errors.length > 0; |
534 | 533 |
535 // Record error message. | 534 // Record error message. |
536 void error(String s) { | 535 void error(String s) { |
537 errors.add(s); | 536 errors.add(s); |
538 } | 537 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 targetOpts.add("--debuggee"); | 614 targetOpts.add("--debuggee"); |
616 print('args: ${targetOpts.join(" ")}'); | 615 print('args: ${targetOpts.join(" ")}'); |
617 | 616 |
618 Process.start(Platform.executable, targetOpts).then((Process process) { | 617 Process.start(Platform.executable, targetOpts).then((Process process) { |
619 print("Debug target process started, pid ${process.pid}."); | 618 print("Debug target process started, pid ${process.pid}."); |
620 process.stdin.close(); | 619 process.stdin.close(); |
621 var debugger = new Debugger(process, new DebugScript(script)); | 620 var debugger = new Debugger(process, new DebugScript(script)); |
622 }); | 621 }); |
623 return true; | 622 return true; |
624 } | 623 } |
OLD | NEW |