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 test_helper; | 5 library test_helper; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:convert'; | 8 import 'dart:convert'; |
9 import 'dart:io'; | 9 import 'dart:io'; |
10 import 'package:observatory/service_io.dart'; | 10 import 'package:observatory/service_io.dart'; |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 process.requestExit(); | 241 process.requestExit(); |
242 if (!_isWebSocketDisconnect(e)) { | 242 if (!_isWebSocketDisconnect(e)) { |
243 print('Unexpected exception in service tests: $e $st'); | 243 print('Unexpected exception in service tests: $e $st'); |
244 throw e; | 244 throw e; |
245 } | 245 } |
246 }); | 246 }); |
247 }); | 247 }); |
248 } | 248 } |
249 } | 249 } |
250 | 250 |
| 251 Future asyncStepOver(Isolate isolate) async { |
| 252 final Completer pausedAtSyntheticBreakpoint = new Completer(); |
| 253 StreamSubscription subscription; |
| 254 |
| 255 // Cancel the subscription. |
| 256 cancelSubscription() { |
| 257 if (subscription != null) { |
| 258 subscription.cancel(); |
| 259 subscription = null; |
| 260 } |
| 261 } |
| 262 |
| 263 // Complete futures with with error. |
| 264 completeError(error) { |
| 265 if (!pausedAtSyntheticBreakpoint.isCompleted) { |
| 266 pausedAtSyntheticBreakpoint.completeError(error); |
| 267 } |
| 268 } |
| 269 |
| 270 // Subscribe to the debugger event stream. |
| 271 Stream stream; |
| 272 try { |
| 273 stream = await isolate.vm.getEventStream(VM.kDebugStream); |
| 274 } catch (e) { |
| 275 completeError(e); |
| 276 return pausedAtSyntheticBreakpoint.future; |
| 277 } |
| 278 |
| 279 Breakpoint syntheticBreakpoint; |
| 280 |
| 281 subscription = stream.listen((ServiceEvent event) async { |
| 282 // Synthetic breakpoint add event. This is the first event we will |
| 283 // receive. |
| 284 bool isAdd = (event.kind == ServiceEvent.kBreakpointAdded) && |
| 285 (event.breakpoint.isSyntheticAsyncContinuation) && |
| 286 (event.owner == isolate); |
| 287 // Resume after synthetic breakpoint added. This is the second event |
| 288 // we will recieve. |
| 289 bool isResume = (event.kind == ServiceEvent.kResume) && |
| 290 (syntheticBreakpoint != null) && |
| 291 (event.owner == isolate); |
| 292 // Paused at synthetic breakpoint. This is the third event we will |
| 293 // receive. |
| 294 bool isPaused = (event.kind == ServiceEvent.kPauseBreakpoint) && |
| 295 (syntheticBreakpoint != null) && |
| 296 (event.breakpoint == syntheticBreakpoint); |
| 297 if (isAdd) { |
| 298 syntheticBreakpoint = event.breakpoint; |
| 299 } else if (isResume) { |
| 300 } else if (isPaused) { |
| 301 pausedAtSyntheticBreakpoint.complete(isolate); |
| 302 syntheticBreakpoint = null; |
| 303 cancelSubscription(); |
| 304 } |
| 305 }); |
| 306 |
| 307 // Issue the step OverAwait command. |
| 308 try { |
| 309 await isolate.stepOverAsyncSuspension(); |
| 310 } catch (e) { |
| 311 // This can fail when another client issued the same resume command |
| 312 // or another client has moved the isolate forward. |
| 313 cancelSubscription(); |
| 314 completeError(e); |
| 315 } |
| 316 |
| 317 return pausedAtSyntheticBreakpoint.future; |
| 318 } |
| 319 |
| 320 |
251 Future<Isolate> hasPausedFor(Isolate isolate, String kind) { | 321 Future<Isolate> hasPausedFor(Isolate isolate, String kind) { |
252 // Set up a listener to wait for breakpoint events. | 322 // Set up a listener to wait for breakpoint events. |
253 Completer completer = new Completer(); | 323 Completer completer = new Completer(); |
254 isolate.vm.getEventStream(VM.kDebugStream).then((stream) { | 324 isolate.vm.getEventStream(VM.kDebugStream).then((stream) { |
255 var subscription; | 325 var subscription; |
256 subscription = stream.listen((ServiceEvent event) { | 326 subscription = stream.listen((ServiceEvent event) { |
257 if (event.kind == kind) { | 327 if (event.kind == kind) { |
258 print('Paused with $kind'); | 328 print('Paused with $kind'); |
259 subscription.cancel(); | 329 subscription.cancel(); |
260 if (completer != null) { | 330 if (completer != null) { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 await isolate.resume(); | 438 await isolate.resume(); |
369 return completer.future; | 439 return completer.future; |
370 } | 440 } |
371 | 441 |
372 IsolateTest resumeIsolateAndAwaitEvent(stream, onEvent) { | 442 IsolateTest resumeIsolateAndAwaitEvent(stream, onEvent) { |
373 return (Isolate isolate) async => | 443 return (Isolate isolate) async => |
374 resumeAndAwaitEvent(isolate, stream, onEvent); | 444 resumeAndAwaitEvent(isolate, stream, onEvent); |
375 } | 445 } |
376 | 446 |
377 | 447 |
| 448 Future<Isolate> stepOver(Isolate isolate) async { |
| 449 await isolate.stepOver(); |
| 450 return hasStoppedAtBreakpoint(isolate); |
| 451 } |
| 452 |
378 Future<Class> getClassFromRootLib(Isolate isolate, String className) async { | 453 Future<Class> getClassFromRootLib(Isolate isolate, String className) async { |
379 Library rootLib = await isolate.rootLibrary.load(); | 454 Library rootLib = await isolate.rootLibrary.load(); |
380 for (var i = 0; i < rootLib.classes.length; i++) { | 455 for (var i = 0; i < rootLib.classes.length; i++) { |
381 Class cls = rootLib.classes[i]; | 456 Class cls = rootLib.classes[i]; |
382 if (cls.name == className) { | 457 if (cls.name == className) { |
383 return cls; | 458 return cls; |
384 } | 459 } |
385 } | 460 } |
386 return null; | 461 return null; |
387 } | 462 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 }, onError: (e, st) { | 526 }, onError: (e, st) { |
452 process.requestExit(); | 527 process.requestExit(); |
453 if (!_isWebSocketDisconnect(e)) { | 528 if (!_isWebSocketDisconnect(e)) { |
454 print('Unexpected exception in service tests: $e $st'); | 529 print('Unexpected exception in service tests: $e $st'); |
455 throw e; | 530 throw e; |
456 } | 531 } |
457 }); | 532 }); |
458 }); | 533 }); |
459 } | 534 } |
460 } | 535 } |
OLD | NEW |