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:io"; | 8 import "dart:io"; |
9 import "dart:json" as json; | 9 import "dart:json" as json; |
10 import "dart:utf"; | 10 import "dart:utf"; |
11 import "dart:async"; | 11 import "dart:async"; |
12 | 12 |
13 | 13 |
14 Map<int, Completer> outstandingCommands; | 14 Map<int, Completer> outstandingCommands; |
15 | 15 |
16 Socket vmSock; | 16 Socket vmSock; |
17 String vmData; | 17 String vmData; |
18 StreamSubscription<String> streamSubscription; | 18 var stdinSubscription; |
| 19 var vmSubscription; |
19 int seqNum = 0; | 20 int seqNum = 0; |
20 int isolate_id = -1; | 21 int isolate_id = -1; |
21 | 22 |
22 final verbose = false; | 23 final verbose = false; |
23 final printMessages = false; | 24 final printMessages = false; |
24 | 25 |
25 // The current stack trace, while the VM is paused. It's a list | 26 // The current stack trace, while the VM is paused. It's a list |
26 // of activation frames. | 27 // of activation frames. |
27 List stackTrace; | 28 List stackTrace; |
28 | 29 |
(...skipping 22 matching lines...) Expand all Loading... |
51 gs <lib_id> <script_url> Get source text of script in library | 52 gs <lib_id> <script_url> Get source text of script in library |
52 tok <lib_id> <script_url> Get line and token table of script in library | 53 tok <lib_id> <script_url> Get line and token table of script in library |
53 epi <none|all|unhandled> Set exception pause info | 54 epi <none|all|unhandled> Set exception pause info |
54 i <id> Interrupt execution of given isolate id | 55 i <id> Interrupt execution of given isolate id |
55 h Print help | 56 h Print help |
56 """); | 57 """); |
57 } | 58 } |
58 | 59 |
59 | 60 |
60 void quitShell() { | 61 void quitShell() { |
61 streamSubscription.cancel(); | 62 vmSubscription.cancel(); |
62 vmSock.close(); | 63 vmSock.close(); |
63 stdin.close(); | 64 stdinSubscription.cancel(); |
64 } | 65 } |
65 | 66 |
66 | 67 |
67 Future sendCmd(Map<String, dynamic> cmd) { | 68 Future sendCmd(Map<String, dynamic> cmd) { |
68 var completer = new Completer(); | 69 var completer = new Completer(); |
69 int id = cmd["id"]; | 70 int id = cmd["id"]; |
70 outstandingCommands[id] = completer; | 71 outstandingCommands[id] = completer; |
71 if (verbose) { | 72 if (verbose) { |
72 print("sending: '${json.stringify(cmd)}'"); | 73 print("sending: '${json.stringify(cmd)}'"); |
73 } | 74 } |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 void printStackTrace(List frames) { | 401 void printStackTrace(List frames) { |
401 for (int i = 0; i < frames.length; i++) { | 402 for (int i = 0; i < frames.length; i++) { |
402 printStackFrame(i, frames[i]); | 403 printStackFrame(i, frames[i]); |
403 } | 404 } |
404 } | 405 } |
405 | 406 |
406 | 407 |
407 void handlePausedEvent(msg) { | 408 void handlePausedEvent(msg) { |
408 assert(msg["params"] != null); | 409 assert(msg["params"] != null); |
409 var reason = msg["params"]["reason"]; | 410 var reason = msg["params"]["reason"]; |
410 isolate_id = msg["params"]["isolateId"]; | 411 isolate_id = msg["params"]["id"]; |
411 stackTrace = msg["params"]["callFrames"]; | 412 stackTrace = msg["params"]["callFrames"]; |
412 assert(stackTrace != null); | 413 assert(stackTrace != null); |
413 assert(stackTrace.length >= 1); | 414 assert(stackTrace.length >= 1); |
414 curFrame = stackTrace[0]; | 415 curFrame = stackTrace[0]; |
415 if (reason == "breakpoint") { | 416 if (reason == "breakpoint") { |
416 print("Isolate $isolate_id paused on breakpoint"); | 417 print("Isolate $isolate_id paused on breakpoint"); |
417 } else if (reason == "interrupted") { | 418 } else if (reason == "interrupted") { |
418 print("Isolate $isolate_id paused due to an interrupt"); | 419 print("Isolate $isolate_id paused due to an interrupt"); |
419 } else { | 420 } else { |
420 assert(reason == "exception"); | 421 assert(reason == "exception"); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 } | 563 } |
563 } | 564 } |
564 return 0; | 565 return 0; |
565 } | 566 } |
566 | 567 |
567 | 568 |
568 void debuggerMain() { | 569 void debuggerMain() { |
569 outstandingCommands = new Map<int, Completer>(); | 570 outstandingCommands = new Map<int, Completer>(); |
570 Socket.connect("127.0.0.1", 5858).then((s) { | 571 Socket.connect("127.0.0.1", 5858).then((s) { |
571 vmSock = s; | 572 vmSock = s; |
572 Stream<String> stringStream = vmSock.transform(new StringDecoder()); | 573 var stringStream = vmSock.transform(new StringDecoder()); |
573 streamSubscription = stringStream.listen( | 574 vmSubscription = stringStream.listen( |
574 (String data) { | 575 (String data) { |
575 processVmData(data); | 576 processVmData(data); |
576 }, | 577 }, |
577 onDone: () { | 578 onDone: () { |
578 print("VM debugger connection closed"); | 579 print("VM debugger connection closed"); |
579 quitShell(); | 580 quitShell(); |
580 }, | 581 }, |
581 onError: (err) { | 582 onError: (err) { |
582 print("Error in debug connection: $err"); | 583 print("Error in debug connection: $err"); |
583 quitShell(); | 584 quitShell(); |
584 }); | 585 }); |
585 stdin.transform(new StringDecoder()) | 586 stdinSubscription = stdin.transform(new StringDecoder()) |
586 .transform(new LineTransformer()) | 587 .transform(new LineTransformer()) |
587 .listen((String line) => processCommand(line)); | 588 .listen((String line) => processCommand(line)); |
588 }); | 589 }); |
589 } | 590 } |
590 | 591 |
591 void main() { | 592 void main() { |
592 Options options = new Options(); | 593 Options options = new Options(); |
593 List<String> arguments = options.arguments; | 594 List<String> arguments = options.arguments; |
594 if (arguments.length > 0) { | 595 if (arguments.length > 0) { |
595 arguments = <String>['--debug', '--verbose_debug']..addAll(arguments); | 596 arguments = <String>['--debug', '--verbose_debug']..addAll(arguments); |
596 Process.start(options.executable, arguments).then((Process process) { | 597 Process.start(options.executable, arguments).then((Process process) { |
597 process.stdin.close(); | 598 process.stdin.close(); |
598 process.exitCode.then((int exitCode) { | 599 process.exitCode.then((int exitCode) { |
599 print('${arguments.join(" ")} exited with $exitCode'); | 600 print('${arguments.join(" ")} exited with $exitCode'); |
600 }); | 601 }); |
601 debuggerMain(); | 602 debuggerMain(); |
602 }); | 603 }); |
603 } else { | 604 } else { |
604 debuggerMain(); | 605 debuggerMain(); |
605 } | 606 } |
606 } | 607 } |
OLD | NEW |