Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(146)

Side by Side Diff: runtime/vm/debugger_api_impl_test.cc

Issue 2974233002: VM: Re-format to use at most one newline between functions (Closed)
Patch Set: Rebase and merge Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/debugger_api_impl.cc ('k') | runtime/vm/debugger_arm.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 #include "include/dart_mirrors_api.h" 5 #include "include/dart_mirrors_api.h"
6 #include "include/dart_tools_api.h" 6 #include "include/dart_tools_api.h"
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/dart_api_impl.h" 8 #include "vm/dart_api_impl.h"
9 #include "vm/lockers.h" 9 #include "vm/lockers.h"
10 #include "vm/unit_test.h" 10 #include "vm/unit_test.h"
11 11
12 namespace dart { 12 namespace dart {
13 13
14 DECLARE_FLAG(bool, trace_shutdown); 14 DECLARE_FLAG(bool, trace_shutdown);
15 15
16 #ifndef PRODUCT 16 #ifndef PRODUCT
17 17
18 static bool breakpoint_hit = false; 18 static bool breakpoint_hit = false;
19 static int breakpoint_hit_counter = 0; 19 static int breakpoint_hit_counter = 0;
20 static Dart_Handle script_lib = NULL; 20 static Dart_Handle script_lib = NULL;
21 21
22 static const bool verbose = true; 22 static const bool verbose = true;
23 23
24 static void LoadScript(const char* source) { 24 static void LoadScript(const char* source) {
25 script_lib = TestCase::LoadTestScript(source, NULL); 25 script_lib = TestCase::LoadTestScript(source, NULL);
26 EXPECT_VALID(script_lib); 26 EXPECT_VALID(script_lib);
27 } 27 }
28 28
29
30 static void SetBreakpointAtEntry(const char* cname, const char* fname) { 29 static void SetBreakpointAtEntry(const char* cname, const char* fname) {
31 ASSERT(script_lib != NULL); 30 ASSERT(script_lib != NULL);
32 ASSERT(!Dart_IsError(script_lib)); 31 ASSERT(!Dart_IsError(script_lib));
33 ASSERT(Dart_IsLibrary(script_lib)); 32 ASSERT(Dart_IsLibrary(script_lib));
34 Dart_Handle res = 33 Dart_Handle res =
35 Dart_SetBreakpointAtEntry(script_lib, NewString(cname), NewString(fname)); 34 Dart_SetBreakpointAtEntry(script_lib, NewString(cname), NewString(fname));
36 EXPECT(Dart_IsInteger(res)); 35 EXPECT(Dart_IsInteger(res));
37 } 36 }
38 37
39
40 static void DisableDebuggabilityOfDartColonLibraries() { 38 static void DisableDebuggabilityOfDartColonLibraries() {
41 const char* dart_colon = "dart:"; 39 const char* dart_colon = "dart:";
42 const intptr_t dart_colon_length = strlen(dart_colon); 40 const intptr_t dart_colon_length = strlen(dart_colon);
43 // Disable debuggability of all dart: libraries. 41 // Disable debuggability of all dart: libraries.
44 Dart_Handle library_ids = Dart_GetLibraryIds(); 42 Dart_Handle library_ids = Dart_GetLibraryIds();
45 intptr_t library_ids_length; 43 intptr_t library_ids_length;
46 Dart_ListLength(library_ids, &library_ids_length); 44 Dart_ListLength(library_ids, &library_ids_length);
47 for (intptr_t i = 0; i < library_ids_length; i++) { 45 for (intptr_t i = 0; i < library_ids_length; i++) {
48 Dart_Handle library_id_handle = Dart_ListGetAt(library_ids, i); 46 Dart_Handle library_id_handle = Dart_ListGetAt(library_ids, i);
49 int64_t library_id; 47 int64_t library_id;
50 Dart_IntegerToInt64(library_id_handle, &library_id); 48 Dart_IntegerToInt64(library_id_handle, &library_id);
51 Dart_Handle library_url_handle = Dart_GetLibraryURL(library_id); 49 Dart_Handle library_url_handle = Dart_GetLibraryURL(library_id);
52 const char* library_url; 50 const char* library_url;
53 Dart_StringToCString(library_url_handle, &library_url); 51 Dart_StringToCString(library_url_handle, &library_url);
54 if (strncmp(library_url, dart_colon, dart_colon_length) == 0) { 52 if (strncmp(library_url, dart_colon, dart_colon_length) == 0) {
55 Dart_SetLibraryDebuggable(library_id, false); 53 Dart_SetLibraryDebuggable(library_id, false);
56 } else { 54 } else {
57 Dart_SetLibraryDebuggable(library_id, true); 55 Dart_SetLibraryDebuggable(library_id, true);
58 } 56 }
59 } 57 }
60 } 58 }
61 59
62
63 static Dart_Handle Invoke(const char* func_name) { 60 static Dart_Handle Invoke(const char* func_name) {
64 ASSERT(script_lib != NULL); 61 ASSERT(script_lib != NULL);
65 ASSERT(!Dart_IsError(script_lib)); 62 ASSERT(!Dart_IsError(script_lib));
66 ASSERT(Dart_IsLibrary(script_lib)); 63 ASSERT(Dart_IsLibrary(script_lib));
67 return Dart_Invoke(script_lib, NewString(func_name), 0, NULL); 64 return Dart_Invoke(script_lib, NewString(func_name), 0, NULL);
68 } 65 }
69 66
70
71 static char const* ToCString(Dart_Handle str) { 67 static char const* ToCString(Dart_Handle str) {
72 EXPECT(Dart_IsString(str)); 68 EXPECT(Dart_IsString(str));
73 char const* c_str = NULL; 69 char const* c_str = NULL;
74 Dart_StringToCString(str, &c_str); 70 Dart_StringToCString(str, &c_str);
75 return c_str; 71 return c_str;
76 } 72 }
77 73
78
79 static int64_t ToInt64(Dart_Handle h) { 74 static int64_t ToInt64(Dart_Handle h) {
80 EXPECT(Dart_IsInteger(h)); 75 EXPECT(Dart_IsInteger(h));
81 int64_t i = 0; 76 int64_t i = 0;
82 Dart_Handle res = Dart_IntegerToInt64(h, &i); 77 Dart_Handle res = Dart_IntegerToInt64(h, &i);
83 EXPECT_VALID(res); 78 EXPECT_VALID(res);
84 return i; 79 return i;
85 } 80 }
86 81
87
88 static double ToDouble(Dart_Handle h) { 82 static double ToDouble(Dart_Handle h) {
89 EXPECT(Dart_IsDouble(h)); 83 EXPECT(Dart_IsDouble(h));
90 double d = 0.0; 84 double d = 0.0;
91 Dart_Handle res = Dart_DoubleValue(h, &d); 85 Dart_Handle res = Dart_DoubleValue(h, &d);
92 EXPECT_VALID(res); 86 EXPECT_VALID(res);
93 return d; 87 return d;
94 } 88 }
95 89
96
97 static char const* BreakpointInfo(Dart_StackTrace trace) { 90 static char const* BreakpointInfo(Dart_StackTrace trace) {
98 static char info_str[128]; 91 static char info_str[128];
99 Dart_ActivationFrame frame; 92 Dart_ActivationFrame frame;
100 Dart_Handle res = Dart_GetActivationFrame(trace, 0, &frame); 93 Dart_Handle res = Dart_GetActivationFrame(trace, 0, &frame);
101 EXPECT_TRUE(res); 94 EXPECT_TRUE(res);
102 Dart_Handle func_name; 95 Dart_Handle func_name;
103 Dart_Handle url; 96 Dart_Handle url;
104 intptr_t line_number = 0; 97 intptr_t line_number = 0;
105 intptr_t library_id = 0; 98 intptr_t library_id = 0;
106 res = Dart_ActivationFrameInfo(frame, &func_name, &url, &line_number, 99 res = Dart_ActivationFrameInfo(frame, &func_name, &url, &line_number,
107 &library_id); 100 &library_id);
108 EXPECT_TRUE(res); 101 EXPECT_TRUE(res);
109 OS::SNPrint(info_str, sizeof(info_str), "function %s (%s:%" Pd ")", 102 OS::SNPrint(info_str, sizeof(info_str), "function %s (%s:%" Pd ")",
110 ToCString(func_name), ToCString(url), line_number); 103 ToCString(func_name), ToCString(url), line_number);
111 return info_str; 104 return info_str;
112 } 105 }
113 106
114
115 static void PrintValue(Dart_Handle value, bool expand); 107 static void PrintValue(Dart_Handle value, bool expand);
116 108
117
118 static void PrintObjectList(Dart_Handle list, const char* prefix, bool expand) { 109 static void PrintObjectList(Dart_Handle list, const char* prefix, bool expand) {
119 intptr_t list_length = 0; 110 intptr_t list_length = 0;
120 Dart_Handle retval = Dart_ListLength(list, &list_length); 111 Dart_Handle retval = Dart_ListLength(list, &list_length);
121 EXPECT_VALID(retval); 112 EXPECT_VALID(retval);
122 for (int i = 0; i + 1 < list_length; i += 2) { 113 for (int i = 0; i + 1 < list_length; i += 2) {
123 Dart_Handle name_handle = Dart_ListGetAt(list, i); 114 Dart_Handle name_handle = Dart_ListGetAt(list, i);
124 EXPECT_VALID(name_handle); 115 EXPECT_VALID(name_handle);
125 EXPECT(Dart_IsString(name_handle)); 116 EXPECT(Dart_IsString(name_handle));
126 Dart_Handle value_handle = Dart_ListGetAt(list, i + 1); 117 Dart_Handle value_handle = Dart_ListGetAt(list, i + 1);
127 OS::Print("\n %s %s = ", prefix, ToCString(name_handle)); 118 OS::Print("\n %s %s = ", prefix, ToCString(name_handle));
128 PrintValue(value_handle, expand); 119 PrintValue(value_handle, expand);
129 } 120 }
130 } 121 }
131 122
132
133 static void PrintObject(Dart_Handle obj, bool expand) { 123 static void PrintObject(Dart_Handle obj, bool expand) {
134 Dart_Handle obj_class = Dart_GetObjClass(obj); 124 Dart_Handle obj_class = Dart_GetObjClass(obj);
135 EXPECT_VALID(obj_class); 125 EXPECT_VALID(obj_class);
136 EXPECT(!Dart_IsNull(obj_class)); 126 EXPECT(!Dart_IsNull(obj_class));
137 Dart_Handle class_name = Dart_ToString(obj_class); 127 Dart_Handle class_name = Dart_ToString(obj_class);
138 EXPECT_VALID(class_name); 128 EXPECT_VALID(class_name);
139 EXPECT(Dart_IsString(class_name)); 129 EXPECT(Dart_IsString(class_name));
140 char const* class_name_str; 130 char const* class_name_str;
141 Dart_StringToCString(class_name, &class_name_str); 131 Dart_StringToCString(class_name, &class_name_str);
142 Dart_Handle fields = Dart_GetInstanceFields(obj); 132 Dart_Handle fields = Dart_GetInstanceFields(obj);
143 EXPECT_VALID(fields); 133 EXPECT_VALID(fields);
144 EXPECT(Dart_IsList(fields)); 134 EXPECT(Dart_IsList(fields));
145 OS::Print("object of type '%s'", class_name_str); 135 OS::Print("object of type '%s'", class_name_str);
146 PrintObjectList(fields, "field", false); 136 PrintObjectList(fields, "field", false);
147 Dart_Handle statics = Dart_GetStaticFields(obj_class); 137 Dart_Handle statics = Dart_GetStaticFields(obj_class);
148 EXPECT_VALID(obj_class); 138 EXPECT_VALID(obj_class);
149 PrintObjectList(statics, "static field", false); 139 PrintObjectList(statics, "static field", false);
150 } 140 }
151 141
152
153 static void PrintValue(Dart_Handle value, bool expand) { 142 static void PrintValue(Dart_Handle value, bool expand) {
154 if (Dart_IsNull(value)) { 143 if (Dart_IsNull(value)) {
155 OS::Print("null"); 144 OS::Print("null");
156 } else if (Dart_IsString(value)) { 145 } else if (Dart_IsString(value)) {
157 Dart_Handle str_value = Dart_ToString(value); 146 Dart_Handle str_value = Dart_ToString(value);
158 EXPECT_VALID(str_value); 147 EXPECT_VALID(str_value);
159 EXPECT(Dart_IsString(str_value)); 148 EXPECT(Dart_IsString(str_value));
160 OS::Print("\"%s\"", ToCString(str_value)); 149 OS::Print("\"%s\"", ToCString(str_value));
161 } else if (Dart_IsNumber(value) || Dart_IsBoolean(value)) { 150 } else if (Dart_IsNumber(value) || Dart_IsBoolean(value)) {
162 Dart_Handle str_value = Dart_ToString(value); 151 Dart_Handle str_value = Dart_ToString(value);
163 EXPECT_VALID(str_value); 152 EXPECT_VALID(str_value);
164 EXPECT(Dart_IsString(str_value)); 153 EXPECT(Dart_IsString(str_value));
165 OS::Print("%s", ToCString(str_value)); 154 OS::Print("%s", ToCString(str_value));
166 } else { 155 } else {
167 PrintObject(value, expand); 156 PrintObject(value, expand);
168 } 157 }
169 } 158 }
170 159
171
172 static void PrintActivationFrame(Dart_ActivationFrame frame) { 160 static void PrintActivationFrame(Dart_ActivationFrame frame) {
173 Dart_Handle func_name; 161 Dart_Handle func_name;
174 Dart_Handle res; 162 Dart_Handle res;
175 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL, NULL); 163 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL, NULL);
176 EXPECT_TRUE(res); 164 EXPECT_TRUE(res);
177 EXPECT(Dart_IsString(func_name)); 165 EXPECT(Dart_IsString(func_name));
178 const char* func_name_chars; 166 const char* func_name_chars;
179 Dart_StringToCString(func_name, &func_name_chars); 167 Dart_StringToCString(func_name, &func_name_chars);
180 OS::Print(" function %s\n", func_name_chars); 168 OS::Print(" function %s\n", func_name_chars);
181 Dart_Handle locals = Dart_GetLocalVariables(frame); 169 Dart_Handle locals = Dart_GetLocalVariables(frame);
182 EXPECT_VALID(locals); 170 EXPECT_VALID(locals);
183 intptr_t list_length = 0; 171 intptr_t list_length = 0;
184 Dart_Handle ret = Dart_ListLength(locals, &list_length); 172 Dart_Handle ret = Dart_ListLength(locals, &list_length);
185 EXPECT_VALID(ret); 173 EXPECT_VALID(ret);
186 for (int i = 0; i + 1 < list_length; i += 2) { 174 for (int i = 0; i + 1 < list_length; i += 2) {
187 Dart_Handle name_handle = Dart_ListGetAt(locals, i); 175 Dart_Handle name_handle = Dart_ListGetAt(locals, i);
188 EXPECT_VALID(name_handle); 176 EXPECT_VALID(name_handle);
189 EXPECT(Dart_IsString(name_handle)); 177 EXPECT(Dart_IsString(name_handle));
190 OS::Print(" local var %s = ", ToCString(name_handle)); 178 OS::Print(" local var %s = ", ToCString(name_handle));
191 Dart_Handle value_handle = Dart_ListGetAt(locals, i + 1); 179 Dart_Handle value_handle = Dart_ListGetAt(locals, i + 1);
192 EXPECT_VALID(value_handle); 180 EXPECT_VALID(value_handle);
193 PrintValue(value_handle, true); 181 PrintValue(value_handle, true);
194 OS::Print("\n"); 182 OS::Print("\n");
195 } 183 }
196 } 184 }
197 185
198
199 static Dart_Handle GetLocalVariable(Dart_ActivationFrame frame, 186 static Dart_Handle GetLocalVariable(Dart_ActivationFrame frame,
200 const char* name) { 187 const char* name) {
201 Dart_Handle locals = Dart_GetLocalVariables(frame); 188 Dart_Handle locals = Dart_GetLocalVariables(frame);
202 EXPECT_VALID(locals); 189 EXPECT_VALID(locals);
203 intptr_t list_length = 0; 190 intptr_t list_length = 0;
204 Dart_Handle ret = Dart_ListLength(locals, &list_length); 191 Dart_Handle ret = Dart_ListLength(locals, &list_length);
205 EXPECT_VALID(ret); 192 EXPECT_VALID(ret);
206 for (int i = 0; i + 1 < list_length; i += 2) { 193 for (int i = 0; i + 1 < list_length; i += 2) {
207 Dart_Handle name_handle = Dart_ListGetAt(locals, i); 194 Dart_Handle name_handle = Dart_ListGetAt(locals, i);
208 EXPECT_VALID(name_handle); 195 EXPECT_VALID(name_handle);
209 EXPECT(Dart_IsString(name_handle)); 196 EXPECT(Dart_IsString(name_handle));
210 if (strcmp(ToCString(name_handle), name) == 0) { 197 if (strcmp(ToCString(name_handle), name) == 0) {
211 Dart_Handle value_handle = Dart_ListGetAt(locals, i + 1); 198 Dart_Handle value_handle = Dart_ListGetAt(locals, i + 1);
212 EXPECT_VALID(value_handle); 199 EXPECT_VALID(value_handle);
213 return value_handle; 200 return value_handle;
214 } 201 }
215 } 202 }
216 FAIL("local variable not found"); 203 FAIL("local variable not found");
217 return Dart_Null(); 204 return Dart_Null();
218 } 205 }
219 206
220
221 static void PrintStackTrace(Dart_StackTrace trace) { 207 static void PrintStackTrace(Dart_StackTrace trace) {
222 intptr_t trace_len; 208 intptr_t trace_len;
223 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); 209 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len);
224 EXPECT_TRUE(res); 210 EXPECT_TRUE(res);
225 for (int i = 0; i < trace_len; i++) { 211 for (int i = 0; i < trace_len; i++) {
226 Dart_ActivationFrame frame; 212 Dart_ActivationFrame frame;
227 res = Dart_GetActivationFrame(trace, i, &frame); 213 res = Dart_GetActivationFrame(trace, i, &frame);
228 EXPECT_TRUE(res); 214 EXPECT_TRUE(res);
229 PrintActivationFrame(frame); 215 PrintActivationFrame(frame);
230 } 216 }
231 } 217 }
232 218
233
234 static void VerifyListEquals(Dart_Handle expected, 219 static void VerifyListEquals(Dart_Handle expected,
235 Dart_Handle got, 220 Dart_Handle got,
236 bool skip_null_expects) { 221 bool skip_null_expects) {
237 EXPECT(Dart_IsList(expected)); 222 EXPECT(Dart_IsList(expected));
238 EXPECT(Dart_IsList(got)); 223 EXPECT(Dart_IsList(got));
239 Dart_Handle res; 224 Dart_Handle res;
240 intptr_t expected_length; 225 intptr_t expected_length;
241 res = Dart_ListLength(expected, &expected_length); 226 res = Dart_ListLength(expected, &expected_length);
242 EXPECT_VALID(res); 227 EXPECT_VALID(res);
243 intptr_t got_length; 228 intptr_t got_length;
244 res = Dart_ListLength(expected, &got_length); 229 res = Dart_ListLength(expected, &got_length);
245 EXPECT_VALID(res); 230 EXPECT_VALID(res);
246 EXPECT_EQ(expected_length, got_length); 231 EXPECT_EQ(expected_length, got_length);
247 for (intptr_t i = 0; i < expected_length; i++) { 232 for (intptr_t i = 0; i < expected_length; i++) {
248 Dart_Handle expected_elem = Dart_ListGetAt(expected, i); 233 Dart_Handle expected_elem = Dart_ListGetAt(expected, i);
249 EXPECT_VALID(expected_elem); 234 EXPECT_VALID(expected_elem);
250 Dart_Handle got_elem = Dart_ListGetAt(got, i); 235 Dart_Handle got_elem = Dart_ListGetAt(got, i);
251 EXPECT_VALID(got_elem); 236 EXPECT_VALID(got_elem);
252 bool equals; 237 bool equals;
253 res = Dart_ObjectEquals(expected_elem, got_elem, &equals); 238 res = Dart_ObjectEquals(expected_elem, got_elem, &equals);
254 EXPECT_VALID(res); 239 EXPECT_VALID(res);
255 EXPECT(equals || (Dart_IsNull(expected_elem) && skip_null_expects)); 240 EXPECT(equals || (Dart_IsNull(expected_elem) && skip_null_expects));
256 } 241 }
257 } 242 }
258 243
259
260 static void VerifyStackFrame(Dart_ActivationFrame frame, 244 static void VerifyStackFrame(Dart_ActivationFrame frame,
261 const char* expected_name, 245 const char* expected_name,
262 Dart_Handle expected_locals, 246 Dart_Handle expected_locals,
263 bool skip_null_expects) { 247 bool skip_null_expects) {
264 Dart_Handle func_name; 248 Dart_Handle func_name;
265 Dart_Handle func; 249 Dart_Handle func;
266 Dart_Handle res; 250 Dart_Handle res;
267 res = Dart_ActivationFrameGetLocation(frame, &func_name, &func, NULL); 251 res = Dart_ActivationFrameGetLocation(frame, &func_name, &func, NULL);
268 EXPECT_TRUE(res); 252 EXPECT_TRUE(res);
269 EXPECT(Dart_IsString(func_name)); 253 EXPECT(Dart_IsString(func_name));
270 const char* func_name_chars; 254 const char* func_name_chars;
271 Dart_StringToCString(func_name, &func_name_chars); 255 Dart_StringToCString(func_name, &func_name_chars);
272 if (expected_name != NULL) { 256 if (expected_name != NULL) {
273 EXPECT_SUBSTRING(expected_name, func_name_chars); 257 EXPECT_SUBSTRING(expected_name, func_name_chars);
274 } 258 }
275 EXPECT(Dart_IsFunction(func)); 259 EXPECT(Dart_IsFunction(func));
276 const char* func_name_chars_from_func_handle; 260 const char* func_name_chars_from_func_handle;
277 Dart_StringToCString(Dart_FunctionName(func), 261 Dart_StringToCString(Dart_FunctionName(func),
278 &func_name_chars_from_func_handle); 262 &func_name_chars_from_func_handle);
279 EXPECT_SUBSTRING(func_name_chars_from_func_handle, func_name_chars); 263 EXPECT_SUBSTRING(func_name_chars_from_func_handle, func_name_chars);
280 264
281 if (!Dart_IsNull(expected_locals)) { 265 if (!Dart_IsNull(expected_locals)) {
282 Dart_Handle locals = Dart_GetLocalVariables(frame); 266 Dart_Handle locals = Dart_GetLocalVariables(frame);
283 EXPECT_VALID(locals); 267 EXPECT_VALID(locals);
284 VerifyListEquals(expected_locals, locals, skip_null_expects); 268 VerifyListEquals(expected_locals, locals, skip_null_expects);
285 } 269 }
286 } 270 }
287 271
288
289 static void VerifyStackTrace(Dart_StackTrace trace, 272 static void VerifyStackTrace(Dart_StackTrace trace,
290 const char* func_names[], 273 const char* func_names[],
291 Dart_Handle local_vars[], 274 Dart_Handle local_vars[],
292 int expected_frames, 275 int expected_frames,
293 bool skip_null_expects) { 276 bool skip_null_expects) {
294 intptr_t trace_len; 277 intptr_t trace_len;
295 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); 278 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len);
296 EXPECT_TRUE(res); 279 EXPECT_TRUE(res);
297 uintptr_t last_frame_pointer = 0; 280 uintptr_t last_frame_pointer = 0;
298 uintptr_t frame_pointer; 281 uintptr_t frame_pointer;
(...skipping 15 matching lines...) Expand all
314 } 297 }
315 last_frame_pointer = frame_pointer; 298 last_frame_pointer = frame_pointer;
316 if (i < expected_frames) { 299 if (i < expected_frames) {
317 VerifyStackFrame(frame, func_names[i], local_vars[i], skip_null_expects); 300 VerifyStackFrame(frame, func_names[i], local_vars[i], skip_null_expects);
318 } else { 301 } else {
319 VerifyStackFrame(frame, NULL, Dart_Null(), skip_null_expects); 302 VerifyStackFrame(frame, NULL, Dart_Null(), skip_null_expects);
320 } 303 }
321 } 304 }
322 } 305 }
323 306
324
325 void TestBreakpointHandler(Dart_IsolateId isolate_id, 307 void TestBreakpointHandler(Dart_IsolateId isolate_id,
326 intptr_t bp_id, 308 intptr_t bp_id,
327 const Dart_CodeLocation& location) { 309 const Dart_CodeLocation& location) {
328 const char* expected_trace[] = {"A.foo", "main"}; 310 const char* expected_trace[] = {"A.foo", "main"};
329 const intptr_t expected_trace_length = 2; 311 const intptr_t expected_trace_length = 2;
330 breakpoint_hit = true; 312 breakpoint_hit = true;
331 breakpoint_hit_counter++; 313 breakpoint_hit_counter++;
332 Dart_StackTrace trace; 314 Dart_StackTrace trace;
333 Dart_GetStackTrace(&trace); 315 Dart_GetStackTrace(&trace);
334 intptr_t trace_len; 316 intptr_t trace_len;
335 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); 317 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len);
336 EXPECT_VALID(res); 318 EXPECT_VALID(res);
337 EXPECT_EQ(expected_trace_length, trace_len); 319 EXPECT_EQ(expected_trace_length, trace_len);
338 for (int i = 0; i < trace_len; i++) { 320 for (int i = 0; i < trace_len; i++) {
339 Dart_ActivationFrame frame; 321 Dart_ActivationFrame frame;
340 res = Dart_GetActivationFrame(trace, i, &frame); 322 res = Dart_GetActivationFrame(trace, i, &frame);
341 EXPECT_VALID(res); 323 EXPECT_VALID(res);
342 Dart_Handle func_name; 324 Dart_Handle func_name;
343 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL, NULL); 325 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL, NULL);
344 EXPECT_VALID(res); 326 EXPECT_VALID(res);
345 EXPECT(Dart_IsString(func_name)); 327 EXPECT(Dart_IsString(func_name));
346 const char* name_chars; 328 const char* name_chars;
347 Dart_StringToCString(func_name, &name_chars); 329 Dart_StringToCString(func_name, &name_chars);
348 EXPECT_STREQ(expected_trace[i], name_chars); 330 EXPECT_STREQ(expected_trace[i], name_chars);
349 if (verbose) OS::Print(" >> %d: %s\n", i, name_chars); 331 if (verbose) OS::Print(" >> %d: %s\n", i, name_chars);
350 } 332 }
351 } 333 }
352 334
353
354 TEST_CASE(Debug_Breakpoint) { 335 TEST_CASE(Debug_Breakpoint) {
355 const char* kScriptChars = 336 const char* kScriptChars =
356 "void moo(s) { } \n" 337 "void moo(s) { } \n"
357 "class A { \n" 338 "class A { \n"
358 " static void foo() { \n" 339 " static void foo() { \n"
359 " moo('good news'); \n" 340 " moo('good news'); \n"
360 " } \n" 341 " } \n"
361 "} \n" 342 "} \n"
362 "void main() { \n" 343 "void main() { \n"
363 " A.foo(); \n" 344 " A.foo(); \n"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 pos = OS::SNPrint(buffer, buffer_size, "%s = %s ", name_cstr, value_cstr); 397 pos = OS::SNPrint(buffer, buffer_size, "%s = %s ", name_cstr, value_cstr);
417 buffer += pos; 398 buffer += pos;
418 buffer_size -= pos; 399 buffer_size -= pos;
419 } 400 }
420 pos = OS::SNPrint(buffer, buffer_size, "}\n"); 401 pos = OS::SNPrint(buffer, buffer_size, "}\n");
421 buffer += pos; 402 buffer += pos;
422 buffer_size -= pos; 403 buffer_size -= pos;
423 } 404 }
424 } 405 }
425 406
426
427 static void InspectOptimizedStack_Breakpoint(Dart_IsolateId isolate_id, 407 static void InspectOptimizedStack_Breakpoint(Dart_IsolateId isolate_id,
428 intptr_t bp_id, 408 intptr_t bp_id,
429 const Dart_CodeLocation& loc) { 409 const Dart_CodeLocation& loc) {
430 Dart_StackTrace trace; 410 Dart_StackTrace trace;
431 Dart_GetStackTrace(&trace); 411 Dart_GetStackTrace(&trace);
432 SaveStackTrace(trace); 412 SaveStackTrace(trace);
433 } 413 }
434 414
435
436 static void InspectStackTest(bool optimize) { 415 static void InspectStackTest(bool optimize) {
437 const char* kScriptChars = 416 const char* kScriptChars =
438 "void breakpointNow() {\n" 417 "void breakpointNow() {\n"
439 "}\n" 418 "}\n"
440 "int helper(int a, int b, bool stop) {\n" 419 "int helper(int a, int b, bool stop) {\n"
441 " if (b == 99 && stop) {\n" 420 " if (b == 99 && stop) {\n"
442 " breakpointNow();\n" 421 " breakpointNow();\n"
443 " }\n" 422 " }\n"
444 " int c = a*b;\n" 423 " int c = a*b;\n"
445 " return c;\n" 424 " return c;\n"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 "[3] middleMan { x = 5 limit = 100 stop = true value = 24255" 487 "[3] middleMan { x = 5 limit = 100 stop = true value = 24255"
509 " i = 99 }\n" 488 " i = 99 }\n"
510 "[4] test { stop = true limit = 100 }\n", 489 "[4] test { stop = true limit = 100 }\n",
511 stack_buffer); 490 stack_buffer);
512 } 491 }
513 492
514 FLAG_optimization_counter_threshold = saved_threshold; 493 FLAG_optimization_counter_threshold = saved_threshold;
515 isolate->set_use_osr(saved_use_osr); 494 isolate->set_use_osr(saved_use_osr);
516 } 495 }
517 496
518
519 TEST_CASE(Debug_InspectStack_NotOptimized) { 497 TEST_CASE(Debug_InspectStack_NotOptimized) {
520 InspectStackTest(false); 498 InspectStackTest(false);
521 } 499 }
522 500
523
524 TEST_CASE(Debug_InspectStack_Optimized) { 501 TEST_CASE(Debug_InspectStack_Optimized) {
525 // Ensure code gets optimized. 502 // Ensure code gets optimized.
526 FLAG_background_compilation = false; 503 FLAG_background_compilation = false;
527 InspectStackTest(true); 504 InspectStackTest(true);
528 } 505 }
529 506
530
531 static void InspectStackWithClosureTest(bool optimize) { 507 static void InspectStackWithClosureTest(bool optimize) {
532 const char* kScriptChars = 508 const char* kScriptChars =
533 "void breakpointNow() {\n" 509 "void breakpointNow() {\n"
534 "}\n" 510 "}\n"
535 "int helper(int a, int b, bool stop) {\n" 511 "int helper(int a, int b, bool stop) {\n"
536 " if (b == 99 && stop) {\n" 512 " if (b == 99 && stop) {\n"
537 " breakpointNow();\n" 513 " breakpointNow();\n"
538 " }\n" 514 " }\n"
539 " int c = a*b;\n" 515 " int c = a*b;\n"
540 " return c;\n" 516 " return c;\n"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 "[4] middleMan { x = 5 limit = 100 stop = true" 584 "[4] middleMan { x = 5 limit = 100 stop = true"
609 " value = 242550 i = 99 }\n" 585 " value = 242550 i = 99 }\n"
610 "[5] test { stop = true limit = 100 }\n", 586 "[5] test { stop = true limit = 100 }\n",
611 stack_buffer); 587 stack_buffer);
612 } 588 }
613 589
614 FLAG_optimization_counter_threshold = saved_threshold; 590 FLAG_optimization_counter_threshold = saved_threshold;
615 FLAG_use_osr = saved_osr; 591 FLAG_use_osr = saved_osr;
616 } 592 }
617 593
618
619 TEST_CASE(Debug_InspectStackWithClosure_NotOptimized) { 594 TEST_CASE(Debug_InspectStackWithClosure_NotOptimized) {
620 InspectStackWithClosureTest(false); 595 InspectStackWithClosureTest(false);
621 } 596 }
622 597
623
624 TEST_CASE(Debug_InspectStackWithClosure_Optimized) { 598 TEST_CASE(Debug_InspectStackWithClosure_Optimized) {
625 // Ensure code gets optimized. 599 // Ensure code gets optimized.
626 FLAG_background_compilation = false; 600 FLAG_background_compilation = false;
627 InspectStackWithClosureTest(true); 601 InspectStackWithClosureTest(true);
628 } 602 }
629 603
630
631 void TestStepOutHandler(Dart_IsolateId isolate_id, 604 void TestStepOutHandler(Dart_IsolateId isolate_id,
632 intptr_t bp_id, 605 intptr_t bp_id,
633 const Dart_CodeLocation& location) { 606 const Dart_CodeLocation& location) {
634 Dart_StackTrace trace; 607 Dart_StackTrace trace;
635 Dart_GetStackTrace(&trace); 608 Dart_GetStackTrace(&trace);
636 const char* expected_bpts[] = {"f1", "foo", "main"}; 609 const char* expected_bpts[] = {"f1", "foo", "main"};
637 const intptr_t expected_bpts_length = ARRAY_SIZE(expected_bpts); 610 const intptr_t expected_bpts_length = ARRAY_SIZE(expected_bpts);
638 intptr_t trace_len; 611 intptr_t trace_len;
639 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); 612 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len);
640 EXPECT_VALID(res); 613 EXPECT_VALID(res);
(...skipping 11 matching lines...) Expand all
652 EXPECT_STREQ(expected_bpts[breakpoint_hit_counter], name_chars); 625 EXPECT_STREQ(expected_bpts[breakpoint_hit_counter], name_chars);
653 } 626 }
654 if (verbose) { 627 if (verbose) {
655 OS::Print(" >> bpt nr %d: %s\n", breakpoint_hit_counter, name_chars); 628 OS::Print(" >> bpt nr %d: %s\n", breakpoint_hit_counter, name_chars);
656 } 629 }
657 breakpoint_hit = true; 630 breakpoint_hit = true;
658 breakpoint_hit_counter++; 631 breakpoint_hit_counter++;
659 Dart_SetStepOut(); 632 Dart_SetStepOut();
660 } 633 }
661 634
662
663 TEST_CASE(Debug_StepOut) { 635 TEST_CASE(Debug_StepOut) {
664 const char* kScriptChars = 636 const char* kScriptChars =
665 "f1() { return 1; } \n" 637 "f1() { return 1; } \n"
666 "f2() { return 2; } \n" 638 "f2() { return 2; } \n"
667 " \n" 639 " \n"
668 "foo() { \n" 640 "foo() { \n"
669 " f1(); \n" 641 " f1(); \n"
670 " return f2(); \n" 642 " return f2(); \n"
671 "} \n" 643 "} \n"
672 " \n" 644 " \n"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 EXPECT_STREQ(step_into_expected_bpts[breakpoint_hit_counter], name_chars); 706 EXPECT_STREQ(step_into_expected_bpts[breakpoint_hit_counter], name_chars);
735 } 707 }
736 if (verbose) { 708 if (verbose) {
737 OS::Print(" >> bpt nr %d: %s\n", breakpoint_hit_counter, name_chars); 709 OS::Print(" >> bpt nr %d: %s\n", breakpoint_hit_counter, name_chars);
738 } 710 }
739 breakpoint_hit = true; 711 breakpoint_hit = true;
740 breakpoint_hit_counter++; 712 breakpoint_hit_counter++;
741 Dart_SetStepInto(); 713 Dart_SetStepInto();
742 } 714 }
743 715
744
745 TEST_CASE(Debug_StepInto) { 716 TEST_CASE(Debug_StepInto) {
746 const char* kScriptChars = 717 const char* kScriptChars =
747 "f1() { return 1; } \n" 718 "f1() { return 1; } \n"
748 "f2() { return 2; } \n" 719 "f2() { return 2; } \n"
749 " \n" 720 " \n"
750 "class X { \n" 721 "class X { \n"
751 " kvmk(a, {b, c}) { \n" 722 " kvmk(a, {b, c}) { \n"
752 " return c + f2(); \n" 723 " return c + f2(); \n"
753 " } \n" 724 " } \n"
754 "} \n" 725 "} \n"
(...skipping 18 matching lines...) Expand all
773 breakpoint_hit_counter = 0; 744 breakpoint_hit_counter = 0;
774 Dart_Handle retval = Invoke("main"); 745 Dart_Handle retval = Invoke("main");
775 EXPECT_VALID(retval); 746 EXPECT_VALID(retval);
776 EXPECT(Dart_IsInteger(retval)); 747 EXPECT(Dart_IsInteger(retval));
777 int64_t int_value = ToInt64(retval); 748 int64_t int_value = ToInt64(retval);
778 EXPECT_EQ(7, int_value); 749 EXPECT_EQ(7, int_value);
779 EXPECT(breakpoint_hit == true); 750 EXPECT(breakpoint_hit == true);
780 EXPECT(breakpoint_hit_counter == ARRAY_SIZE(step_into_expected_bpts)); 751 EXPECT(breakpoint_hit_counter == ARRAY_SIZE(step_into_expected_bpts));
781 } 752 }
782 753
783
784 static void StepIntoHandler(Dart_IsolateId isolate_id, 754 static void StepIntoHandler(Dart_IsolateId isolate_id,
785 intptr_t bp_id, 755 intptr_t bp_id,
786 const Dart_CodeLocation& location) { 756 const Dart_CodeLocation& location) {
787 Dart_StackTrace trace; 757 Dart_StackTrace trace;
788 Dart_GetStackTrace(&trace); 758 Dart_GetStackTrace(&trace);
789 if (verbose) { 759 if (verbose) {
790 OS::Print(">>> Breakpoint nr. %d in %s <<<\n", breakpoint_hit_counter, 760 OS::Print(">>> Breakpoint nr. %d in %s <<<\n", breakpoint_hit_counter,
791 BreakpointInfo(trace)); 761 BreakpointInfo(trace));
792 PrintStackTrace(trace); 762 PrintStackTrace(trace);
793 } 763 }
794 breakpoint_hit = true; 764 breakpoint_hit = true;
795 breakpoint_hit_counter++; 765 breakpoint_hit_counter++;
796 Dart_SetStepInto(); 766 Dart_SetStepInto();
797 } 767 }
798 768
799
800 TEST_CASE(Debug_IgnoreBP) { 769 TEST_CASE(Debug_IgnoreBP) {
801 const char* kScriptChars = 770 const char* kScriptChars =
802 "class B { \n" 771 "class B { \n"
803 " static var z = 0; \n" 772 " static var z = 0; \n"
804 " var i = 100; \n" 773 " var i = 100; \n"
805 " var d = 3.14; \n" 774 " var d = 3.14; \n"
806 " var s = 'Dr Seuss'; \n" 775 " var s = 'Dr Seuss'; \n"
807 "} \n" 776 "} \n"
808 " \n" 777 " \n"
809 "main() { \n" 778 "main() { \n"
810 " var x = new B(); \n" 779 " var x = new B(); \n"
811 " return x.i + 1; \n" 780 " return x.i + 1; \n"
812 "} \n"; 781 "} \n";
813 782
814 LoadScript(kScriptChars); 783 LoadScript(kScriptChars);
815 Dart_SetPausedEventHandler(&StepIntoHandler); 784 Dart_SetPausedEventHandler(&StepIntoHandler);
816 785
817 SetBreakpointAtEntry("", "main"); 786 SetBreakpointAtEntry("", "main");
818 787
819 breakpoint_hit = false; 788 breakpoint_hit = false;
820 breakpoint_hit_counter = 0; 789 breakpoint_hit_counter = 0;
821 Dart_Handle retval = Invoke("main"); 790 Dart_Handle retval = Invoke("main");
822 EXPECT_VALID(retval); 791 EXPECT_VALID(retval);
823 EXPECT(Dart_IsInteger(retval)); 792 EXPECT(Dart_IsInteger(retval));
824 int64_t int_value = ToInt64(retval); 793 int64_t int_value = ToInt64(retval);
825 EXPECT_EQ(101, int_value); 794 EXPECT_EQ(101, int_value);
826 EXPECT(breakpoint_hit == true); 795 EXPECT(breakpoint_hit == true);
827 } 796 }
828 797
829
830 TEST_CASE(Debug_DeoptimizeFunction) { 798 TEST_CASE(Debug_DeoptimizeFunction) {
831 const char* kScriptChars = 799 const char* kScriptChars =
832 "foo(x) => 2 * x; \n" 800 "foo(x) => 2 * x; \n"
833 " \n" 801 " \n"
834 "warmup() { \n" 802 "warmup() { \n"
835 " for (int i = 0; i < 5000; i++) { \n" 803 " for (int i = 0; i < 5000; i++) { \n"
836 " foo(i); \n" 804 " foo(i); \n"
837 " } \n" 805 " } \n"
838 "} \n" 806 "} \n"
839 " \n" 807 " \n"
840 "main() { \n" 808 "main() { \n"
841 " return foo(99); \n" 809 " return foo(99); \n"
842 "} \n"; 810 "} \n";
843 811
844 LoadScript(kScriptChars); 812 LoadScript(kScriptChars);
845 Dart_SetPausedEventHandler(&StepIntoHandler); 813 Dart_SetPausedEventHandler(&StepIntoHandler);
846 814
847
848 // Cause function foo to be optimized before we set a BP. 815 // Cause function foo to be optimized before we set a BP.
849 Dart_Handle res = Invoke("warmup"); 816 Dart_Handle res = Invoke("warmup");
850 EXPECT_VALID(res); 817 EXPECT_VALID(res);
851 818
852 // Now set breakpoint in main and then step into optimized function foo. 819 // Now set breakpoint in main and then step into optimized function foo.
853 SetBreakpointAtEntry("", "main"); 820 SetBreakpointAtEntry("", "main");
854 821
855
856 breakpoint_hit = false; 822 breakpoint_hit = false;
857 breakpoint_hit_counter = 0; 823 breakpoint_hit_counter = 0;
858 Dart_Handle retval = Invoke("main"); 824 Dart_Handle retval = Invoke("main");
859 EXPECT_VALID(retval); 825 EXPECT_VALID(retval);
860 EXPECT(Dart_IsInteger(retval)); 826 EXPECT(Dart_IsInteger(retval));
861 int64_t int_value = ToInt64(retval); 827 int64_t int_value = ToInt64(retval);
862 EXPECT_EQ(2 * 99, int_value); 828 EXPECT_EQ(2 * 99, int_value);
863 EXPECT(breakpoint_hit == true); 829 EXPECT(breakpoint_hit == true);
864 } 830 }
865 831
866
867 void TestSingleStepHandler(Dart_IsolateId isolate_id, 832 void TestSingleStepHandler(Dart_IsolateId isolate_id,
868 intptr_t bp_id, 833 intptr_t bp_id,
869 const Dart_CodeLocation& location) { 834 const Dart_CodeLocation& location) {
870 Dart_StackTrace trace; 835 Dart_StackTrace trace;
871 Dart_GetStackTrace(&trace); 836 Dart_GetStackTrace(&trace);
872 const char* expected_bpts[] = {"moo", "moo", "foo", "moo", "moo", 837 const char* expected_bpts[] = {"moo", "moo", "foo", "moo", "moo",
873 "foo", "moo", "moo", "foo", "main"}; 838 "foo", "moo", "moo", "foo", "main"};
874 const intptr_t expected_bpts_length = ARRAY_SIZE(expected_bpts); 839 const intptr_t expected_bpts_length = ARRAY_SIZE(expected_bpts);
875 intptr_t trace_len; 840 intptr_t trace_len;
876 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); 841 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len);
(...skipping 12 matching lines...) Expand all
889 OS::Print(" >> bpt nr %d: %s\n", breakpoint_hit_counter, name_chars); 854 OS::Print(" >> bpt nr %d: %s\n", breakpoint_hit_counter, name_chars);
890 } 855 }
891 if (breakpoint_hit_counter < expected_bpts_length) { 856 if (breakpoint_hit_counter < expected_bpts_length) {
892 EXPECT_STREQ(expected_bpts[breakpoint_hit_counter], name_chars); 857 EXPECT_STREQ(expected_bpts[breakpoint_hit_counter], name_chars);
893 } 858 }
894 breakpoint_hit = true; 859 breakpoint_hit = true;
895 breakpoint_hit_counter++; 860 breakpoint_hit_counter++;
896 Dart_SetStepOver(); 861 Dart_SetStepOver();
897 } 862 }
898 863
899
900 TEST_CASE(Debug_SingleStep) { 864 TEST_CASE(Debug_SingleStep) {
901 const char* kScriptChars = 865 const char* kScriptChars =
902 "moo(s) { return 1; } \n" 866 "moo(s) { return 1; } \n"
903 " \n" 867 " \n"
904 "void foo() { \n" 868 "void foo() { \n"
905 " moo('step one'); \n" 869 " moo('step one'); \n"
906 " moo('step two'); \n" 870 " moo('step two'); \n"
907 " moo('step three'); \n" 871 " moo('step three'); \n"
908 "} \n" 872 "} \n"
909 " \n" 873 " \n"
910 "void main() { \n" 874 "void main() { \n"
911 " foo(); \n" 875 " foo(); \n"
912 "} \n"; 876 "} \n";
913 877
914 LoadScript(kScriptChars); 878 LoadScript(kScriptChars);
915 Dart_SetPausedEventHandler(&TestSingleStepHandler); 879 Dart_SetPausedEventHandler(&TestSingleStepHandler);
916 880
917 SetBreakpointAtEntry("", "moo"); 881 SetBreakpointAtEntry("", "moo");
918 882
919 breakpoint_hit = false; 883 breakpoint_hit = false;
920 breakpoint_hit_counter = 0; 884 breakpoint_hit_counter = 0;
921 Dart_Handle retval = Invoke("main"); 885 Dart_Handle retval = Invoke("main");
922 EXPECT_VALID(retval); 886 EXPECT_VALID(retval);
923 EXPECT(breakpoint_hit == true); 887 EXPECT(breakpoint_hit == true);
924 } 888 }
925 889
926
927 static void ClosureBreakpointHandler(Dart_IsolateId isolate_id, 890 static void ClosureBreakpointHandler(Dart_IsolateId isolate_id,
928 intptr_t bp_id, 891 intptr_t bp_id,
929 const Dart_CodeLocation& location) { 892 const Dart_CodeLocation& location) {
930 Dart_StackTrace trace; 893 Dart_StackTrace trace;
931 Dart_GetStackTrace(&trace); 894 Dart_GetStackTrace(&trace);
932 const char* expected_trace[] = {"callback", "main"}; 895 const char* expected_trace[] = {"callback", "main"};
933 const intptr_t expected_trace_length = 2; 896 const intptr_t expected_trace_length = 2;
934 breakpoint_hit_counter++; 897 breakpoint_hit_counter++;
935 intptr_t trace_len; 898 intptr_t trace_len;
936 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); 899 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len);
937 EXPECT_VALID(res); 900 EXPECT_VALID(res);
938 EXPECT_EQ(expected_trace_length, trace_len); 901 EXPECT_EQ(expected_trace_length, trace_len);
939 for (int i = 0; i < trace_len; i++) { 902 for (int i = 0; i < trace_len; i++) {
940 Dart_ActivationFrame frame; 903 Dart_ActivationFrame frame;
941 res = Dart_GetActivationFrame(trace, i, &frame); 904 res = Dart_GetActivationFrame(trace, i, &frame);
942 EXPECT_VALID(res); 905 EXPECT_VALID(res);
943 Dart_Handle func_name; 906 Dart_Handle func_name;
944 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL, NULL); 907 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL, NULL);
945 EXPECT_VALID(res); 908 EXPECT_VALID(res);
946 EXPECT(Dart_IsString(func_name)); 909 EXPECT(Dart_IsString(func_name));
947 const char* name_chars; 910 const char* name_chars;
948 Dart_StringToCString(func_name, &name_chars); 911 Dart_StringToCString(func_name, &name_chars);
949 EXPECT_STREQ(expected_trace[i], name_chars); 912 EXPECT_STREQ(expected_trace[i], name_chars);
950 if (verbose) OS::Print(" >> %d: %s\n", i, name_chars); 913 if (verbose) OS::Print(" >> %d: %s\n", i, name_chars);
951 } 914 }
952 } 915 }
953 916
954
955 TEST_CASE(Debug_ClosureBreakpoint) { 917 TEST_CASE(Debug_ClosureBreakpoint) {
956 const char* kScriptChars = 918 const char* kScriptChars =
957 "callback(s) { \n" 919 "callback(s) { \n"
958 " return 111; \n" 920 " return 111; \n"
959 "} \n" 921 "} \n"
960 " \n" 922 " \n"
961 "main() { \n" 923 "main() { \n"
962 " var h = callback; \n" 924 " var h = callback; \n"
963 " h('bla'); \n" 925 " h('bla'); \n"
964 " callback('jada'); \n" 926 " callback('jada'); \n"
965 " return 442; \n" 927 " return 442; \n"
966 "} \n"; 928 "} \n";
967 929
968 LoadScript(kScriptChars); 930 LoadScript(kScriptChars);
969 Dart_SetPausedEventHandler(&ClosureBreakpointHandler); 931 Dart_SetPausedEventHandler(&ClosureBreakpointHandler);
970 932
971 SetBreakpointAtEntry("", "callback"); 933 SetBreakpointAtEntry("", "callback");
972 934
973 breakpoint_hit_counter = 0; 935 breakpoint_hit_counter = 0;
974 Dart_Handle retval = Invoke("main"); 936 Dart_Handle retval = Invoke("main");
975 EXPECT_VALID(retval); 937 EXPECT_VALID(retval);
976 int64_t int_value = ToInt64(retval); 938 int64_t int_value = ToInt64(retval);
977 EXPECT_EQ(442, int_value); 939 EXPECT_EQ(442, int_value);
978 EXPECT_EQ(2, breakpoint_hit_counter); 940 EXPECT_EQ(2, breakpoint_hit_counter);
979 } 941 }
980 942
981
982 static void ExprClosureBreakpointHandler(Dart_IsolateId isolate_id, 943 static void ExprClosureBreakpointHandler(Dart_IsolateId isolate_id,
983 intptr_t bp_id, 944 intptr_t bp_id,
984 const Dart_CodeLocation& location) { 945 const Dart_CodeLocation& location) {
985 Dart_StackTrace trace; 946 Dart_StackTrace trace;
986 Dart_GetStackTrace(&trace); 947 Dart_GetStackTrace(&trace);
987 static const char* expected_trace[] = {"<anonymous closure>", "main"}; 948 static const char* expected_trace[] = {"<anonymous closure>", "main"};
988 Dart_Handle add_locals = Dart_NewList(4); 949 Dart_Handle add_locals = Dart_NewList(4);
989 Dart_ListSetAt(add_locals, 0, NewString("a")); 950 Dart_ListSetAt(add_locals, 0, NewString("a"));
990 Dart_ListSetAt(add_locals, 1, Dart_NewInteger(10)); 951 Dart_ListSetAt(add_locals, 1, Dart_NewInteger(10));
991 Dart_ListSetAt(add_locals, 2, NewString("b")); 952 Dart_ListSetAt(add_locals, 2, NewString("b"));
992 Dart_ListSetAt(add_locals, 3, Dart_NewInteger(20)); 953 Dart_ListSetAt(add_locals, 3, Dart_NewInteger(20));
993 Dart_Handle expected_locals[] = {add_locals, Dart_Null()}; 954 Dart_Handle expected_locals[] = {add_locals, Dart_Null()};
994 breakpoint_hit_counter++; 955 breakpoint_hit_counter++;
995 PrintStackTrace(trace); 956 PrintStackTrace(trace);
996 VerifyStackTrace(trace, expected_trace, expected_locals, 2, false); 957 VerifyStackTrace(trace, expected_trace, expected_locals, 2, false);
997 } 958 }
998 959
999
1000 TEST_CASE(Debug_ExprClosureBreakpoint) { 960 TEST_CASE(Debug_ExprClosureBreakpoint) {
1001 const char* kScriptChars = 961 const char* kScriptChars =
1002 "var c; \n" 962 "var c; \n"
1003 " \n" 963 " \n"
1004 "main() { \n" 964 "main() { \n"
1005 " c = (a, b) { \n" 965 " c = (a, b) { \n"
1006 " return a + b; \n" 966 " return a + b; \n"
1007 " }; \n" 967 " }; \n"
1008 " return c(10, 20); \n" 968 " return c(10, 20); \n"
1009 "} \n"; 969 "} \n";
1010 970
1011 LoadScript(kScriptChars); 971 LoadScript(kScriptChars);
1012 Dart_SetPausedEventHandler(&ExprClosureBreakpointHandler); 972 Dart_SetPausedEventHandler(&ExprClosureBreakpointHandler);
1013 973
1014 Dart_Handle script_url = NewString(TestCase::url()); 974 Dart_Handle script_url = NewString(TestCase::url());
1015 intptr_t line_no = 5; // In closure 'add'. 975 intptr_t line_no = 5; // In closure 'add'.
1016 Dart_Handle res = Dart_SetBreakpoint(script_url, line_no); 976 Dart_Handle res = Dart_SetBreakpoint(script_url, line_no);
1017 EXPECT_VALID(res); 977 EXPECT_VALID(res);
1018 EXPECT(Dart_IsInteger(res)); 978 EXPECT(Dart_IsInteger(res));
1019 979
1020 breakpoint_hit_counter = 0; 980 breakpoint_hit_counter = 0;
1021 Dart_Handle retval = Invoke("main"); 981 Dart_Handle retval = Invoke("main");
1022 EXPECT_VALID(retval); 982 EXPECT_VALID(retval);
1023 int64_t int_value = ToInt64(retval); 983 int64_t int_value = ToInt64(retval);
1024 EXPECT_EQ(30, int_value); 984 EXPECT_EQ(30, int_value);
1025 EXPECT_EQ(1, breakpoint_hit_counter); 985 EXPECT_EQ(1, breakpoint_hit_counter);
1026 } 986 }
1027 987
1028
1029 void TestBreakpointHandlerWithVerify(Dart_IsolateId isolate_id, 988 void TestBreakpointHandlerWithVerify(Dart_IsolateId isolate_id,
1030 intptr_t bp_id, 989 intptr_t bp_id,
1031 const Dart_CodeLocation& location) { 990 const Dart_CodeLocation& location) {
1032 breakpoint_hit = true; 991 breakpoint_hit = true;
1033 breakpoint_hit_counter++; 992 breakpoint_hit_counter++;
1034 Dart_StackTrace trace; 993 Dart_StackTrace trace;
1035 Dart_GetStackTrace(&trace); 994 Dart_GetStackTrace(&trace);
1036 Dart_ActivationFrame frame; 995 Dart_ActivationFrame frame;
1037 Dart_Handle res = Dart_GetActivationFrame(trace, 0, &frame); 996 Dart_Handle res = Dart_GetActivationFrame(trace, 0, &frame);
1038 EXPECT_VALID(res); 997 EXPECT_VALID(res);
1039 Dart_Handle func_name; 998 Dart_Handle func_name;
1040 intptr_t line_number = -1; 999 intptr_t line_number = -1;
1041 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, &line_number, NULL); 1000 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, &line_number, NULL);
1042 EXPECT_NE(-1, line_number); 1001 EXPECT_NE(-1, line_number);
1043 if (verbose) OS::Print("Hit line %" Pd "\n", line_number); 1002 if (verbose) OS::Print("Hit line %" Pd "\n", line_number);
1044 1003
1045 VerifyPointersVisitor::VerifyPointers(); 1004 VerifyPointersVisitor::VerifyPointers();
1046 } 1005 }
1047 1006
1048
1049 static void NoopNativeFunction(Dart_NativeArguments args) { 1007 static void NoopNativeFunction(Dart_NativeArguments args) {
1050 Dart_EnterScope(); 1008 Dart_EnterScope();
1051 Dart_SetReturnValue(args, Dart_True()); 1009 Dart_SetReturnValue(args, Dart_True());
1052 Dart_ExitScope(); 1010 Dart_ExitScope();
1053 } 1011 }
1054 1012
1055
1056 static Dart_NativeFunction NoopNativeResolver(Dart_Handle name, 1013 static Dart_NativeFunction NoopNativeResolver(Dart_Handle name,
1057 int arg_count, 1014 int arg_count,
1058 bool* auto_setup_scope) { 1015 bool* auto_setup_scope) {
1059 ASSERT(auto_setup_scope != NULL); 1016 ASSERT(auto_setup_scope != NULL);
1060 *auto_setup_scope = false; 1017 *auto_setup_scope = false;
1061 return &NoopNativeFunction; 1018 return &NoopNativeFunction;
1062 } 1019 }
1063 1020
1064
1065 TEST_CASE(Debug_BreakpointStubPatching) { 1021 TEST_CASE(Debug_BreakpointStubPatching) {
1066 // Note changes to this script may require changes to the breakpoint line 1022 // Note changes to this script may require changes to the breakpoint line
1067 // numbers below. 1023 // numbers below.
1068 const char* kScriptChars = 1024 const char* kScriptChars =
1069 "bar(i) {} \n" 1025 "bar(i) {} \n"
1070 "nat() native 'a'; \n" 1026 "nat() native 'a'; \n"
1071 "foo(n) { \n" 1027 "foo(n) { \n"
1072 " for(var i = 0; i < n; i++) { \n" 1028 " for(var i = 0; i < n; i++) { \n"
1073 " bar(i); \n" // Static call. 1029 " bar(i); \n" // Static call.
1074 " i++; \n" // Instance call. 1030 " i++; \n" // Instance call.
(...skipping 30 matching lines...) Expand all
1105 } 1061 }
1106 1062
1107 breakpoint_hit = false; 1063 breakpoint_hit = false;
1108 breakpoint_hit_counter = 0; 1064 breakpoint_hit_counter = 0;
1109 Dart_Handle retval = Invoke("main"); 1065 Dart_Handle retval = Invoke("main");
1110 EXPECT_VALID(retval); 1066 EXPECT_VALID(retval);
1111 EXPECT(breakpoint_hit == true); 1067 EXPECT(breakpoint_hit == true);
1112 EXPECT_EQ(num_breakpoints, breakpoint_hit_counter); 1068 EXPECT_EQ(num_breakpoints, breakpoint_hit_counter);
1113 } 1069 }
1114 1070
1115
1116 static intptr_t bp_id_to_be_deleted; 1071 static intptr_t bp_id_to_be_deleted;
1117 1072
1118 static void DeleteBreakpointHandler(Dart_IsolateId isolate_id, 1073 static void DeleteBreakpointHandler(Dart_IsolateId isolate_id,
1119 intptr_t bp_id, 1074 intptr_t bp_id,
1120 const Dart_CodeLocation& location) { 1075 const Dart_CodeLocation& location) {
1121 Dart_StackTrace trace; 1076 Dart_StackTrace trace;
1122 Dart_GetStackTrace(&trace); 1077 Dart_GetStackTrace(&trace);
1123 const char* expected_trace[] = {"foo", "main"}; 1078 const char* expected_trace[] = {"foo", "main"};
1124 const intptr_t expected_trace_length = 2; 1079 const intptr_t expected_trace_length = 2;
1125 breakpoint_hit_counter++; 1080 breakpoint_hit_counter++;
(...skipping 16 matching lines...) Expand all
1142 } 1097 }
1143 // Remove the breakpoint after we've hit it twice 1098 // Remove the breakpoint after we've hit it twice
1144 if (breakpoint_hit_counter == 2) { 1099 if (breakpoint_hit_counter == 2) {
1145 if (verbose) OS::Print("uninstalling breakpoint\n"); 1100 if (verbose) OS::Print("uninstalling breakpoint\n");
1146 EXPECT_EQ(bp_id_to_be_deleted, bp_id); 1101 EXPECT_EQ(bp_id_to_be_deleted, bp_id);
1147 Dart_Handle res = Dart_RemoveBreakpoint(bp_id); 1102 Dart_Handle res = Dart_RemoveBreakpoint(bp_id);
1148 EXPECT_VALID(res); 1103 EXPECT_VALID(res);
1149 } 1104 }
1150 } 1105 }
1151 1106
1152
1153 TEST_CASE(Debug_DeleteBreakpoint) { 1107 TEST_CASE(Debug_DeleteBreakpoint) {
1154 const char* kScriptChars = 1108 const char* kScriptChars =
1155 "moo(s) { } \n" 1109 "moo(s) { } \n"
1156 " \n" 1110 " \n"
1157 "foo() { \n" 1111 "foo() { \n"
1158 " moo('good news'); \n" 1112 " moo('good news'); \n"
1159 "} \n" 1113 "} \n"
1160 " \n" 1114 " \n"
1161 "void main() { \n" 1115 "void main() { \n"
1162 " foo(); \n" 1116 " foo(); \n"
(...skipping 16 matching lines...) Expand all
1179 // Function main() calls foo() 3 times. On the second iteration, the 1133 // Function main() calls foo() 3 times. On the second iteration, the
1180 // breakpoint is removed by the handler, so we expect the breakpoint 1134 // breakpoint is removed by the handler, so we expect the breakpoint
1181 // to fire twice only. 1135 // to fire twice only.
1182 bp_id_to_be_deleted = bp_id; 1136 bp_id_to_be_deleted = bp_id;
1183 breakpoint_hit_counter = 0; 1137 breakpoint_hit_counter = 0;
1184 Dart_Handle retval = Invoke("main"); 1138 Dart_Handle retval = Invoke("main");
1185 EXPECT_VALID(retval); 1139 EXPECT_VALID(retval);
1186 EXPECT_EQ(2, breakpoint_hit_counter); 1140 EXPECT_EQ(2, breakpoint_hit_counter);
1187 } 1141 }
1188 1142
1189
1190 static void InspectStaticFieldHandler(Dart_IsolateId isolate_id, 1143 static void InspectStaticFieldHandler(Dart_IsolateId isolate_id,
1191 intptr_t bp_id, 1144 intptr_t bp_id,
1192 const Dart_CodeLocation& location) { 1145 const Dart_CodeLocation& location) {
1193 Dart_StackTrace trace; 1146 Dart_StackTrace trace;
1194 Dart_GetStackTrace(&trace); 1147 Dart_GetStackTrace(&trace);
1195 ASSERT(script_lib != NULL); 1148 ASSERT(script_lib != NULL);
1196 ASSERT(!Dart_IsError(script_lib)); 1149 ASSERT(!Dart_IsError(script_lib));
1197 ASSERT(Dart_IsLibrary(script_lib)); 1150 ASSERT(Dart_IsLibrary(script_lib));
1198 Dart_Handle class_A = Dart_GetClass(script_lib, NewString("A")); 1151 Dart_Handle class_A = Dart_GetClass(script_lib, NewString("A"));
1199 EXPECT_VALID(class_A); 1152 EXPECT_VALID(class_A);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1236 EXPECT_VALID(value_handle); 1189 EXPECT_VALID(value_handle);
1237 EXPECT(Dart_IsString(value_handle)); 1190 EXPECT(Dart_IsString(value_handle));
1238 char const* value; 1191 char const* value;
1239 Dart_StringToCString(value_handle, &value); 1192 Dart_StringToCString(value_handle, &value);
1240 EXPECT_STREQ(expected[expected_idx].field_value, value); 1193 EXPECT_STREQ(expected[expected_idx].field_value, value);
1241 OS::Print(" %s: %s\n", name, value); 1194 OS::Print(" %s: %s\n", name, value);
1242 expected_idx++; 1195 expected_idx++;
1243 } 1196 }
1244 } 1197 }
1245 1198
1246
1247 TEST_CASE(Debug_InspectStaticField) { 1199 TEST_CASE(Debug_InspectStaticField) {
1248 const char* kScriptChars = 1200 const char* kScriptChars =
1249 " class A { \n" 1201 " class A { \n"
1250 " static var bla = 'yada yada yada'; \n" 1202 " static var bla = 'yada yada yada'; \n"
1251 " static var u; \n" 1203 " static var u; \n"
1252 " } \n" 1204 " } \n"
1253 " \n" 1205 " \n"
1254 " debugBreak() { } \n" 1206 " debugBreak() { } \n"
1255 " main() { \n" 1207 " main() { \n"
1256 " var a = new A(); \n" 1208 " var a = new A(); \n"
1257 " debugBreak(); \n" 1209 " debugBreak(); \n"
1258 " A.u = 442; \n" 1210 " A.u = 442; \n"
1259 " A.bla = 'silence is golden'; \n" 1211 " A.bla = 'silence is golden'; \n"
1260 " debugBreak(); \n" 1212 " debugBreak(); \n"
1261 " } \n"; 1213 " } \n";
1262 1214
1263 LoadScript(kScriptChars); 1215 LoadScript(kScriptChars);
1264 Dart_SetPausedEventHandler(&InspectStaticFieldHandler); 1216 Dart_SetPausedEventHandler(&InspectStaticFieldHandler);
1265 SetBreakpointAtEntry("", "debugBreak"); 1217 SetBreakpointAtEntry("", "debugBreak");
1266 1218
1267 breakpoint_hit_counter = 0; 1219 breakpoint_hit_counter = 0;
1268 Dart_Handle retval = Invoke("main"); 1220 Dart_Handle retval = Invoke("main");
1269 EXPECT_VALID(retval); 1221 EXPECT_VALID(retval);
1270 } 1222 }
1271 1223
1272
1273 TEST_CASE(Debug_InspectObject) { 1224 TEST_CASE(Debug_InspectObject) {
1274 const char* kScriptChars = 1225 const char* kScriptChars =
1275 " class A { \n" 1226 " class A { \n"
1276 " var a_field = 'a'; \n" 1227 " var a_field = 'a'; \n"
1277 " static var bla = 'yada yada yada'; \n" 1228 " static var bla = 'yada yada yada'; \n"
1278 " static var error = unresolvedName(); \n" 1229 " static var error = unresolvedName(); \n"
1279 " var d = 42.1; \n" 1230 " var d = 42.1; \n"
1280 " } \n" 1231 " } \n"
1281 " class B extends A { \n" 1232 " class B extends A { \n"
1282 " var oneDay = const Duration(hours: 24); \n" 1233 " var oneDay = const Duration(hours: 24); \n"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1384 // The static field "error" should result in a compile error. 1335 // The static field "error" should result in a compile error.
1385 name_handle = Dart_ListGetAt(fields, 2); 1336 name_handle = Dart_ListGetAt(fields, 2);
1386 EXPECT_VALID(name_handle); 1337 EXPECT_VALID(name_handle);
1387 EXPECT(Dart_IsString(name_handle)); 1338 EXPECT(Dart_IsString(name_handle));
1388 Dart_StringToCString(name_handle, &name); 1339 Dart_StringToCString(name_handle, &name);
1389 EXPECT_STREQ("error", name); 1340 EXPECT_STREQ("error", name);
1390 value_handle = Dart_ListGetAt(fields, 3); 1341 value_handle = Dart_ListGetAt(fields, 3);
1391 EXPECT(Dart_IsError(value_handle)); 1342 EXPECT(Dart_IsError(value_handle));
1392 } 1343 }
1393 1344
1394
1395 static Dart_IsolateId test_isolate_id = ILLEGAL_ISOLATE_ID; 1345 static Dart_IsolateId test_isolate_id = ILLEGAL_ISOLATE_ID;
1396 static int verify_callback = 0; 1346 static int verify_callback = 0;
1397 static void TestIsolateID(Dart_IsolateId isolate_id, Dart_IsolateEvent kind) { 1347 static void TestIsolateID(Dart_IsolateId isolate_id, Dart_IsolateEvent kind) {
1398 if (kind == kCreated) { 1348 if (kind == kCreated) {
1399 EXPECT(test_isolate_id == ILLEGAL_ISOLATE_ID); 1349 EXPECT(test_isolate_id == ILLEGAL_ISOLATE_ID);
1400 test_isolate_id = isolate_id; 1350 test_isolate_id = isolate_id;
1401 Dart_Isolate isolate = Dart_GetIsolate(isolate_id); 1351 Dart_Isolate isolate = Dart_GetIsolate(isolate_id);
1402 EXPECT(isolate == Dart_CurrentIsolate()); 1352 EXPECT(isolate == Dart_CurrentIsolate());
1403 verify_callback |= 0x1; // Register create callback. 1353 verify_callback |= 0x1; // Register create callback.
1404 } else if (kind == kInterrupted) { 1354 } else if (kind == kInterrupted) {
1405 EXPECT(test_isolate_id == isolate_id); 1355 EXPECT(test_isolate_id == isolate_id);
1406 Dart_Isolate isolate = Dart_GetIsolate(isolate_id); 1356 Dart_Isolate isolate = Dart_GetIsolate(isolate_id);
1407 EXPECT(isolate == Dart_CurrentIsolate()); 1357 EXPECT(isolate == Dart_CurrentIsolate());
1408 verify_callback |= 0x2; // Register interrupt callback. 1358 verify_callback |= 0x2; // Register interrupt callback.
1409 } else if (kind == kShutdown) { 1359 } else if (kind == kShutdown) {
1410 EXPECT(test_isolate_id == isolate_id); 1360 EXPECT(test_isolate_id == isolate_id);
1411 Dart_Isolate isolate = Dart_GetIsolate(isolate_id); 1361 Dart_Isolate isolate = Dart_GetIsolate(isolate_id);
1412 EXPECT(isolate == Dart_CurrentIsolate()); 1362 EXPECT(isolate == Dart_CurrentIsolate());
1413 verify_callback |= 0x4; // Register shutdown callback. 1363 verify_callback |= 0x4; // Register shutdown callback.
1414 } 1364 }
1415 } 1365 }
1416 1366
1417
1418 VM_UNIT_TEST_CASE(Debug_IsolateID) { 1367 VM_UNIT_TEST_CASE(Debug_IsolateID) {
1419 const char* kScriptChars = 1368 const char* kScriptChars =
1420 "void moo(s) { } \n" 1369 "void moo(s) { } \n"
1421 "class A { \n" 1370 "class A { \n"
1422 " static void foo() { \n" 1371 " static void foo() { \n"
1423 " moo('good news'); \n" 1372 " moo('good news'); \n"
1424 " } \n" 1373 " } \n"
1425 "} \n" 1374 "} \n"
1426 "void main() { \n" 1375 "void main() { \n"
1427 " A.foo(); \n" 1376 " A.foo(); \n"
1428 "} \n"; 1377 "} \n";
1429 1378
1430 Dart_SetIsolateEventHandler(&TestIsolateID); 1379 Dart_SetIsolateEventHandler(&TestIsolateID);
1431 Dart_Isolate isolate = TestCase::CreateTestIsolate(); 1380 Dart_Isolate isolate = TestCase::CreateTestIsolate();
1432 ASSERT(isolate != NULL); 1381 ASSERT(isolate != NULL);
1433 Dart_EnterScope(); 1382 Dart_EnterScope();
1434 LoadScript(kScriptChars); 1383 LoadScript(kScriptChars);
1435 Dart_Handle retval = Invoke("main"); 1384 Dart_Handle retval = Invoke("main");
1436 EXPECT_VALID(retval); 1385 EXPECT_VALID(retval);
1437 EXPECT(test_isolate_id != ILLEGAL_ISOLATE_ID); 1386 EXPECT(test_isolate_id != ILLEGAL_ISOLATE_ID);
1438 EXPECT(Dart_GetIsolate(test_isolate_id) == isolate); 1387 EXPECT(Dart_GetIsolate(test_isolate_id) == isolate);
1439 EXPECT(Dart_GetIsolateId(isolate) == test_isolate_id); 1388 EXPECT(Dart_GetIsolateId(isolate) == test_isolate_id);
1440 Dart_ExitScope(); 1389 Dart_ExitScope();
1441 Dart_ShutdownIsolate(); 1390 Dart_ShutdownIsolate();
1442 Dart_SetIsolateEventHandler(NULL); 1391 Dart_SetIsolateEventHandler(NULL);
1443 EXPECT(verify_callback == 0x5); // Only created and shutdown events. 1392 EXPECT(verify_callback == 0x5); // Only created and shutdown events.
1444 } 1393 }
1445 1394
1446
1447 static Monitor* sync = NULL; 1395 static Monitor* sync = NULL;
1448 static bool isolate_interrupted = false; 1396 static bool isolate_interrupted = false;
1449 static bool pause_event_handled = false; 1397 static bool pause_event_handled = false;
1450 static bool interrupt_thread_stopped = false; 1398 static bool interrupt_thread_stopped = false;
1451 static Dart_IsolateId interrupt_isolate_id = ILLEGAL_ISOLATE_ID; 1399 static Dart_IsolateId interrupt_isolate_id = ILLEGAL_ISOLATE_ID;
1452 static volatile bool continue_isolate_loop = true; 1400 static volatile bool continue_isolate_loop = true;
1453 1401
1454
1455 static void InterruptIsolateHandler(Dart_IsolateId isolateId, 1402 static void InterruptIsolateHandler(Dart_IsolateId isolateId,
1456 intptr_t breakpointId, 1403 intptr_t breakpointId,
1457 const Dart_CodeLocation& location) { 1404 const Dart_CodeLocation& location) {
1458 MonitorLocker ml(sync); 1405 MonitorLocker ml(sync);
1459 pause_event_handled = true; 1406 pause_event_handled = true;
1460 ml.Notify(); 1407 ml.Notify();
1461 } 1408 }
1462 1409
1463 static void TestInterruptIsolate(Dart_IsolateId isolate_id, 1410 static void TestInterruptIsolate(Dart_IsolateId isolate_id,
1464 Dart_IsolateEvent kind) { 1411 Dart_IsolateEvent kind) {
(...skipping 15 matching lines...) Expand all
1480 } 1427 }
1481 } else if (kind == kShutdown) { 1428 } else if (kind == kShutdown) {
1482 if (interrupt_isolate_id == isolate_id) { 1429 if (interrupt_isolate_id == isolate_id) {
1483 MonitorLocker ml(sync); 1430 MonitorLocker ml(sync);
1484 interrupt_isolate_id = ILLEGAL_ISOLATE_ID; 1431 interrupt_isolate_id = ILLEGAL_ISOLATE_ID;
1485 ml.Notify(); 1432 ml.Notify();
1486 } 1433 }
1487 } 1434 }
1488 } 1435 }
1489 1436
1490
1491 static void InterruptNativeFunction(Dart_NativeArguments args) { 1437 static void InterruptNativeFunction(Dart_NativeArguments args) {
1492 Dart_EnterScope(); 1438 Dart_EnterScope();
1493 Dart_Handle val = Dart_NewBoolean(continue_isolate_loop); 1439 Dart_Handle val = Dart_NewBoolean(continue_isolate_loop);
1494 Dart_SetReturnValue(args, val); 1440 Dart_SetReturnValue(args, val);
1495 Dart_ExitScope(); 1441 Dart_ExitScope();
1496 } 1442 }
1497 1443
1498
1499 static Dart_NativeFunction InterruptNativeResolver(Dart_Handle name, 1444 static Dart_NativeFunction InterruptNativeResolver(Dart_Handle name,
1500 int arg_count, 1445 int arg_count,
1501 bool* auto_setup_scope) { 1446 bool* auto_setup_scope) {
1502 ASSERT(auto_setup_scope != NULL); 1447 ASSERT(auto_setup_scope != NULL);
1503 *auto_setup_scope = false; 1448 *auto_setup_scope = false;
1504 return &InterruptNativeFunction; 1449 return &InterruptNativeFunction;
1505 } 1450 }
1506 1451
1507
1508 static void InterruptIsolateRun(uword unused) { 1452 static void InterruptIsolateRun(uword unused) {
1509 const char* kScriptChars = 1453 const char* kScriptChars =
1510 "void moo(s) { } \n" 1454 "void moo(s) { } \n"
1511 "class A { \n" 1455 "class A { \n"
1512 " static check() native 'a'; \n" 1456 " static check() native 'a'; \n"
1513 " static void foo() { \n" 1457 " static void foo() { \n"
1514 " var loop = true; \n" 1458 " var loop = true; \n"
1515 " while (loop) { \n" 1459 " while (loop) { \n"
1516 " moo('good news'); \n" 1460 " moo('good news'); \n"
1517 " loop = check(); \n" 1461 " loop = check(); \n"
(...skipping 18 matching lines...) Expand all
1536 Dart_ExitScope(); 1480 Dart_ExitScope();
1537 Dart_ShutdownIsolate(); 1481 Dart_ShutdownIsolate();
1538 { 1482 {
1539 // Notify the waiting thread that we are done. 1483 // Notify the waiting thread that we are done.
1540 MonitorLocker ml(sync); 1484 MonitorLocker ml(sync);
1541 interrupt_thread_stopped = true; 1485 interrupt_thread_stopped = true;
1542 ml.Notify(); 1486 ml.Notify();
1543 } 1487 }
1544 } 1488 }
1545 1489
1546
1547 TEST_CASE(Debug_InterruptIsolate) { 1490 TEST_CASE(Debug_InterruptIsolate) {
1548 bool saved_flag = FLAG_trace_shutdown; 1491 bool saved_flag = FLAG_trace_shutdown;
1549 FLAG_trace_shutdown = true; 1492 FLAG_trace_shutdown = true;
1550 sync = new Monitor(); 1493 sync = new Monitor();
1551 Dart_SetIsolateEventHandler(&TestInterruptIsolate); 1494 Dart_SetIsolateEventHandler(&TestInterruptIsolate);
1552 EXPECT(interrupt_isolate_id == ILLEGAL_ISOLATE_ID); 1495 EXPECT(interrupt_isolate_id == ILLEGAL_ISOLATE_ID);
1553 Dart_SetPausedEventHandler(InterruptIsolateHandler); 1496 Dart_SetPausedEventHandler(InterruptIsolateHandler);
1554 { 1497 {
1555 MonitorLocker ml(sync); 1498 MonitorLocker ml(sync);
1556 interrupt_thread_stopped = false; 1499 interrupt_thread_stopped = false;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1600 { 1543 {
1601 MonitorLocker ml(sync); 1544 MonitorLocker ml(sync);
1602 while (!interrupt_thread_stopped) { 1545 while (!interrupt_thread_stopped) {
1603 ml.Wait(); 1546 ml.Wait();
1604 } 1547 }
1605 } 1548 }
1606 OS::PrintErr("Complete\n"); 1549 OS::PrintErr("Complete\n");
1607 FLAG_trace_shutdown = saved_flag; 1550 FLAG_trace_shutdown = saved_flag;
1608 } 1551 }
1609 1552
1610
1611 static void StackTraceDump1BreakpointHandler( 1553 static void StackTraceDump1BreakpointHandler(
1612 Dart_IsolateId isolate_id, 1554 Dart_IsolateId isolate_id,
1613 intptr_t bp_id, 1555 intptr_t bp_id,
1614 const Dart_CodeLocation& location) { 1556 const Dart_CodeLocation& location) {
1615 Dart_StackTrace trace; 1557 Dart_StackTrace trace;
1616 Dart_GetStackTrace(&trace); 1558 Dart_GetStackTrace(&trace);
1617 const int kStackTraceLen = 4; 1559 const int kStackTraceLen = 4;
1618 static const char* expected_trace[kStackTraceLen] = { 1560 static const char* expected_trace[kStackTraceLen] = {
1619 "local_to_main", "Test.local1_to_func1", "Test.func1", "main"}; 1561 "local_to_main", "Test.local1_to_func1", "Test.func1", "main"};
1620 1562
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1687 Dart_ListSetAt(frame3_locals, 12, NewString("main_local")); 1629 Dart_ListSetAt(frame3_locals, 12, NewString("main_local"));
1688 Dart_ListSetAt(frame3_locals, 13, Dart_Null()); 1630 Dart_ListSetAt(frame3_locals, 13, Dart_Null());
1689 1631
1690 Dart_Handle expected_locals[] = {frame0_locals, frame1_locals, frame2_locals, 1632 Dart_Handle expected_locals[] = {frame0_locals, frame1_locals, frame2_locals,
1691 frame3_locals}; 1633 frame3_locals};
1692 breakpoint_hit_counter++; 1634 breakpoint_hit_counter++;
1693 VerifyStackTrace(trace, expected_trace, expected_locals, kStackTraceLen, 1635 VerifyStackTrace(trace, expected_trace, expected_locals, kStackTraceLen,
1694 true); 1636 true);
1695 } 1637 }
1696 1638
1697
1698 TEST_CASE(Debug_StackTraceDump1) { 1639 TEST_CASE(Debug_StackTraceDump1) {
1699 const char* kScriptChars = 1640 const char* kScriptChars =
1700 "class Test {\n" 1641 "class Test {\n"
1701 " Test(int local);\n" 1642 " Test(int local);\n"
1702 "\n" 1643 "\n"
1703 " int func1(int func(int i, int j)) {\n" 1644 " int func1(int func(int i, int j)) {\n"
1704 " var i = 0;\n" 1645 " var i = 0;\n"
1705 " var j = 0;\n" 1646 " var j = 0;\n"
1706 " var k = 0;\n" 1647 " var k = 0;\n"
1707 " var l = 0;\n" 1648 " var l = 0;\n"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1749 EXPECT(Dart_IsInteger(res)); 1690 EXPECT(Dart_IsInteger(res));
1750 1691
1751 breakpoint_hit_counter = 0; 1692 breakpoint_hit_counter = 0;
1752 Dart_Handle retval = Invoke("main"); 1693 Dart_Handle retval = Invoke("main");
1753 EXPECT_VALID(retval); 1694 EXPECT_VALID(retval);
1754 int64_t int_value = ToInt64(retval); 1695 int64_t int_value = ToInt64(retval);
1755 EXPECT_EQ(195, int_value); 1696 EXPECT_EQ(195, int_value);
1756 EXPECT_EQ(1, breakpoint_hit_counter); 1697 EXPECT_EQ(1, breakpoint_hit_counter);
1757 } 1698 }
1758 1699
1759
1760 static void StackTraceDump2ExceptionHandler(Dart_IsolateId isolate_id, 1700 static void StackTraceDump2ExceptionHandler(Dart_IsolateId isolate_id,
1761 Dart_Handle exception_object, 1701 Dart_Handle exception_object,
1762 Dart_StackTrace trace) { 1702 Dart_StackTrace trace) {
1763 const int kStackTraceLen = 5; 1703 const int kStackTraceLen = 5;
1764 static const char* expected_trace[kStackTraceLen] = { 1704 static const char* expected_trace[kStackTraceLen] = {
1765 "Object._noSuchMethod", "Object.noSuchMethod", "Test.local1_to_func1", 1705 "Object._noSuchMethod", "Object.noSuchMethod", "Test.local1_to_func1",
1766 "Test.func1", "main"}; 1706 "Test.func1", "main"};
1767 1707
1768 intptr_t trace_len; 1708 intptr_t trace_len;
1769 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); 1709 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1845 Dart_ListSetAt(frame4_locals, 10, NewString("func1")); 1785 Dart_ListSetAt(frame4_locals, 10, NewString("func1"));
1846 Dart_ListSetAt(frame4_locals, 11, Dart_Null()); 1786 Dart_ListSetAt(frame4_locals, 11, Dart_Null());
1847 1787
1848 Dart_Handle expected_locals[] = {frame0_locals, frame1_locals, frame2_locals, 1788 Dart_Handle expected_locals[] = {frame0_locals, frame1_locals, frame2_locals,
1849 frame3_locals, frame4_locals}; 1789 frame3_locals, frame4_locals};
1850 breakpoint_hit_counter++; 1790 breakpoint_hit_counter++;
1851 VerifyStackTrace(trace, expected_trace, expected_locals, kStackTraceLen, 1791 VerifyStackTrace(trace, expected_trace, expected_locals, kStackTraceLen,
1852 true); 1792 true);
1853 } 1793 }
1854 1794
1855
1856 TEST_CASE(Debug_StackTraceDump2) { 1795 TEST_CASE(Debug_StackTraceDump2) {
1857 const char* kScriptChars = 1796 const char* kScriptChars =
1858 "class Test {\n" 1797 "class Test {\n"
1859 " Test(int local);\n" 1798 " Test(int local);\n"
1860 "\n" 1799 "\n"
1861 " int func1(int func(int i, int j)) {\n" 1800 " int func1(int func(int i, int j)) {\n"
1862 " var i = 0;\n" 1801 " var i = 0;\n"
1863 " var j = 0;\n" 1802 " var j = 0;\n"
1864 " var k = 0;\n" 1803 " var k = 0;\n"
1865 " var l = 0;\n" 1804 " var l = 0;\n"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1898 Dart_SetExceptionThrownHandler(&StackTraceDump2ExceptionHandler); 1837 Dart_SetExceptionThrownHandler(&StackTraceDump2ExceptionHandler);
1899 breakpoint_hit_counter = 0; 1838 breakpoint_hit_counter = 0;
1900 Dart_SetExceptionPauseInfo(kPauseOnAllExceptions); 1839 Dart_SetExceptionPauseInfo(kPauseOnAllExceptions);
1901 1840
1902 Dart_Handle retval = Invoke("main"); 1841 Dart_Handle retval = Invoke("main");
1903 EXPECT(Dart_IsError(retval)); 1842 EXPECT(Dart_IsError(retval));
1904 EXPECT(Dart_IsUnhandledExceptionError(retval)); 1843 EXPECT(Dart_IsUnhandledExceptionError(retval));
1905 EXPECT_EQ(1, breakpoint_hit_counter); 1844 EXPECT_EQ(1, breakpoint_hit_counter);
1906 } 1845 }
1907 1846
1908
1909 void TestEvaluateHandler(Dart_IsolateId isolate_id, 1847 void TestEvaluateHandler(Dart_IsolateId isolate_id,
1910 intptr_t bp_id, 1848 intptr_t bp_id,
1911 const Dart_CodeLocation& location) { 1849 const Dart_CodeLocation& location) {
1912 Dart_StackTrace trace; 1850 Dart_StackTrace trace;
1913 Dart_GetStackTrace(&trace); 1851 Dart_GetStackTrace(&trace);
1914 intptr_t trace_len; 1852 intptr_t trace_len;
1915 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); 1853 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len);
1916 EXPECT_VALID(res); 1854 EXPECT_VALID(res);
1917 EXPECT_EQ(1, trace_len); 1855 EXPECT_EQ(1, trace_len);
1918 Dart_ActivationFrame frame; 1856 Dart_ActivationFrame frame;
(...skipping 21 matching lines...) Expand all
1940 // persistent. 1878 // persistent.
1941 h = Dart_EvaluateExpr(p, NewString("_factor")); 1879 h = Dart_EvaluateExpr(p, NewString("_factor"));
1942 EXPECT_VALID(h); 1880 EXPECT_VALID(h);
1943 EXPECT(Dart_IsInteger(h)); 1881 EXPECT(Dart_IsInteger(h));
1944 EXPECT_EQ(10, ToInt64(h)); 1882 EXPECT_EQ(10, ToInt64(h));
1945 1883
1946 breakpoint_hit = true; 1884 breakpoint_hit = true;
1947 breakpoint_hit_counter++; 1885 breakpoint_hit_counter++;
1948 } 1886 }
1949 1887
1950
1951 TEST_CASE(Debug_EvaluateExpr) { 1888 TEST_CASE(Debug_EvaluateExpr) {
1952 const char* kScriptChars = 1889 const char* kScriptChars =
1953 "import 'dart:math'; \n" 1890 "import 'dart:math'; \n"
1954 "main() { \n" 1891 "main() { \n"
1955 " var p = new Point(3, 4); \n" 1892 " var p = new Point(3, 4); \n"
1956 " l = [1, 2, 3]; /*BP*/ \n" 1893 " l = [1, 2, 3]; /*BP*/ \n"
1957 " m = {'\"': 'quote' , \n" 1894 " m = {'\"': 'quote' , \n"
1958 " \"\t\": 'tab' }; \n" 1895 " \"\t\": 'tab' }; \n"
1959 " return p; \n" 1896 " return p; \n"
1960 "} \n" 1897 "} \n"
1961 "var _factor = 2; \n" 1898 "var _factor = 2; \n"
1962 "var l; \n" 1899 "var l; \n"
1963 "var m; \n" 1900 "var m; \n"
1964 "class Point { \n" 1901 "class Point { \n"
1965 " var x, y; \n" 1902 " var x, y; \n"
1966 " Point(this.x, this.y); \n" 1903 " Point(this.x, this.y); \n"
1967 "} \n"; 1904 "} \n";
1968 1905
1969 LoadScript(kScriptChars); 1906 LoadScript(kScriptChars);
1970 Dart_SetPausedEventHandler(&TestEvaluateHandler); 1907 Dart_SetPausedEventHandler(&TestEvaluateHandler);
1971 1908
1972
1973 Dart_Handle script_url = NewString(TestCase::url()); 1909 Dart_Handle script_url = NewString(TestCase::url());
1974 intptr_t line_no = 4; 1910 intptr_t line_no = 4;
1975 Dart_Handle res = Dart_SetBreakpoint(script_url, line_no); 1911 Dart_Handle res = Dart_SetBreakpoint(script_url, line_no);
1976 EXPECT_VALID(res); 1912 EXPECT_VALID(res);
1977 1913
1978 breakpoint_hit = false; 1914 breakpoint_hit = false;
1979 Dart_Handle point = Invoke("main"); 1915 Dart_Handle point = Invoke("main");
1980 EXPECT_VALID(point); 1916 EXPECT_VALID(point);
1981 EXPECT(breakpoint_hit == true); 1917 EXPECT(breakpoint_hit == true);
1982 1918
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2039 len = Dart_EvaluateExpr(script_lib, NewString("((x) => l.length + x)(1)")); 1975 len = Dart_EvaluateExpr(script_lib, NewString("((x) => l.length + x)(1)"));
2040 EXPECT_VALID(len); 1976 EXPECT_VALID(len);
2041 EXPECT(Dart_IsNumber(len)); 1977 EXPECT(Dart_IsNumber(len));
2042 EXPECT_EQ(6, ToInt64(len)); 1978 EXPECT_EQ(6, ToInt64(len));
2043 1979
2044 Dart_Handle error = 1980 Dart_Handle error =
2045 Dart_EvaluateExpr(script_lib, NewString("new NonexistingType()")); 1981 Dart_EvaluateExpr(script_lib, NewString("new NonexistingType()"));
2046 EXPECT(Dart_IsError(error)); 1982 EXPECT(Dart_IsError(error));
2047 } 1983 }
2048 1984
2049
2050 static void EvaluateInActivationOfEvaluateHandler(Dart_IsolateId isolate_id, 1985 static void EvaluateInActivationOfEvaluateHandler(Dart_IsolateId isolate_id,
2051 Dart_Handle exception_object, 1986 Dart_Handle exception_object,
2052 Dart_StackTrace trace) { 1987 Dart_StackTrace trace) {
2053 breakpoint_hit_counter++; 1988 breakpoint_hit_counter++;
2054 Dart_ActivationFrame top_frame = 0; 1989 Dart_ActivationFrame top_frame = 0;
2055 Dart_Handle result = Dart_GetActivationFrame(trace, 0, &top_frame); 1990 Dart_Handle result = Dart_GetActivationFrame(trace, 0, &top_frame);
2056 EXPECT_VALID(result); 1991 EXPECT_VALID(result);
2057 1992
2058 result = Dart_ActivationFrameEvaluate(top_frame, NewString("p.r")); 1993 result = Dart_ActivationFrameEvaluate(top_frame, NewString("p.r"));
2059 EXPECT_VALID(result); 1994 EXPECT_VALID(result);
2060 EXPECT_EQ(5.0, ToDouble(result)); 1995 EXPECT_EQ(5.0, ToDouble(result));
2061 } 1996 }
2062 1997
2063
2064 TEST_CASE(Debug_EvaluateInActivationOfEvaluate) { 1998 TEST_CASE(Debug_EvaluateInActivationOfEvaluate) {
2065 // This library deliberately declares no top-level variables or methods. This 1999 // This library deliberately declares no top-level variables or methods. This
2066 // exercises a path in eval where a library may have no top-level anonymous 2000 // exercises a path in eval where a library may have no top-level anonymous
2067 // classes. 2001 // classes.
2068 const char* kScriptChars = 2002 const char* kScriptChars =
2069 "import 'dart:math'; \n" 2003 "import 'dart:math'; \n"
2070 "class Point { \n" 2004 "class Point { \n"
2071 " var x, y; \n" 2005 " var x, y; \n"
2072 " Point(this.x, this.y); \n" 2006 " Point(this.x, this.y); \n"
2073 " get r => sqrt(x*x + y*y); \n" 2007 " get r => sqrt(x*x + y*y); \n"
2074 "} \n"; 2008 "} \n";
2075 LoadScript(kScriptChars); 2009 LoadScript(kScriptChars);
2076 Dart_FinalizeLoading(false); 2010 Dart_FinalizeLoading(false);
2077 2011
2078 Dart_SetExceptionThrownHandler(&EvaluateInActivationOfEvaluateHandler); 2012 Dart_SetExceptionThrownHandler(&EvaluateInActivationOfEvaluateHandler);
2079 Dart_SetExceptionPauseInfo(kPauseOnAllExceptions); 2013 Dart_SetExceptionPauseInfo(kPauseOnAllExceptions);
2080 breakpoint_hit_counter = 0; 2014 breakpoint_hit_counter = 0;
2081 2015
2082 Dart_Handle result = Dart_EvaluateExpr( 2016 Dart_Handle result = Dart_EvaluateExpr(
2083 script_lib, NewString("() { var p = new Point(3, 4); throw p; } ())")); 2017 script_lib, NewString("() { var p = new Point(3, 4); throw p; } ())"));
2084 EXPECT(Dart_IsError(result)); 2018 EXPECT(Dart_IsError(result));
2085 EXPECT_EQ(1, breakpoint_hit_counter); 2019 EXPECT_EQ(1, breakpoint_hit_counter);
2086 } 2020 }
2087 2021
2088
2089 static void UnhandledExceptionHandler(Dart_IsolateId isolate_id, 2022 static void UnhandledExceptionHandler(Dart_IsolateId isolate_id,
2090 Dart_Handle exception_object, 2023 Dart_Handle exception_object,
2091 Dart_StackTrace trace) { 2024 Dart_StackTrace trace) {
2092 breakpoint_hit_counter++; 2025 breakpoint_hit_counter++;
2093 } 2026 }
2094 2027
2095
2096 // Check that the debugger is not called when an exception is 2028 // Check that the debugger is not called when an exception is
2097 // caught by Dart code. 2029 // caught by Dart code.
2098 TEST_CASE(Debug_BreakOnUnhandledException) { 2030 TEST_CASE(Debug_BreakOnUnhandledException) {
2099 const char* kScriptChars = 2031 const char* kScriptChars =
2100 "main() { \n" 2032 "main() { \n"
2101 " try { \n" 2033 " try { \n"
2102 " throw 'broccoli'; \n" 2034 " throw 'broccoli'; \n"
2103 " } catch (e) { \n" 2035 " } catch (e) { \n"
2104 " return 'carrots'; \n" 2036 " return 'carrots'; \n"
2105 " } \n" 2037 " } \n"
(...skipping 17 matching lines...) Expand all
2123 // Check that the debugger is called when "break on all 2055 // Check that the debugger is called when "break on all
2124 // exceptions" is turned on. 2056 // exceptions" is turned on.
2125 Dart_SetExceptionPauseInfo(kPauseOnAllExceptions); 2057 Dart_SetExceptionPauseInfo(kPauseOnAllExceptions);
2126 Dart_Handle res2 = Invoke("main"); 2058 Dart_Handle res2 = Invoke("main");
2127 EXPECT_VALID(res2); 2059 EXPECT_VALID(res2);
2128 EXPECT(Dart_IsString(res2)); 2060 EXPECT(Dart_IsString(res2));
2129 EXPECT_STREQ("carrots", ToCString(res2)); 2061 EXPECT_STREQ("carrots", ToCString(res2));
2130 EXPECT_EQ(1, breakpoint_hit_counter); 2062 EXPECT_EQ(1, breakpoint_hit_counter);
2131 } 2063 }
2132 2064
2133
2134 TEST_CASE(Debug_GetClosureInfo) { 2065 TEST_CASE(Debug_GetClosureInfo) {
2135 const char* kScriptChars = 2066 const char* kScriptChars =
2136 "void foo() { return 43; } \n" 2067 "void foo() { return 43; } \n"
2137 " \n" 2068 " \n"
2138 "main() { \n" 2069 "main() { \n"
2139 " return foo; \n" 2070 " return foo; \n"
2140 "} \n"; 2071 "} \n";
2141 2072
2142 LoadScript(kScriptChars); 2073 LoadScript(kScriptChars);
2143 Dart_Handle clo = Invoke("main"); 2074 Dart_Handle clo = Invoke("main");
(...skipping 11 matching lines...) Expand all
2155 EXPECT(Dart_IsString(name)); 2086 EXPECT(Dart_IsString(name));
2156 EXPECT_STREQ("foo", ToCString(name)); 2087 EXPECT_STREQ("foo", ToCString(name));
2157 EXPECT(Dart_IsString(sig)); 2088 EXPECT(Dart_IsString(sig));
2158 EXPECT_STREQ("() => void", ToCString(sig)); 2089 EXPECT_STREQ("() => void", ToCString(sig));
2159 EXPECT(Dart_IsString(loc.script_url)); 2090 EXPECT(Dart_IsString(loc.script_url));
2160 EXPECT_STREQ("test-lib", ToCString(loc.script_url)); 2091 EXPECT_STREQ("test-lib", ToCString(loc.script_url));
2161 EXPECT_EQ(0, loc.token_pos); 2092 EXPECT_EQ(0, loc.token_pos);
2162 EXPECT(loc.library_id > 0); 2093 EXPECT(loc.library_id > 0);
2163 } 2094 }
2164 2095
2165
2166 TEST_CASE(Debug_GetSupertype) { 2096 TEST_CASE(Debug_GetSupertype) {
2167 const char* kScriptChars = 2097 const char* kScriptChars =
2168 "class Test {\n" 2098 "class Test {\n"
2169 "}\n" 2099 "}\n"
2170 "class Test1 extends Test {\n" 2100 "class Test1 extends Test {\n"
2171 "}\n" 2101 "}\n"
2172 "class Test2<T> {\n" 2102 "class Test2<T> {\n"
2173 "}\n" 2103 "}\n"
2174 "class Test3 extends Test2<int> {\n" 2104 "class Test3 extends Test2<int> {\n"
2175 "}\n" 2105 "}\n"
2176 "class Test4<A, B> extends Test2<A> {\n" 2106 "class Test4<A, B> extends Test2<A> {\n"
2177 "}\n" 2107 "}\n"
2178 "class Test5<A, B, C> extends Test4<A, B> {\n" 2108 "class Test5<A, B, C> extends Test4<A, B> {\n"
2179 "}\n" 2109 "}\n"
2180 "var s = new Set();\n" 2110 "var s = new Set();\n"
2181 "var l = new List();\n" 2111 "var l = new List();\n"
2182 "int main() {\n" 2112 "int main() {\n"
2183 "}\n"; 2113 "}\n";
2184 2114
2185
2186 Zone* zone = thread->zone(); 2115 Zone* zone = thread->zone();
2187 LoadScript(kScriptChars); 2116 LoadScript(kScriptChars);
2188 ASSERT(script_lib != NULL); 2117 ASSERT(script_lib != NULL);
2189 ASSERT(Dart_IsLibrary(script_lib)); 2118 ASSERT(Dart_IsLibrary(script_lib));
2190 Dart_Handle core_lib = Dart_LookupLibrary(NewString("dart:core")); 2119 Dart_Handle core_lib = Dart_LookupLibrary(NewString("dart:core"));
2191 2120
2192 Dart_Handle Test_name = Dart_NewStringFromCString("Test"); 2121 Dart_Handle Test_name = Dart_NewStringFromCString("Test");
2193 Dart_Handle Test1_name = Dart_NewStringFromCString("Test1"); 2122 Dart_Handle Test1_name = Dart_NewStringFromCString("Test1");
2194 Dart_Handle Test2_name = Dart_NewStringFromCString("Test2"); 2123 Dart_Handle Test2_name = Dart_NewStringFromCString("Test2");
2195 Dart_Handle Test3_name = Dart_NewStringFromCString("Test3"); 2124 Dart_Handle Test3_name = Dart_NewStringFromCString("Test3");
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
2262 { 2191 {
2263 Dart_Handle list_type = Dart_GetType(core_lib, list_name, 0, NULL); 2192 Dart_Handle list_type = Dart_GetType(core_lib, list_name, 0, NULL);
2264 Dart_Handle super_type = Dart_GetSupertype(list_type); 2193 Dart_Handle super_type = Dart_GetSupertype(list_type);
2265 EXPECT(!Dart_IsError(super_type)); 2194 EXPECT(!Dart_IsError(super_type));
2266 super_type = Dart_GetSupertype(super_type); 2195 super_type = Dart_GetSupertype(super_type);
2267 EXPECT(!Dart_IsError(super_type)); 2196 EXPECT(!Dart_IsError(super_type));
2268 EXPECT(super_type == Dart_Null()); 2197 EXPECT(super_type == Dart_Null());
2269 } 2198 }
2270 } 2199 }
2271 2200
2272
2273 TEST_CASE(Debug_ListSuperType) { 2201 TEST_CASE(Debug_ListSuperType) {
2274 const char* kScriptChars = 2202 const char* kScriptChars =
2275 "List testMain() {" 2203 "List testMain() {"
2276 " List a = new List();" 2204 " List a = new List();"
2277 " a.add(10);" 2205 " a.add(10);"
2278 " a.add(20);" 2206 " a.add(20);"
2279 " a.add(30);" 2207 " a.add(30);"
2280 " return a;" 2208 " return a;"
2281 "}" 2209 "}"
2282 "" 2210 ""
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
2357 " null, 5, 17, 5, 18, 9, 19, 12," 2285 " null, 5, 17, 5, 18, 9, 19, 12,"
2358 " null, 6, 21, 1," 2286 " null, 6, 21, 1,"
2359 " null, 8, 24, 1, 25, 5, 26, 6, 27, 8," 2287 " null, 8, 24, 1, 25, 5, 26, 6, 27, 8,"
2360 " null, 9, 29, 1]", 2288 " null, 9, 29, 1]",
2361 tokens_cstr); 2289 tokens_cstr);
2362 } 2290 }
2363 2291
2364 #endif 2292 #endif
2365 2293
2366 } // namespace dart 2294 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/debugger_api_impl.cc ('k') | runtime/vm/debugger_arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698