| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | |
| 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. | |
| 4 // VMOptions=--error_on_bad_type --error_on_bad_override | |
| 5 | |
| 6 import 'dart:developer'; | |
| 7 import 'package:observatory/service_io.dart'; | |
| 8 import 'package:unittest/unittest.dart'; | |
| 9 import 'service_test_common.dart'; | |
| 10 import 'test_helper.dart'; | |
| 11 | |
| 12 const alwaysInline = "AlwaysInline"; | |
| 13 const noInline = "NeverInline"; | |
| 14 | |
| 15 int LINE_A = 35; | |
| 16 int LINE_B = 40; | |
| 17 int LINE_C = 43; | |
| 18 int LINE_D = 47; | |
| 19 | |
| 20 int global = 0; | |
| 21 | |
| 22 @noInline | |
| 23 b3(x) { | |
| 24 int sum = 0; | |
| 25 try { | |
| 26 for (int i = 0; i < x; i++) { | |
| 27 sum += x; | |
| 28 } | |
| 29 } catch (e) { | |
| 30 print("caught $e"); | |
| 31 } | |
| 32 if (global >= 100) { | |
| 33 debugger(); | |
| 34 } | |
| 35 global = global + 1; // Line A | |
| 36 return sum; | |
| 37 } | |
| 38 | |
| 39 @alwaysInline | |
| 40 b2(x) => b3(x); // Line B | |
| 41 | |
| 42 @alwaysInline | |
| 43 b1(x) => b2(x); // Line C | |
| 44 | |
| 45 test() { | |
| 46 while (true) { | |
| 47 b1(10000); // Line D | |
| 48 } | |
| 49 } | |
| 50 | |
| 51 var tests = [ | |
| 52 hasStoppedAtBreakpoint, | |
| 53 stoppedAtLine(LINE_A), | |
| 54 | |
| 55 (Isolate isolate) async { | |
| 56 // We are not able to rewind frame 0. | |
| 57 bool caughtException; | |
| 58 try { | |
| 59 await isolate.rewind(0); | |
| 60 expect(false, isTrue, reason:'Unreachable'); | |
| 61 } on ServerRpcException catch(e) { | |
| 62 caughtException = true; | |
| 63 expect(e.code, equals(ServerRpcException.kCannotResume)); | |
| 64 expect(e.message, 'Frame must be in bounds [1..9]: saw 0'); | |
| 65 } | |
| 66 expect(caughtException, isTrue); | |
| 67 }, | |
| 68 | |
| 69 (Isolate isolate) async { | |
| 70 // We are not able to rewind frame 10. | |
| 71 bool caughtException; | |
| 72 try { | |
| 73 await isolate.rewind(10); | |
| 74 expect(false, isTrue, reason:'Unreachable'); | |
| 75 } on ServerRpcException catch(e) { | |
| 76 caughtException = true; | |
| 77 expect(e.code, equals(ServerRpcException.kCannotResume)); | |
| 78 expect(e.message, 'Frame must be in bounds [1..9]: saw 10'); | |
| 79 } | |
| 80 expect(caughtException, isTrue); | |
| 81 }, | |
| 82 | |
| 83 (Isolate isolate) async { | |
| 84 // We are at our breakpoint with global=100. | |
| 85 var result = await isolate.rootLibrary.evaluate('global'); | |
| 86 print('global is $result'); | |
| 87 expect(result.type, equals('Instance')); | |
| 88 expect(result.valueAsString, equals('100')); | |
| 89 | |
| 90 // Rewind the top stack frame. | |
| 91 result = await isolate.rewind(1); | |
| 92 expect(result['type'], equals('Success')); | |
| 93 }, | |
| 94 | |
| 95 hasStoppedAtBreakpoint, | |
| 96 stoppedAtLine(LINE_B), | |
| 97 | |
| 98 (Isolate isolate) async { | |
| 99 var result = await isolate.resume(); | |
| 100 expect(result['type'], equals('Success')); | |
| 101 }, | |
| 102 | |
| 103 hasStoppedAtBreakpoint, | |
| 104 stoppedAtLine(LINE_A), | |
| 105 | |
| 106 (Isolate isolate) async { | |
| 107 // global still is equal to 100. We did not execute "global++". | |
| 108 var result = await isolate.rootLibrary.evaluate('global'); | |
| 109 print('global is $result'); | |
| 110 expect(result.type, equals('Instance')); | |
| 111 expect(result.valueAsString, equals('100')); | |
| 112 | |
| 113 // Resume again, for fun. | |
| 114 result = await isolate.resume(); | |
| 115 expect(result['type'], equals('Success')); | |
| 116 }, | |
| 117 | |
| 118 hasStoppedAtBreakpoint, | |
| 119 stoppedAtLine(LINE_A), | |
| 120 | |
| 121 (Isolate isolate) async { | |
| 122 // global is now 101. | |
| 123 var result = await isolate.rootLibrary.evaluate('global'); | |
| 124 print('global is $result'); | |
| 125 expect(result.type, equals('Instance')); | |
| 126 expect(result.valueAsString, equals('101')); | |
| 127 | |
| 128 // Rewind up to 'test'/ | |
| 129 result = await isolate.rewind(3); | |
| 130 expect(result['type'], equals('Success')); | |
| 131 }, | |
| 132 | |
| 133 hasStoppedAtBreakpoint, | |
| 134 stoppedAtLine(LINE_D), | |
| 135 | |
| 136 (Isolate isolate) async { | |
| 137 // Reset global to 0 and start again. | |
| 138 var result = await isolate.rootLibrary.evaluate('global=0'); | |
| 139 print('set global to $result'); | |
| 140 expect(result.type, equals('Instance')); | |
| 141 expect(result.valueAsString, equals('0')); | |
| 142 | |
| 143 result = await isolate.resume(); | |
| 144 expect(result['type'], equals('Success')); | |
| 145 }, | |
| 146 | |
| 147 hasStoppedAtBreakpoint, | |
| 148 stoppedAtLine(LINE_A), | |
| 149 | |
| 150 (Isolate isolate) async { | |
| 151 // We are at our breakpoint with global=100. | |
| 152 var result = await isolate.rootLibrary.evaluate('global'); | |
| 153 print('global is $result'); | |
| 154 expect(result.type, equals('Instance')); | |
| 155 expect(result.valueAsString, equals('100')); | |
| 156 | |
| 157 // Rewind the top 2 stack frames. | |
| 158 result = await isolate.rewind(2); | |
| 159 expect(result['type'], equals('Success')); | |
| 160 }, | |
| 161 | |
| 162 hasStoppedAtBreakpoint, | |
| 163 stoppedAtLine(LINE_C), | |
| 164 ]; | |
| 165 | |
| 166 | |
| 167 main(args) => runIsolateTests(args, tests, testeeConcurrent: test, | |
| 168 extraArgs: | |
| 169 ['--trace-rewind', | |
| 170 '--no-prune-dead-locals', | |
| 171 '--enable-inlining-annotations', | |
| 172 '--no-background-compilation', | |
| 173 '--optimization-counter-threshold=10']); | |
| OLD | NEW |