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

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

Issue 9484002: StepOver, StepInto, StepOut (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
« 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_debugger_api.h" 5 #include "include/dart_debugger_api.h"
6 #include "platform/assert.h" 6 #include "platform/assert.h"
7 #include "vm/dart_api_impl.h" 7 #include "vm/dart_api_impl.h"
8 #include "vm/unit_test.h" 8 #include "vm/unit_test.h"
9 9
10 namespace dart { 10 namespace dart {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 const char* name_chars; 53 const char* name_chars;
54 Dart_StringToCString(func_name, &name_chars); 54 Dart_StringToCString(func_name, &name_chars);
55 EXPECT_STREQ(expected_trace[i], name_chars); 55 EXPECT_STREQ(expected_trace[i], name_chars);
56 if (verbose) printf(" >> %d: %s\n", i, name_chars); 56 if (verbose) printf(" >> %d: %s\n", i, name_chars);
57 } 57 }
58 } 58 }
59 59
60 60
61 TEST_CASE(Debug_Breakpoint) { 61 TEST_CASE(Debug_Breakpoint) {
62 const char* kScriptChars = 62 const char* kScriptChars =
63 "void moo(s) { }\n" 63 "void moo(s) { } \n"
64 "class A {\n" 64 "class A { \n"
65 " static void foo() {\n" 65 " static void foo() { \n"
66 " moo('good news');\n" 66 " moo('good news'); \n"
67 " }\n" 67 " } \n"
68 "}\n" 68 "} \n"
69 "void main() {\n" 69 "void main() { \n"
70 " A.foo();\n" 70 " A.foo(); \n"
71 "}\n"; 71 "} \n";
72 72
73 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 73 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
74 EXPECT(!Dart_IsError(lib)); 74 EXPECT(!Dart_IsError(lib));
75 75
76 Dart_SetBreakpointHandler(&TestBreakpointHandler); 76 Dart_SetBreakpointHandler(&TestBreakpointHandler);
77 77
78 Dart_Handle c_name = Dart_NewString("A"); 78 Dart_Handle c_name = Dart_NewString("A");
79 Dart_Handle f_name = Dart_NewString("foo"); 79 Dart_Handle f_name = Dart_NewString("foo");
80 Dart_Breakpoint bpt; 80 Dart_Breakpoint bpt;
81 Dart_Handle res = Dart_SetBreakpointAtEntry(lib, c_name, f_name, &bpt); 81 Dart_Handle res = Dart_SetBreakpointAtEntry(lib, c_name, f_name, &bpt);
82 EXPECT_NOT_ERROR(res); 82 EXPECT_NOT_ERROR(res);
83 83
84 breakpoint_hit = false; 84 breakpoint_hit = false;
85 Dart_Handle retval = Invoke(lib, "main"); 85 Dart_Handle retval = Invoke(lib, "main");
86 EXPECT(!Dart_IsError(retval)); 86 EXPECT(!Dart_IsError(retval));
87 EXPECT(breakpoint_hit == true); 87 EXPECT(breakpoint_hit == true);
88 } 88 }
89 89
90 90
91 void TestStepOutHandler(Dart_Breakpoint bpt, Dart_StackTrace trace) {
92 const char* expected_bpts[] = {"f1", "foo", "main"};
93 const intptr_t expected_bpts_length = ARRAY_SIZE(expected_bpts);
94 intptr_t trace_len;
95 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len);
96 EXPECT_NOT_ERROR(res);
97 EXPECT(breakpoint_hit_counter < expected_bpts_length);
98 Dart_ActivationFrame frame;
99 res = Dart_GetActivationFrame(trace, 0, &frame);
100 EXPECT_NOT_ERROR(res);
101 Dart_Handle func_name;
102 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL);
103 EXPECT_NOT_ERROR(res);
104 EXPECT(Dart_IsString(func_name));
105 const char* name_chars;
106 Dart_StringToCString(func_name, &name_chars);
107 if (breakpoint_hit_counter < expected_bpts_length) {
108 EXPECT_STREQ(expected_bpts[breakpoint_hit_counter], name_chars);
109 }
110 if (verbose) {
111 printf(" >> bpt nr %d: %s\n", breakpoint_hit_counter, name_chars);
112 }
113 breakpoint_hit = true;
114 breakpoint_hit_counter++;
115 Dart_SetStepOut();
116 }
117
118
119 TEST_CASE(Debug_StepOut) {
120 const char* kScriptChars =
121 "void f1() { return 1; } \n"
122 "void f2() { return 2; } \n"
123 " \n"
124 "void foo() { \n"
125 " f1(); \n"
126 " return f2(); \n"
127 "} \n"
128 " \n"
129 "void main() { \n"
130 " return foo(); \n"
131 "} \n";
132
133 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
134 EXPECT(!Dart_IsError(lib));
135
136 Dart_SetBreakpointHandler(&TestStepOutHandler);
137
138 // Set a breakpoint in function f1, then repeatedly step out until
139 // we get to main. We should see one breakpoint each in f1,
140 // foo, main, but not in f2.
141 Dart_Handle c_name = Dart_NewString("");
142 Dart_Handle f_name = Dart_NewString("f1");
143 Dart_Breakpoint bpt;
144 Dart_Handle res = Dart_SetBreakpointAtEntry(lib, c_name, f_name, &bpt);
145 EXPECT_NOT_ERROR(res);
146
147 breakpoint_hit = false;
148 breakpoint_hit_counter = 0;
149 Dart_Handle retval = Invoke(lib, "main");
150 EXPECT(!Dart_IsError(retval));
151 EXPECT(Dart_IsInteger(retval));
152 int64_t int_value = 0;
153 Dart_IntegerToInt64(retval, &int_value);
154 EXPECT_EQ(2, int_value);
155 EXPECT(breakpoint_hit == true);
156 }
157
158
159 void TestStepIntoHandler(Dart_Breakpoint bpt, Dart_StackTrace trace) {
160 const char* expected_bpts[] = {
161 "main",
162 "foo",
163 "f1",
164 "foo",
165 "X.X.",
166 "Object.Object.",
167 "X.X.",
168 "foo",
169 "X.kvmk",
170 "f2",
171 "X.kvmk",
172 "IntegerImplementation.+",
173 "IntegerImplementation.addFromInteger",
174 "IntegerImplementation.+",
175 "X.kvmk",
176 "foo",
177 "main"
178 };
179 const intptr_t expected_bpts_length = ARRAY_SIZE(expected_bpts);
180 intptr_t trace_len;
181 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len);
182 EXPECT_NOT_ERROR(res);
183 EXPECT(breakpoint_hit_counter < expected_bpts_length);
184 Dart_ActivationFrame frame;
185 res = Dart_GetActivationFrame(trace, 0, &frame);
186 EXPECT_NOT_ERROR(res);
187 Dart_Handle func_name;
188 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL);
189 EXPECT_NOT_ERROR(res);
190 EXPECT(Dart_IsString(func_name));
191 const char* name_chars;
192 Dart_StringToCString(func_name, &name_chars);
193 if (breakpoint_hit_counter < expected_bpts_length) {
194 EXPECT_STREQ(expected_bpts[breakpoint_hit_counter], name_chars);
195 }
196 if (verbose) {
197 printf(" >> bpt nr %d: %s\n", breakpoint_hit_counter, name_chars);
198 }
199 breakpoint_hit = true;
200 breakpoint_hit_counter++;
201 Dart_SetStepInto();
202 }
203
204
205 TEST_CASE(Debug_StepInto) {
206 const char* kScriptChars =
207 "void f1() { return 1; } \n"
208 "void f2() { return 2; } \n"
209 " \n"
210 "class X { \n"
211 " kvmk(a, [b, c]) { \n"
212 " return c + f2(); \n"
213 " } \n"
214 "} \n"
215 " \n"
216 "void foo() { \n"
217 " f1(); \n"
218 " var o = new X(); \n"
219 " return o.kvmk(3, c:5); \n"
220 "} \n"
221 " \n"
222 "void main() { \n"
223 " return foo(); \n"
224 "} \n";
225
226 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
227 EXPECT(!Dart_IsError(lib));
228
229 Dart_SetBreakpointHandler(&TestStepIntoHandler);
230
231 // Set a breakpoint in function f1, then repeatedly step out until
232 // we get to main. We should see one breakpoint each in f1,
233 // foo, main, but not in f2.
234 Dart_Handle c_name = Dart_NewString("");
235 Dart_Handle f_name = Dart_NewString("main");
236 Dart_Breakpoint bpt;
237 Dart_Handle res = Dart_SetBreakpointAtEntry(lib, c_name, f_name, &bpt);
238 EXPECT_NOT_ERROR(res);
239
240 breakpoint_hit = false;
241 breakpoint_hit_counter = 0;
242 Dart_Handle retval = Invoke(lib, "main");
243 EXPECT(!Dart_IsError(retval));
244 EXPECT(Dart_IsInteger(retval));
245 int64_t int_value = 0;
246 Dart_IntegerToInt64(retval, &int_value);
247 EXPECT_EQ(7, int_value);
248 EXPECT(breakpoint_hit == true);
249 }
250
251
252 void TestSingleStepHandler(Dart_Breakpoint bpt, Dart_StackTrace trace) {
253 const char* expected_bpts[] = {
254 "moo", "foo", "moo", "foo", "moo", "foo", "main"};
255 const intptr_t expected_bpts_length = ARRAY_SIZE(expected_bpts);
256 intptr_t trace_len;
257 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len);
258 EXPECT_NOT_ERROR(res);
259 EXPECT(breakpoint_hit_counter < expected_bpts_length);
260 Dart_ActivationFrame frame;
261 res = Dart_GetActivationFrame(trace, 0, &frame);
262 EXPECT_NOT_ERROR(res);
263 Dart_Handle func_name;
264 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL);
265 EXPECT_NOT_ERROR(res);
266 EXPECT(Dart_IsString(func_name));
267 const char* name_chars;
268 Dart_StringToCString(func_name, &name_chars);
269 if (breakpoint_hit_counter < expected_bpts_length) {
270 EXPECT_STREQ(expected_bpts[breakpoint_hit_counter], name_chars);
271 }
272 if (verbose) {
273 printf(" >> bpt nr %d: %s\n", breakpoint_hit_counter, name_chars);
274 }
275 breakpoint_hit = true;
276 breakpoint_hit_counter++;
277 Dart_SetStepOver();
278 }
279
280
281 TEST_CASE(Debug_SingleStep) {
282 const char* kScriptChars =
283 "void moo(s) { return 1; } \n"
284 " \n"
285 "void foo() { \n"
286 " moo('step one'); \n"
287 " moo('step two'); \n"
288 " moo('step three'); \n"
289 "} \n"
290 " \n"
291 "void main() { \n"
292 " foo(); \n"
293 "} \n";
294
295 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
296 EXPECT(!Dart_IsError(lib));
297
298 Dart_SetBreakpointHandler(&TestSingleStepHandler);
299
300 Dart_Handle c_name = Dart_NewString("");
301 Dart_Handle f_name = Dart_NewString("moo");
302 Dart_Breakpoint bpt;
303 Dart_Handle res = Dart_SetBreakpointAtEntry(lib, c_name, f_name, &bpt);
304 EXPECT_NOT_ERROR(res);
305
306 breakpoint_hit = false;
307 breakpoint_hit_counter = 0;
308 Dart_Handle retval = Invoke(lib, "main");
309 EXPECT(!Dart_IsError(retval));
310 EXPECT(breakpoint_hit == true);
311 }
312
313
314
91 static void DeleteBreakpointHandler(Dart_Breakpoint bpt, 315 static void DeleteBreakpointHandler(Dart_Breakpoint bpt,
92 Dart_StackTrace trace) { 316 Dart_StackTrace trace) {
93 const char* expected_trace[] = {"foo", "main"}; 317 const char* expected_trace[] = {"foo", "main"};
94 const intptr_t expected_trace_length = 2; 318 const intptr_t expected_trace_length = 2;
95 breakpoint_hit_counter++; 319 breakpoint_hit_counter++;
96 intptr_t trace_len; 320 intptr_t trace_len;
97 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); 321 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len);
98 EXPECT_NOT_ERROR(res); 322 EXPECT_NOT_ERROR(res);
99 EXPECT_EQ(expected_trace_length, trace_len); 323 EXPECT_EQ(expected_trace_length, trace_len);
100 for (int i = 0; i < trace_len; i++) { 324 for (int i = 0; i < trace_len; i++) {
(...skipping 13 matching lines...) Expand all
114 if (breakpoint_hit_counter == 2) { 338 if (breakpoint_hit_counter == 2) {
115 if (verbose) printf("uninstalling breakpoint\n"); 339 if (verbose) printf("uninstalling breakpoint\n");
116 Dart_Handle res = Dart_DeleteBreakpoint(bpt); 340 Dart_Handle res = Dart_DeleteBreakpoint(bpt);
117 EXPECT_NOT_ERROR(res); 341 EXPECT_NOT_ERROR(res);
118 } 342 }
119 } 343 }
120 344
121 345
122 TEST_CASE(Debug_DeleteBreakpoint) { 346 TEST_CASE(Debug_DeleteBreakpoint) {
123 const char* kScriptChars = 347 const char* kScriptChars =
124 "moo(s) { }\n" 348 "moo(s) { } \n"
125 "\n" 349 " \n"
126 "foo() {\n" 350 "foo() { \n"
127 " moo('good news');\n" 351 " moo('good news'); \n"
128 "}\n" 352 "} \n"
129 "\n" 353 " \n"
130 "void main() {\n" 354 "void main() { \n"
131 " foo();\n" 355 " foo(); \n"
132 " foo();\n" 356 " foo(); \n"
133 " foo();\n" 357 " foo(); \n"
134 "}\n"; 358 "} \n";
135 359
136 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 360 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
137 EXPECT(!Dart_IsError(lib)); 361 EXPECT(!Dart_IsError(lib));
138 362
139 Dart_Handle script_url = Dart_NewString(TestCase::url()); 363 Dart_Handle script_url = Dart_NewString(TestCase::url());
140 Dart_Handle line_no = Dart_NewInteger(4); // In function 'foo'. 364 Dart_Handle line_no = Dart_NewInteger(4); // In function 'foo'.
141 365
142 Dart_SetBreakpointHandler(&DeleteBreakpointHandler); 366 Dart_SetBreakpointHandler(&DeleteBreakpointHandler);
143 367
144 Dart_Breakpoint bpt; 368 Dart_Breakpoint bpt;
145 Dart_Handle res = Dart_SetBreakpointAtLine(script_url, line_no, &bpt); 369 Dart_Handle res = Dart_SetBreakpointAtLine(script_url, line_no, &bpt);
146 EXPECT_NOT_ERROR(res); 370 EXPECT_NOT_ERROR(res);
147 371
148 // Function main() calls foo() 3 times. On the second iteration, the 372 // Function main() calls foo() 3 times. On the second iteration, the
149 // breakpoint is removed by the handler, so we expect the breakpoint 373 // breakpoint is removed by the handler, so we expect the breakpoint
150 // to fire twice only. 374 // to fire twice only.
151 breakpoint_hit_counter = 0; 375 breakpoint_hit_counter = 0;
152 Dart_Handle retval = Invoke(lib, "main"); 376 Dart_Handle retval = Invoke(lib, "main");
153 EXPECT(!Dart_IsError(retval)); 377 EXPECT(!Dart_IsError(retval));
154 EXPECT(breakpoint_hit_counter == 2); 378 EXPECT(breakpoint_hit_counter == 2);
155 } 379 }
156 380
157 381
158 TEST_CASE(Debug_InspectObject) { 382 TEST_CASE(Debug_InspectObject) {
159 const char* kScriptChars = 383 const char* kScriptChars =
160 " class A { \n" 384 " class A { \n"
161 " var a_field = 'a'; \n" 385 " var a_field = 'a'; \n"
162 " static var bla = 'yada yada yada';\n" 386 " static var bla = 'yada yada yada'; \n"
163 " static var error = unresolvedName(); \n" 387 " static var error = unresolvedName(); \n"
164 " var d = 42.1; \n" 388 " var d = 42.1; \n"
165 " } \n" 389 " } \n"
166 " class B extends A { \n" 390 " class B extends A { \n"
167 " var oneDay = const Duration(hours: 24); \n" 391 " var oneDay = const Duration(hours: 24); \n"
168 " static var bla = 'blah blah'; \n" 392 " static var bla = 'blah blah'; \n"
169 " } \n" 393 " } \n"
170 " get_b() { return new B(); } \n" 394 " get_b() { return new B(); } \n"
171 " get_int() { return 666; } \n"; 395 " get_int() { return 666; } \n";
172 396
173 // Number of instance fields in an object of class B. 397 // Number of instance fields in an object of class B.
174 const intptr_t kNumObjectFields = 3; 398 const intptr_t kNumObjectFields = 3;
175 399
176 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 400 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
177 EXPECT_NOT_ERROR(lib); 401 EXPECT_NOT_ERROR(lib);
178 402
179 Dart_Handle object_b = Invoke(lib, "get_b"); 403 Dart_Handle object_b = Invoke(lib, "get_b");
180 404
181 EXPECT_NOT_ERROR(object_b); 405 EXPECT_NOT_ERROR(object_b);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 EXPECT(Dart_IsString(name_handle)); 498 EXPECT(Dart_IsString(name_handle));
275 Dart_StringToCString(name_handle, &name); 499 Dart_StringToCString(name_handle, &name);
276 EXPECT_STREQ("error", name); 500 EXPECT_STREQ("error", name);
277 value_handle = Dart_ListGetAt(fields, 3); 501 value_handle = Dart_ListGetAt(fields, 3);
278 EXPECT(Dart_IsError(value_handle)); 502 EXPECT(Dart_IsError(value_handle));
279 } 503 }
280 504
281 505
282 TEST_CASE(Debug_LookupSourceLine) { 506 TEST_CASE(Debug_LookupSourceLine) {
283 const char* kScriptChars = 507 const char* kScriptChars =
284 /*1*/ "class A {\n" 508 /*1*/ "class A { \n"
285 /*2*/ " static void foo() {\n" 509 /*2*/ " static void foo() { \n"
286 /*3*/ " moo('good news');\n" 510 /*3*/ " moo('good news'); \n"
287 /*4*/ " }\n" 511 /*4*/ " } \n"
288 /*5*/ "}\n" 512 /*5*/ "} \n"
289 /*6*/ "\n" 513 /*6*/ " \n"
290 /*7*/ "void main() {\n" 514 /*7*/ "void main() { \n"
291 /*8*/ " A.foo();\n" 515 /*8*/ " A.foo(); \n"
292 /*9*/ "}\n" 516 /*9*/ "} \n"
293 /*10*/ "\n"; 517 /*10*/ " \n";
294 518
295 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 519 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
296 EXPECT(!Dart_IsError(lib)); 520 EXPECT(!Dart_IsError(lib));
297 521
298 const Library& test_lib = Library::CheckedHandle(Api::UnwrapHandle(lib)); 522 const Library& test_lib = Library::CheckedHandle(Api::UnwrapHandle(lib));
299 const String& script_url = String::Handle(String::New(TestCase::url())); 523 const String& script_url = String::Handle(String::New(TestCase::url()));
300 Function& func = Function::Handle(); 524 Function& func = Function::Handle();
301 525
302 // TODO(hausner): Looking up functions from source and line number 526 // TODO(hausner): Looking up functions from source and line number
303 // needs to be refined. We currently dont find "main" on line 7. 527 // needs to be refined. We currently dont find "main" on line 7.
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 EXPECT(Dart_IsString(source)); 572 EXPECT(Dart_IsString(source));
349 char const* source_chars; 573 char const* source_chars;
350 Dart_StringToCString(source, &source_chars); 574 Dart_StringToCString(source, &source_chars);
351 printf("\n=== source: ===\n%s", source_chars); 575 printf("\n=== source: ===\n%s", source_chars);
352 EXPECT_STREQ(kScriptChars, source_chars); 576 EXPECT_STREQ(kScriptChars, source_chars);
353 } 577 }
354 578
355 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). 579 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64).
356 580
357 } // namespace dart 581 } // 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