OLD | NEW |
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 "include/dart_mirrors_api.h" |
6 #include "platform/assert.h" | 7 #include "platform/assert.h" |
7 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
8 #include "vm/thread.h" | 9 #include "vm/thread.h" |
9 #include "vm/unit_test.h" | 10 #include "vm/unit_test.h" |
10 | 11 |
11 namespace dart { | 12 namespace dart { |
12 | 13 |
13 static bool breakpoint_hit = false; | 14 static bool breakpoint_hit = false; |
14 static int breakpoint_hit_counter = 0; | 15 static int breakpoint_hit_counter = 0; |
15 static Dart_Handle script_lib = NULL; | 16 static Dart_Handle script_lib = NULL; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 static char const* BreakpointInfo(Dart_StackTrace trace) { | 71 static char const* BreakpointInfo(Dart_StackTrace trace) { |
71 static char info_str[128]; | 72 static char info_str[128]; |
72 Dart_ActivationFrame frame; | 73 Dart_ActivationFrame frame; |
73 Dart_Handle res = Dart_GetActivationFrame(trace, 0, &frame); | 74 Dart_Handle res = Dart_GetActivationFrame(trace, 0, &frame); |
74 EXPECT_TRUE(res); | 75 EXPECT_TRUE(res); |
75 Dart_Handle func_name; | 76 Dart_Handle func_name; |
76 Dart_Handle url; | 77 Dart_Handle url; |
77 intptr_t line_number = 0; | 78 intptr_t line_number = 0; |
78 intptr_t library_id = 0; | 79 intptr_t library_id = 0; |
79 res = Dart_ActivationFrameInfo( | 80 res = Dart_ActivationFrameInfo( |
80 frame, &func_name, &url, &line_number, &library_id); | 81 frame, &func_name, NULL, &url, &line_number, &library_id); |
81 EXPECT_TRUE(res); | 82 EXPECT_TRUE(res); |
82 OS::SNPrint(info_str, sizeof(info_str), "function %s (%s:%" Pd ")", | 83 OS::SNPrint(info_str, sizeof(info_str), "function %s (%s:%" Pd ")", |
83 ToCString(func_name), ToCString(url), line_number); | 84 ToCString(func_name), ToCString(url), line_number); |
84 return info_str; | 85 return info_str; |
85 } | 86 } |
86 | 87 |
87 | 88 |
88 static void PrintValue(Dart_Handle value, bool expand); | 89 static void PrintValue(Dart_Handle value, bool expand); |
89 | 90 |
90 | 91 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 OS::Print("%s", ToCString(str_value)); | 139 OS::Print("%s", ToCString(str_value)); |
139 } else { | 140 } else { |
140 PrintObject(value, expand); | 141 PrintObject(value, expand); |
141 } | 142 } |
142 } | 143 } |
143 | 144 |
144 | 145 |
145 static void PrintActivationFrame(Dart_ActivationFrame frame) { | 146 static void PrintActivationFrame(Dart_ActivationFrame frame) { |
146 Dart_Handle func_name; | 147 Dart_Handle func_name; |
147 Dart_Handle res; | 148 Dart_Handle res; |
148 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL, NULL); | 149 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL, NULL, NULL); |
149 EXPECT_TRUE(res); | 150 EXPECT_TRUE(res); |
150 EXPECT(Dart_IsString(func_name)); | 151 EXPECT(Dart_IsString(func_name)); |
151 const char* func_name_chars; | 152 const char* func_name_chars; |
152 Dart_StringToCString(func_name, &func_name_chars); | 153 Dart_StringToCString(func_name, &func_name_chars); |
153 OS::Print(" function %s\n", func_name_chars); | 154 OS::Print(" function %s\n", func_name_chars); |
154 Dart_Handle locals = Dart_GetLocalVariables(frame); | 155 Dart_Handle locals = Dart_GetLocalVariables(frame); |
155 EXPECT_VALID(locals); | 156 EXPECT_VALID(locals); |
156 intptr_t list_length = 0; | 157 intptr_t list_length = 0; |
157 Dart_Handle ret = Dart_ListLength(locals, &list_length); | 158 Dart_Handle ret = Dart_ListLength(locals, &list_length); |
158 EXPECT_VALID(ret); | 159 EXPECT_VALID(ret); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 } | 230 } |
230 } | 231 } |
231 | 232 |
232 | 233 |
233 static void VerifyStackFrame(Dart_ActivationFrame frame, | 234 static void VerifyStackFrame(Dart_ActivationFrame frame, |
234 const char* expected_name, | 235 const char* expected_name, |
235 Dart_Handle expected_locals, | 236 Dart_Handle expected_locals, |
236 bool skip_null_expects) { | 237 bool skip_null_expects) { |
237 Dart_Handle func_name; | 238 Dart_Handle func_name; |
238 Dart_Handle res; | 239 Dart_Handle res; |
239 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL, NULL); | 240 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL, NULL, NULL); |
240 EXPECT_TRUE(res); | 241 EXPECT_TRUE(res); |
241 EXPECT(Dart_IsString(func_name)); | 242 EXPECT(Dart_IsString(func_name)); |
242 const char* func_name_chars; | 243 const char* func_name_chars; |
243 Dart_StringToCString(func_name, &func_name_chars); | 244 Dart_StringToCString(func_name, &func_name_chars); |
244 if (expected_name != NULL) { | 245 if (expected_name != NULL) { |
245 EXPECT_SUBSTRING(expected_name, func_name_chars); | 246 EXPECT_SUBSTRING(expected_name, func_name_chars); |
246 } | 247 } |
247 | 248 |
248 if (!Dart_IsNull(expected_locals)) { | 249 if (!Dart_IsNull(expected_locals)) { |
249 Dart_Handle locals = Dart_GetLocalVariables(frame); | 250 Dart_Handle locals = Dart_GetLocalVariables(frame); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 breakpoint_hit_counter++; | 286 breakpoint_hit_counter++; |
286 intptr_t trace_len; | 287 intptr_t trace_len; |
287 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); | 288 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); |
288 EXPECT_VALID(res); | 289 EXPECT_VALID(res); |
289 EXPECT_EQ(expected_trace_length, trace_len); | 290 EXPECT_EQ(expected_trace_length, trace_len); |
290 for (int i = 0; i < trace_len; i++) { | 291 for (int i = 0; i < trace_len; i++) { |
291 Dart_ActivationFrame frame; | 292 Dart_ActivationFrame frame; |
292 res = Dart_GetActivationFrame(trace, i, &frame); | 293 res = Dart_GetActivationFrame(trace, i, &frame); |
293 EXPECT_VALID(res); | 294 EXPECT_VALID(res); |
294 Dart_Handle func_name; | 295 Dart_Handle func_name; |
295 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL, NULL); | 296 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL, NULL, NULL); |
296 EXPECT_VALID(res); | 297 EXPECT_VALID(res); |
297 EXPECT(Dart_IsString(func_name)); | 298 EXPECT(Dart_IsString(func_name)); |
298 const char* name_chars; | 299 const char* name_chars; |
299 Dart_StringToCString(func_name, &name_chars); | 300 Dart_StringToCString(func_name, &name_chars); |
300 EXPECT_STREQ(expected_trace[i], name_chars); | 301 EXPECT_STREQ(expected_trace[i], name_chars); |
301 if (verbose) OS::Print(" >> %d: %s\n", i, name_chars); | 302 if (verbose) OS::Print(" >> %d: %s\n", i, name_chars); |
302 } | 303 } |
303 } | 304 } |
304 | 305 |
305 | 306 |
(...skipping 27 matching lines...) Expand all Loading... |
333 const char* expected_bpts[] = {"f1", "foo", "main"}; | 334 const char* expected_bpts[] = {"f1", "foo", "main"}; |
334 const intptr_t expected_bpts_length = ARRAY_SIZE(expected_bpts); | 335 const intptr_t expected_bpts_length = ARRAY_SIZE(expected_bpts); |
335 intptr_t trace_len; | 336 intptr_t trace_len; |
336 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); | 337 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); |
337 EXPECT_VALID(res); | 338 EXPECT_VALID(res); |
338 EXPECT(breakpoint_hit_counter < expected_bpts_length); | 339 EXPECT(breakpoint_hit_counter < expected_bpts_length); |
339 Dart_ActivationFrame frame; | 340 Dart_ActivationFrame frame; |
340 res = Dart_GetActivationFrame(trace, 0, &frame); | 341 res = Dart_GetActivationFrame(trace, 0, &frame); |
341 EXPECT_VALID(res); | 342 EXPECT_VALID(res); |
342 Dart_Handle func_name; | 343 Dart_Handle func_name; |
343 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL, NULL); | 344 Dart_Handle function; |
| 345 res = Dart_ActivationFrameInfo(frame, &func_name, &function, NULL, NULL, |
| 346 NULL); |
344 EXPECT_VALID(res); | 347 EXPECT_VALID(res); |
345 EXPECT(Dart_IsString(func_name)); | 348 EXPECT(Dart_IsString(func_name)); |
| 349 EXPECT(Dart_IsFunction(function)); |
346 const char* name_chars; | 350 const char* name_chars; |
| 351 const char* name_chars_from_function_handle; |
347 Dart_StringToCString(func_name, &name_chars); | 352 Dart_StringToCString(func_name, &name_chars); |
| 353 Dart_StringToCString(Dart_FunctionName(function), |
| 354 &name_chars_from_function_handle); |
348 if (breakpoint_hit_counter < expected_bpts_length) { | 355 if (breakpoint_hit_counter < expected_bpts_length) { |
349 EXPECT_STREQ(expected_bpts[breakpoint_hit_counter], name_chars); | 356 EXPECT_STREQ(expected_bpts[breakpoint_hit_counter], name_chars); |
350 } | 357 } |
| 358 EXPECT_STREQ(name_chars, name_chars_from_function_handle); |
351 if (verbose) { | 359 if (verbose) { |
352 OS::Print(" >> bpt nr %d: %s\n", breakpoint_hit_counter, name_chars); | 360 OS::Print(" >> bpt nr %d: %s\n", breakpoint_hit_counter, name_chars); |
353 } | 361 } |
354 breakpoint_hit = true; | 362 breakpoint_hit = true; |
355 breakpoint_hit_counter++; | 363 breakpoint_hit_counter++; |
356 Dart_SetStepOut(); | 364 Dart_SetStepOut(); |
357 } | 365 } |
358 | 366 |
359 | 367 |
360 TEST_CASE(Debug_StepOut) { | 368 TEST_CASE(Debug_StepOut) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 }; | 419 }; |
412 const intptr_t expected_bpts_length = ARRAY_SIZE(expected_bpts); | 420 const intptr_t expected_bpts_length = ARRAY_SIZE(expected_bpts); |
413 intptr_t trace_len; | 421 intptr_t trace_len; |
414 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); | 422 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); |
415 EXPECT_VALID(res); | 423 EXPECT_VALID(res); |
416 EXPECT(breakpoint_hit_counter < expected_bpts_length); | 424 EXPECT(breakpoint_hit_counter < expected_bpts_length); |
417 Dart_ActivationFrame frame; | 425 Dart_ActivationFrame frame; |
418 res = Dart_GetActivationFrame(trace, 0, &frame); | 426 res = Dart_GetActivationFrame(trace, 0, &frame); |
419 EXPECT_VALID(res); | 427 EXPECT_VALID(res); |
420 Dart_Handle func_name; | 428 Dart_Handle func_name; |
421 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL, NULL); | 429 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL, NULL, NULL); |
422 EXPECT_VALID(res); | 430 EXPECT_VALID(res); |
423 EXPECT(Dart_IsString(func_name)); | 431 EXPECT(Dart_IsString(func_name)); |
424 const char* name_chars; | 432 const char* name_chars; |
425 Dart_StringToCString(func_name, &name_chars); | 433 Dart_StringToCString(func_name, &name_chars); |
426 if (breakpoint_hit_counter < expected_bpts_length) { | 434 if (breakpoint_hit_counter < expected_bpts_length) { |
427 EXPECT_STREQ(expected_bpts[breakpoint_hit_counter], name_chars); | 435 EXPECT_STREQ(expected_bpts[breakpoint_hit_counter], name_chars); |
428 } | 436 } |
429 if (verbose) { | 437 if (verbose) { |
430 OS::Print(" >> bpt nr %d: %s\n", breakpoint_hit_counter, name_chars); | 438 OS::Print(" >> bpt nr %d: %s\n", breakpoint_hit_counter, name_chars); |
431 } | 439 } |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 "moo", "foo", "moo", "foo", "moo", "foo", "main"}; | 569 "moo", "foo", "moo", "foo", "moo", "foo", "main"}; |
562 const intptr_t expected_bpts_length = ARRAY_SIZE(expected_bpts); | 570 const intptr_t expected_bpts_length = ARRAY_SIZE(expected_bpts); |
563 intptr_t trace_len; | 571 intptr_t trace_len; |
564 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); | 572 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); |
565 EXPECT_VALID(res); | 573 EXPECT_VALID(res); |
566 EXPECT(breakpoint_hit_counter < expected_bpts_length); | 574 EXPECT(breakpoint_hit_counter < expected_bpts_length); |
567 Dart_ActivationFrame frame; | 575 Dart_ActivationFrame frame; |
568 res = Dart_GetActivationFrame(trace, 0, &frame); | 576 res = Dart_GetActivationFrame(trace, 0, &frame); |
569 EXPECT_VALID(res); | 577 EXPECT_VALID(res); |
570 Dart_Handle func_name; | 578 Dart_Handle func_name; |
571 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL, NULL); | 579 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL, NULL, NULL); |
572 EXPECT_VALID(res); | 580 EXPECT_VALID(res); |
573 EXPECT(Dart_IsString(func_name)); | 581 EXPECT(Dart_IsString(func_name)); |
574 const char* name_chars; | 582 const char* name_chars; |
575 Dart_StringToCString(func_name, &name_chars); | 583 Dart_StringToCString(func_name, &name_chars); |
576 if (verbose) { | 584 if (verbose) { |
577 OS::Print(" >> bpt nr %d: %s\n", breakpoint_hit_counter, name_chars); | 585 OS::Print(" >> bpt nr %d: %s\n", breakpoint_hit_counter, name_chars); |
578 } | 586 } |
579 if (breakpoint_hit_counter < expected_bpts_length) { | 587 if (breakpoint_hit_counter < expected_bpts_length) { |
580 EXPECT_STREQ(expected_bpts[breakpoint_hit_counter], name_chars); | 588 EXPECT_STREQ(expected_bpts[breakpoint_hit_counter], name_chars); |
581 } | 589 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
621 breakpoint_hit_counter++; | 629 breakpoint_hit_counter++; |
622 intptr_t trace_len; | 630 intptr_t trace_len; |
623 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); | 631 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); |
624 EXPECT_VALID(res); | 632 EXPECT_VALID(res); |
625 EXPECT_EQ(expected_trace_length, trace_len); | 633 EXPECT_EQ(expected_trace_length, trace_len); |
626 for (int i = 0; i < trace_len; i++) { | 634 for (int i = 0; i < trace_len; i++) { |
627 Dart_ActivationFrame frame; | 635 Dart_ActivationFrame frame; |
628 res = Dart_GetActivationFrame(trace, i, &frame); | 636 res = Dart_GetActivationFrame(trace, i, &frame); |
629 EXPECT_VALID(res); | 637 EXPECT_VALID(res); |
630 Dart_Handle func_name; | 638 Dart_Handle func_name; |
631 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL, NULL); | 639 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL, NULL, NULL); |
632 EXPECT_VALID(res); | 640 EXPECT_VALID(res); |
633 EXPECT(Dart_IsString(func_name)); | 641 EXPECT(Dart_IsString(func_name)); |
634 const char* name_chars; | 642 const char* name_chars; |
635 Dart_StringToCString(func_name, &name_chars); | 643 Dart_StringToCString(func_name, &name_chars); |
636 EXPECT_STREQ(expected_trace[i], name_chars); | 644 EXPECT_STREQ(expected_trace[i], name_chars); |
637 if (verbose) OS::Print(" >> %d: %s\n", i, name_chars); | 645 if (verbose) OS::Print(" >> %d: %s\n", i, name_chars); |
638 } | 646 } |
639 } | 647 } |
640 | 648 |
641 | 649 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 breakpoint_hit_counter++; | 731 breakpoint_hit_counter++; |
724 intptr_t trace_len; | 732 intptr_t trace_len; |
725 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); | 733 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); |
726 EXPECT_VALID(res); | 734 EXPECT_VALID(res); |
727 EXPECT_EQ(expected_trace_length, trace_len); | 735 EXPECT_EQ(expected_trace_length, trace_len); |
728 for (int i = 0; i < trace_len; i++) { | 736 for (int i = 0; i < trace_len; i++) { |
729 Dart_ActivationFrame frame; | 737 Dart_ActivationFrame frame; |
730 res = Dart_GetActivationFrame(trace, i, &frame); | 738 res = Dart_GetActivationFrame(trace, i, &frame); |
731 EXPECT_VALID(res); | 739 EXPECT_VALID(res); |
732 Dart_Handle func_name; | 740 Dart_Handle func_name; |
733 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL, NULL); | 741 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL, NULL, NULL); |
734 EXPECT_VALID(res); | 742 EXPECT_VALID(res); |
735 EXPECT(Dart_IsString(func_name)); | 743 EXPECT(Dart_IsString(func_name)); |
736 const char* name_chars; | 744 const char* name_chars; |
737 Dart_StringToCString(func_name, &name_chars); | 745 Dart_StringToCString(func_name, &name_chars); |
738 EXPECT_STREQ(expected_trace[i], name_chars); | 746 EXPECT_STREQ(expected_trace[i], name_chars); |
739 if (verbose) OS::Print(" >> %d: %s\n", i, name_chars); | 747 if (verbose) OS::Print(" >> %d: %s\n", i, name_chars); |
740 } | 748 } |
741 // Remove the breakpoint after we've hit it twice | 749 // Remove the breakpoint after we've hit it twice |
742 if (breakpoint_hit_counter == 2) { | 750 if (breakpoint_hit_counter == 2) { |
743 if (verbose) OS::Print("uninstalling breakpoint\n"); | 751 if (verbose) OS::Print("uninstalling breakpoint\n"); |
(...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1752 | 1760 |
1753 Dart_Handle list_type = Dart_InstanceGetType(list_access_test_obj); | 1761 Dart_Handle list_type = Dart_InstanceGetType(list_access_test_obj); |
1754 Dart_Handle super_type = Dart_GetSupertype(list_type); | 1762 Dart_Handle super_type = Dart_GetSupertype(list_type); |
1755 EXPECT(!Dart_IsError(super_type)); | 1763 EXPECT(!Dart_IsError(super_type)); |
1756 super_type = Dart_GetSupertype(super_type); | 1764 super_type = Dart_GetSupertype(super_type); |
1757 EXPECT(!Dart_IsError(super_type)); | 1765 EXPECT(!Dart_IsError(super_type)); |
1758 EXPECT(super_type == Dart_Null()); | 1766 EXPECT(super_type == Dart_Null()); |
1759 } | 1767 } |
1760 | 1768 |
1761 } // namespace dart | 1769 } // namespace dart |
OLD | NEW |