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:io"; | 17 import "dart:io"; |
17 import "dart:utf"; | 18 import "dart:utf"; |
18 import "dart:json" as JSON; | 19 import "dart:json" as JSON; |
19 | 20 |
20 | 21 |
21 // Whether or not to print debug target process on the console. | 22 // Whether or not to print debug target process on the console. |
22 var showDebuggeeOutput = false; | 23 var showDebuggeeOutput = false; |
23 | 24 |
24 // Whether or not to print the debugger wire messages on the console. | 25 // Whether or not to print the debugger wire messages on the console. |
25 var verboseWire = false; | 26 var verboseWire = false; |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 int isolateId = 0; | 208 int isolateId = 0; |
208 int libraryId = null; | 209 int libraryId = null; |
209 | 210 |
210 int nextMessageId = 0; | 211 int nextMessageId = 0; |
211 bool isPaused = false; | 212 bool isPaused = false; |
212 bool pendingAck = false; | 213 bool pendingAck = false; |
213 | 214 |
214 Debugger(this.targetProcess) { | 215 Debugger(this.targetProcess) { |
215 var stdoutStringStream = targetProcess.stdout | 216 var stdoutStringStream = targetProcess.stdout |
216 .transform(new StringDecoder()) | 217 .transform(new StringDecoder()) |
217 .transform(new LineTransformer()); | 218 .transform(new LineSplitter()); |
218 stdoutStringStream.listen((line) { | 219 stdoutStringStream.listen((line) { |
219 if (showDebuggeeOutput) { | 220 if (showDebuggeeOutput) { |
220 print("TARG: $line"); | 221 print("TARG: $line"); |
221 } | 222 } |
222 if (line.startsWith("Debugger listening")) { | 223 if (line.startsWith("Debugger listening")) { |
223 RegExp portExpr = new RegExp(r"\d+"); | 224 RegExp portExpr = new RegExp(r"\d+"); |
224 var port = portExpr.stringMatch(line); | 225 var port = portExpr.stringMatch(line); |
225 var pid = targetProcess.pid; | 226 var pid = targetProcess.pid; |
226 print("Coverage target process (pid $pid) found " | 227 print("Coverage target process (pid $pid) found " |
227 "listening on port $port."); | 228 "listening on port $port."); |
228 openConnection(int.parse(port)); | 229 openConnection(int.parse(port)); |
229 } | 230 } |
230 }); | 231 }); |
231 | 232 |
232 var stderrStringStream = targetProcess.stderr | 233 var stderrStringStream = targetProcess.stderr |
233 .transform(new StringDecoder()) | 234 .transform(new StringDecoder()) |
234 .transform(new LineTransformer()); | 235 .transform(new LineSplitter()); |
235 stderrStringStream.listen((line) { | 236 stderrStringStream.listen((line) { |
236 if (showDebuggeeOutput) { | 237 if (showDebuggeeOutput) { |
237 print("TARG: $line"); | 238 print("TARG: $line"); |
238 } | 239 } |
239 }); | 240 }); |
240 } | 241 } |
241 | 242 |
242 // Handle debugger events, updating the debugger state. | 243 // Handle debugger events, updating the debugger state. |
243 void handleEvent(Map<String,dynamic> msg) { | 244 void handleEvent(Map<String,dynamic> msg) { |
244 if (msg["event"] == "isolate") { | 245 if (msg["event"] == "isolate") { |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 targetOpts.add(str); | 540 targetOpts.add(str); |
540 break; | 541 break; |
541 } | 542 } |
542 } | 543 } |
543 | 544 |
544 Process.start(options.executable, targetOpts).then((Process process) { | 545 Process.start(options.executable, targetOpts).then((Process process) { |
545 process.stdin.close(); | 546 process.stdin.close(); |
546 debugger = new Debugger(process); | 547 debugger = new Debugger(process); |
547 }); | 548 }); |
548 } | 549 } |
OLD | NEW |