OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // Simple interactive debugger shell that connects to the Dart VM's debugger | 5 // Simple interactive debugger shell that connects to the Dart VM's debugger |
6 // connection port. | 6 // connection port. |
7 | 7 |
| 8 import "dart:convert"; |
8 import "dart:io"; | 9 import "dart:io"; |
9 import "dart:json" as json; | 10 import "dart:json" as json; |
10 import "dart:utf"; | 11 import "dart:utf"; |
11 import "dart:async"; | 12 import "dart:async"; |
12 | 13 |
13 | 14 |
14 Map<int, Completer> outstandingCommands; | 15 Map<int, Completer> outstandingCommands; |
15 | 16 |
16 Socket vmSock; | 17 Socket vmSock; |
17 String vmData; | 18 String vmData; |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 } | 584 } |
584 return 0; | 585 return 0; |
585 } | 586 } |
586 | 587 |
587 | 588 |
588 void debuggerMain() { | 589 void debuggerMain() { |
589 outstandingCommands = new Map<int, Completer>(); | 590 outstandingCommands = new Map<int, Completer>(); |
590 Socket.connect("127.0.0.1", 5858).then((s) { | 591 Socket.connect("127.0.0.1", 5858).then((s) { |
591 vmSock = s; | 592 vmSock = s; |
592 vmSock.setOption(SocketOption.TCP_NODELAY, true); | 593 vmSock.setOption(SocketOption.TCP_NODELAY, true); |
593 var stringStream = vmSock.transform(new StringDecoder()); | 594 var stringStream = vmSock.transform(UTF8.decoder); |
594 vmSubscription = stringStream.listen( | 595 vmSubscription = stringStream.listen( |
595 (String data) { | 596 (String data) { |
596 processVmData(data); | 597 processVmData(data); |
597 }, | 598 }, |
598 onDone: () { | 599 onDone: () { |
599 print("VM debugger connection closed"); | 600 print("VM debugger connection closed"); |
600 quitShell(); | 601 quitShell(); |
601 }, | 602 }, |
602 onError: (err) { | 603 onError: (err) { |
603 print("Error in debug connection: $err"); | 604 print("Error in debug connection: $err"); |
604 // TODO(floitsch): do we want to print the stack trace? | 605 // TODO(floitsch): do we want to print the stack trace? |
605 quitShell(); | 606 quitShell(); |
606 }); | 607 }); |
607 stdinSubscription = stdin.transform(new StringDecoder()) | 608 stdinSubscription = stdin.transform(UTF8.decoder) |
608 .transform(new LineTransformer()) | 609 .transform(new LineSplitter()) |
609 .listen((String line) => processCommand(line)); | 610 .listen((String line) => processCommand(line)); |
610 }); | 611 }); |
611 } | 612 } |
612 | 613 |
613 void main() { | 614 void main() { |
614 Options options = new Options(); | 615 Options options = new Options(); |
615 List<String> arguments = options.arguments; | 616 List<String> arguments = options.arguments; |
616 if (arguments.length > 0) { | 617 if (arguments.length > 0) { |
617 arguments = <String>['--debug', '--verbose_debug']..addAll(arguments); | 618 arguments = <String>['--debug', '--verbose_debug']..addAll(arguments); |
618 Process.start(options.executable, arguments).then((Process process) { | 619 Process.start(options.executable, arguments).then((Process process) { |
619 process.stdin.close(); | 620 process.stdin.close(); |
620 process.exitCode.then((int exitCode) { | 621 process.exitCode.then((int exitCode) { |
621 print('${arguments.join(" ")} exited with $exitCode'); | 622 print('${arguments.join(" ")} exited with $exitCode'); |
622 }); | 623 }); |
623 debuggerMain(); | 624 debuggerMain(); |
624 }); | 625 }); |
625 } else { | 626 } else { |
626 debuggerMain(); | 627 debuggerMain(); |
627 } | 628 } |
628 } | 629 } |
OLD | NEW |