| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 #include "include/dart_debugger_api.h" |
| 6 |
| 7 #include "vm/assert.h" |
| 8 #include "vm/unit_test.h" |
| 9 |
| 10 namespace dart { |
| 11 |
| 12 #if defined(TARGET_ARCH_IA32) // Only ia32 can run execution tests. |
| 13 |
| 14 |
| 15 static bool breakpoint_hit = false; |
| 16 |
| 17 static const bool verbose = false; |
| 18 |
| 19 #define EXPECT_NOT_ERROR(handle) \ |
| 20 if (Dart_IsError(handle)) { \ |
| 21 OS::Print("Error: %s\n", Dart_GetError(handle)); \ |
| 22 } \ |
| 23 EXPECT(!Dart_IsError(handle)); |
| 24 |
| 25 |
| 26 void TestBreakpointHandler(Dart_Breakpoint bpt, Dart_StackTrace trace) { |
| 27 const char* expected_trace[] = {"A.foo", "main"}; |
| 28 const intptr_t expected_trace_length = 2; |
| 29 breakpoint_hit = true; |
| 30 intptr_t trace_len; |
| 31 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); |
| 32 EXPECT_NOT_ERROR(res); |
| 33 EXPECT_EQ(expected_trace_length, trace_len); |
| 34 for (int i = 0; i < trace_len; i++) { |
| 35 Dart_ActivationFrame frame; |
| 36 res = Dart_GetActivationFrame(trace, i, &frame); |
| 37 EXPECT_NOT_ERROR(res); |
| 38 Dart_Handle func_name; |
| 39 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL); |
| 40 EXPECT_NOT_ERROR(res); |
| 41 EXPECT(Dart_IsString(func_name)); |
| 42 const char* name_chars; |
| 43 Dart_StringToCString(func_name, &name_chars); |
| 44 EXPECT_STREQ(expected_trace[i], name_chars); |
| 45 if (verbose) printf(" >> %d: %s\n", i, name_chars); |
| 46 } |
| 47 } |
| 48 |
| 49 |
| 50 UNIT_TEST_CASE(Breakpoint) { |
| 51 const char* kScriptChars = |
| 52 "void moo(s) { }\n" |
| 53 "class A {\n" |
| 54 " static void foo() {\n" |
| 55 " moo('good news');\n" |
| 56 " }\n" |
| 57 "}\n" |
| 58 "void main() {\n" |
| 59 " A.foo();\n" |
| 60 "}\n"; |
| 61 |
| 62 TestIsolateScope __test_isolate__; |
| 63 |
| 64 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 65 EXPECT(!Dart_IsError(lib)); |
| 66 |
| 67 Dart_SetBreakpointHandler(&TestBreakpointHandler); |
| 68 |
| 69 Dart_Handle c_name = Dart_NewString("A"); |
| 70 Dart_Handle f_name = Dart_NewString("foo"); |
| 71 Dart_Breakpoint bpt; |
| 72 Dart_Handle res = Dart_SetBreakpointAtEntry(lib, c_name, f_name, &bpt); |
| 73 EXPECT_NOT_ERROR(res); |
| 74 |
| 75 breakpoint_hit = false; |
| 76 Dart_Handle retval = Dart_InvokeStatic(lib, |
| 77 Dart_NewString(""), |
| 78 Dart_NewString("main"), |
| 79 0, |
| 80 NULL); |
| 81 EXPECT(!Dart_IsError(retval)); |
| 82 EXPECT(breakpoint_hit == true); |
| 83 } |
| 84 |
| 85 #endif // TARGET_ARCH_IA32. |
| 86 |
| 87 } // namespace dart |
| OLD | NEW |