| Index: runtime/vm/debugger_api_impl_test.cc
|
| ===================================================================
|
| --- runtime/vm/debugger_api_impl_test.cc (revision 26007)
|
| +++ runtime/vm/debugger_api_impl_test.cc (working copy)
|
| @@ -151,6 +151,28 @@
|
| }
|
|
|
|
|
| +static Dart_Handle GetLocalVariable(Dart_ActivationFrame frame,
|
| + const char* name) {
|
| + Dart_Handle locals = Dart_GetLocalVariables(frame);
|
| + EXPECT_VALID(locals);
|
| + intptr_t list_length = 0;
|
| + Dart_Handle ret = Dart_ListLength(locals, &list_length);
|
| + EXPECT_VALID(ret);
|
| + for (int i = 0; i + 1 < list_length; i += 2) {
|
| + Dart_Handle name_handle = Dart_ListGetAt(locals, i);
|
| + EXPECT_VALID(name_handle);
|
| + EXPECT(Dart_IsString(name_handle));
|
| + if (strcmp(ToCString(name_handle), name) == 0) {
|
| + Dart_Handle value_handle = Dart_ListGetAt(locals, i + 1);
|
| + EXPECT_VALID(value_handle);
|
| + return value_handle;
|
| + }
|
| + }
|
| + EXPECT(!"local variable not found");
|
| + return Dart_Null();
|
| +}
|
| +
|
| +
|
| static void PrintStackTrace(Dart_StackTrace trace) {
|
| intptr_t trace_len;
|
| Dart_Handle res = Dart_StackTraceLength(trace, &trace_len);
|
| @@ -1448,6 +1470,82 @@
|
| }
|
|
|
|
|
| +void TestEvaluateHandler(Dart_IsolateId isolate_id,
|
| + const Dart_CodeLocation& location) {
|
| + Dart_StackTrace trace;
|
| + Dart_GetStackTrace(&trace);
|
| + intptr_t trace_len;
|
| + Dart_Handle res = Dart_StackTraceLength(trace, &trace_len);
|
| + EXPECT_VALID(res);
|
| + EXPECT_EQ(1, trace_len);
|
| + Dart_ActivationFrame frame;
|
| + res = Dart_GetActivationFrame(trace, 0, &frame);
|
| + EXPECT_VALID(res);
|
| +
|
| + // Get the local variable p and evaluate an expression in the
|
| + // context of p.
|
| + Dart_Handle p = GetLocalVariable(frame, "p");
|
| + EXPECT_VALID(p);
|
| + EXPECT(!Dart_IsNull(p));
|
| +
|
| + Dart_Handle r = Dart_EvaluateExpr(p, NewString("sqrt(x*x + y*this.y)"));
|
| + EXPECT_VALID(r);
|
| + EXPECT(Dart_IsNumber(r));
|
| + double d;
|
| + Dart_DoubleValue(r, &d);
|
| + EXPECT_EQ(5.0, d);
|
| +
|
| + breakpoint_hit = true;
|
| + breakpoint_hit_counter++;
|
| +}
|
| +
|
| +
|
| +TEST_CASE(Debug_EvaluateExpr) {
|
| + const char* kScriptChars =
|
| + "import 'dart:math'; \n"
|
| + "main() { \n"
|
| + " var p = new Point(3, 4); \n"
|
| + " l = [1, 2, 3]; /*BP*/ \n"
|
| + " return p; \n"
|
| + "} \n"
|
| + "var _factor = 2; \n"
|
| + "var l; \n"
|
| + "class Point { \n"
|
| + " var x, y; \n"
|
| + " Point(this.x, this.y); \n"
|
| + "} \n";
|
| +
|
| + LoadScript(kScriptChars);
|
| + Dart_SetPausedEventHandler(&TestEvaluateHandler);
|
| +
|
| +
|
| + Dart_Handle script_url = NewString(TestCase::url());
|
| + intptr_t line_no = 4;
|
| + Dart_Handle res = Dart_SetBreakpoint(script_url, line_no);
|
| + EXPECT_VALID(res);
|
| +
|
| + breakpoint_hit = false;
|
| + Dart_Handle point = Invoke("main");
|
| + EXPECT_VALID(point);
|
| + EXPECT(breakpoint_hit == true);
|
| +
|
| + Dart_Handle r =
|
| + Dart_EvaluateExpr(point, NewString("_factor * sqrt(x*x + y*y)"));
|
| + EXPECT_VALID(r);
|
| + EXPECT(Dart_IsNumber(r));
|
| + double d;
|
| + Dart_DoubleValue(r, &d);
|
| + EXPECT_EQ(10.0, d);
|
| +
|
| + Dart_Handle len = Dart_EvaluateExpr(point, NewString("l.length"));
|
| + EXPECT_VALID(len);
|
| + EXPECT(Dart_IsNumber(len));
|
| + int64_t l = 0;
|
| + Dart_IntegerToInt64(len, &l);
|
| + EXPECT_EQ(3, l);
|
| +}
|
| +
|
| +
|
| TEST_CASE(Debug_GetSupertype) {
|
| const char* kScriptChars =
|
| "class Test {\n"
|
|
|