| 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/unit_test.h" | 8 #include "vm/unit_test.h" |
| 9 | 9 |
| 10 namespace dart { | 10 namespace dart { |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 | 299 |
| 300 Dart_Handle c_name = Dart_NewString(""); | 300 Dart_Handle c_name = Dart_NewString(""); |
| 301 Dart_Handle f_name = Dart_NewString("moo"); | 301 Dart_Handle f_name = Dart_NewString("moo"); |
| 302 Dart_Breakpoint bpt; | 302 Dart_Breakpoint bpt; |
| 303 Dart_Handle res = Dart_SetBreakpointAtEntry(lib, c_name, f_name, &bpt); | 303 Dart_Handle res = Dart_SetBreakpointAtEntry(lib, c_name, f_name, &bpt); |
| 304 EXPECT_NOT_ERROR(res); | 304 EXPECT_NOT_ERROR(res); |
| 305 | 305 |
| 306 breakpoint_hit = false; | 306 breakpoint_hit = false; |
| 307 breakpoint_hit_counter = 0; | 307 breakpoint_hit_counter = 0; |
| 308 Dart_Handle retval = Invoke(lib, "main"); | 308 Dart_Handle retval = Invoke(lib, "main"); |
| 309 EXPECT(!Dart_IsError(retval)); | 309 EXPECT_NOT_ERROR(retval); |
| 310 EXPECT(breakpoint_hit == true); | 310 EXPECT(breakpoint_hit == true); |
| 311 } | 311 } |
| 312 | 312 |
| 313 | 313 |
| 314 static void ClosureBreakpointHandler(Dart_Breakpoint bpt, |
| 315 Dart_StackTrace trace) { |
| 316 const char* expected_trace[] = {"callback", "main"}; |
| 317 const intptr_t expected_trace_length = 2; |
| 318 breakpoint_hit_counter++; |
| 319 intptr_t trace_len; |
| 320 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); |
| 321 EXPECT_NOT_ERROR(res); |
| 322 EXPECT_EQ(expected_trace_length, trace_len); |
| 323 for (int i = 0; i < trace_len; i++) { |
| 324 Dart_ActivationFrame frame; |
| 325 res = Dart_GetActivationFrame(trace, i, &frame); |
| 326 EXPECT_NOT_ERROR(res); |
| 327 Dart_Handle func_name; |
| 328 res = Dart_ActivationFrameInfo(frame, &func_name, NULL, NULL); |
| 329 EXPECT_NOT_ERROR(res); |
| 330 EXPECT(Dart_IsString(func_name)); |
| 331 const char* name_chars; |
| 332 Dart_StringToCString(func_name, &name_chars); |
| 333 EXPECT_STREQ(expected_trace[i], name_chars); |
| 334 if (verbose) printf(" >> %d: %s\n", i, name_chars); |
| 335 } |
| 336 } |
| 337 |
| 338 |
| 339 TEST_CASE(Debug_ClosureBreakpoint) { |
| 340 const char* kScriptChars = |
| 341 "callback(s) { \n" |
| 342 " return 111; \n" |
| 343 "} \n" |
| 344 " \n" |
| 345 "main() { \n" |
| 346 " var h = callback; \n" |
| 347 " h('bla'); \n" |
| 348 " callback('jada'); \n" |
| 349 " return 442; \n" |
| 350 "} \n"; |
| 351 |
| 352 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 353 EXPECT(!Dart_IsError(lib)); |
| 354 |
| 355 Dart_SetBreakpointHandler(&ClosureBreakpointHandler); |
| 356 |
| 357 Dart_Handle c_name = Dart_NewString(""); |
| 358 Dart_Handle f_name = Dart_NewString("callback"); |
| 359 Dart_Breakpoint bpt; |
| 360 Dart_Handle res = Dart_SetBreakpointAtEntry(lib, c_name, f_name, &bpt); |
| 361 EXPECT_NOT_ERROR(res); |
| 362 |
| 363 breakpoint_hit_counter = 0; |
| 364 Dart_Handle retval = Invoke(lib, "main"); |
| 365 EXPECT_NOT_ERROR(retval); |
| 366 int64_t int_value = 0; |
| 367 Dart_IntegerToInt64(retval, &int_value); |
| 368 EXPECT_EQ(442, int_value); |
| 369 EXPECT_EQ(2, breakpoint_hit_counter); |
| 370 } |
| 371 |
| 314 | 372 |
| 315 static void DeleteBreakpointHandler(Dart_Breakpoint bpt, | 373 static void DeleteBreakpointHandler(Dart_Breakpoint bpt, |
| 316 Dart_StackTrace trace) { | 374 Dart_StackTrace trace) { |
| 317 const char* expected_trace[] = {"foo", "main"}; | 375 const char* expected_trace[] = {"foo", "main"}; |
| 318 const intptr_t expected_trace_length = 2; | 376 const intptr_t expected_trace_length = 2; |
| 319 breakpoint_hit_counter++; | 377 breakpoint_hit_counter++; |
| 320 intptr_t trace_len; | 378 intptr_t trace_len; |
| 321 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); | 379 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); |
| 322 EXPECT_NOT_ERROR(res); | 380 EXPECT_NOT_ERROR(res); |
| 323 EXPECT_EQ(expected_trace_length, trace_len); | 381 EXPECT_EQ(expected_trace_length, trace_len); |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 EXPECT(Dart_IsString(source)); | 630 EXPECT(Dart_IsString(source)); |
| 573 char const* source_chars; | 631 char const* source_chars; |
| 574 Dart_StringToCString(source, &source_chars); | 632 Dart_StringToCString(source, &source_chars); |
| 575 printf("\n=== source: ===\n%s", source_chars); | 633 printf("\n=== source: ===\n%s", source_chars); |
| 576 EXPECT_STREQ(kScriptChars, source_chars); | 634 EXPECT_STREQ(kScriptChars, source_chars); |
| 577 } | 635 } |
| 578 | 636 |
| 579 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 637 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 580 | 638 |
| 581 } // namespace dart | 639 } // namespace dart |
| OLD | NEW |