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 |
11 // | 11 // |
12 // --wire see json messages sent between the processes. | 12 // --wire see json messages sent between the processes. |
13 // --verbose see the stdout and stderr output of the debug | 13 // --verbose see the stdout and stderr output of the debug |
14 // target process. | 14 // target process. |
15 | 15 |
16 import "dart:convert"; | 16 import "dart:convert"; |
17 import "dart:io"; | 17 import "dart:io"; |
18 import "dart:json" as JSON; | |
19 | 18 |
20 | 19 |
21 // Whether or not to print debug target process on the console. | 20 // Whether or not to print debug target process on the console. |
22 var showDebuggeeOutput = false; | 21 var showDebuggeeOutput = false; |
23 | 22 |
24 // Whether or not to print the debugger wire messages on the console. | 23 // Whether or not to print the debugger wire messages on the console. |
25 var verboseWire = false; | 24 var verboseWire = false; |
26 | 25 |
27 var debugger = null; | 26 var debugger = null; |
28 | 27 |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 void handleMessages() { | 303 void handleMessages() { |
305 var msg = responses.getNextMessage(); | 304 var msg = responses.getNextMessage(); |
306 while (msg != null) { | 305 while (msg != null) { |
307 if (verboseWire) print("RECV: $msg"); | 306 if (verboseWire) print("RECV: $msg"); |
308 if (responses.haveGarbage()) { | 307 if (responses.haveGarbage()) { |
309 error("Error: leftover text after message: '${responses.buffer}'"); | 308 error("Error: leftover text after message: '${responses.buffer}'"); |
310 error("Previous message may be malformed, was: '$msg'"); | 309 error("Previous message may be malformed, was: '$msg'"); |
311 cleanup(); | 310 cleanup(); |
312 return; | 311 return; |
313 } | 312 } |
314 var msgObj = JSON.parse(msg); | 313 var msgObj = JSON.decode(msg); |
315 handleMessage(msgObj); | 314 handleMessage(msgObj); |
316 if (errorsDetected) { | 315 if (errorsDetected) { |
317 error("Error while handling message from coverage target"); | 316 error("Error while handling message from coverage target"); |
318 error("Message received from coverage target: $msg"); | 317 error("Message received from coverage target: $msg"); |
319 cleanup(); | 318 cleanup(); |
320 return; | 319 return; |
321 } | 320 } |
322 if (shutdownEventSeen) { | 321 if (shutdownEventSeen) { |
323 if (outstandingCommand != null) { | 322 if (outstandingCommand != null) { |
324 error("Error: outstanding command when shutdown received"); | 323 error("Error: outstanding command when shutdown received"); |
(...skipping 11 matching lines...) Expand all Loading... |
336 outstandingCommand = cmd; | 335 outstandingCommand = cmd; |
337 } | 336 } |
338 msg = responses.getNextMessage(); | 337 msg = responses.getNextMessage(); |
339 } | 338 } |
340 } | 339 } |
341 | 340 |
342 // Send a debugger command to the target VM. | 341 // Send a debugger command to the target VM. |
343 void sendMessage(Map<String,dynamic> msg) { | 342 void sendMessage(Map<String,dynamic> msg) { |
344 assert(msg["id"] != null); | 343 assert(msg["id"] != null); |
345 msg["id"] = nextMessageId++; | 344 msg["id"] = nextMessageId++; |
346 String jsonMsg = JSON.stringify(msg); | 345 String jsonMsg = JSON.encode(msg); |
347 if (verboseWire) print("SEND: $jsonMsg"); | 346 if (verboseWire) print("SEND: $jsonMsg"); |
348 socket.write(jsonMsg); | 347 socket.write(jsonMsg); |
349 } | 348 } |
350 | 349 |
351 void getLineNumberTable(String url, int libId) { | 350 void getLineNumberTable(String url, int libId) { |
352 queuedCommands.add(new GetLineTableCmd(isolateId, libId, url)); | 351 queuedCommands.add(new GetLineTableCmd(isolateId, libId, url)); |
353 } | 352 } |
354 | 353 |
355 void getLibraries() { | 354 void getLibraries() { |
356 queuedCommands.add(new GetLibrariesCmd(isolateId)); | 355 queuedCommands.add(new GetLibrariesCmd(isolateId)); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
474 return false; | 473 return false; |
475 } else { | 474 } else { |
476 return char != "{"; | 475 return char != "{"; |
477 } | 476 } |
478 } | 477 } |
479 | 478 |
480 // Returns the character length of the next json message in the | 479 // Returns the character length of the next json message in the |
481 // 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. |
482 // The object value must start with '{' and continues to the | 481 // The object value must start with '{' and continues to the |
483 // matching '}'. No attempt is made to otherwise validate the contents | 482 // matching '}'. No attempt is made to otherwise validate the contents |
484 // as JSON. If it is invalid, a later JSON.parse() will fail. | 483 // as JSON. If it is invalid, a later JSON.decode() will fail. |
485 int objectLength() { | 484 int objectLength() { |
486 int skipWhitespace(int index) { | 485 int skipWhitespace(int index) { |
487 while (index < buffer.length) { | 486 while (index < buffer.length) { |
488 String char = buffer[index]; | 487 String char = buffer[index]; |
489 if (char != " " && char != "\n" && char != "\r" && char != "\t") break; | 488 if (char != " " && char != "\n" && char != "\r" && char != "\t") break; |
490 index++; | 489 index++; |
491 } | 490 } |
492 return index; | 491 return index; |
493 } | 492 } |
494 int skipString(int index) { | 493 int skipString(int index) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 targetOpts.add(str); | 538 targetOpts.add(str); |
540 break; | 539 break; |
541 } | 540 } |
542 } | 541 } |
543 | 542 |
544 Process.start(options.executable, targetOpts).then((Process process) { | 543 Process.start(options.executable, targetOpts).then((Process process) { |
545 process.stdin.close(); | 544 process.stdin.close(); |
546 debugger = new Debugger(process); | 545 debugger = new Debugger(process); |
547 }); | 546 }); |
548 } | 547 } |
OLD | NEW |