| OLD | NEW |
| 1 // Copyright (c) 2015, the Dartino project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, the Dartino 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.md file. | 3 // BSD-style license that can be found in the LICENSE.md file. |
| 4 | 4 |
| 5 import "dart:async"; | 5 import "dart:async"; |
| 6 | 6 |
| 7 import "dart:convert" show | 7 import "dart:convert" show |
| 8 UTF8; | 8 UTF8; |
| 9 | 9 |
| 10 import "dart:io" show | 10 import "dart:io" show |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 final bool echo; | 70 final bool echo; |
| 71 final Uri base; | 71 final Uri base; |
| 72 final Sink<List<int>> stdout; | 72 final Sink<List<int>> stdout; |
| 73 | 73 |
| 74 bool printForTesting = false; | 74 bool printForTesting = false; |
| 75 | 75 |
| 76 bool get colorsDisabled => printForTesting; | 76 bool get colorsDisabled => printForTesting; |
| 77 bool verbose = true; | 77 bool verbose = true; |
| 78 | 78 |
| 79 String previousLine = ''; | 79 String previousLine = ''; |
| 80 bool quitDebugger = false; |
| 80 | 81 |
| 81 int processPagingCount = 10; | 82 int processPagingCount = 10; |
| 82 int processPagingCurrent = 0; | 83 int processPagingCurrent = 0; |
| 83 | 84 |
| 84 CommandLineDebugger( | 85 CommandLineDebugger( |
| 85 this.vmContext, this.stream, this.base, this.stdout, {bool echo: false}) | 86 this.vmContext, this.stream, this.base, this.stdout, {bool echo: false}) |
| 86 : echo = echo, | 87 : echo = echo, |
| 87 printForTesting = echo; | 88 printForTesting = echo; |
| 88 | 89 |
| 89 void printPrompt() => writeStdout('> '); | 90 void printPrompt() => writeStdout('> '); |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 } | 380 } |
| 380 if (variable == null) { | 381 if (variable == null) { |
| 381 writeStdoutLine('### no such variable: $variableName'); | 382 writeStdoutLine('### no such variable: $variableName'); |
| 382 } else { | 383 } else { |
| 383 writeStdoutLine(vmContext.remoteObjectToString(variable)); | 384 writeStdoutLine(vmContext.remoteObjectToString(variable)); |
| 384 } | 385 } |
| 385 break; | 386 break; |
| 386 case 'q': | 387 case 'q': |
| 387 case 'quit': | 388 case 'quit': |
| 388 await vmContext.terminate(); | 389 await vmContext.terminate(); |
| 390 quitDebugger = true; |
| 389 break; | 391 break; |
| 390 case 'r': | 392 case 'r': |
| 391 case 'run': | 393 case 'run': |
| 392 if (checkNotLoaded("use 'restart' to run again")) { | 394 if (checkNotLoaded("use 'restart' to run again")) { |
| 393 await handleProcessStopResponse(await vmContext.startRunning()); | 395 await handleProcessStopResponse(await vmContext.startRunning()); |
| 394 } | 396 } |
| 395 break; | 397 break; |
| 396 case 'step': | 398 case 'step': |
| 397 case 's': | 399 case 's': |
| 398 if (checkRunning('cannot step to next expression')) { | 400 if (checkRunning('cannot step to next expression')) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 default: | 439 default: |
| 438 writeStdoutLine('### invalid flag $toggle'); | 440 writeStdoutLine('### invalid flag $toggle'); |
| 439 break; | 441 break; |
| 440 } | 442 } |
| 441 break; | 443 break; |
| 442 default: | 444 default: |
| 443 writeStdoutLine('### unknown command: $command'); | 445 writeStdoutLine('### unknown command: $command'); |
| 444 break; | 446 break; |
| 445 } | 447 } |
| 446 previousLine = line; | 448 previousLine = line; |
| 447 if (!vmContext.terminated) printPrompt(); | |
| 448 } | 449 } |
| 449 | 450 |
| 450 bool toggleVerbose() => verbose = !verbose; | 451 bool toggleVerbose() => verbose = !verbose; |
| 451 | 452 |
| 452 // This method is used to deal with the stopped process command responses | 453 // This method is used to deal with the stopped process command responses |
| 453 // that can be returned when sending the Dartino VM a command request. | 454 // that can be returned when sending the Dartino VM a command request. |
| 454 Future handleProcessStopResponse( | 455 Future handleProcessStopResponse( |
| 455 VmCommand response) async { | 456 VmCommand response) async { |
| 456 String output = await processStopResponseToString( | 457 String output = await processStopResponseToString( |
| 457 vmContext, | 458 vmContext, |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 if (vmContext.running) { | 492 if (vmContext.running) { |
| 492 String prefix = '### process already running'; | 493 String prefix = '### process already running'; |
| 493 writeStdoutLine(postfix != null ? '$prefix, $postfix' : prefix); | 494 writeStdoutLine(postfix != null ? '$prefix, $postfix' : prefix); |
| 494 } | 495 } |
| 495 return !vmContext.running; | 496 return !vmContext.running; |
| 496 } | 497 } |
| 497 | 498 |
| 498 Future<int> run(SessionState state, {Uri snapshotLocation}) async { | 499 Future<int> run(SessionState state, {Uri snapshotLocation}) async { |
| 499 await vmContext.initialize(state, snapshotLocation: snapshotLocation); | 500 await vmContext.initialize(state, snapshotLocation: snapshotLocation); |
| 500 writeStdoutLine(BANNER); | 501 writeStdoutLine(BANNER); |
| 501 printPrompt(); | |
| 502 StreamIterator streamIterator = new StreamIterator(stream); | 502 StreamIterator streamIterator = new StreamIterator(stream); |
| 503 while (await streamIterator.moveNext()) { | 503 |
| 504 Future<bool> getNext() async { |
| 505 printPrompt(); |
| 506 return await streamIterator.moveNext(); |
| 507 } |
| 508 |
| 509 while (!quitDebugger && await getNext()) { |
| 504 try { | 510 try { |
| 505 await handleLine(streamIterator); | 511 await handleLine(streamIterator); |
| 506 } catch (e, s) { | 512 } catch (e, s) { |
| 507 Future cancel = streamIterator.cancel()?.catchError((_) {}); | 513 Future cancel = streamIterator.cancel()?.catchError((_) {}); |
| 508 if (!vmContext.terminated) { | 514 if (!vmContext.terminated) { |
| 509 await vmContext.terminate().catchError((_) {}); | 515 await vmContext.terminate().catchError((_) {}); |
| 510 } | 516 } |
| 511 await cancel; | 517 await cancel; |
| 512 return new Future.error(e, s); | 518 return new Future.error(e, s); |
| 513 } | 519 } |
| 514 if (vmContext.terminated) { | |
| 515 await streamIterator.cancel(); | |
| 516 } | |
| 517 } | 520 } |
| 518 if (!vmContext.terminated) await vmContext.terminate(); | 521 if (!vmContext.terminated) { |
| 522 await vmContext.terminate(); |
| 523 } |
| 519 return vmContext.interactiveExitCode; | 524 return vmContext.interactiveExitCode; |
| 520 } | 525 } |
| 521 | 526 |
| 522 // Prompt the user to select among a set of choices. | 527 // Prompt the user to select among a set of choices. |
| 523 // Returns a set of indexes that are the chosen indexes from the input set. | 528 // Returns a set of indexes that are the chosen indexes from the input set. |
| 524 // If the size of choices is less then two, then the result is that the full | 529 // If the size of choices is less then two, then the result is that the full |
| 525 // input set is selected without prompting the user. Otherwise the user is | 530 // input set is selected without prompting the user. Otherwise the user is |
| 526 // interactively prompted to choose a selection. | 531 // interactively prompted to choose a selection. |
| 527 Future<Iterable<int>> select( | 532 Future<Iterable<int>> select( |
| 528 StreamIterator stream, | 533 StreamIterator stream, |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 return ''; | 638 return ''; |
| 634 } else if (response is ProcessTerminated) { | 639 } else if (response is ProcessTerminated) { |
| 635 return '### process terminated\n'; | 640 return '### process terminated\n'; |
| 636 | 641 |
| 637 } else if (response is ConnectionError) { | 642 } else if (response is ConnectionError) { |
| 638 return '### lost connection to the virtual machine\n'; | 643 return '### lost connection to the virtual machine\n'; |
| 639 } | 644 } |
| 640 return ''; | 645 return ''; |
| 641 } | 646 } |
| 642 } | 647 } |
| OLD | NEW |