| 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 "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 | 6 |
| 7 #include "include/dart_debugger_api.h" | 7 #include "include/dart_debugger_api.h" |
| 8 #include "vm/dart_api_impl.h" | 8 #include "vm/dart_api_impl.h" |
| 9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
| 10 #include "vm/debugger.h" | 10 #include "vm/debugger.h" |
| (...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 "[0, port, ['classes', '%" Pd "', 'fields', '9', 'x']" | 917 "[0, port, ['classes', '%" Pd "', 'fields', '9', 'x']" |
| 918 ",[], []]", cid); | 918 ",[], []]", cid); |
| 919 Service::HandleIsolateMessage(isolate, service_msg); | 919 Service::HandleIsolateMessage(isolate, service_msg); |
| 920 handler.HandleNextMessage(); | 920 handler.HandleNextMessage(); |
| 921 ExpectSubstringF(handler.msg(), | 921 ExpectSubstringF(handler.msg(), |
| 922 "{\"type\":\"Error\",\"id\":\"\",\"message\":\"Command too long\"," | 922 "{\"type\":\"Error\",\"id\":\"\",\"message\":\"Command too long\"," |
| 923 "\"request\":" | 923 "\"request\":" |
| 924 "{\"arguments\":[\"classes\",\"%" Pd "\",\"fields\",\"9\",\"x\"]," | 924 "{\"arguments\":[\"classes\",\"%" Pd "\",\"fields\",\"9\",\"x\"]," |
| 925 "\"option_keys\":[],\"option_values\":[]}}", cid); | 925 "\"option_keys\":[],\"option_values\":[]}}", cid); |
| 926 | 926 |
| 927 // Invalid function request. | 927 // Invalid function command. |
| 928 service_msg = EvalF(h_lib, | 928 service_msg = EvalF(h_lib, |
| 929 "[0, port, ['classes', '%" Pd "', 'functions', '9'," | 929 "[0, port, ['classes', '%" Pd "', 'functions', '0'," |
| 930 "'x'], [], []]", cid); | 930 "'x', 'y'], [], []]", cid); |
| 931 Service::HandleIsolateMessage(isolate, service_msg); | 931 Service::HandleIsolateMessage(isolate, service_msg); |
| 932 handler.HandleNextMessage(); | 932 handler.HandleNextMessage(); |
| 933 ExpectSubstringF(handler.msg(), | 933 ExpectSubstringF(handler.msg(), |
| 934 "{\"type\":\"Error\",\"id\":\"\",\"message\":\"Command too long\"," | 934 "{\"type\":\"Error\",\"id\":\"\",\"message\":\"Command too long\"," |
| 935 "\"request\":" | 935 "\"request\":" |
| 936 "{\"arguments\":[\"classes\",\"%" Pd "\",\"functions\",\"9\",\"x\"]," | 936 "{\"arguments\":[\"classes\",\"%" Pd "\",\"functions\",\"0\",\"x\",\"y\"]," |
| 937 "\"option_keys\":[],\"option_values\":[]}}", cid); |
| 938 |
| 939 // Invalid function subcommand with valid function id. |
| 940 service_msg = EvalF(h_lib, |
| 941 "[0, port, ['classes', '%" Pd "', 'functions', '0'," |
| 942 "'x'], [], []]", cid); |
| 943 Service::HandleIsolateMessage(isolate, service_msg); |
| 944 handler.HandleNextMessage(); |
| 945 ExpectSubstringF(handler.msg(), |
| 946 "{\"type\":\"Error\",\"id\":\"\",\"message\":\"Invalid sub collection x\"," |
| 947 "\"request\":" |
| 948 "{\"arguments\":[\"classes\",\"%" Pd "\",\"functions\",\"0\",\"x\"]," |
| 937 "\"option_keys\":[],\"option_values\":[]}}", cid); | 949 "\"option_keys\":[],\"option_values\":[]}}", cid); |
| 938 | 950 |
| 939 // Retained size of all instances of class B. | 951 // Retained size of all instances of class B. |
| 940 const Class& class_b = Class::Handle(GetClass(lib, "B")); | 952 const Class& class_b = Class::Handle(GetClass(lib, "B")); |
| 941 EXPECT(!class_b.IsNull()); | 953 EXPECT(!class_b.IsNull()); |
| 942 const Instance& b0 = Instance::Handle(Instance::New(class_b)); | 954 const Instance& b0 = Instance::Handle(Instance::New(class_b)); |
| 943 const Instance& b1 = Instance::Handle(Instance::New(class_b)); | 955 const Instance& b1 = Instance::Handle(Instance::New(class_b)); |
| 944 service_msg = EvalF(h_lib, "[0, port, ['classes', '%" Pd "', 'retained']," | 956 service_msg = EvalF(h_lib, "[0, port, ['classes', '%" Pd "', 'retained']," |
| 945 "[], []]", class_b.id()); | 957 "[], []]", class_b.id()); |
| 946 Service::HandleIsolateMessage(isolate, service_msg); | 958 Service::HandleIsolateMessage(isolate, service_msg); |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1499 Service::HandleIsolateMessage(isolate, service_msg); | 1511 Service::HandleIsolateMessage(isolate, service_msg); |
| 1500 handler.HandleNextMessage(); | 1512 handler.HandleNextMessage(); |
| 1501 EXPECT_STREQ( | 1513 EXPECT_STREQ( |
| 1502 "{\"type\":\"CodeCoverage\",\"id\":\"coverage\",\"coverage\":[" | 1514 "{\"type\":\"CodeCoverage\",\"id\":\"coverage\",\"coverage\":[" |
| 1503 "{\"source\":\"test-lib\",\"script\":{" | 1515 "{\"source\":\"test-lib\",\"script\":{" |
| 1504 "\"type\":\"@Script\",\"id\":\"scripts\\/test-lib\"," | 1516 "\"type\":\"@Script\",\"id\":\"scripts\\/test-lib\"," |
| 1505 "\"name\":\"test-lib\",\"user_name\":\"test-lib\"," | 1517 "\"name\":\"test-lib\",\"user_name\":\"test-lib\"," |
| 1506 "\"kind\":\"script\"},\"hits\":[5,1,7,4,8,3]}]}", handler.msg()); | 1518 "\"kind\":\"script\"},\"hits\":[5,1,7,4,8,3]}]}", handler.msg()); |
| 1507 } | 1519 } |
| 1508 | 1520 |
| 1521 |
| 1522 TEST_CASE(Service_ClassesFunctionsCoverage) { |
| 1523 const char* kScript = |
| 1524 "var port;\n" // Set to our mock port by C++. |
| 1525 "\n" |
| 1526 "class Foo {\n" |
| 1527 " var x;\n" |
| 1528 " Foo(this.x);\n" |
| 1529 " bar() {\n" |
| 1530 " x = x * x;\n" |
| 1531 " x = x / 13;\n" |
| 1532 " }\n" |
| 1533 " badum(var a) => 4 + a;\n" |
| 1534 "}\n" |
| 1535 "main() {\n" |
| 1536 " var foo = new Foo(7);\n" |
| 1537 " foo.bar();\n" |
| 1538 "}"; |
| 1539 |
| 1540 Isolate* isolate = Isolate::Current(); |
| 1541 Dart_Handle h_lib = TestCase::LoadTestScript(kScript, NULL); |
| 1542 EXPECT_VALID(h_lib); |
| 1543 Library& lib = Library::Handle(); |
| 1544 lib ^= Api::UnwrapHandle(h_lib); |
| 1545 EXPECT(!lib.IsNull()); |
| 1546 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); |
| 1547 EXPECT_VALID(result); |
| 1548 |
| 1549 // Build a mock message handler and wrap it in a dart port. |
| 1550 ServiceTestMessageHandler handler; |
| 1551 Dart_Port port_id = PortMap::CreatePort(&handler); |
| 1552 Dart_Handle port = Api::NewHandle(isolate, SendPort::New(port_id)); |
| 1553 EXPECT_VALID(port); |
| 1554 EXPECT_VALID(Dart_SetField(h_lib, NewString("port"), port)); |
| 1555 |
| 1556 // Look up the service id of Foo. |
| 1557 const Class& cls = Class::Handle( |
| 1558 lib.LookupClass(String::Handle(String::New("Foo")))); |
| 1559 ASSERT(!cls.IsNull()); |
| 1560 ClassTable* table = isolate->class_table(); |
| 1561 intptr_t i; |
| 1562 for (i = 1; i < table->NumCids(); i++) { |
| 1563 if (table->HasValidClassAt(i) && table->At(i) == cls.raw()) { |
| 1564 break; |
| 1565 } |
| 1566 } |
| 1567 ASSERT(i != table->NumCids()); |
| 1568 |
| 1569 // Look up the service if of the function Foo.bar. |
| 1570 const Function& func = Function::Handle( |
| 1571 cls.LookupFunction(String::Handle(String::New("bar")))); |
| 1572 ASSERT(!func.IsNull()); |
| 1573 intptr_t function_id = -1; |
| 1574 function_id = cls.FindFunctionIndex(func); |
| 1575 ASSERT(function_id != -1); |
| 1576 |
| 1577 char buf[1024]; |
| 1578 OS::SNPrint(buf, sizeof(buf), |
| 1579 "[0, port, ['classes', '%" Pd "', 'functions'," |
| 1580 "'% " Pd "', 'coverage'], [], []]", i, function_id); |
| 1581 |
| 1582 Array& service_msg = Array::Handle(); |
| 1583 service_msg = Eval(h_lib, buf); |
| 1584 Service::HandleIsolateMessage(isolate, service_msg); |
| 1585 handler.HandleNextMessage(); |
| 1586 EXPECT_STREQ( |
| 1587 "{\"type\":\"CodeCoverage\",\"id\":\"coverage\",\"coverage\":[" |
| 1588 "{\"source\":\"test-lib\",\"script\":{" |
| 1589 "\"type\":\"@Script\",\"id\":\"scripts\\/test-lib\"," |
| 1590 "\"name\":\"test-lib\",\"user_name\":\"test-lib\"," |
| 1591 "\"kind\":\"script\"},\"hits\":[7,4,8,3]}]}", handler.msg()); |
| 1592 } |
| 1593 |
| 1509 #endif | 1594 #endif |
| 1510 | 1595 |
| 1511 | 1596 |
| 1512 TEST_CASE(Service_AllocationProfile) { | 1597 TEST_CASE(Service_AllocationProfile) { |
| 1513 const char* kScript = | 1598 const char* kScript = |
| 1514 "var port;\n" // Set to our mock port by C++. | 1599 "var port;\n" // Set to our mock port by C++. |
| 1515 "\n" | 1600 "\n" |
| 1516 "var x = 7;\n" | 1601 "var x = 7;\n" |
| 1517 "main() {\n" | 1602 "main() {\n" |
| 1518 " x = x * x;\n" | 1603 " x = x * x;\n" |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1801 service_msg = Eval(h_lib, "[0, port, ['profile'], ['tags'], ['hidden']]"); | 1886 service_msg = Eval(h_lib, "[0, port, ['profile'], ['tags'], ['hidden']]"); |
| 1802 Service::HandleIsolateMessage(isolate, service_msg); | 1887 Service::HandleIsolateMessage(isolate, service_msg); |
| 1803 handler.HandleNextMessage(); | 1888 handler.HandleNextMessage(); |
| 1804 // Expect error. | 1889 // Expect error. |
| 1805 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); | 1890 EXPECT_SUBSTRING("\"type\":\"Error\"", handler.msg()); |
| 1806 } | 1891 } |
| 1807 | 1892 |
| 1808 #endif // !defined(TARGET_ARCH_ARM64) | 1893 #endif // !defined(TARGET_ARCH_ARM64) |
| 1809 | 1894 |
| 1810 } // namespace dart | 1895 } // namespace dart |
| OLD | NEW |