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

Side by Side Diff: runtime/observatory/lib/src/elements/debugger.dart

Issue 1398823002: We can now name the current VM using the service protocol. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 months 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 debugger_page_element; 5 library debugger_page_element;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:html'; 8 import 'dart:html';
9 import 'dart:math';
9 import 'observatory_element.dart'; 10 import 'observatory_element.dart';
10 import 'package:observatory/app.dart'; 11 import 'package:observatory/app.dart';
11 import 'package:observatory/cli.dart'; 12 import 'package:observatory/cli.dart';
12 import 'package:observatory/debugger.dart'; 13 import 'package:observatory/debugger.dart';
13 import 'package:observatory/service.dart'; 14 import 'package:observatory/service.dart';
14 import 'package:logging/logging.dart'; 15 import 'package:logging/logging.dart';
15 import 'package:polymer/polymer.dart'; 16 import 'package:polymer/polymer.dart';
16 17
17 // TODO(turnidge): Move Debugger, DebuggerCommand to debugger library. 18 // TODO(turnidge): Move Debugger, DebuggerCommand to debugger library.
18 abstract class DebuggerCommand extends Command { 19 abstract class DebuggerCommand extends Command {
(...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 for (var isolate in debugger.vm.isolates) { 957 for (var isolate in debugger.vm.isolates) {
957 if (isolate.name.startsWith(args[0])) { 958 if (isolate.name.startsWith(args[0])) {
958 result.add('${isolate.name} '); 959 result.add('${isolate.name} ');
959 } 960 }
960 } 961 }
961 return new Future.value(result); 962 return new Future.value(result);
962 } 963 }
963 String helpShort = 'Switch the current isolate'; 964 String helpShort = 'Switch the current isolate';
964 965
965 String helpLong = 966 String helpLong =
966 'Switch the current isolate.\n' 967 'Switch, list, or rename isolates.\n'
967 '\n' 968 '\n'
968 'Syntax: isolate <number>\n' 969 'Syntax: isolate <number>\n'
969 ' isolate <name>\n'; 970 ' isolate <name>\n';
970 } 971 }
971 972
972 String _isolateRunState(Isolate isolate) { 973 String _isolateRunState(Isolate isolate) {
973 if (isolate.paused) { 974 if (isolate.paused) {
974 return 'paused'; 975 return 'paused';
975 } else if (isolate.running) { 976 } else if (isolate.running) {
976 return 'running'; 977 return 'running';
(...skipping 16 matching lines...) Expand all
993 994
994 // Refresh all isolates first. 995 // Refresh all isolates first.
995 var pending = []; 996 var pending = [];
996 for (var isolate in debugger.vm.isolates) { 997 for (var isolate in debugger.vm.isolates) {
997 pending.add(isolate.reload()); 998 pending.add(isolate.reload());
998 } 999 }
999 await Future.wait(pending); 1000 await Future.wait(pending);
1000 1001
1001 const maxIdLen = 9; 1002 const maxIdLen = 9;
1002 const maxRunStateLen = 7; 1003 const maxRunStateLen = 7;
1003 var maxNameLen = 0; 1004 var maxNameLen = 'NAME'.length;
1004 for (var isolate in debugger.vm.isolates) { 1005 for (var isolate in debugger.vm.isolates) {
1005 if (isolate.name.length > maxNameLen) { 1006 maxNameLen = max(maxNameLen, isolate.name.length);
1006 maxNameLen = isolate.name.length;
1007 }
1008 } 1007 }
1009 1008
1010 debugger.console.print("${'ID'.padLeft(maxIdLen, ' ')} " 1009 debugger.console.print("${'ID'.padLeft(maxIdLen, ' ')} "
1011 "${'ORIGIN'.padLeft(maxIdLen, ' ')} " 1010 "${'ORIGIN'.padLeft(maxIdLen, ' ')} "
1012 "${'NAME'.padRight(maxNameLen, ' ')} " 1011 "${'NAME'.padRight(maxNameLen, ' ')} "
1013 "${'STATE'.padRight(maxRunStateLen, ' ')} " 1012 "${'STATE'.padRight(maxRunStateLen, ' ')} "
1014 "CURRENT"); 1013 "CURRENT");
1015 for (var isolate in debugger.vm.isolates) { 1014 for (var isolate in debugger.vm.isolates) {
1016 String current = (isolate == debugger.isolate ? '*' : ''); 1015 String current = (isolate == debugger.isolate ? '*' : '');
1017 debugger.console.print( 1016 debugger.console.print(
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 } 1117 }
1119 1118
1120 String helpShort = 'Refresh debugging information of various sorts'; 1119 String helpShort = 'Refresh debugging information of various sorts';
1121 1120
1122 String helpLong = 1121 String helpLong =
1123 'Refresh debugging information of various sorts.\n' 1122 'Refresh debugging information of various sorts.\n'
1124 '\n' 1123 '\n'
1125 'Syntax: refresh <subcommand>\n'; 1124 'Syntax: refresh <subcommand>\n';
1126 } 1125 }
1127 1126
1127 class VmListCommand extends DebuggerCommand {
1128 VmListCommand(Debugger debugger) : super(debugger, 'list', []);
1129
1130 Future run(List<String> args) async {
1131 if (args.length > 0) {
1132 debugger.console.print('vm list expects no arguments');
1133 return;
1134 }
1135 if (debugger.vm == null) {
1136 debugger.console.print("No connected VMs");
1137 return;
1138 }
1139 // TODO(turnidge): Right now there is only one vm listed.
1140 var vmList = [debugger.vm];
1141
1142 var maxAddrLen = 'ADDRESS'.length;
1143 var maxNameLen = 'NAME'.length;
1144
1145 for (var vm in vmList) {
1146 maxAddrLen = max(maxAddrLen, vm.target.networkAddress.length);
1147 maxNameLen = max(maxNameLen, vm.name.length);
1148 }
1149
1150 debugger.console.print("${'ADDRESS'.padRight(maxAddrLen, ' ')} "
1151 "${'NAME'.padRight(maxNameLen, ' ')} "
1152 "CURRENT");
1153 for (var vm in vmList) {
1154 String current = (vm == debugger.vm ? '*' : '');
1155 debugger.console.print(
1156 "${vm.target.networkAddress.padRight(maxAddrLen, ' ')} "
1157 "${vm.name.padRight(maxNameLen, ' ')} "
1158 "${current}");
1159 }
1160 }
1161
1162 String helpShort = 'List all connected Dart virtual machines';
1163
1164 String helpLong =
1165 'List all connected Dart virtual machines..\n'
1166 '\n'
1167 'Syntax: vm list\n';
1168 }
1169
1170 class VmNameCommand extends DebuggerCommand {
1171 VmNameCommand(Debugger debugger) : super(debugger, 'name', []);
1172
1173 Future run(List<String> args) async {
1174 if (args.length != 1) {
1175 debugger.console.print('vm name expects one argument');
1176 return;
1177 }
1178 if (debugger.vm == null) {
1179 debugger.console.print('There is no current vm');
1180 return;
1181 }
1182 await debugger.vm.setName(args[0]);
1183 }
1184
1185 String helpShort = 'Rename the current Dart virtual machine';
1186
1187 String helpLong =
1188 'Rename the current Dart virtual machine.\n'
1189 '\n'
1190 'Syntax: vm name <name>\n';
1191 }
1192
1128 class VmRestartCommand extends DebuggerCommand { 1193 class VmRestartCommand extends DebuggerCommand {
1129 VmRestartCommand(Debugger debugger) : super(debugger, 'restart', []); 1194 VmRestartCommand(Debugger debugger) : super(debugger, 'restart', []);
1130 1195
1131 Future handleModalInput(String line) async { 1196 Future handleModalInput(String line) async {
1132 if (line == 'yes') { 1197 if (line == 'yes') {
1133 debugger.console.printRed('Restarting VM...'); 1198 debugger.console.printRed('Restarting VM...');
1134 await debugger.vm.restart(); 1199 await debugger.vm.restart();
1135 debugger.input.exitMode(); 1200 debugger.input.exitMode();
1136 } else if (line == 'no') { 1201 } else if (line == 'no') {
1137 debugger.console.printRed('VM restart canceled.'); 1202 debugger.console.printRed('VM restart canceled.');
(...skipping 10 matching lines...) Expand all
1148 String helpShort = 'Restart a Dart virtual machine'; 1213 String helpShort = 'Restart a Dart virtual machine';
1149 1214
1150 String helpLong = 1215 String helpLong =
1151 'Restart a Dart virtual machine.\n' 1216 'Restart a Dart virtual machine.\n'
1152 '\n' 1217 '\n'
1153 'Syntax: vm restart\n'; 1218 'Syntax: vm restart\n';
1154 } 1219 }
1155 1220
1156 class VmCommand extends DebuggerCommand { 1221 class VmCommand extends DebuggerCommand {
1157 VmCommand(Debugger debugger) : super(debugger, 'vm', [ 1222 VmCommand(Debugger debugger) : super(debugger, 'vm', [
1223 new VmListCommand(debugger),
1224 new VmNameCommand(debugger),
1158 new VmRestartCommand(debugger), 1225 new VmRestartCommand(debugger),
1159 ]); 1226 ]);
1160 1227
1161 Future run(List<String> args) async { 1228 Future run(List<String> args) async {
1162 debugger.console.print("'vm' expects a subcommand (see 'help vm')"); 1229 debugger.console.print("'vm' expects a subcommand (see 'help vm')");
1163 } 1230 }
1164 1231
1165 String helpShort = 'Manage a Dart virtual machine'; 1232 String helpShort = 'Manage a Dart virtual machine';
1166 1233
1167 String helpLong = 1234 String helpLong =
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
1510 console.print( 1577 console.print(
1511 'Breakpoint ${bpId} ${verb} at ${locString}'); 1578 'Breakpoint ${bpId} ${verb} at ${locString}');
1512 } else { 1579 } else {
1513 console.print( 1580 console.print(
1514 'Future breakpoint ${bpId} ${verb} at ${locString}'); 1581 'Future breakpoint ${bpId} ${verb} at ${locString}');
1515 } 1582 }
1516 } 1583 }
1517 1584
1518 void onEvent(ServiceEvent event) { 1585 void onEvent(ServiceEvent event) {
1519 switch(event.kind) { 1586 switch(event.kind) {
1587 case ServiceEvent.kVMUpdate:
1588 var vm = event.owner;
1589 console.print("VM ${vm.target.networkAddress} renamed to '${vm.name}'");
1590 break;
1591
1520 case ServiceEvent.kIsolateStart: 1592 case ServiceEvent.kIsolateStart:
1521 { 1593 {
1522 var iso = event.owner; 1594 var iso = event.owner;
1523 console.print( 1595 console.print(
1524 "Isolate ${iso.number} '${iso.name}' has been created"); 1596 "Isolate ${iso.number} '${iso.name}' has been created");
1525 if (isolate == null) { 1597 if (isolate == null) {
1526 console.print("Switching to isolate ${iso.number} '${iso.name}'"); 1598 console.print("Switching to isolate ${iso.number} '${iso.name}'");
1527 isolate = iso; 1599 isolate = iso;
1528 } 1600 }
1529 } 1601 }
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1802 isolateChanged(oldValue) { 1874 isolateChanged(oldValue) {
1803 debugger.updateIsolate(isolate); 1875 debugger.updateIsolate(isolate);
1804 } 1876 }
1805 ObservatoryDebugger debugger = new ObservatoryDebugger(); 1877 ObservatoryDebugger debugger = new ObservatoryDebugger();
1806 1878
1807 DebuggerPageElement.created() : super.created() { 1879 DebuggerPageElement.created() : super.created() {
1808 debugger.page = this; 1880 debugger.page = this;
1809 } 1881 }
1810 1882
1811 StreamSubscription _resizeSubscription; 1883 StreamSubscription _resizeSubscription;
1884 Future<StreamSubscription> _vmSubscriptionFuture;
1812 Future<StreamSubscription> _isolateSubscriptionFuture; 1885 Future<StreamSubscription> _isolateSubscriptionFuture;
1813 Future<StreamSubscription> _debugSubscriptionFuture; 1886 Future<StreamSubscription> _debugSubscriptionFuture;
1814 Future<StreamSubscription> _stdoutSubscriptionFuture; 1887 Future<StreamSubscription> _stdoutSubscriptionFuture;
1815 Future<StreamSubscription> _stderrSubscriptionFuture; 1888 Future<StreamSubscription> _stderrSubscriptionFuture;
1816 Future<StreamSubscription> _logSubscriptionFuture; 1889 Future<StreamSubscription> _logSubscriptionFuture;
1817 1890
1818 @override 1891 @override
1819 void attached() { 1892 void attached() {
1820 super.attached(); 1893 super.attached();
1821 _onResize(null); 1894 _onResize(null);
1822 1895
1823 // Wire the debugger object to the stack, console, and command line. 1896 // Wire the debugger object to the stack, console, and command line.
1824 var stackElement = $['stackElement']; 1897 var stackElement = $['stackElement'];
1825 debugger.stackElement = stackElement; 1898 debugger.stackElement = stackElement;
1826 stackElement.debugger = debugger; 1899 stackElement.debugger = debugger;
1827 debugger.console = $['console']; 1900 debugger.console = $['console'];
1828 debugger.input = $['commandline']; 1901 debugger.input = $['commandline'];
1829 debugger.input.debugger = debugger; 1902 debugger.input.debugger = debugger;
1830 debugger.init(); 1903 debugger.init();
1831 1904
1832 _resizeSubscription = window.onResize.listen(_onResize); 1905 _resizeSubscription = window.onResize.listen(_onResize);
1906 _vmSubscriptionFuture =
1907 app.vm.listenEventStream(VM.kVMStream, debugger.onEvent);
1833 _isolateSubscriptionFuture = 1908 _isolateSubscriptionFuture =
1834 app.vm.listenEventStream(VM.kIsolateStream, debugger.onEvent); 1909 app.vm.listenEventStream(VM.kIsolateStream, debugger.onEvent);
1835 _debugSubscriptionFuture = 1910 _debugSubscriptionFuture =
1836 app.vm.listenEventStream(VM.kDebugStream, debugger.onEvent); 1911 app.vm.listenEventStream(VM.kDebugStream, debugger.onEvent);
1837 _stdoutSubscriptionFuture = 1912 _stdoutSubscriptionFuture =
1838 app.vm.listenEventStream(VM.kStdoutStream, debugger.onStdout); 1913 app.vm.listenEventStream(VM.kStdoutStream, debugger.onStdout);
1839 if (_stdoutSubscriptionFuture != null) { 1914 if (_stdoutSubscriptionFuture != null) {
1840 // TODO(turnidge): How do we want to handle this in general? 1915 // TODO(turnidge): How do we want to handle this in general?
1841 _stdoutSubscriptionFuture.catchError((e, st) { 1916 _stdoutSubscriptionFuture.catchError((e, st) {
1842 Logger.root.info('Failed to subscribe to stdout: $e\n$st\n'); 1917 Logger.root.info('Failed to subscribe to stdout: $e\n$st\n');
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1885 int available = windowHeight - fixedHeight; 1960 int available = windowHeight - fixedHeight;
1886 int stackHeight = available ~/ 1.6; 1961 int stackHeight = available ~/ 1.6;
1887 stackDiv.style.setProperty('height', '${stackHeight}px'); 1962 stackDiv.style.setProperty('height', '${stackHeight}px');
1888 } 1963 }
1889 1964
1890 @override 1965 @override
1891 void detached() { 1966 void detached() {
1892 debugger.isolate = null; 1967 debugger.isolate = null;
1893 _resizeSubscription.cancel(); 1968 _resizeSubscription.cancel();
1894 _resizeSubscription = null; 1969 _resizeSubscription = null;
1970 cancelFutureSubscription(_vmSubscriptionFuture);
1971 _vmSubscriptionFuture = null;
1895 cancelFutureSubscription(_isolateSubscriptionFuture); 1972 cancelFutureSubscription(_isolateSubscriptionFuture);
1896 _isolateSubscriptionFuture = null; 1973 _isolateSubscriptionFuture = null;
1897 cancelFutureSubscription(_debugSubscriptionFuture); 1974 cancelFutureSubscription(_debugSubscriptionFuture);
1898 _debugSubscriptionFuture = null; 1975 _debugSubscriptionFuture = null;
1899 cancelFutureSubscription(_stdoutSubscriptionFuture); 1976 cancelFutureSubscription(_stdoutSubscriptionFuture);
1900 _stdoutSubscriptionFuture = null; 1977 _stdoutSubscriptionFuture = null;
1901 cancelFutureSubscription(_stderrSubscriptionFuture); 1978 cancelFutureSubscription(_stderrSubscriptionFuture);
1902 _stderrSubscriptionFuture = null; 1979 _stderrSubscriptionFuture = null;
1903 cancelFutureSubscription(_logSubscriptionFuture); 1980 cancelFutureSubscription(_logSubscriptionFuture);
1904 _logSubscriptionFuture = null; 1981 _logSubscriptionFuture = null;
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
2492 } 2569 }
2493 }); 2570 });
2494 } 2571 }
2495 2572
2496 void focus() { 2573 void focus() {
2497 $['textBox'].focus(); 2574 $['textBox'].focus();
2498 } 2575 }
2499 2576
2500 DebuggerInputElement.created() : super.created(); 2577 DebuggerInputElement.created() : super.created();
2501 } 2578 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698