OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 "vm/dart_api_impl.h" | 6 #include "vm/dart_api_impl.h" |
7 #include "vm/dart_entry.h" | 7 #include "vm/dart_entry.h" |
8 #include "vm/debugger.h" | 8 #include "vm/debugger.h" |
9 #include "vm/globals.h" | 9 #include "vm/globals.h" |
10 #include "vm/message_handler.h" | 10 #include "vm/message_handler.h" |
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); | 688 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); |
689 EXPECT_VALID(result); | 689 EXPECT_VALID(result); |
690 const Class& class_a = Class::Handle(GetClass(lib, "A")); | 690 const Class& class_a = Class::Handle(GetClass(lib, "A")); |
691 EXPECT(!class_a.IsNull()); | 691 EXPECT(!class_a.IsNull()); |
692 const Function& function_c = Function::Handle(GetFunction(class_a, "c")); | 692 const Function& function_c = Function::Handle(GetFunction(class_a, "c")); |
693 EXPECT(!function_c.IsNull()); | 693 EXPECT(!function_c.IsNull()); |
694 const Code& code_c = Code::Handle(function_c.CurrentCode()); | 694 const Code& code_c = Code::Handle(function_c.CurrentCode()); |
695 EXPECT(!code_c.IsNull()); | 695 EXPECT(!code_c.IsNull()); |
696 // Use the entry of the code object as it's reference. | 696 // Use the entry of the code object as it's reference. |
697 uword entry = code_c.EntryPoint(); | 697 uword entry = code_c.EntryPoint(); |
| 698 int64_t compile_timestamp = code_c.compile_timestamp(); |
698 EXPECT_GT(code_c.Size(), 16); | 699 EXPECT_GT(code_c.Size(), 16); |
699 uword last = entry + code_c.Size(); | 700 uword last = entry + code_c.Size(); |
700 | 701 |
701 // Build a mock message handler and wrap it in a dart port. | 702 // Build a mock message handler and wrap it in a dart port. |
702 ServiceTestMessageHandler handler; | 703 ServiceTestMessageHandler handler; |
703 Dart_Port port_id = PortMap::CreatePort(&handler); | 704 Dart_Port port_id = PortMap::CreatePort(&handler); |
704 Dart_Handle port = | 705 Dart_Handle port = |
705 Api::NewHandle(isolate, DartLibraryCalls::NewSendPort(port_id)); | 706 Api::NewHandle(isolate, DartLibraryCalls::NewSendPort(port_id)); |
706 EXPECT_VALID(port); | 707 EXPECT_VALID(port); |
707 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); | 708 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); |
708 | 709 |
709 Instance& service_msg = Instance::Handle(); | 710 Instance& service_msg = Instance::Handle(); |
710 | 711 |
711 // Request an invalid code object. | 712 // Request an invalid code object. |
712 service_msg = Eval(h_lib, "[port, ['code', '0'], [], []]"); | 713 service_msg = Eval(h_lib, "[port, ['code', '0'], [], []]"); |
713 Service::HandleIsolateMessage(isolate, service_msg); | 714 Service::HandleIsolateMessage(isolate, service_msg); |
714 handler.HandleNextMessage(); | 715 handler.HandleNextMessage(); |
715 EXPECT_STREQ( | 716 EXPECT_STREQ( |
716 "{\"type\":\"Error\",\"id\":\"\",\"message\":\"Could not find code at 0\"," | 717 "{\"type\":\"Error\",\"id\":\"\",\"message\":\"Malformed code id: 0\"," |
717 "\"request\":{\"arguments\":[\"code\",\"0\"]," | 718 "\"request\":{\"arguments\":[\"code\",\"0\"]," |
718 "\"option_keys\":[],\"option_values\":[]}}", handler.msg()); | 719 "\"option_keys\":[],\"option_values\":[]}}", handler.msg()); |
719 | 720 |
720 // The following four tests check that a code object can be found | 721 // The following test checks that a code object can be found only |
721 // inside the range: [code.EntryPoint(), code.EntryPoint() + code.Size()). | 722 // at compile_timestamp()-code.EntryPoint(). |
722 // Request code object at code.EntryPoint() | 723 service_msg = EvalF(h_lib, "[port, ['code', '%" Px64"-%" Px "'], [], []]", |
723 // Expect this to succeed as it is inside [entry, entry + size). | 724 compile_timestamp, |
724 service_msg = EvalF(h_lib, "[port, ['code', '%" Px "'], [], []]", entry); | 725 entry); |
725 Service::HandleIsolateMessage(isolate, service_msg); | 726 Service::HandleIsolateMessage(isolate, service_msg); |
726 handler.HandleNextMessage(); | 727 handler.HandleNextMessage(); |
727 { | 728 { |
728 // Only perform a partial match. | 729 // Only perform a partial match. |
729 const intptr_t kBufferSize = 512; | 730 const intptr_t kBufferSize = 512; |
730 char buffer[kBufferSize]; | 731 char buffer[kBufferSize]; |
731 OS::SNPrint(buffer, kBufferSize-1, | 732 OS::SNPrint(buffer, kBufferSize-1, |
732 "{\"type\":\"Code\",\"id\":\"code\\/%" Px "\",", entry); | 733 "{\"type\":\"Code\",\"id\":\"code\\/%" Px64 "-%" Px "\",", |
| 734 compile_timestamp, |
| 735 entry); |
733 EXPECT_SUBSTRING(buffer, handler.msg()); | 736 EXPECT_SUBSTRING(buffer, handler.msg()); |
734 } | 737 } |
735 | 738 |
736 // Request code object at code.EntryPoint() + 16. | 739 // Request code object at compile_timestamp-code.EntryPoint() + 16 |
737 // Expect this to succeed as it is inside [entry, entry + size). | 740 // Expect this to fail because the address is not the entry point. |
738 uintptr_t address = entry + 16; | 741 uintptr_t address = entry + 16; |
739 service_msg = EvalF(h_lib, "[port, ['code', '%" Px "'], [], []]", address); | 742 service_msg = EvalF(h_lib, "[port, ['code', '%" Px64"-%" Px "'], [], []]", |
| 743 compile_timestamp, |
| 744 address); |
740 Service::HandleIsolateMessage(isolate, service_msg); | 745 Service::HandleIsolateMessage(isolate, service_msg); |
741 handler.HandleNextMessage(); | 746 handler.HandleNextMessage(); |
742 { | 747 { |
743 // Only perform a partial match. | 748 // Only perform a partial match. |
744 const intptr_t kBufferSize = 512; | 749 const intptr_t kBufferSize = 512; |
745 char buffer[kBufferSize]; | 750 char buffer[kBufferSize]; |
746 OS::SNPrint(buffer, kBufferSize-1, | 751 OS::SNPrint(buffer, kBufferSize-1, |
747 "{\"type\":\"Code\",\"id\":\"code\\/%" Px "\",", entry); | 752 "Could not find code with id: %" Px64 "-%" Px "", |
| 753 compile_timestamp, |
| 754 address); |
748 EXPECT_SUBSTRING(buffer, handler.msg()); | 755 EXPECT_SUBSTRING(buffer, handler.msg()); |
749 } | 756 } |
750 | 757 |
751 // Request code object at code.EntryPoint() + code.Size() - 1. | 758 // Request code object at (compile_timestamp - 1)-code.EntryPoint() |
752 // Expect this to succeed as it is inside [entry, entry + size). | 759 // Expect this to fail because the timestamp is wrong. |
753 address = last - 1; | 760 address = entry; |
754 service_msg = EvalF(h_lib, "[port, ['code', '%" Px "'], [], []]", address); | 761 service_msg = EvalF(h_lib, "[port, ['code', '%" Px64"-%" Px "'], [], []]", |
| 762 compile_timestamp - 1, |
| 763 address); |
755 Service::HandleIsolateMessage(isolate, service_msg); | 764 Service::HandleIsolateMessage(isolate, service_msg); |
756 handler.HandleNextMessage(); | 765 handler.HandleNextMessage(); |
757 { | 766 { |
758 // Only perform a partial match. | 767 // Only perform a partial match. |
759 const intptr_t kBufferSize = 512; | 768 const intptr_t kBufferSize = 512; |
760 char buffer[kBufferSize]; | 769 char buffer[kBufferSize]; |
761 OS::SNPrint(buffer, kBufferSize-1, | 770 OS::SNPrint(buffer, kBufferSize-1, |
762 "{\"type\":\"Code\",\"id\":\"code\\/%" Px "\",", entry); | 771 "Could not find code with id: %" Px64 "-%" Px "", |
| 772 compile_timestamp - 1, |
| 773 address); |
763 EXPECT_SUBSTRING(buffer, handler.msg()); | 774 EXPECT_SUBSTRING(buffer, handler.msg()); |
764 } | 775 } |
765 | 776 |
766 // Request code object at code.EntryPoint() + code.Size(). Expect this | 777 // Request native code at address. Expect the null code object back. |
767 // to fail as it's outside of [entry, entry + size). | |
768 address = last; | 778 address = last; |
769 service_msg = EvalF(h_lib, "[port, ['code', '%" Px "'], [], []]", address); | 779 service_msg = EvalF(h_lib, "[port, ['code', 'native-%" Px "'], [], []]", |
| 780 address); |
770 Service::HandleIsolateMessage(isolate, service_msg); | 781 Service::HandleIsolateMessage(isolate, service_msg); |
771 handler.HandleNextMessage(); | 782 handler.HandleNextMessage(); |
772 { | 783 EXPECT_STREQ("{\"type\":\"null\"}", handler.msg()); |
773 const intptr_t kBufferSize = 1024; | 784 |
774 char buffer[kBufferSize]; | 785 // Request malformed native code. |
775 OS::SNPrint(buffer, kBufferSize-1, | 786 service_msg = EvalF(h_lib, "[port, ['code', 'native%" Px "'], [], []]", |
776 "{\"type\":\"Error\",\"id\":\"\"," | 787 address); |
777 "\"message\":\"Could not find code at %" Px "\"," | 788 Service::HandleIsolateMessage(isolate, service_msg); |
778 "\"request\":{\"arguments\":[\"code\",\"%" Px "\"]," | 789 handler.HandleNextMessage(); |
779 "\"option_keys\":[],\"option_values\":[]}}", address, address); | 790 EXPECT_SUBSTRING("\"message\":\"Malformed code id:", handler.msg()); |
780 EXPECT_STREQ(buffer, handler.msg()); | |
781 } | |
782 } | 791 } |
783 | 792 |
784 | 793 |
785 TEST_CASE(Service_Cpu) { | 794 TEST_CASE(Service_Cpu) { |
786 const char* kScript = | 795 const char* kScript = |
787 "var port;\n" // Set to our mock port by C++. | 796 "var port;\n" // Set to our mock port by C++. |
788 "\n" | 797 "\n" |
789 "main() {\n" | 798 "main() {\n" |
790 "}"; | 799 "}"; |
791 | 800 |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1009 Service::HandleIsolateMessage(isolate, service_msg); | 1018 Service::HandleIsolateMessage(isolate, service_msg); |
1010 handler.HandleNextMessage(); | 1019 handler.HandleNextMessage(); |
1011 EXPECT_STREQ("alpha", handler.msg()); | 1020 EXPECT_STREQ("alpha", handler.msg()); |
1012 service_msg = Eval(lib, "[port, ['beta'], [], []]"); | 1021 service_msg = Eval(lib, "[port, ['beta'], [], []]"); |
1013 Service::HandleIsolateMessage(isolate, service_msg); | 1022 Service::HandleIsolateMessage(isolate, service_msg); |
1014 handler.HandleNextMessage(); | 1023 handler.HandleNextMessage(); |
1015 EXPECT_STREQ("beta", handler.msg()); | 1024 EXPECT_STREQ("beta", handler.msg()); |
1016 } | 1025 } |
1017 | 1026 |
1018 } // namespace dart | 1027 } // namespace dart |
OLD | NEW |