| 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 // This test forks a second vm process that runs a dart script as | 5 // This test forks a second vm process that runs a dart script as |
| 6 // a debug target, single stepping through the entire program, and | 6 // a debug target, single stepping through the entire program, and |
| 7 // recording each breakpoint. At the end, a coverage map of the source | 7 // recording each breakpoint. At the end, a coverage map of the source |
| 8 // is printed. | 8 // is printed. |
| 9 // | 9 // |
| 10 // Usage: dart coverage.dart [--wire] [--verbose] target_script.dart | 10 // Usage: dart coverage.dart [--wire] [--verbose] target_script.dart |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 socket.write(jsonMsg); | 347 socket.write(jsonMsg); |
| 348 } | 348 } |
| 349 | 349 |
| 350 void getLineNumberTable(String url, int libId) { | 350 void getLineNumberTable(String url, int libId) { |
| 351 queuedCommands.add(new GetLineTableCmd(isolateId, libId, url)); | 351 queuedCommands.add(new GetLineTableCmd(isolateId, libId, url)); |
| 352 } | 352 } |
| 353 | 353 |
| 354 void getLibraries() { | 354 void getLibraries() { |
| 355 queuedCommands.add(new GetLibrariesCmd(isolateId)); | 355 queuedCommands.add(new GetLibrariesCmd(isolateId)); |
| 356 } | 356 } |
| 357 | 357 |
| 358 void enableDebugging(libraryId, enable) { | 358 void enableDebugging(libraryId, enable) { |
| 359 queuedCommands.add(new SetLibraryPropertiesCmd(isolateId, libraryId, enable)
); | 359 queuedCommands.add(new SetLibraryPropertiesCmd(isolateId, libraryId, enable)
); |
| 360 } | 360 } |
| 361 | 361 |
| 362 bool get errorsDetected => errors.length > 0; | 362 bool get errorsDetected => errors.length > 0; |
| 363 | 363 |
| 364 // Record error message. | 364 // Record error message. |
| 365 void error(String s) { | 365 void error(String s) { |
| 366 errors.add(s); | 366 errors.add(s); |
| 367 } | 367 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 | 434 |
| 435 // Class to buffer wire protocol data from coverage target and | 435 // Class to buffer wire protocol data from coverage target and |
| 436 // break it down to individual json messages. | 436 // break it down to individual json messages. |
| 437 class JsonBuffer { | 437 class JsonBuffer { |
| 438 String buffer = null; | 438 String buffer = null; |
| 439 | 439 |
| 440 append(String s) { | 440 append(String s) { |
| 441 if (buffer == null || buffer.length == 0) { | 441 if (buffer == null || buffer.length == 0) { |
| 442 buffer = s; | 442 buffer = s; |
| 443 } else { | 443 } else { |
| 444 buffer = buffer.concat(s); | 444 buffer = buffer + s; |
| 445 } | 445 } |
| 446 } | 446 } |
| 447 | 447 |
| 448 String getNextMessage() { | 448 String getNextMessage() { |
| 449 if (buffer == null) return null; | 449 if (buffer == null) return null; |
| 450 int msgLen = objectLength(); | 450 int msgLen = objectLength(); |
| 451 if (msgLen == 0) return null; | 451 if (msgLen == 0) return null; |
| 452 String msg = null; | 452 String msg = null; |
| 453 if (msgLen == buffer.length) { | 453 if (msgLen == buffer.length) { |
| 454 msg = buffer; | 454 msg = buffer; |
| 455 buffer = null; | 455 buffer = null; |
| 456 } else { | 456 } else { |
| 457 assert(msgLen < buffer.length); | 457 assert(msgLen < buffer.length); |
| 458 msg = buffer.substring(0, msgLen); | 458 msg = buffer.substring(0, msgLen); |
| 459 buffer = buffer.substring(msgLen); | 459 buffer = buffer.substring(msgLen); |
| 460 } | 460 } |
| 461 return msg; | 461 return msg; |
| 462 } | 462 } |
| 463 | 463 |
| 464 bool haveGarbage() { | 464 bool haveGarbage() { |
| 465 if (buffer == null || buffer.length == 0) return false; | 465 if (buffer == null || buffer.length == 0) return false; |
| 466 var i = 0, char = " "; | 466 var i = 0, char = " "; |
| 467 while (i < buffer.length) { | 467 while (i < buffer.length) { |
| 468 char = buffer[i]; | 468 char = buffer[i]; |
| 469 if (char != " " && char != "\n" && char != "\r" && char != "\t") break; | 469 if (char != " " && char != "\n" && char != "\r" && char != "\t") break; |
| 470 i++; | 470 i++; |
| 471 } | 471 } |
| 472 if (i >= buffer.length) { | 472 if (i >= buffer.length) { |
| 473 return false; | 473 return false; |
| 474 } else { | 474 } else { |
| 475 return char != "{"; | 475 return char != "{"; |
| 476 } | 476 } |
| 477 } | 477 } |
| 478 | 478 |
| 479 // Returns the character length of the next json message in the | 479 // Returns the character length of the next json message in the |
| 480 // buffer, or 0 if there is only a partial message in the buffer. | 480 // buffer, or 0 if there is only a partial message in the buffer. |
| 481 // The object value must start with '{' and continues to the | 481 // The object value must start with '{' and continues to the |
| 482 // matching '}'. No attempt is made to otherwise validate the contents | 482 // matching '}'. No attempt is made to otherwise validate the contents |
| 483 // as JSON. If it is invalid, a later JSON.decode() will fail. | 483 // as JSON. If it is invalid, a later JSON.decode() will fail. |
| 484 int objectLength() { | 484 int objectLength() { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 targetOpts.add(str); | 538 targetOpts.add(str); |
| 539 break; | 539 break; |
| 540 } | 540 } |
| 541 } | 541 } |
| 542 | 542 |
| 543 Process.start(options.executable, targetOpts).then((Process process) { | 543 Process.start(options.executable, targetOpts).then((Process process) { |
| 544 process.stdin.close(); | 544 process.stdin.close(); |
| 545 debugger = new Debugger(process); | 545 debugger = new Debugger(process); |
| 546 }); | 546 }); |
| 547 } | 547 } |
| OLD | NEW |