| OLD | NEW |
| 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/cli.dart'; | 10 import 'package:observatory/cli.dart'; |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 return debugger.isolate.addBreakpoint(loc.script, loc.line).then((result
) { | 246 return debugger.isolate.addBreakpoint(loc.script, loc.line).then((result
) { |
| 247 if (result is DartError) { | 247 if (result is DartError) { |
| 248 debugger.console.print('Unable to set breakpoint at ${loc}'); | 248 debugger.console.print('Unable to set breakpoint at ${loc}'); |
| 249 } else { | 249 } else { |
| 250 // TODO(turnidge): Adding a duplicate breakpoint is | 250 // TODO(turnidge): Adding a duplicate breakpoint is |
| 251 // currently ignored. May want to change the protocol to | 251 // currently ignored. May want to change the protocol to |
| 252 // inform us when this happens. | 252 // inform us when this happens. |
| 253 | 253 |
| 254 // The BreakpointResolved event prints resolved | 254 // The BreakpointResolved event prints resolved |
| 255 // breakpoints already. Just print the unresolved ones here. | 255 // breakpoints already. Just print the unresolved ones here. |
| 256 ServiceMap bpt = result; | 256 Breakpoint bpt = result; |
| 257 if (!bpt['resolved']) { | 257 if (!bpt.resolved) { |
| 258 var script = bpt['location']['script']; | 258 var script = bpt.script; |
| 259 var bpId = bpt['breakpointNumber']; | 259 var bpId = bpt.number; |
| 260 var tokenPos = bpt['location']['tokenPos']; | 260 var tokenPos = bpt.tokenPos; |
| 261 return script.load().then((_) { | 261 return script.load().then((_) { |
| 262 var line = script.tokenToLine(tokenPos); | 262 var line = script.tokenToLine(tokenPos); |
| 263 var col = script.tokenToCol(tokenPos); | 263 var col = script.tokenToCol(tokenPos); |
| 264 debugger.console.print( | 264 debugger.console.print( |
| 265 'Future breakpoint ${bpId} added at ' | 265 'Future breakpoint ${bpId} added at ' |
| 266 '${script.name}:${line}:${col}'); | 266 '${script.name}:${line}:${col}'); |
| 267 }); | 267 }); |
| 268 } | 268 } |
| 269 } | 269 } |
| 270 }); | 270 }); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 return null; | 329 return null; |
| 330 } | 330 } |
| 331 if (loc.col != null) { | 331 if (loc.col != null) { |
| 332 // TODO(turnidge): Add tokenPos clear support. | 332 // TODO(turnidge): Add tokenPos clear support. |
| 333 debugger.console.print( | 333 debugger.console.print( |
| 334 'Ignoring column: ' | 334 'Ignoring column: ' |
| 335 'clearing breakpoint at a specific column not yet implemented'); | 335 'clearing breakpoint at a specific column not yet implemented'); |
| 336 } | 336 } |
| 337 | 337 |
| 338 for (var bpt in debugger.isolate.breakpoints) { | 338 for (var bpt in debugger.isolate.breakpoints) { |
| 339 var script = bpt['location']['script']; | 339 var script = bpt.script; |
| 340 if (script.id == loc.script.id) { | 340 if (script.id == loc.script.id) { |
| 341 assert(script.loaded); | 341 assert(script.loaded); |
| 342 var line = script.tokenToLine(bpt['location']['tokenPos']); | 342 var line = script.tokenToLine(bpt.tokenPos); |
| 343 if (line == loc.line) { | 343 if (line == loc.line) { |
| 344 return debugger.isolate.removeBreakpoint(bpt).then((result) { | 344 return debugger.isolate.removeBreakpoint(bpt).then((result) { |
| 345 if (result is DartError) { | 345 if (result is DartError) { |
| 346 debugger.console.print( | 346 debugger.console.print( |
| 347 'Unable to clear breakpoint at ${loc}: ${result.message}')
; | 347 'Unable to clear breakpoint at ${loc}: ${result.message}')
; |
| 348 return; | 348 return; |
| 349 } else { | 349 } else { |
| 350 // TODO(turnidge): Add a BreakpointRemoved event to | 350 // TODO(turnidge): Add a BreakpointRemoved event to |
| 351 // the service instead of printing here. | 351 // the service instead of printing here. |
| 352 var bpId = bpt['breakpointNumber']; | 352 var bpId = bpt.number; |
| 353 debugger.console.print( | 353 debugger.console.print('Breakpoint ${bpId} removed at ${loc}')
; |
| 354 'Breakpoint ${bpId} removed at ${loc}'); | |
| 355 return; | 354 return; |
| 356 } | 355 } |
| 357 }); | 356 }); |
| 358 } | 357 } |
| 359 } | 358 } |
| 360 } | 359 } |
| 361 debugger.console.print('No breakpoint found at ${loc}'); | 360 debugger.console.print('No breakpoint found at ${loc}'); |
| 362 } else { | 361 } else { |
| 363 debugger.console.print(loc.errorMessage); | 362 debugger.console.print(loc.errorMessage); |
| 364 } | 363 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 | 402 |
| 404 // TODO(turnidge): Add argument completion. | 403 // TODO(turnidge): Add argument completion. |
| 405 class DeleteCommand extends DebuggerCommand { | 404 class DeleteCommand extends DebuggerCommand { |
| 406 DeleteCommand(Debugger debugger) : super(debugger, 'delete', []); | 405 DeleteCommand(Debugger debugger) : super(debugger, 'delete', []); |
| 407 | 406 |
| 408 Future run(List<String> args) { | 407 Future run(List<String> args) { |
| 409 if (args.length < 1) { | 408 if (args.length < 1) { |
| 410 debugger.console.print('delete expects one or more arguments'); | 409 debugger.console.print('delete expects one or more arguments'); |
| 411 return new Future.value(null); | 410 return new Future.value(null); |
| 412 } | 411 } |
| 413 List toDelete = []; | 412 List toRemove = []; |
| 414 for (var arg in args) { | 413 for (var arg in args) { |
| 415 int id = int.parse(arg); | 414 int id = int.parse(arg); |
| 416 var bpt = null; | 415 var bptToRemove = null; |
| 417 for (var candidate in debugger.isolate.breakpoints) { | 416 for (var bpt in debugger.isolate.breakpoints) { |
| 418 if (candidate['breakpointNumber'] == id) { | 417 if (bpt.number == id) { |
| 419 bpt = candidate; | 418 bptToRemove = bpt; |
| 420 break; | 419 break; |
| 421 } | 420 } |
| 422 } | 421 } |
| 423 if (bpt == null) { | 422 if (bptToRemove == null) { |
| 424 debugger.console.print("Invalid breakpoint id '${id}'"); | 423 debugger.console.print("Invalid breakpoint id '${id}'"); |
| 425 return new Future.value(null); | 424 return new Future.value(null); |
| 426 } | 425 } |
| 427 toDelete.add(bpt); | 426 toRemove.add(bptToRemove); |
| 428 } | 427 } |
| 429 List pending = []; | 428 List pending = []; |
| 430 for (var bpt in toDelete) { | 429 for (var bpt in toRemove) { |
| 431 pending.add(debugger.isolate.removeBreakpoint(bpt).then((_) { | 430 pending.add(debugger.isolate.removeBreakpoint(bpt).then((_) { |
| 432 var id = bpt['breakpointNumber']; | 431 var id = bpt.number; |
| 433 debugger.console.print("Removed breakpoint $id"); | 432 debugger.console.print("Removed breakpoint $id"); |
| 434 })); | 433 })); |
| 435 } | 434 } |
| 436 return Future.wait(pending); | 435 return Future.wait(pending); |
| 437 } | 436 } |
| 438 | 437 |
| 439 String helpShort = 'Remove a breakpoint by breakpoint id'; | 438 String helpShort = 'Remove a breakpoint by breakpoint id'; |
| 440 | 439 |
| 441 String helpLong = | 440 String helpLong = |
| 442 'Remove a breakpoint by breakpoint id.\n' | 441 'Remove a breakpoint by breakpoint id.\n' |
| 443 '\n' | 442 '\n' |
| 444 'Syntax: delete <bp-id>\n' | 443 'Syntax: delete <bp-id>\n' |
| 445 ' delete <bp-id> <bp-id> ...\n'; | 444 ' delete <bp-id> <bp-id> ...\n'; |
| 446 } | 445 } |
| 447 | 446 |
| 448 class InfoBreakpointsCommand extends DebuggerCommand { | 447 class InfoBreakpointsCommand extends DebuggerCommand { |
| 449 InfoBreakpointsCommand(Debugger debugger) | 448 InfoBreakpointsCommand(Debugger debugger) |
| 450 : super(debugger, 'breakpoints', []); | 449 : super(debugger, 'breakpoints', []); |
| 451 | 450 |
| 452 Future run(List<String> args) { | 451 Future run(List<String> args) { |
| 453 return debugger.isolate.reloadBreakpoints().then((_) { | 452 return debugger.isolate.reloadBreakpoints().then((_) { |
| 454 if (debugger.isolate.breakpoints.isEmpty) { | 453 if (debugger.isolate.breakpoints.isEmpty) { |
| 455 debugger.console.print('No breakpoints'); | 454 debugger.console.print('No breakpoints'); |
| 456 } | 455 } |
| 457 for (var bpt in debugger.isolate.breakpoints) { | 456 for (var bpt in debugger.isolate.breakpoints) { |
| 458 var bpId = bpt['breakpointNumber']; | 457 var bpId = bpt.number; |
| 459 var script = bpt['location']['script']; | 458 var script = bpt.script; |
| 460 var tokenPos = bpt['location']['tokenPos']; | 459 var tokenPos = bpt.tokenPos; |
| 461 var line = script.tokenToLine(tokenPos); | 460 var line = script.tokenToLine(tokenPos); |
| 462 var col = script.tokenToCol(tokenPos); | 461 var col = script.tokenToCol(tokenPos); |
| 463 var extras = new StringBuffer(); | 462 var extras = new StringBuffer(); |
| 464 if (!bpt['resolved']) { | 463 if (!bpt.resolved) { |
| 465 extras.write(' unresolved'); | 464 extras.write(' unresolved'); |
| 466 } | 465 } |
| 467 if (!bpt['enabled']) { | 466 if (!bpt.enabled) { |
| 468 extras.write(' disabled'); | 467 extras.write(' disabled'); |
| 469 } | 468 } |
| 470 debugger.console.print( | 469 debugger.console.print( |
| 471 'Breakpoint ${bpId} at ${script.name}:${line}:${col}${extras}'); | 470 'Breakpoint ${bpId} at ${script.name}:${line}:${col}${extras}'); |
| 472 } | 471 } |
| 473 }); | 472 }); |
| 474 } | 473 } |
| 475 | 474 |
| 476 String helpShort = 'List all breakpoints'; | 475 String helpShort = 'List all breakpoints'; |
| 477 | 476 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 console.print( | 681 console.print( |
| 683 "Paused at isolate exit (type 'continue' to exit the isolate')"); | 682 "Paused at isolate exit (type 'continue' to exit the isolate')"); |
| 684 } | 683 } |
| 685 if (stack['frames'].length > 0) { | 684 if (stack['frames'].length > 0) { |
| 686 var frame = stack['frames'][0]; | 685 var frame = stack['frames'][0]; |
| 687 var script = frame['script']; | 686 var script = frame['script']; |
| 688 script.load().then((_) { | 687 script.load().then((_) { |
| 689 var line = script.tokenToLine(frame['tokenPos']); | 688 var line = script.tokenToLine(frame['tokenPos']); |
| 690 var col = script.tokenToCol(frame['tokenPos']); | 689 var col = script.tokenToCol(frame['tokenPos']); |
| 691 if (event.breakpoint != null) { | 690 if (event.breakpoint != null) { |
| 692 var bpId = event.breakpoint['breakpointNumber']; | 691 var bpId = event.breakpoint.number; |
| 693 console.print('Breakpoint ${bpId} at ${script.name}:${line}:${col}'); | 692 console.print('Breakpoint ${bpId} at ${script.name}:${line}:${col}'); |
| 694 } else if (event.exception != null) { | 693 } else if (event.exception != null) { |
| 695 // TODO(turnidge): Test this. | 694 // TODO(turnidge): Test this. |
| 696 console.print( | 695 console.print( |
| 697 'Exception ${event.exception} at ${script.name}:${line}:${col}'); | 696 'Exception ${event.exception} at ${script.name}:${line}:${col}'); |
| 698 } else { | 697 } else { |
| 699 console.print('Paused at ${script.name}:${line}:${col}'); | 698 console.print('Paused at ${script.name}:${line}:${col}'); |
| 700 } | 699 } |
| 701 }); | 700 }); |
| 702 } | 701 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 718 _refreshStack(event).then((_) { | 717 _refreshStack(event).then((_) { |
| 719 _reportPause(event); | 718 _reportPause(event); |
| 720 }); | 719 }); |
| 721 break; | 720 break; |
| 722 | 721 |
| 723 case 'IsolateResumed': | 722 case 'IsolateResumed': |
| 724 console.print('Continuing...'); | 723 console.print('Continuing...'); |
| 725 break; | 724 break; |
| 726 | 725 |
| 727 case 'BreakpointResolved': | 726 case 'BreakpointResolved': |
| 728 var bpId = event.breakpoint['breakpointNumber']; | 727 var bpId = event.breakpoint.number; |
| 729 var script = event.breakpoint['location']['script']; | 728 var script = event.breakpoint.script; |
| 730 var tokenPos = event.breakpoint['location']['tokenPos']; | 729 var tokenPos = event.breakpoint.tokenPos; |
| 731 var line = script.tokenToLine(tokenPos); | 730 var line = script.tokenToLine(tokenPos); |
| 732 var col = script.tokenToCol(tokenPos); | 731 var col = script.tokenToCol(tokenPos); |
| 733 console.print( | 732 console.print( |
| 734 'Breakpoint ${bpId} added at ${script.name}:${line}:${col}'); | 733 'Breakpoint ${bpId} added at ${script.name}:${line}:${col}'); |
| 735 break; | 734 break; |
| 736 | 735 |
| 737 case '_Graph': | 736 case '_Graph': |
| 738 case 'IsolateCreated': | 737 case 'IsolateCreated': |
| 739 case 'GC': | 738 case 'GC': |
| 740 // Ignore these events for now. | 739 // Ignore these events for now. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 788 // TODO(turnidge): Implement real command line history. | 787 // TODO(turnidge): Implement real command line history. |
| 789 String lastCommand; | 788 String lastCommand; |
| 790 | 789 |
| 791 Future run(String command) { | 790 Future run(String command) { |
| 792 if (command == '' && lastCommand != null) { | 791 if (command == '' && lastCommand != null) { |
| 793 command = lastCommand; | 792 command = lastCommand; |
| 794 } | 793 } |
| 795 console.printBold('\$ $command'); | 794 console.printBold('\$ $command'); |
| 796 return cmd.runCommand(command).then((_) { | 795 return cmd.runCommand(command).then((_) { |
| 797 lastCommand = command; | 796 lastCommand = command; |
| 798 }).catchError((e) { | 797 }).catchError((e, s) { |
| 799 console.print('ERROR $e'); | 798 console.print('ERROR $e\n$s'); |
| 800 }); | 799 }); |
| 801 } | 800 } |
| 802 } | 801 } |
| 803 | 802 |
| 804 @CustomTag('debugger-page') | 803 @CustomTag('debugger-page') |
| 805 class DebuggerPageElement extends ObservatoryElement { | 804 class DebuggerPageElement extends ObservatoryElement { |
| 806 @published Isolate isolate; | 805 @published Isolate isolate; |
| 807 | 806 |
| 808 isolateChanged(oldValue) { | 807 isolateChanged(oldValue) { |
| 809 if (isolate != null) { | 808 if (isolate != null) { |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1073 debugger.run(command).whenComplete(_notBusy); | 1072 debugger.run(command).whenComplete(_notBusy); |
| 1074 } | 1073 } |
| 1075 break; | 1074 break; |
| 1076 } | 1075 } |
| 1077 }); | 1076 }); |
| 1078 } | 1077 } |
| 1079 | 1078 |
| 1080 DebuggerInputElement.created() : super.created(); | 1079 DebuggerInputElement.created() : super.created(); |
| 1081 } | 1080 } |
| 1082 | 1081 |
| OLD | NEW |