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

Side by Side Diff: tools/ddbg.dart

Issue 114923006: Some small changes to isolate handling in ddbg. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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:convert";
9 import "dart:io"; 9 import "dart:io";
10 import "dart:async"; 10 import "dart:async";
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 outstandingCommands[id] = completer; 71 outstandingCommands[id] = completer;
72 if (verbose) { 72 if (verbose) {
73 print("sending: '${JSON.encode(cmd)}'"); 73 print("sending: '${JSON.encode(cmd)}'");
74 } 74 }
75 vmSock.write(JSON.encode(cmd)); 75 vmSock.write(JSON.encode(cmd));
76 return completer.future; 76 return completer.future;
77 } 77 }
78 78
79 79
80 bool checkCurrentIsolate() { 80 bool checkCurrentIsolate() {
81 if (currentIsolate != null) { 81 if (vmSock == null) {
82 return true; 82 print("There is no active script. Try 'help run'.");
83 return false;
83 } 84 }
84 print("Need valid current isolate"); 85 if (currentIsolate == null) {
85 return false; 86 print('There is no current isolate.');
87 return false;
88 }
89 return true;
90 }
91
92
93 void setCurrentIsolate(TargetIsolate isolate) {
94 if (isolate != currentIsolate) {
95 currentIsolate = isolate;
96 if (mainIsolate == null) {
97 print("Main isolate is ${isolate.id}");
98 mainIsolate = isolate;
99 }
100 print("Current isolate is now ${isolate.id}");
101 }
86 } 102 }
87 103
88 104
89 bool checkPaused() { 105 bool checkPaused() {
90 if (!checkCurrentIsolate()) return false; 106 if (!checkCurrentIsolate()) return false;
91 if (currentIsolate.isPaused) return true; 107 if (currentIsolate.isPaused) return true;
92 print("Current isolate must be paused"); 108 print("Current isolate must be paused");
93 return false; 109 return false;
94 } 110 }
95 111
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
519 cmdLine = cmdLine.trim(); 535 cmdLine = cmdLine.trim();
520 var args = cmdLine.split(' '); 536 var args = cmdLine.split(' ');
521 if (args.length == 0) { 537 if (args.length == 0) {
522 return; 538 return;
523 } 539 }
524 var command = args[0]; 540 var command = args[0];
525 541
526 var resume_commands = 542 var resume_commands =
527 { 'r':'resume', 's':'stepOver', 'si':'stepInto', 'so':'stepOut'}; 543 { 'r':'resume', 's':'stepOver', 'si':'stepInto', 'so':'stepOut'};
528 if (resume_commands[command] != null) { 544 if (resume_commands[command] != null) {
529 if (!checkPaused()) return; 545 if (!checkPaused()) {
546 cmdo.show();
547 return;
548 }
530 var cmd = { "id": seqNum, 549 var cmd = { "id": seqNum,
531 "command": resume_commands[command], 550 "command": resume_commands[command],
532 "params": { "isolateId" : currentIsolate.id } }; 551 "params": { "isolateId" : currentIsolate.id } };
533 sendCmd(cmd).then(showPromptAfter(handleResumedResponse)); 552 sendCmd(cmd).then(showPromptAfter(handleResumedResponse));
534 } else if (command == "bt") { 553 } else if (command == "bt") {
554 if (!checkCurrentIsolate()) {
555 cmdo.show();
556 return;
557 }
535 var cmd = { "id": seqNum, 558 var cmd = { "id": seqNum,
536 "command": "getStackTrace", 559 "command": "getStackTrace",
537 "params": { "isolateId" : currentIsolate.id } }; 560 "params": { "isolateId" : currentIsolate.id } };
538 sendCmd(cmd).then(showPromptAfter(handleStackTraceResponse)); 561 sendCmd(cmd).then(showPromptAfter(handleStackTraceResponse));
539 } else if (command == "ll") { 562 } else if (command == "ll") {
563 if (!checkCurrentIsolate()) {
564 cmdo.show();
565 return;
566 }
540 var cmd = { "id": seqNum, 567 var cmd = { "id": seqNum,
541 "command": "getLibraries", 568 "command": "getLibraries",
542 "params": { "isolateId" : currentIsolate.id } }; 569 "params": { "isolateId" : currentIsolate.id } };
543 sendCmd(cmd).then(showPromptAfter(handleGetLibraryResponse)); 570 sendCmd(cmd).then(showPromptAfter(handleGetLibraryResponse));
544 } else if (command == "sbp" && args.length >= 2) { 571 } else if (command == "sbp" && args.length >= 2) {
572 if (!checkCurrentIsolate()) {
573 cmdo.show();
574 return;
575 }
545 var url, line; 576 var url, line;
546 if (args.length == 2 && currentIsolate.pausedLocation != null) { 577 if (args.length == 2 && currentIsolate.pausedLocation != null) {
547 url = currentIsolate.pausedLocation["url"]; 578 url = currentIsolate.pausedLocation["url"];
548 assert(url != null); 579 assert(url != null);
549 line = int.parse(args[1]); 580 line = int.parse(args[1]);
550 } else { 581 } else {
551 url = args[1]; 582 url = args[1];
552 line = int.parse(args[2]); 583 line = int.parse(args[2]);
553 } 584 }
554 var cmd = { "id": seqNum, 585 var cmd = { "id": seqNum,
555 "command": "setBreakpoint", 586 "command": "setBreakpoint",
556 "params": { "isolateId" : currentIsolate.id, 587 "params": { "isolateId" : currentIsolate.id,
557 "url": url, 588 "url": url,
558 "line": line }}; 589 "line": line }};
559 sendCmd(cmd).then(showPromptAfter(handleSetBpResponse)); 590 sendCmd(cmd).then(showPromptAfter(handleSetBpResponse));
560 } else if (command == "rbp" && args.length == 2) { 591 } else if (command == "rbp" && args.length == 2) {
592 if (!checkCurrentIsolate()) {
593 cmdo.show();
594 return;
595 }
561 var cmd = { "id": seqNum, 596 var cmd = { "id": seqNum,
562 "command": "removeBreakpoint", 597 "command": "removeBreakpoint",
563 "params": { "isolateId" : currentIsolate.id, 598 "params": { "isolateId" : currentIsolate.id,
564 "breakpointId": int.parse(args[1]) } }; 599 "breakpointId": int.parse(args[1]) } };
565 sendCmd(cmd).then(showPromptAfter(handleGenericResponse)); 600 sendCmd(cmd).then(showPromptAfter(handleGenericResponse));
566 } else if (command == "ls" && args.length == 2) { 601 } else if (command == "ls" && args.length == 2) {
602 if (!checkCurrentIsolate()) {
603 cmdo.show();
604 return;
605 }
567 var cmd = { "id": seqNum, 606 var cmd = { "id": seqNum,
568 "command": "getScriptURLs", 607 "command": "getScriptURLs",
569 "params": { "isolateId" : currentIsolate.id, 608 "params": { "isolateId" : currentIsolate.id,
570 "libraryId": int.parse(args[1]) } }; 609 "libraryId": int.parse(args[1]) } };
571 sendCmd(cmd).then(showPromptAfter(handleGetScriptsResponse)); 610 sendCmd(cmd).then(showPromptAfter(handleGetScriptsResponse));
572 } else if (command == "eval" && args.length > 3) { 611 } else if (command == "eval" && args.length > 3) {
612 if (!checkCurrentIsolate()) {
613 cmdo.show();
614 return;
615 }
573 var expr = args.getRange(3, args.length).join(" "); 616 var expr = args.getRange(3, args.length).join(" ");
574 var target = args[1]; 617 var target = args[1];
575 if (target == "obj") { 618 if (target == "obj") {
576 target = "objectId"; 619 target = "objectId";
577 } else if (target == "cls") { 620 } else if (target == "cls") {
578 target = "classId"; 621 target = "classId";
579 } else if (target == "lib") { 622 } else if (target == "lib") {
580 target = "libraryId"; 623 target = "libraryId";
581 } else { 624 } else {
582 huh(); 625 huh();
583 return; 626 return;
584 } 627 }
585 var cmd = { "id": seqNum, 628 var cmd = { "id": seqNum,
586 "command": "evaluateExpr", 629 "command": "evaluateExpr",
587 "params": { "isolateId": currentIsolate.id, 630 "params": { "isolateId": currentIsolate.id,
588 target: int.parse(args[2]), 631 target: int.parse(args[2]),
589 "expression": expr } }; 632 "expression": expr } };
590 sendCmd(cmd).then(showPromptAfter(handleEvalResponse)); 633 sendCmd(cmd).then(showPromptAfter(handleEvalResponse));
591 } else if (command == "po" && args.length == 2) { 634 } else if (command == "po" && args.length == 2) {
635 if (!checkCurrentIsolate()) {
636 cmdo.show();
637 return;
638 }
592 var cmd = { "id": seqNum, 639 var cmd = { "id": seqNum,
593 "command": "getObjectProperties", 640 "command": "getObjectProperties",
594 "params": { "isolateId" : currentIsolate.id, 641 "params": { "isolateId" : currentIsolate.id,
595 "objectId": int.parse(args[1]) } }; 642 "objectId": int.parse(args[1]) } };
596 sendCmd(cmd).then(showPromptAfter(handleGetObjPropsResponse)); 643 sendCmd(cmd).then(showPromptAfter(handleGetObjPropsResponse));
597 } else if (command == "pl" && args.length >= 3) { 644 } else if (command == "pl" && args.length >= 3) {
645 if (!checkCurrentIsolate()) {
646 cmdo.show();
647 return;
648 }
598 var cmd; 649 var cmd;
599 if (args.length == 3) { 650 if (args.length == 3) {
600 cmd = { "id": seqNum, 651 cmd = { "id": seqNum,
601 "command": "getListElements", 652 "command": "getListElements",
602 "params": { "isolateId" : currentIsolate.id, 653 "params": { "isolateId" : currentIsolate.id,
603 "objectId": int.parse(args[1]), 654 "objectId": int.parse(args[1]),
604 "index": int.parse(args[2]) } }; 655 "index": int.parse(args[2]) } };
605 } else { 656 } else {
606 cmd = { "id": seqNum, 657 cmd = { "id": seqNum,
607 "command": "getListElements", 658 "command": "getListElements",
608 "params": { "isolateId" : currentIsolate.id, 659 "params": { "isolateId" : currentIsolate.id,
609 "objectId": int.parse(args[1]), 660 "objectId": int.parse(args[1]),
610 "index": int.parse(args[2]), 661 "index": int.parse(args[2]),
611 "length": int.parse(args[3]) } }; 662 "length": int.parse(args[3]) } };
612 } 663 }
613 sendCmd(cmd).then(showPromptAfter(handleGetListResponse)); 664 sendCmd(cmd).then(showPromptAfter(handleGetListResponse));
614 } else if (command == "pc" && args.length == 2) { 665 } else if (command == "pc" && args.length == 2) {
666 if (!checkCurrentIsolate()) {
667 cmdo.show();
668 return;
669 }
615 var cmd = { "id": seqNum, 670 var cmd = { "id": seqNum,
616 "command": "getClassProperties", 671 "command": "getClassProperties",
617 "params": { "isolateId" : currentIsolate.id, 672 "params": { "isolateId" : currentIsolate.id,
618 "classId": int.parse(args[1]) } }; 673 "classId": int.parse(args[1]) } };
619 sendCmd(cmd).then(showPromptAfter(handleGetClassPropsResponse)); 674 sendCmd(cmd).then(showPromptAfter(handleGetClassPropsResponse));
620 } else if (command == "plib" && args.length == 2) { 675 } else if (command == "plib" && args.length == 2) {
676 if (!checkCurrentIsolate()) {
677 cmdo.show();
678 return;
679 }
621 var cmd = { "id": seqNum, 680 var cmd = { "id": seqNum,
622 "command": "getLibraryProperties", 681 "command": "getLibraryProperties",
623 "params": {"isolateId" : currentIsolate.id, 682 "params": {"isolateId" : currentIsolate.id,
624 "libraryId": int.parse(args[1]) } }; 683 "libraryId": int.parse(args[1]) } };
625 sendCmd(cmd).then(showPromptAfter(handleGetLibraryPropsResponse)); 684 sendCmd(cmd).then(showPromptAfter(handleGetLibraryPropsResponse));
626 } else if (command == "slib" && args.length == 3) { 685 } else if (command == "slib" && args.length == 3) {
686 if (!checkCurrentIsolate()) {
687 cmdo.show();
688 return;
689 }
627 var cmd = { "id": seqNum, 690 var cmd = { "id": seqNum,
628 "command": "setLibraryProperties", 691 "command": "setLibraryProperties",
629 "params": {"isolateId" : currentIsolate.id, 692 "params": {"isolateId" : currentIsolate.id,
630 "libraryId": int.parse(args[1]), 693 "libraryId": int.parse(args[1]),
631 "debuggingEnabled": args[2] } }; 694 "debuggingEnabled": args[2] } };
632 sendCmd(cmd).then(showPromptAfter(handleSetLibraryPropsResponse)); 695 sendCmd(cmd).then(showPromptAfter(handleSetLibraryPropsResponse));
633 } else if (command == "pg" && args.length == 2) { 696 } else if (command == "pg" && args.length == 2) {
697 if (!checkCurrentIsolate()) {
698 cmdo.show();
699 return;
700 }
634 var cmd = { "id": seqNum, 701 var cmd = { "id": seqNum,
635 "command": "getGlobalVariables", 702 "command": "getGlobalVariables",
636 "params": { "isolateId" : currentIsolate.id, 703 "params": { "isolateId" : currentIsolate.id,
637 "libraryId": int.parse(args[1]) } }; 704 "libraryId": int.parse(args[1]) } };
638 sendCmd(cmd).then(showPromptAfter(handleGetGlobalVarsResponse)); 705 sendCmd(cmd).then(showPromptAfter(handleGetGlobalVarsResponse));
639 } else if (command == "gs" && args.length == 3) { 706 } else if (command == "gs" && args.length == 3) {
707 if (!checkCurrentIsolate()) {
708 cmdo.show();
709 return;
710 }
640 var cmd = { "id": seqNum, 711 var cmd = { "id": seqNum,
641 "command": "getScriptSource", 712 "command": "getScriptSource",
642 "params": { "isolateId" : currentIsolate.id, 713 "params": { "isolateId" : currentIsolate.id,
643 "libraryId": int.parse(args[1]), 714 "libraryId": int.parse(args[1]),
644 "url": args[2] } }; 715 "url": args[2] } };
645 sendCmd(cmd).then(showPromptAfter(handleGetSourceResponse)); 716 sendCmd(cmd).then(showPromptAfter(handleGetSourceResponse));
646 } else if (command == "tok" && args.length == 3) { 717 } else if (command == "tok" && args.length == 3) {
718 if (!checkCurrentIsolate()) {
719 cmdo.show();
720 return;
721 }
647 var cmd = { "id": seqNum, 722 var cmd = { "id": seqNum,
648 "command": "getLineNumberTable", 723 "command": "getLineNumberTable",
649 "params": { "isolateId" : currentIsolate.id, 724 "params": { "isolateId" : currentIsolate.id,
650 "libraryId": int.parse(args[1]), 725 "libraryId": int.parse(args[1]),
651 "url": args[2] } }; 726 "url": args[2] } };
652 sendCmd(cmd).then(showPromptAfter(handleGetLineTableResponse)); 727 sendCmd(cmd).then(showPromptAfter(handleGetLineTableResponse));
653 } else if (command == "epi" && args.length == 2) { 728 } else if (command == "epi" && args.length == 2) {
729 if (!checkCurrentIsolate()) {
730 cmdo.show();
731 return;
732 }
654 var cmd = { "id": seqNum, 733 var cmd = { "id": seqNum,
655 "command": "setPauseOnException", 734 "command": "setPauseOnException",
656 "params": { "isolateId" : currentIsolate.id, 735 "params": { "isolateId" : currentIsolate.id,
657 "exceptions": args[1] } }; 736 "exceptions": args[1] } };
658 sendCmd(cmd).then(showPromptAfter(handleGenericResponse)); 737 sendCmd(cmd).then(showPromptAfter(handleGenericResponse));
659 } else if (command == "li") { 738 } else if (command == "li") {
739 if (!checkCurrentIsolate()) {
740 cmdo.show();
741 return;
742 }
660 var cmd = { "id": seqNum, "command": "getIsolateIds" }; 743 var cmd = { "id": seqNum, "command": "getIsolateIds" };
661 sendCmd(cmd).then(showPromptAfter(handleGetIsolatesResponse)); 744 sendCmd(cmd).then(showPromptAfter(handleGetIsolatesResponse));
662 } else if (command == "sci" && args.length == 2) { 745 } else if (command == "sci" && args.length == 2) {
663 var id = int.parse(args[1]); 746 var id = int.parse(args[1]);
664 if (targetIsolates[id] != null) { 747 if (targetIsolates[id] != null) {
665 currentIsolate = targetIsolates[id]; 748 setCurrentIsolate(targetIsolates[id]);
666 print("Setting current target isolate to $id");
667 } else { 749 } else {
668 print("$id is not a valid isolate id"); 750 print("$id is not a valid isolate id");
669 } 751 }
670 cmdo.show(); 752 cmdo.show();
671 } else if (command == "i" && args.length == 2) { 753 } else if (command == "i" && args.length == 2) {
672 var cmd = { "id": seqNum, 754 var cmd = { "id": seqNum,
673 "command": "interrupt", 755 "command": "interrupt",
674 "params": { "isolateId": int.parse(args[1]) } }; 756 "params": { "isolateId": int.parse(args[1]) } };
675 sendCmd(cmd).then(showPromptAfter(handleGenericResponse)); 757 sendCmd(cmd).then(showPromptAfter(handleGenericResponse));
676 } else if (command.length == 0) { 758 } else if (command.length == 0) {
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 Future handlePausedEvent(msg) { 1102 Future handlePausedEvent(msg) {
1021 assert(msg["params"] != null); 1103 assert(msg["params"] != null);
1022 var reason = msg["params"]["reason"]; 1104 var reason = msg["params"]["reason"];
1023 int isolateId = msg["params"]["isolateId"]; 1105 int isolateId = msg["params"]["isolateId"];
1024 assert(isolateId != null); 1106 assert(isolateId != null);
1025 var isolate = targetIsolates[isolateId]; 1107 var isolate = targetIsolates[isolateId];
1026 assert(isolate != null); 1108 assert(isolate != null);
1027 assert(!isolate.isPaused); 1109 assert(!isolate.isPaused);
1028 var location = msg["params"]["location"];; 1110 var location = msg["params"]["location"];;
1029 assert(location != null); 1111 assert(location != null);
1112 setCurrentIsolate(isolate);
1030 isolate.pausedLocation = location; 1113 isolate.pausedLocation = location;
1031 if (reason == "breakpoint") { 1114 if (reason == "breakpoint") {
1032 var bpId = (msg["params"]["breakpointId"]); 1115 var bpId = (msg["params"]["breakpointId"]);
1033 var label = (bpId != null) ? "Breakpoint $bpId" : null; 1116 var label = (bpId != null) ? "Breakpoint $bpId" : null;
1034 return printLocation(label, location); 1117 return printLocation(label, location);
1035 } else if (reason == "interrupted") { 1118 } else if (reason == "interrupted") {
1036 return printLocation("Interrupted", location); 1119 return printLocation("Interrupted", location);
1037 } else { 1120 } else {
1038 assert(reason == "exception"); 1121 assert(reason == "exception");
1039 var excObj = msg["params"]["exception"]; 1122 var excObj = msg["params"]["exception"];
1040 print("Isolate $isolateId paused on exception"); 1123 print("Isolate $isolateId paused on exception");
1041 print(remoteObject(excObj)); 1124 print(remoteObject(excObj));
1042 return new Future.value(); 1125 return new Future.value();
1043 } 1126 }
1044 } 1127 }
1045 1128
1046 void handleIsolateEvent(msg) { 1129 void handleIsolateEvent(msg) {
1047 Map params = msg["params"]; 1130 Map params = msg["params"];
1048 assert(params != null); 1131 assert(params != null);
1049 var isolateId = params["id"]; 1132 var isolateId = params["id"];
1050 var reason = params["reason"]; 1133 var reason = params["reason"];
1051 if (reason == "created") { 1134 if (reason == "created") {
1052 print("Isolate $isolateId has been created."); 1135 print("Isolate $isolateId has been created.");
1053 assert(targetIsolates[isolateId] == null); 1136 assert(targetIsolates[isolateId] == null);
1054 targetIsolates[isolateId] = new TargetIsolate(isolateId); 1137 targetIsolates[isolateId] = new TargetIsolate(isolateId);
1055 if (mainIsolate == null) {
1056 mainIsolate = targetIsolates[isolateId];
1057 currentIsolate = mainIsolate;
1058 print("Current isolate set to ${currentIsolate.id}.");
1059 }
1060 } else { 1138 } else {
1061 assert(reason == "shutdown"); 1139 assert(reason == "shutdown");
1062 var isolate = targetIsolates.remove(isolateId); 1140 var isolate = targetIsolates.remove(isolateId);
1063 assert(isolate != null); 1141 assert(isolate != null);
1064 if (isolate == mainIsolate) { 1142 if (isolate == mainIsolate) {
1065 mainIsolate = null; 1143 mainIsolate = null;
1066 print("Main isolate ${isolate.id} has terminated."); 1144 print("Main isolate ${isolate.id} has terminated.");
1067 } else { 1145 } else {
1068 print("Isolate ${isolate.id} has terminated."); 1146 print("Isolate ${isolate.id} has terminated.");
1069 } 1147 }
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1404 handleUncaughtError: debuggerError)); 1482 handleUncaughtError: debuggerError));
1405 1483
1406 zone.run(() { 1484 zone.run(() {
1407 parseArgs(args); 1485 parseArgs(args);
1408 cmdo = new Commando(completer: debuggerCommandCompleter); 1486 cmdo = new Commando(completer: debuggerCommandCompleter);
1409 cmdSubscription = cmdo.commands.listen(processCommand, 1487 cmdSubscription = cmdo.commands.listen(processCommand,
1410 onError: processError, 1488 onError: processError,
1411 onDone: processDone); 1489 onDone: processDone);
1412 }); 1490 });
1413 } 1491 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698