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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 EXPECT(Dart_IsString(name_handle)); | 144 EXPECT(Dart_IsString(name_handle)); |
145 OS::Print(" local var %s = ", ToCString(name_handle)); | 145 OS::Print(" local var %s = ", ToCString(name_handle)); |
146 Dart_Handle value_handle = Dart_ListGetAt(locals, i + 1); | 146 Dart_Handle value_handle = Dart_ListGetAt(locals, i + 1); |
147 EXPECT_VALID(value_handle); | 147 EXPECT_VALID(value_handle); |
148 PrintValue(value_handle, true); | 148 PrintValue(value_handle, true); |
149 OS::Print("\n"); | 149 OS::Print("\n"); |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 | 153 |
| 154 static Dart_Handle GetLocalVariable(Dart_ActivationFrame frame, |
| 155 const char* name) { |
| 156 Dart_Handle locals = Dart_GetLocalVariables(frame); |
| 157 EXPECT_VALID(locals); |
| 158 intptr_t list_length = 0; |
| 159 Dart_Handle ret = Dart_ListLength(locals, &list_length); |
| 160 EXPECT_VALID(ret); |
| 161 for (int i = 0; i + 1 < list_length; i += 2) { |
| 162 Dart_Handle name_handle = Dart_ListGetAt(locals, i); |
| 163 EXPECT_VALID(name_handle); |
| 164 EXPECT(Dart_IsString(name_handle)); |
| 165 if (strcmp(ToCString(name_handle), name) == 0) { |
| 166 Dart_Handle value_handle = Dart_ListGetAt(locals, i + 1); |
| 167 EXPECT_VALID(value_handle); |
| 168 return value_handle; |
| 169 } |
| 170 } |
| 171 EXPECT(!"local variable not found"); |
| 172 return Dart_Null(); |
| 173 } |
| 174 |
| 175 |
154 static void PrintStackTrace(Dart_StackTrace trace) { | 176 static void PrintStackTrace(Dart_StackTrace trace) { |
155 intptr_t trace_len; | 177 intptr_t trace_len; |
156 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); | 178 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); |
157 EXPECT_TRUE(res); | 179 EXPECT_TRUE(res); |
158 for (int i = 0; i < trace_len; i++) { | 180 for (int i = 0; i < trace_len; i++) { |
159 Dart_ActivationFrame frame; | 181 Dart_ActivationFrame frame; |
160 res = Dart_GetActivationFrame(trace, i, &frame); | 182 res = Dart_GetActivationFrame(trace, i, &frame); |
161 EXPECT_TRUE(res); | 183 EXPECT_TRUE(res); |
162 PrintActivationFrame(frame); | 184 PrintActivationFrame(frame); |
163 } | 185 } |
(...skipping 1277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1441 breakpoint_hit_counter = 0; | 1463 breakpoint_hit_counter = 0; |
1442 Dart_SetExceptionPauseInfo(kPauseOnAllExceptions); | 1464 Dart_SetExceptionPauseInfo(kPauseOnAllExceptions); |
1443 | 1465 |
1444 Dart_Handle retval = Invoke("main"); | 1466 Dart_Handle retval = Invoke("main"); |
1445 EXPECT(Dart_IsError(retval)); | 1467 EXPECT(Dart_IsError(retval)); |
1446 EXPECT(Dart_IsUnhandledExceptionError(retval)); | 1468 EXPECT(Dart_IsUnhandledExceptionError(retval)); |
1447 EXPECT_EQ(1, breakpoint_hit_counter); | 1469 EXPECT_EQ(1, breakpoint_hit_counter); |
1448 } | 1470 } |
1449 | 1471 |
1450 | 1472 |
| 1473 void TestEvaluateHandler(Dart_IsolateId isolate_id, |
| 1474 const Dart_CodeLocation& location) { |
| 1475 Dart_StackTrace trace; |
| 1476 Dart_GetStackTrace(&trace); |
| 1477 intptr_t trace_len; |
| 1478 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); |
| 1479 EXPECT_VALID(res); |
| 1480 EXPECT_EQ(1, trace_len); |
| 1481 Dart_ActivationFrame frame; |
| 1482 res = Dart_GetActivationFrame(trace, 0, &frame); |
| 1483 EXPECT_VALID(res); |
| 1484 |
| 1485 // Get the local variable p and evaluate an expression in the |
| 1486 // context of p. |
| 1487 Dart_Handle p = GetLocalVariable(frame, "p"); |
| 1488 EXPECT_VALID(p); |
| 1489 EXPECT(!Dart_IsNull(p)); |
| 1490 |
| 1491 Dart_Handle r = Dart_EvaluateExpr(p, NewString("sqrt(x*x + y*this.y)")); |
| 1492 EXPECT_VALID(r); |
| 1493 EXPECT(Dart_IsNumber(r)); |
| 1494 double d; |
| 1495 Dart_DoubleValue(r, &d); |
| 1496 EXPECT_EQ(5.0, d); |
| 1497 |
| 1498 breakpoint_hit = true; |
| 1499 breakpoint_hit_counter++; |
| 1500 } |
| 1501 |
| 1502 |
| 1503 TEST_CASE(Debug_EvaluateExpr) { |
| 1504 const char* kScriptChars = |
| 1505 "import 'dart:math'; \n" |
| 1506 "main() { \n" |
| 1507 " var p = new Point(3, 4); \n" |
| 1508 " l = [1, 2, 3]; /*BP*/ \n" |
| 1509 " return p; \n" |
| 1510 "} \n" |
| 1511 "var _factor = 2; \n" |
| 1512 "var l; \n" |
| 1513 "class Point { \n" |
| 1514 " var x, y; \n" |
| 1515 " Point(this.x, this.y); \n" |
| 1516 "} \n"; |
| 1517 |
| 1518 LoadScript(kScriptChars); |
| 1519 Dart_SetPausedEventHandler(&TestEvaluateHandler); |
| 1520 |
| 1521 |
| 1522 Dart_Handle script_url = NewString(TestCase::url()); |
| 1523 intptr_t line_no = 4; |
| 1524 Dart_Handle res = Dart_SetBreakpoint(script_url, line_no); |
| 1525 EXPECT_VALID(res); |
| 1526 |
| 1527 breakpoint_hit = false; |
| 1528 Dart_Handle point = Invoke("main"); |
| 1529 EXPECT_VALID(point); |
| 1530 EXPECT(breakpoint_hit == true); |
| 1531 |
| 1532 Dart_Handle r = |
| 1533 Dart_EvaluateExpr(point, NewString("_factor * sqrt(x*x + y*y)")); |
| 1534 EXPECT_VALID(r); |
| 1535 EXPECT(Dart_IsNumber(r)); |
| 1536 double d; |
| 1537 Dart_DoubleValue(r, &d); |
| 1538 EXPECT_EQ(10.0, d); |
| 1539 |
| 1540 Dart_Handle len = Dart_EvaluateExpr(point, NewString("l.length")); |
| 1541 EXPECT_VALID(len); |
| 1542 EXPECT(Dart_IsNumber(len)); |
| 1543 int64_t l = 0; |
| 1544 Dart_IntegerToInt64(len, &l); |
| 1545 EXPECT_EQ(3, l); |
| 1546 } |
| 1547 |
| 1548 |
1451 TEST_CASE(Debug_GetSupertype) { | 1549 TEST_CASE(Debug_GetSupertype) { |
1452 const char* kScriptChars = | 1550 const char* kScriptChars = |
1453 "class Test {\n" | 1551 "class Test {\n" |
1454 "}\n" | 1552 "}\n" |
1455 "class Test1 extends Test {\n" | 1553 "class Test1 extends Test {\n" |
1456 "}\n" | 1554 "}\n" |
1457 "class Test2<T> {\n" | 1555 "class Test2<T> {\n" |
1458 "}\n" | 1556 "}\n" |
1459 "class Test3 extends Test2<int> {\n" | 1557 "class Test3 extends Test2<int> {\n" |
1460 "}\n" | 1558 "}\n" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1587 | 1685 |
1588 Dart_Handle list_type = Dart_InstanceGetType(list_access_test_obj); | 1686 Dart_Handle list_type = Dart_InstanceGetType(list_access_test_obj); |
1589 Dart_Handle super_type = Dart_GetSupertype(list_type); | 1687 Dart_Handle super_type = Dart_GetSupertype(list_type); |
1590 EXPECT(!Dart_IsError(super_type)); | 1688 EXPECT(!Dart_IsError(super_type)); |
1591 super_type = Dart_GetSupertype(super_type); | 1689 super_type = Dart_GetSupertype(super_type); |
1592 EXPECT(!Dart_IsError(super_type)); | 1690 EXPECT(!Dart_IsError(super_type)); |
1593 EXPECT(super_type == Dart_Null()); | 1691 EXPECT(super_type == Dart_Null()); |
1594 } | 1692 } |
1595 | 1693 |
1596 } // namespace dart | 1694 } // namespace dart |
OLD | NEW |