OLD | NEW |
---|---|
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 used by debugger wire protocol tests (standalone VM debugging). | 5 // Library used by debugger wire protocol tests (standalone VM debugging). |
6 | 6 |
7 library DartDebugger; | 7 library DartDebugger; |
8 | 8 |
9 import "dart:async"; | 9 import "dart:async"; |
10 import "dart:io"; | 10 import "dart:io"; |
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
481 onError: (e) { | 481 onError: (e) { |
482 String msg = "Error while connecting to debugee: $e"; | 482 String msg = "Error while connecting to debugee: $e"; |
483 var trace = getAttachedStackTrace(e); | 483 var trace = getAttachedStackTrace(e); |
484 if (trace != null) msg += "\nStackTrace: $trace"; | 484 if (trace != null) msg += "\nStackTrace: $trace"; |
485 error(msg); | 485 error(msg); |
486 close(killDebugee: true); | 486 close(killDebugee: true); |
487 }); | 487 }); |
488 } | 488 } |
489 | 489 |
490 void close({killDebugee: false}) { | 490 void close({killDebugee: false}) { |
491 void exit() { | |
492 if (errorsDetected) throw "Errors detected"; | |
493 exit(errors.length); | |
494 } | |
491 if (errorsDetected) { | 495 if (errorsDetected) { |
492 for (int i = 0; i < errors.length; i++) print(errors[i]); | 496 for (int i = 0; i < errors.length; i++) print(errors[i]); |
493 } | 497 } |
494 if (socket != null) socket.close(); | 498 if (socket != null) { |
499 socket.close().catchError((error) { | |
500 print("Error occured while closing socket: $error"); | |
501 }; | |
502 } | |
495 if (killDebugee) { | 503 if (killDebugee) { |
496 targetProcess.kill(); | 504 if (!targetProcess.kill()) { |
497 print("Target process killed"); | 505 print("Could not send kill signal to target process."); |
hausner
2013/05/15 15:43:36
After printing this, you still wait for the target
ricow1
2013/05/16 07:19:55
From the api docs:
Returns true if the process is
kustermann
2013/05/16 08:06:08
We wait for the exitCode and if the target process
hausner
2013/05/16 15:38:32
Thanks for the explanation Rico and Martin. Thinki
| |
506 } else { | |
507 print("Successfully sent kill signal to target process."); | |
508 } | |
509 targetProcess.exitCode.then((exitCode) { | |
510 exit(); | |
511 }); | |
512 } else { | |
513 exit(); | |
498 } | 514 } |
499 if (errorsDetected) throw "Errors detected"; | |
500 exit(errors.length); | |
501 } | 515 } |
502 } | 516 } |
503 | 517 |
504 | 518 |
505 bool RunScript(List script) { | 519 bool RunScript(List script) { |
506 var options = new Options(); | 520 var options = new Options(); |
507 if (options.arguments.contains("--debuggee")) { | 521 if (options.arguments.contains("--debuggee")) { |
508 return false; | 522 return false; |
509 } | 523 } |
510 verboseWire = options.arguments.contains("--wire"); | 524 verboseWire = options.arguments.contains("--wire"); |
511 | 525 |
512 // Pick a port in the upper half of the port number range. | 526 // Pick a port in the upper half of the port number range. |
513 var seed = new DateTime.now().millisecondsSinceEpoch; | 527 var seed = new DateTime.now().millisecondsSinceEpoch; |
514 Random random = new Random(seed); | 528 Random random = new Random(seed); |
515 var debugPort = random.nextInt(32000) + 32000; | 529 var debugPort = random.nextInt(32000) + 32000; |
516 print('using debug port $debugPort ...'); | 530 print('using debug port $debugPort ...'); |
517 ServerSocket.bind('127.0.0.1', debugPort).then((ServerSocket s) { | 531 ServerSocket.bind('127.0.0.1', debugPort).then((ServerSocket s) { |
518 s.close(); | 532 s.close(); |
519 var targetOpts = [ "--debug:$debugPort" ]; | 533 var targetOpts = [ "--debug:$debugPort" ]; |
520 // --verbose_debug is necessary so the test knows when the debuggee | 534 // --verbose_debug is necessary so the test knows when the debuggee |
521 // is initialized. | 535 // is initialized. |
522 targetOpts.add("--verbose_debug"); | 536 targetOpts.add("--verbose_debug"); |
523 targetOpts.add(options.script); | 537 targetOpts.add(options.script); |
524 targetOpts.add("--debuggee"); | 538 targetOpts.add("--debuggee"); |
525 print('args: ${targetOpts.join(" ")}'); | 539 print('args: ${targetOpts.join(" ")}'); |
526 | 540 |
527 Process.start(options.executable, targetOpts).then((Process process) { | 541 Process.start(options.executable, targetOpts).then((Process process) { |
528 print("Debug target process started"); | 542 print("Debug target process started"); |
529 process.stdin.close(); | 543 process.stdin.close(); |
530 process.exitCode.then((int exitCode) { | 544 process.exitCode.then((int exitCode) { |
531 if (exitCode != 0) throw "bad exit code: $exitCode"; | 545 if (exitCode != 0) throw "bad exit code: $exitCode"; |
532 print("Debug target process exited with exit code $exitCode"); | 546 print("Debug target process exited with exit code $exitCode"); |
533 }); | 547 }); |
534 var debugger = | 548 var debugger = |
535 new Debugger(process, debugPort, new DebugScript(script)); | 549 new Debugger(process, debugPort, new DebugScript(script)); |
536 }); | 550 }); |
537 }, | 551 }, |
538 onError: (e) { | 552 onError: (e) { |
539 if (++retries >= 3) { | 553 if (++retries >= 3) { |
540 print('unable to find unused port: $e'); | 554 print('unable to find unused port: $e'); |
541 var trace = getAttachedStackTrace(e); | 555 var trace = getAttachedStackTrace(e); |
542 if (trace != null) print("StackTrace: $trace"); | 556 if (trace != null) print("StackTrace: $trace"); |
543 return -1; | 557 return -1; |
544 } else { | 558 } else { |
545 // Retry with another random port. | 559 // Retry with another random port. |
546 RunScript(script); | 560 RunScript(script); |
547 } | 561 } |
548 }); | 562 }); |
549 return true; | 563 return true; |
550 } | 564 } |
OLD | NEW |