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 "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/thread.h" | 8 #include "vm/thread.h" |
9 #include "vm/unit_test.h" | 9 #include "vm/unit_test.h" |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 EXPECT_VALID(script_lib); | 24 EXPECT_VALID(script_lib); |
25 } | 25 } |
26 | 26 |
27 | 27 |
28 static void SetBreakpointAtEntry(const char* cname, const char* fname) { | 28 static void SetBreakpointAtEntry(const char* cname, const char* fname) { |
29 ASSERT(script_lib != NULL); | 29 ASSERT(script_lib != NULL); |
30 ASSERT(!Dart_IsError(script_lib)); | 30 ASSERT(!Dart_IsError(script_lib)); |
31 ASSERT(Dart_IsLibrary(script_lib)); | 31 ASSERT(Dart_IsLibrary(script_lib)); |
32 Dart_Breakpoint bpt; | 32 Dart_Breakpoint bpt; |
33 Dart_Handle res = Dart_SetBreakpointAtEntry(script_lib, | 33 Dart_Handle res = Dart_SetBreakpointAtEntry(script_lib, |
34 Dart_NewString(cname), | 34 NewString(cname), |
35 Dart_NewString(fname), | 35 NewString(fname), |
36 &bpt); | 36 &bpt); |
37 EXPECT_VALID(res); | 37 EXPECT_VALID(res); |
38 } | 38 } |
39 | 39 |
40 | 40 |
41 static Dart_Handle Invoke(const char* func_name) { | 41 static Dart_Handle Invoke(const char* func_name) { |
42 ASSERT(script_lib != NULL); | 42 ASSERT(script_lib != NULL); |
43 ASSERT(!Dart_IsError(script_lib)); | 43 ASSERT(!Dart_IsError(script_lib)); |
44 ASSERT(Dart_IsLibrary(script_lib)); | 44 ASSERT(Dart_IsLibrary(script_lib)); |
45 return Dart_Invoke(script_lib, Dart_NewString(func_name), 0, NULL); | 45 return Dart_Invoke(script_lib, NewString(func_name), 0, NULL); |
46 } | 46 } |
47 | 47 |
48 | 48 |
49 static char const* ToCString(Dart_Handle str) { | 49 static char const* ToCString(Dart_Handle str) { |
50 EXPECT(Dart_IsString(str)); | 50 EXPECT(Dart_IsString(str)); |
51 char const* c_str = NULL; | 51 char const* c_str = NULL; |
52 Dart_StringToCString(str, &c_str); | 52 Dart_StringToCString(str, &c_str); |
53 return c_str; | 53 return c_str; |
54 } | 54 } |
55 | 55 |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 EXPECT_EQ(442, int_value); | 625 EXPECT_EQ(442, int_value); |
626 EXPECT_EQ(2, breakpoint_hit_counter); | 626 EXPECT_EQ(2, breakpoint_hit_counter); |
627 } | 627 } |
628 | 628 |
629 | 629 |
630 static void ExprClosureBreakpointHandler(Dart_IsolateId isolate_id, | 630 static void ExprClosureBreakpointHandler(Dart_IsolateId isolate_id, |
631 Dart_Breakpoint bpt, | 631 Dart_Breakpoint bpt, |
632 Dart_StackTrace trace) { | 632 Dart_StackTrace trace) { |
633 static const char* expected_trace[] = {"add", "main"}; | 633 static const char* expected_trace[] = {"add", "main"}; |
634 Dart_Handle add_locals = Dart_NewList(4); | 634 Dart_Handle add_locals = Dart_NewList(4); |
635 Dart_ListSetAt(add_locals, 0, Dart_NewString("a")); | 635 Dart_ListSetAt(add_locals, 0, NewString("a")); |
636 Dart_ListSetAt(add_locals, 1, Dart_NewInteger(10)); | 636 Dart_ListSetAt(add_locals, 1, Dart_NewInteger(10)); |
637 Dart_ListSetAt(add_locals, 2, Dart_NewString("b")); | 637 Dart_ListSetAt(add_locals, 2, NewString("b")); |
638 Dart_ListSetAt(add_locals, 3, Dart_NewInteger(20)); | 638 Dart_ListSetAt(add_locals, 3, Dart_NewInteger(20)); |
639 Dart_Handle expected_locals[] = {add_locals, Dart_Null()}; | 639 Dart_Handle expected_locals[] = {add_locals, Dart_Null()}; |
640 breakpoint_hit_counter++; | 640 breakpoint_hit_counter++; |
641 PrintStackTrace(trace); | 641 PrintStackTrace(trace); |
642 VerifyStackTrace(trace, expected_trace, expected_locals, 2); | 642 VerifyStackTrace(trace, expected_trace, expected_locals, 2); |
643 } | 643 } |
644 | 644 |
645 | 645 |
646 TEST_CASE(Debug_ExprClosureBreakpoint) { | 646 TEST_CASE(Debug_ExprClosureBreakpoint) { |
647 const char* kScriptChars = | 647 const char* kScriptChars = |
648 "var c; \n" | 648 "var c; \n" |
649 " \n" | 649 " \n" |
650 "main() { \n" | 650 "main() { \n" |
651 " c = add(a, b) { \n" | 651 " c = add(a, b) { \n" |
652 " return a + b; \n" | 652 " return a + b; \n" |
653 " }; \n" | 653 " }; \n" |
654 " return c(10, 20); \n" | 654 " return c(10, 20); \n" |
655 "} \n"; | 655 "} \n"; |
656 | 656 |
657 LoadScript(kScriptChars); | 657 LoadScript(kScriptChars); |
658 Dart_SetBreakpointHandler(&ExprClosureBreakpointHandler); | 658 Dart_SetBreakpointHandler(&ExprClosureBreakpointHandler); |
659 | 659 |
660 Dart_Handle script_url = Dart_NewString(TestCase::url()); | 660 Dart_Handle script_url = NewString(TestCase::url()); |
661 intptr_t line_no = 5; // In closure 'add'. | 661 intptr_t line_no = 5; // In closure 'add'. |
662 Dart_Handle res = Dart_SetBreakpoint(script_url, line_no); | 662 Dart_Handle res = Dart_SetBreakpoint(script_url, line_no); |
663 EXPECT_VALID(res); | 663 EXPECT_VALID(res); |
664 EXPECT(Dart_IsInteger(res)); | 664 EXPECT(Dart_IsInteger(res)); |
665 | 665 |
666 breakpoint_hit_counter = 0; | 666 breakpoint_hit_counter = 0; |
667 Dart_Handle retval = Invoke("main"); | 667 Dart_Handle retval = Invoke("main"); |
668 EXPECT_VALID(retval); | 668 EXPECT_VALID(retval); |
669 int64_t int_value = 0; | 669 int64_t int_value = 0; |
670 Dart_IntegerToInt64(retval, &int_value); | 670 Dart_IntegerToInt64(retval, &int_value); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
716 "} \n" | 716 "} \n" |
717 " \n" | 717 " \n" |
718 "void main() { \n" | 718 "void main() { \n" |
719 " foo(); \n" | 719 " foo(); \n" |
720 " foo(); \n" | 720 " foo(); \n" |
721 " foo(); \n" | 721 " foo(); \n" |
722 "} \n"; | 722 "} \n"; |
723 | 723 |
724 LoadScript(kScriptChars); | 724 LoadScript(kScriptChars); |
725 | 725 |
726 Dart_Handle script_url = Dart_NewString(TestCase::url()); | 726 Dart_Handle script_url = NewString(TestCase::url()); |
727 intptr_t line_no = 4; // In function 'foo'. | 727 intptr_t line_no = 4; // In function 'foo'. |
728 | 728 |
729 Dart_SetBreakpointHandler(&DeleteBreakpointHandler); | 729 Dart_SetBreakpointHandler(&DeleteBreakpointHandler); |
730 | 730 |
731 Dart_Handle res = Dart_SetBreakpoint(script_url, line_no); | 731 Dart_Handle res = Dart_SetBreakpoint(script_url, line_no); |
732 EXPECT_VALID(res); | 732 EXPECT_VALID(res); |
733 EXPECT(Dart_IsInteger(res)); | 733 EXPECT(Dart_IsInteger(res)); |
734 int64_t bp_id = 0; | 734 int64_t bp_id = 0; |
735 Dart_IntegerToInt64(res, &bp_id); | 735 Dart_IntegerToInt64(res, &bp_id); |
736 | 736 |
737 // Function main() calls foo() 3 times. On the second iteration, the | 737 // Function main() calls foo() 3 times. On the second iteration, the |
738 // breakpoint is removed by the handler, so we expect the breakpoint | 738 // breakpoint is removed by the handler, so we expect the breakpoint |
739 // to fire twice only. | 739 // to fire twice only. |
740 bp_id_to_be_deleted = bp_id; | 740 bp_id_to_be_deleted = bp_id; |
741 breakpoint_hit_counter = 0; | 741 breakpoint_hit_counter = 0; |
742 Dart_Handle retval = Invoke("main"); | 742 Dart_Handle retval = Invoke("main"); |
743 EXPECT_VALID(retval); | 743 EXPECT_VALID(retval); |
744 EXPECT_EQ(2, breakpoint_hit_counter); | 744 EXPECT_EQ(2, breakpoint_hit_counter); |
745 } | 745 } |
746 | 746 |
747 | 747 |
748 static void InspectStaticFieldHandler(Dart_IsolateId isolate_id, | 748 static void InspectStaticFieldHandler(Dart_IsolateId isolate_id, |
749 Dart_Breakpoint bpt, | 749 Dart_Breakpoint bpt, |
750 Dart_StackTrace trace) { | 750 Dart_StackTrace trace) { |
751 ASSERT(script_lib != NULL); | 751 ASSERT(script_lib != NULL); |
752 ASSERT(!Dart_IsError(script_lib)); | 752 ASSERT(!Dart_IsError(script_lib)); |
753 ASSERT(Dart_IsLibrary(script_lib)); | 753 ASSERT(Dart_IsLibrary(script_lib)); |
754 Dart_Handle class_A = Dart_GetClass(script_lib, Dart_NewString("A")); | 754 Dart_Handle class_A = Dart_GetClass(script_lib, NewString("A")); |
755 EXPECT_VALID(class_A); | 755 EXPECT_VALID(class_A); |
756 | 756 |
757 const int expected_num_fields = 2; | 757 const int expected_num_fields = 2; |
758 struct { | 758 struct { |
759 const char* field_name; | 759 const char* field_name; |
760 const char* field_value; | 760 const char* field_value; |
761 } expected[] = { | 761 } expected[] = { |
762 // Expected values at first breakpoint. | 762 // Expected values at first breakpoint. |
763 { "bla", "yada yada yada"}, | 763 { "bla", "yada yada yada"}, |
764 { "u", "null" }, | 764 { "u", "null" }, |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1008 Dart_ListLength(scripts, &num_scripts); | 1008 Dart_ListLength(scripts, &num_scripts); |
1009 EXPECT(num_scripts >= 0); | 1009 EXPECT(num_scripts >= 0); |
1010 for (int i = 0; i < num_scripts; i++) { | 1010 for (int i = 0; i < num_scripts; i++) { |
1011 Dart_Handle script_url = Dart_ListGetAt(scripts, i); | 1011 Dart_Handle script_url = Dart_ListGetAt(scripts, i); |
1012 char const* chars; | 1012 char const* chars; |
1013 Dart_StringToCString(script_url, &chars); | 1013 Dart_StringToCString(script_url, &chars); |
1014 OS::Print(" script %d: '%s'\n", i + 1, chars); | 1014 OS::Print(" script %d: '%s'\n", i + 1, chars); |
1015 } | 1015 } |
1016 } | 1016 } |
1017 | 1017 |
1018 Dart_Handle lib_url = Dart_NewString(TestCase::url()); | 1018 Dart_Handle lib_url = NewString(TestCase::url()); |
1019 Dart_Handle source = Dart_GetScriptSource(lib_url, lib_url); | 1019 Dart_Handle source = Dart_GetScriptSource(lib_url, lib_url); |
1020 EXPECT(Dart_IsString(source)); | 1020 EXPECT(Dart_IsString(source)); |
1021 char const* source_chars; | 1021 char const* source_chars; |
1022 Dart_StringToCString(source, &source_chars); | 1022 Dart_StringToCString(source, &source_chars); |
1023 OS::Print("\n=== source: ===\n%s", source_chars); | 1023 OS::Print("\n=== source: ===\n%s", source_chars); |
1024 EXPECT_STREQ(kScriptChars, source_chars); | 1024 EXPECT_STREQ(kScriptChars, source_chars); |
1025 } | 1025 } |
1026 | 1026 |
1027 | 1027 |
1028 TEST_CASE(GetLibraryURLs) { | 1028 TEST_CASE(GetLibraryURLs) { |
1029 const char* kScriptChars = | 1029 const char* kScriptChars = |
1030 "main() {" | 1030 "main() {" |
1031 " return 12345;" | 1031 " return 12345;" |
1032 "}"; | 1032 "}"; |
1033 | 1033 |
1034 Dart_Handle lib_list = Dart_GetLibraryURLs(); | 1034 Dart_Handle lib_list = Dart_GetLibraryURLs(); |
1035 EXPECT_VALID(lib_list); | 1035 EXPECT_VALID(lib_list); |
1036 EXPECT(Dart_IsList(lib_list)); | 1036 EXPECT(Dart_IsList(lib_list)); |
1037 Dart_Handle list_as_string = Dart_ToString(lib_list); | 1037 Dart_Handle list_as_string = Dart_ToString(lib_list); |
1038 const char* list_cstr = ""; | 1038 const char* list_cstr = ""; |
1039 EXPECT_VALID(Dart_StringToCString(list_as_string, &list_cstr)); | 1039 EXPECT_VALID(Dart_StringToCString(list_as_string, &list_cstr)); |
1040 EXPECT_NOTSUBSTRING(TestCase::url(), list_cstr); | 1040 EXPECT_NOTSUBSTRING(TestCase::url(), list_cstr); |
1041 | 1041 |
1042 // Load a script. | 1042 // Load a script. |
1043 Dart_Handle url = Dart_NewString(TestCase::url()); | 1043 Dart_Handle url = NewString(TestCase::url()); |
1044 Dart_Handle source = Dart_NewString(kScriptChars); | 1044 Dart_Handle source = NewString(kScriptChars); |
1045 EXPECT_VALID(Dart_LoadScript(url, source)); | 1045 EXPECT_VALID(Dart_LoadScript(url, source)); |
1046 | 1046 |
1047 lib_list = Dart_GetLibraryURLs(); | 1047 lib_list = Dart_GetLibraryURLs(); |
1048 EXPECT_VALID(lib_list); | 1048 EXPECT_VALID(lib_list); |
1049 EXPECT(Dart_IsList(lib_list)); | 1049 EXPECT(Dart_IsList(lib_list)); |
1050 list_as_string = Dart_ToString(lib_list); | 1050 list_as_string = Dart_ToString(lib_list); |
1051 list_cstr = ""; | 1051 list_cstr = ""; |
1052 EXPECT_VALID(Dart_StringToCString(list_as_string, &list_cstr)); | 1052 EXPECT_VALID(Dart_StringToCString(list_as_string, &list_cstr)); |
1053 EXPECT_SUBSTRING(TestCase::url(), list_cstr); | 1053 EXPECT_SUBSTRING(TestCase::url(), list_cstr); |
1054 } | 1054 } |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1220 while (interrupt_isolate_id != ILLEGAL_ISOLATE_ID) { | 1220 while (interrupt_isolate_id != ILLEGAL_ISOLATE_ID) { |
1221 ml.Wait(); | 1221 ml.Wait(); |
1222 } | 1222 } |
1223 } | 1223 } |
1224 EXPECT(interrupt_isolate_id == ILLEGAL_ISOLATE_ID); | 1224 EXPECT(interrupt_isolate_id == ILLEGAL_ISOLATE_ID); |
1225 } | 1225 } |
1226 | 1226 |
1227 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 1227 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
1228 | 1228 |
1229 } // namespace dart | 1229 } // namespace dart |
OLD | NEW |