| 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/unit_test.h" | 8 #include "vm/unit_test.h" |
| 9 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| (...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 " c = add(a, b) { \n" | 604 " c = add(a, b) { \n" |
| 605 " return a + b; \n" | 605 " return a + b; \n" |
| 606 " }; \n" | 606 " }; \n" |
| 607 " return c(10, 20); \n" | 607 " return c(10, 20); \n" |
| 608 "} \n"; | 608 "} \n"; |
| 609 | 609 |
| 610 LoadScript(kScriptChars); | 610 LoadScript(kScriptChars); |
| 611 Dart_SetBreakpointHandler(&ExprClosureBreakpointHandler); | 611 Dart_SetBreakpointHandler(&ExprClosureBreakpointHandler); |
| 612 | 612 |
| 613 Dart_Handle script_url = Dart_NewString(TestCase::url()); | 613 Dart_Handle script_url = Dart_NewString(TestCase::url()); |
| 614 Dart_Handle line_no = Dart_NewInteger(5); // In closure 'add'. | 614 intptr_t line_no = 5; // In closure 'add'. |
| 615 Dart_Breakpoint bpt; | 615 Dart_Handle res = Dart_SetBreakpoint(script_url, line_no); |
| 616 Dart_Handle res = Dart_SetBreakpointAtLine(script_url, line_no, &bpt); | |
| 617 EXPECT_NOT_ERROR(res); | 616 EXPECT_NOT_ERROR(res); |
| 617 EXPECT(Dart_IsInteger(res)); |
| 618 | 618 |
| 619 breakpoint_hit_counter = 0; | 619 breakpoint_hit_counter = 0; |
| 620 Dart_Handle retval = Invoke("main"); | 620 Dart_Handle retval = Invoke("main"); |
| 621 EXPECT_NOT_ERROR(retval); | 621 EXPECT_NOT_ERROR(retval); |
| 622 int64_t int_value = 0; | 622 int64_t int_value = 0; |
| 623 Dart_IntegerToInt64(retval, &int_value); | 623 Dart_IntegerToInt64(retval, &int_value); |
| 624 EXPECT_EQ(30, int_value); | 624 EXPECT_EQ(30, int_value); |
| 625 EXPECT_EQ(1, breakpoint_hit_counter); | 625 EXPECT_EQ(1, breakpoint_hit_counter); |
| 626 } | 626 } |
| 627 | 627 |
| 628 | 628 |
| 629 static intptr_t bp_id_to_be_deleted; |
| 630 |
| 629 static void DeleteBreakpointHandler(Dart_Breakpoint bpt, | 631 static void DeleteBreakpointHandler(Dart_Breakpoint bpt, |
| 630 Dart_StackTrace trace) { | 632 Dart_StackTrace trace) { |
| 631 const char* expected_trace[] = {"foo", "main"}; | 633 const char* expected_trace[] = {"foo", "main"}; |
| 632 const intptr_t expected_trace_length = 2; | 634 const intptr_t expected_trace_length = 2; |
| 633 breakpoint_hit_counter++; | 635 breakpoint_hit_counter++; |
| 634 intptr_t trace_len; | 636 intptr_t trace_len; |
| 635 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); | 637 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); |
| 636 EXPECT_NOT_ERROR(res); | 638 EXPECT_NOT_ERROR(res); |
| 637 EXPECT_EQ(expected_trace_length, trace_len); | 639 EXPECT_EQ(expected_trace_length, trace_len); |
| 638 for (int i = 0; i < trace_len; i++) { | 640 for (int i = 0; i < trace_len; i++) { |
| 639 Dart_ActivationFrame frame; | 641 Dart_ActivationFrame frame; |
| 640 res = Dart_GetActivationFrame(trace, i, &frame); | 642 res = Dart_GetActivationFrame(trace, i, &frame); |
| 641 EXPECT_NOT_ERROR(res); | 643 EXPECT_NOT_ERROR(res); |
| 642 Dart_Handle func_name; | 644 Dart_Handle func_name; |
| 643 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL); | 645 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL); |
| 644 EXPECT_NOT_ERROR(res); | 646 EXPECT_NOT_ERROR(res); |
| 645 EXPECT(Dart_IsString(func_name)); | 647 EXPECT(Dart_IsString(func_name)); |
| 646 const char* name_chars; | 648 const char* name_chars; |
| 647 Dart_StringToCString(func_name, &name_chars); | 649 Dart_StringToCString(func_name, &name_chars); |
| 648 EXPECT_STREQ(expected_trace[i], name_chars); | 650 EXPECT_STREQ(expected_trace[i], name_chars); |
| 649 if (verbose) OS::Print(" >> %d: %s\n", i, name_chars); | 651 if (verbose) OS::Print(" >> %d: %s\n", i, name_chars); |
| 650 } | 652 } |
| 651 // Remove the breakpoint after we've hit it twice | 653 // Remove the breakpoint after we've hit it twice |
| 652 if (breakpoint_hit_counter == 2) { | 654 if (breakpoint_hit_counter == 2) { |
| 653 if (verbose) OS::Print("uninstalling breakpoint\n"); | 655 if (verbose) OS::Print("uninstalling breakpoint\n"); |
| 654 Dart_Handle res = Dart_DeleteBreakpoint(bpt); | 656 Dart_Handle res = Dart_RemoveBreakpoint(bp_id_to_be_deleted); |
| 655 EXPECT_NOT_ERROR(res); | 657 EXPECT_NOT_ERROR(res); |
| 656 } | 658 } |
| 657 } | 659 } |
| 658 | 660 |
| 659 | 661 |
| 660 TEST_CASE(Debug_DeleteBreakpoint) { | 662 TEST_CASE(Debug_DeleteBreakpoint) { |
| 661 const char* kScriptChars = | 663 const char* kScriptChars = |
| 662 "moo(s) { } \n" | 664 "moo(s) { } \n" |
| 663 " \n" | 665 " \n" |
| 664 "foo() { \n" | 666 "foo() { \n" |
| 665 " moo('good news'); \n" | 667 " moo('good news'); \n" |
| 666 "} \n" | 668 "} \n" |
| 667 " \n" | 669 " \n" |
| 668 "void main() { \n" | 670 "void main() { \n" |
| 669 " foo(); \n" | 671 " foo(); \n" |
| 670 " foo(); \n" | 672 " foo(); \n" |
| 671 " foo(); \n" | 673 " foo(); \n" |
| 672 "} \n"; | 674 "} \n"; |
| 673 | 675 |
| 674 LoadScript(kScriptChars); | 676 LoadScript(kScriptChars); |
| 675 | 677 |
| 676 Dart_Handle script_url = Dart_NewString(TestCase::url()); | 678 Dart_Handle script_url = Dart_NewString(TestCase::url()); |
| 677 Dart_Handle line_no = Dart_NewInteger(4); // In function 'foo'. | 679 intptr_t line_no = 4; // In function 'foo'. |
| 678 | 680 |
| 679 Dart_SetBreakpointHandler(&DeleteBreakpointHandler); | 681 Dart_SetBreakpointHandler(&DeleteBreakpointHandler); |
| 680 | 682 |
| 681 Dart_Breakpoint bpt; | 683 Dart_Handle res = Dart_SetBreakpoint(script_url, line_no); |
| 682 Dart_Handle res = Dart_SetBreakpointAtLine(script_url, line_no, &bpt); | |
| 683 EXPECT_NOT_ERROR(res); | 684 EXPECT_NOT_ERROR(res); |
| 685 EXPECT(Dart_IsInteger(res)); |
| 686 int64_t bp_id = 0; |
| 687 Dart_IntegerToInt64(res, &bp_id); |
| 684 | 688 |
| 685 // Function main() calls foo() 3 times. On the second iteration, the | 689 // Function main() calls foo() 3 times. On the second iteration, the |
| 686 // breakpoint is removed by the handler, so we expect the breakpoint | 690 // breakpoint is removed by the handler, so we expect the breakpoint |
| 687 // to fire twice only. | 691 // to fire twice only. |
| 692 bp_id_to_be_deleted = bp_id; |
| 688 breakpoint_hit_counter = 0; | 693 breakpoint_hit_counter = 0; |
| 689 Dart_Handle retval = Invoke("main"); | 694 Dart_Handle retval = Invoke("main"); |
| 690 EXPECT(!Dart_IsError(retval)); | 695 EXPECT(!Dart_IsError(retval)); |
| 691 EXPECT_EQ(2, breakpoint_hit_counter); | 696 EXPECT_EQ(2, breakpoint_hit_counter); |
| 692 } | 697 } |
| 693 | 698 |
| 694 | 699 |
| 695 static void InspectStaticFieldHandler(Dart_Breakpoint bpt, | 700 static void InspectStaticFieldHandler(Dart_Breakpoint bpt, |
| 696 Dart_StackTrace trace) { | 701 Dart_StackTrace trace) { |
| 697 ASSERT(script_lib != NULL); | 702 ASSERT(script_lib != NULL); |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 966 EXPECT(Dart_IsString(source)); | 971 EXPECT(Dart_IsString(source)); |
| 967 char const* source_chars; | 972 char const* source_chars; |
| 968 Dart_StringToCString(source, &source_chars); | 973 Dart_StringToCString(source, &source_chars); |
| 969 OS::Print("\n=== source: ===\n%s", source_chars); | 974 OS::Print("\n=== source: ===\n%s", source_chars); |
| 970 EXPECT_STREQ(kScriptChars, source_chars); | 975 EXPECT_STREQ(kScriptChars, source_chars); |
| 971 } | 976 } |
| 972 | 977 |
| 973 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 978 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 974 | 979 |
| 975 } // namespace dart | 980 } // namespace dart |
| OLD | NEW |