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

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

Issue 1312763010: Support column-based breakpoints in the VM and Observatory. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: hausner review Created 5 years, 3 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 'observatory_element.dart'; 9 import 'observatory_element.dart';
10 import 'package:observatory/app.dart'; 10 import 'package:observatory/app.dart';
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
630 ' set <option> # Get current value for option\n' 630 ' set <option> # Get current value for option\n'
631 ' set <option> <value> # Set value for option'; 631 ' set <option> <value> # Set value for option';
632 } 632 }
633 633
634 class BreakCommand extends DebuggerCommand { 634 class BreakCommand extends DebuggerCommand {
635 BreakCommand(Debugger debugger) : super(debugger, 'break', []); 635 BreakCommand(Debugger debugger) : super(debugger, 'break', []);
636 636
637 Future run(List<String> args) async { 637 Future run(List<String> args) async {
638 if (args.length > 1) { 638 if (args.length > 1) {
639 debugger.console.print('not implemented'); 639 debugger.console.print('not implemented');
640 return new Future.value(null); 640 return;
641 } 641 }
642 var arg = (args.length == 0 ? '' : args[0]); 642 var arg = (args.length == 0 ? '' : args[0]);
643 var loc = await DebuggerLocation.parse(debugger, arg); 643 var loc = await DebuggerLocation.parse(debugger, arg);
644 if (loc.valid) { 644 if (loc.valid) {
645 if (loc.function != null) { 645 if (loc.function != null) {
646 try { 646 try {
647 await debugger.isolate.addBreakpointAtEntry(loc.function); 647 await debugger.isolate.addBreakpointAtEntry(loc.function);
648 } on ServerRpcException catch(e) { 648 } on ServerRpcException catch(e) {
649 if (e.code == ServerRpcException.kCannotAddBreakpoint) { 649 if (e.code == ServerRpcException.kCannotAddBreakpoint) {
650 debugger.console.print('Unable to set breakpoint at ${loc}'); 650 debugger.console.print('Unable to set breakpoint at ${loc}');
651 } else { 651 } else {
652 rethrow; 652 rethrow;
653 } 653 }
654 } 654 }
655 } else { 655 } else {
656 assert(loc.script != null); 656 assert(loc.script != null);
657 if (loc.col != null) { 657 var script = loc.script;
658 // TODO(turnidge): Add tokenPos breakpoint support. 658 await script.load();
659 if (loc.line < 1 || loc.line > script.lines.length) {
659 debugger.console.print( 660 debugger.console.print(
660 'Ignoring column: ' 661 'line number must be in range [1,${script.lines.length}]');
661 'adding breakpoint at a specific column not yet implemented'); 662 return;
662 } 663 }
663 try { 664 try {
664 await debugger.isolate.addBreakpoint(loc.script, loc.line); 665 await debugger.isolate.addBreakpoint(script, loc.line, loc.col);
665 } on ServerRpcException catch(e) { 666 } on ServerRpcException catch(e) {
666 if (e.code == ServerRpcException.kCannotAddBreakpoint) { 667 if (e.code == ServerRpcException.kCannotAddBreakpoint) {
667 debugger.console.print('Unable to set breakpoint at ${loc}'); 668 debugger.console.print('Unable to set breakpoint at ${loc}');
668 } else { 669 } else {
669 rethrow; 670 rethrow;
670 } 671 }
671 } 672 }
672 } 673 }
673 } else { 674 } else {
674 debugger.console.print(loc.errorMessage); 675 debugger.console.print(loc.errorMessage);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 ' (e.g \'break test.dart:11:8\')\n' 712 ' (e.g \'break test.dart:11:8\')\n'
712 ' break <function> ' 713 ' break <function> '
713 '# Break at the named function\n' 714 '# Break at the named function\n'
714 ' ' 715 ' '
715 ' (e.g \'break main\' or \'break Class.someFunction\')\n'; 716 ' (e.g \'break main\' or \'break Class.someFunction\')\n';
716 } 717 }
717 718
718 class ClearCommand extends DebuggerCommand { 719 class ClearCommand extends DebuggerCommand {
719 ClearCommand(Debugger debugger) : super(debugger, 'clear', []); 720 ClearCommand(Debugger debugger) : super(debugger, 'clear', []);
720 721
721 Future run(List<String> args) { 722 Future run(List<String> args) async {
722 if (args.length > 1) { 723 if (args.length > 1) {
723 debugger.console.print('not implemented'); 724 debugger.console.print('not implemented');
724 return new Future.value(null); 725 return;
725 } 726 }
726 var arg = (args.length == 0 ? '' : args[0]); 727 var arg = (args.length == 0 ? '' : args[0]);
727 return DebuggerLocation.parse(debugger, arg).then((loc) { 728 var loc = await DebuggerLocation.parse(debugger, arg);
728 if (loc.valid) { 729 if (!loc.valid) {
729 if (loc.function != null) { 730 debugger.console.print(loc.errorMessage);
730 debugger.console.print( 731 return;
731 'Ignoring breakpoint at $loc: ' 732 }
732 'Function entry breakpoints not yet implemented'); 733 if (loc.function != null) {
733 return null; 734 debugger.console.print(
734 } 735 'Ignoring breakpoint at $loc: '
735 if (loc.col != null) { 736 'Clearing function breakpoints not yet implemented');
736 // TODO(turnidge): Add tokenPos clear support. 737 return;
737 debugger.console.print( 738 }
738 'Ignoring column: '
739 'clearing breakpoint at a specific column not yet implemented');
740 }
741 739
742 for (var bpt in debugger.isolate.breakpoints.values) { 740 var script = loc.script;
743 var script = bpt.location.script; 741 if (loc.line < 1 || loc.line > script.lines.length) {
744 if (script.id == loc.script.id) { 742 debugger.console.print(
745 assert(script.loaded); 743 'line number must be in range [1,${script.lines.length}]');
746 var line = script.tokenToLine(bpt.location.tokenPos); 744 return;
747 if (line == loc.line) { 745 }
748 return debugger.isolate.removeBreakpoint(bpt).then((result) { 746 var lineInfo = script.getLine(loc.line);
749 if (result is DartError) { 747 var bpts = lineInfo.breakpoints;
750 debugger.console.print( 748 var foundBreakpoint = false;
751 'Unable to clear breakpoint at ${loc}: ${result.message}') ; 749 if (bpts != null) {
752 return; 750 var bptList = bpts.toList();
753 } 751 for (var bpt in bptList) {
754 }); 752 if (loc.col == null ||
755 } 753 loc.col == script.tokenToCol(bpt.location.tokenPos)) {
754 foundBreakpoint = true;
755 var result = await debugger.isolate.removeBreakpoint(bpt);
756 if (result is DartError) {
757 debugger.console.print(
758 'Error clearing breakpoint ${bpt.number}: ${result.message}');
756 } 759 }
757 } 760 }
758 debugger.console.print('No breakpoint found at ${loc}');
759 } else {
760 debugger.console.print(loc.errorMessage);
761 } 761 }
762 }); 762 }
763 if (!foundBreakpoint) {
764 debugger.console.print('No breakpoint found at ${loc}');
765 }
763 } 766 }
764 767
765 Future<List<String>> complete(List<String> args) { 768 Future<List<String>> complete(List<String> args) {
766 if (args.length != 1) { 769 if (args.length != 1) {
767 return new Future.value([args.join('')]); 770 return new Future.value([args.join('')]);
768 } 771 }
769 return new Future.value(DebuggerLocation.complete(debugger, args[0])); 772 return new Future.value(DebuggerLocation.complete(debugger, args[0]));
770 } 773 }
771 774
772 String helpShort = 'Remove a breakpoint by source location or function name' 775 String helpShort = 'Remove a breakpoint by source location or function name'
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 'Remove a breakpoint by breakpoint id.\n' 842 'Remove a breakpoint by breakpoint id.\n'
840 '\n' 843 '\n'
841 'Syntax: delete <bp-id>\n' 844 'Syntax: delete <bp-id>\n'
842 ' delete <bp-id> <bp-id> ...\n'; 845 ' delete <bp-id> <bp-id> ...\n';
843 } 846 }
844 847
845 class InfoBreakpointsCommand extends DebuggerCommand { 848 class InfoBreakpointsCommand extends DebuggerCommand {
846 InfoBreakpointsCommand(Debugger debugger) 849 InfoBreakpointsCommand(Debugger debugger)
847 : super(debugger, 'breakpoints', []); 850 : super(debugger, 'breakpoints', []);
848 851
849 Future run(List<String> args) { 852 Future run(List<String> args) async {
850 if (debugger.isolate.breakpoints.isEmpty) { 853 if (debugger.isolate.breakpoints.isEmpty) {
851 debugger.console.print('No breakpoints'); 854 debugger.console.print('No breakpoints');
852 } 855 }
853 List bpts = debugger.isolate.breakpoints.values.toList(); 856 List bpts = debugger.isolate.breakpoints.values.toList();
854 bpts.sort((a, b) => a.number - b.number); 857 bpts.sort((a, b) => a.number - b.number);
855 for (var bpt in bpts) { 858 for (var bpt in bpts) {
856 var bpId = bpt.number; 859 var bpId = bpt.number;
857 var script = bpt.location.script; 860 var locString = await bpt.location.toUserString();
858 var tokenPos = bpt.location.tokenPos;
859 var line = script.tokenToLine(tokenPos);
860 var col = script.tokenToCol(tokenPos);
861 if (!bpt.resolved) { 861 if (!bpt.resolved) {
862 debugger.console.print( 862 debugger.console.print(
863 'Future breakpoint ${bpId} at ${script.name}:${line}:${col}'); 863 'Future breakpoint ${bpId} at ${locString}');
864 } else { 864 } else {
865 debugger.console.print( 865 debugger.console.print(
866 'Breakpoint ${bpId} at ${script.name}:${line}:${col}'); 866 'Breakpoint ${bpId} at ${locString}');
867 } 867 }
868 } 868 }
869 return new Future.value(null);
870 } 869 }
871 870
872 String helpShort = 'List all breakpoints'; 871 String helpShort = 'List all breakpoints';
873 872
874 String helpLong = 873 String helpLong =
875 'List all breakpoints.\n' 874 'List all breakpoints.\n'
876 '\n' 875 '\n'
877 'Syntax: info breakpoints\n'; 876 'Syntax: info breakpoints\n';
878 } 877 }
879 878
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
1381 // paused-at-isolate-exit. Maybe we shutdown part of the debugger too 1380 // paused-at-isolate-exit. Maybe we shutdown part of the debugger too
1382 // soon? 1381 // soon?
1383 console.printRef(event.exception); 1382 console.printRef(event.exception);
1384 } else { 1383 } else {
1385 console.print('Paused at ${script.name}:${line}:${col}'); 1384 console.print('Paused at ${script.name}:${line}:${col}');
1386 } 1385 }
1387 }); 1386 });
1388 } 1387 }
1389 } 1388 }
1390 1389
1391 Future _reportBreakpointEvent(ServiceEvent event) { 1390 Future _reportBreakpointEvent(ServiceEvent event) async {
1392 var bpt = event.breakpoint; 1391 var bpt = event.breakpoint;
1393 var verb = null; 1392 var verb = null;
1394 switch (event.kind) { 1393 switch (event.kind) {
1395 case ServiceEvent.kBreakpointAdded: 1394 case ServiceEvent.kBreakpointAdded:
1396 verb = 'added'; 1395 verb = 'added';
1397 break; 1396 break;
1398 case ServiceEvent.kBreakpointResolved: 1397 case ServiceEvent.kBreakpointResolved:
1399 verb = 'resolved'; 1398 verb = 'resolved';
1400 break; 1399 break;
1401 case ServiceEvent.kBreakpointRemoved: 1400 case ServiceEvent.kBreakpointRemoved:
1402 verb = 'removed'; 1401 verb = 'removed';
1403 break; 1402 break;
1404 default: 1403 default:
1405 break; 1404 break;
1406 } 1405 }
1407 var script = bpt.location.script; 1406 var script = bpt.location.script;
1408 return script.load().then((_) { 1407 await script.load();
1409 var bpId = bpt.number; 1408
1410 var tokenPos = bpt.location.tokenPos; 1409 var bpId = bpt.number;
1411 var line = script.tokenToLine(tokenPos); 1410 var locString = await bpt.location.toUserString();
1412 var col = script.tokenToCol(tokenPos); 1411 if (bpt.resolved) {
1413 if (bpt.resolved) { 1412 console.print(
1414 console.print( 1413 'Breakpoint ${bpId} ${verb} at ${locString}');
1415 'Breakpoint ${bpId} ${verb} at ${script.name}:${line}:${col}'); 1414 } else {
1416 } else { 1415 console.print(
1417 console.print( 1416 'Future breakpoint ${bpId} ${verb} at ${locString}');
1418 'Future breakpoint ${bpId} ${verb} at ${script.name}:${line}:${col}' ); 1417 }
1419 }
1420 });
1421 } 1418 }
1422 1419
1423 void onEvent(ServiceEvent event) { 1420 void onEvent(ServiceEvent event) {
1424 switch(event.kind) { 1421 switch(event.kind) {
1425 case ServiceEvent.kIsolateStart: 1422 case ServiceEvent.kIsolateStart:
1426 { 1423 {
1427 var iso = event.owner; 1424 var iso = event.owner;
1428 console.print( 1425 console.print(
1429 "Isolate ${iso.number} '${iso.name}' has been created"); 1426 "Isolate ${iso.number} '${iso.name}' has been created");
1430 } 1427 }
(...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after
2359 } 2356 }
2360 }); 2357 });
2361 } 2358 }
2362 2359
2363 void focus() { 2360 void focus() {
2364 $['textBox'].focus(); 2361 $['textBox'].focus();
2365 } 2362 }
2366 2363
2367 DebuggerInputElement.created() : super.created(); 2364 DebuggerInputElement.created() : super.created();
2368 } 2365 }
OLDNEW
« no previous file with comments | « runtime/observatory/lib/src/debugger/debugger_location.dart ('k') | runtime/observatory/lib/src/elements/script_inset.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698