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

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

Issue 1120133002: Rework error handling in the service protocol and in Observatory. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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 | Annotate | Revision Log
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 'observatory_element.dart'; 9 import 'observatory_element.dart';
10 import 'package:observatory/app.dart'; 10 import 'package:observatory/app.dart';
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 alias = 'p'; 110 alias = 'p';
111 } 111 }
112 112
113 Future run(List<String> args) { 113 Future run(List<String> args) {
114 if (args.length < 1) { 114 if (args.length < 1) {
115 debugger.console.print('print expects arguments'); 115 debugger.console.print('print expects arguments');
116 return new Future.value(null); 116 return new Future.value(null);
117 } 117 }
118 var expr = args.join(''); 118 var expr = args.join('');
119 return debugger.isolate.evalFrame(debugger.currentFrame, expr) 119 return debugger.isolate.evalFrame(debugger.currentFrame, expr)
120 .then((response) { 120 .then((ServiceObject response) {
121 if (response is DartError) { 121 if (response is DartError) {
122 debugger.console.print(response.message); 122 debugger.console.print(response.message);
123 } else { 123 } else {
124 debugger.console.print('= ', newline:false); 124 debugger.console.print('= ', newline:false);
125 debugger.console.printRef(response); 125 debugger.console.printRef(response);
126 } 126 }
127 }); 127 });
128 } 128 }
129 129
130 String helpShort = 'Evaluate and print an expression in the current frame'; 130 String helpShort = 'Evaluate and print an expression in the current frame';
131 131
132 String helpLong = 132 String helpLong =
133 'Evaluate and print an expression in the current frame.\n' 133 'Evaluate and print an expression in the current frame.\n'
134 '\n' 134 '\n'
135 'Syntax: print <expression>\n' 135 'Syntax: print <expression>\n'
136 ' p <expression>\n'; 136 ' p <expression>\n';
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 362
363 String helpLong = 363 String helpLong =
364 'Continue running the isolate until the current function exits.\n' 364 'Continue running the isolate until the current function exits.\n'
365 '\n' 365 '\n'
366 'Syntax: finish\n'; 366 'Syntax: finish\n';
367 } 367 }
368 368
369 class BreakCommand extends DebuggerCommand { 369 class BreakCommand extends DebuggerCommand {
370 BreakCommand(Debugger debugger) : super(debugger, 'break', []); 370 BreakCommand(Debugger debugger) : super(debugger, 'break', []);
371 371
372 Future run(List<String> args) { 372 Future run(List<String> args) async {
373 if (args.length > 1) { 373 if (args.length > 1) {
374 debugger.console.print('not implemented'); 374 debugger.console.print('not implemented');
375 return new Future.value(null); 375 return new Future.value(null);
376 } 376 }
377 var arg = (args.length == 0 ? '' : args[0]); 377 var arg = (args.length == 0 ? '' : args[0]);
378 return SourceLocation.parse(debugger, arg).then((loc) { 378 var loc = await SourceLocation.parse(debugger, arg);
379 if (loc.valid) { 379 if (loc.valid) {
380 if (loc.function != null) { 380 if (loc.function != null) {
381 return debugger.isolate.addBreakpointAtEntry(loc.function) 381 try {
382 .then((result) => _handleBreakpointResult(loc, result)); 382 await debugger.isolate.addBreakpointAtEntry(loc.function);
383 } else { 383 } on ServerRpcException catch(e) {
384 assert(loc.script != null); 384 if (e.code == ServerRpcException.kNoBreakAtFunction) {
385 if (loc.col != null) { 385 debugger.console.print('Unable to set breakpoint at ${loc}');
386 // TODO(turnidge): Add tokenPos breakpoint support. 386 } else {
387 debugger.console.print( 387 rethrow;
388 'Ignoring column: '
389 'adding breakpoint at a specific column not yet implemented');
390 } 388 }
391 return debugger.isolate.addBreakpoint(loc.script, loc.line)
392 .then((result) => _handleBreakpointResult(loc, result));
393 } 389 }
394 } else { 390 } else {
395 debugger.console.print(loc.errorMessage); 391 assert(loc.script != null);
392 if (loc.col != null) {
393 // TODO(turnidge): Add tokenPos breakpoint support.
394 debugger.console.print(
395 'Ignoring column: '
396 'adding breakpoint at a specific column not yet implemented');
397 }
398 try {
399 await debugger.isolate.addBreakpoint(loc.script, loc.line);
400 } on ServerRpcException catch(e) {
401 if (e.code == ServerRpcException.kNoBreakAtLine) {
402 debugger.console.print('Unable to set breakpoint at ${loc}');
403 } else {
404 rethrow;
405 }
406 }
396 } 407 }
397 });
398 }
399
400 Future _handleBreakpointResult(loc, result) {
401 if (result is DartError) {
402 debugger.console.print('Unable to set breakpoint at ${loc}');
403 } else { 408 } else {
404 // TODO(turnidge): Adding a duplicate breakpoint is 409 debugger.console.print(loc.errorMessage);
405 // currently ignored. May want to change the protocol to
406 // inform us when this happens.
407 } 410 }
408 return new Future.value(null);
409 } 411 }
410 412
411 Future<List<String>> complete(List<String> args) { 413 Future<List<String>> complete(List<String> args) {
412 if (args.length != 1) { 414 if (args.length != 1) {
413 return new Future.value([args.join('')]); 415 return new Future.value([args.join('')]);
414 } 416 }
415 // TODO - fix SourceLocation complete 417 // TODO - fix SourceLocation complete
416 return new Future.value(SourceLocation.complete(debugger, args[0])); 418 return new Future.value(SourceLocation.complete(debugger, args[0]));
417 } 419 }
418 420
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after
961 console.print('No current isolate'); 963 console.print('No current isolate');
962 } else if (_isolate.idle) { 964 } else if (_isolate.idle) {
963 console.print('Isolate is idle'); 965 console.print('Isolate is idle');
964 } else if (_isolate.running) { 966 } else if (_isolate.running) {
965 console.print("Isolate is running (type 'pause' to interrupt)"); 967 console.print("Isolate is running (type 'pause' to interrupt)");
966 } else if (_isolate.pauseEvent != null) { 968 } else if (_isolate.pauseEvent != null) {
967 _reportPause(_isolate.pauseEvent); 969 _reportPause(_isolate.pauseEvent);
968 } else { 970 } else {
969 console.print('Isolate is in unknown state'); 971 console.print('Isolate is in unknown state');
970 } 972 }
973 warnOutOfDate();
971 } 974 }
972 975
973 void _reportPause(ServiceEvent event) { 976 void _reportPause(ServiceEvent event) {
974 if (event.eventType == ServiceEvent.kPauseStart) { 977 if (event.eventType == ServiceEvent.kPauseStart) {
975 console.print( 978 console.print(
976 "Paused at isolate start (type 'continue' to start the isolate')"); 979 "Paused at isolate start (type 'continue' to start the isolate')");
977 } else if (event.eventType == ServiceEvent.kPauseExit) { 980 } else if (event.eventType == ServiceEvent.kPauseExit) {
978 console.print( 981 console.print(
979 "Paused at isolate exit (type 'continue' to exit the isolate')"); 982 "Paused at isolate exit (type 'continue' to exit the isolate')");
980 } 983 }
981 if (stack['frames'].length > 0) { 984 if (stack['frames'].length > 0) {
982 var frame = stack['frames'][0]; 985 var frame = stack['frames'][0];
983 var script = frame['script']; 986 var script = frame['script'];
984 script.load().then((_) { 987 script.load().then((_) {
985 var line = script.tokenToLine(frame['tokenPos']); 988 var line = script.tokenToLine(frame['tokenPos']);
986 var col = script.tokenToCol(frame['tokenPos']); 989 var col = script.tokenToCol(frame['tokenPos']);
987 if (event.breakpoint != null) { 990 if (event.breakpoint != null) {
988 var bpId = event.breakpoint.number; 991 var bpId = event.breakpoint.number;
989 console.print('Breakpoint ${bpId} at ${script.name}:${line}:${col}'); 992 console.print('Paused at breakpoint ${bpId} at '
993 '${script.name}:${line}:${col}');
990 } else if (event.exception != null) { 994 } else if (event.exception != null) {
991 // TODO(turnidge): Test this. 995 // TODO(turnidge): Test this.
992 console.print( 996 console.print('Paused due to exception ${event.exception} at '
993 'Exception ${event.exception} at ${script.name}:${line}:${col}'); 997 '${script.name}:${line}:${col}');
994 } else { 998 } else {
995 console.print('Paused at ${script.name}:${line}:${col}'); 999 console.print('Paused at ${script.name}:${line}:${col}');
996 } 1000 }
997 }); 1001 });
998 } 1002 }
999 } 1003 }
1000 1004
1001 Future _reportBreakpointEvent(ServiceEvent event) { 1005 Future _reportBreakpointEvent(ServiceEvent event) {
1002 var bpt = event.breakpoint; 1006 var bpt = event.breakpoint;
1003 var verb = null; 1007 var verb = null;
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 String lastCommand; 1142 String lastCommand;
1139 1143
1140 Future run(String command) { 1144 Future run(String command) {
1141 if (command == '' && lastCommand != null) { 1145 if (command == '' && lastCommand != null) {
1142 command = lastCommand; 1146 command = lastCommand;
1143 } 1147 }
1144 console.printBold('\$ $command'); 1148 console.printBold('\$ $command');
1145 return cmd.runCommand(command).then((_) { 1149 return cmd.runCommand(command).then((_) {
1146 lastCommand = command; 1150 lastCommand = command;
1147 }).catchError((e, s) { 1151 }).catchError((e, s) {
1148 console.print('ERROR $e\n$s'); 1152 if (e is NetworkRpcException) {
1153 console.printRed('Unable to execute command because the connection '
1154 'to the VM has been closed');
1155 } else {
1156 if (s != null) {
1157 console.printRed('Internal error: $e\n$s');
1158 } else {
1159 console.printRed('Internal error: $e\n');
1160 }
1161 }
1149 }); 1162 });
1150 } 1163 }
1151 1164
1152 String historyPrev(String command) { 1165 String historyPrev(String command) {
1153 return cmd.historyPrev(command); 1166 return cmd.historyPrev(command);
1154 } 1167 }
1155 1168
1156 String historyNext(String command) { 1169 String historyNext(String command) {
1157 return cmd.historyNext(command); 1170 return cmd.historyNext(command);
1158 } 1171 }
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1344 1357
1345 Set<Script> activeScripts() { 1358 Set<Script> activeScripts() {
1346 var s = new Set<Script>(); 1359 var s = new Set<Script>();
1347 List frameElements = $['frameList'].children; 1360 List frameElements = $['frameList'].children;
1348 for (var frameElement in frameElements) { 1361 for (var frameElement in frameElements) {
1349 s.add(frameElement.children[0].script); 1362 s.add(frameElement.children[0].script);
1350 } 1363 }
1351 return s; 1364 return s;
1352 } 1365 }
1353 1366
1354 doPauseIsolate(_) { 1367 Future doPauseIsolate() {
1355 if (debugger != null) { 1368 if (debugger != null) {
1356 return debugger.isolate.pause(); 1369 return debugger.isolate.pause();
1357 } else { 1370 } else {
1358 return new Future.value(null); 1371 return new Future.value(null);
1359 } 1372 }
1360 } 1373 }
1361 1374
1362 doRefreshStack(_) { 1375 Future doRefreshStack() {
1363 if (debugger != null) { 1376 if (debugger != null) {
1364 return debugger.refreshStack(); 1377 return debugger.refreshStack();
1365 } else { 1378 } else {
1366 return new Future.value(null); 1379 return new Future.value(null);
1367 } 1380 }
1368 } 1381 }
1369 1382
1370 DebuggerStackElement.created() : super.created(); 1383 DebuggerStackElement.created() : super.created();
1371 } 1384 }
1372 1385
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1565 var span = new SpanElement(); 1578 var span = new SpanElement();
1566 span.classes.add('bold'); 1579 span.classes.add('bold');
1567 span.appendText(line); 1580 span.appendText(line);
1568 if (newline) { 1581 if (newline) {
1569 span.appendText('\n'); 1582 span.appendText('\n');
1570 } 1583 }
1571 $['consoleText'].children.add(span); 1584 $['consoleText'].children.add(span);
1572 span.scrollIntoView(); 1585 span.scrollIntoView();
1573 } 1586 }
1574 1587
1588 void printRed(String line, { bool newline:true }) {
1589 var span = new SpanElement();
1590 span.classes.add('red');
1591 span.appendText(line);
1592 if (newline) {
1593 span.appendText('\n');
1594 }
1595 $['consoleText'].children.add(span);
1596 span.scrollIntoView();
1597 }
1598
1575 void printRef(Instance ref, { bool newline:true }) { 1599 void printRef(Instance ref, { bool newline:true }) {
1576 var refElement = new Element.tag('instance-ref'); 1600 var refElement = new Element.tag('instance-ref');
1577 refElement.ref = ref; 1601 refElement.ref = ref;
1578 $['consoleText'].children.add(refElement); 1602 $['consoleText'].children.add(refElement);
1579 if (newline) { 1603 if (newline) {
1580 this.newline(); 1604 this.newline();
1581 } 1605 }
1582 refElement.scrollIntoView(); 1606 refElement.scrollIntoView();
1583 } 1607 }
1584 1608
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1643 default: 1667 default:
1644 busy = false; 1668 busy = false;
1645 break; 1669 break;
1646 } 1670 }
1647 }); 1671 });
1648 } 1672 }
1649 1673
1650 DebuggerInputElement.created() : super.created(); 1674 DebuggerInputElement.created() : super.created();
1651 } 1675 }
1652 1676
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698