| 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 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 Dart_Handle retval = Invoke(lib, "main"); | 363 Dart_Handle retval = Invoke(lib, "main"); |
| 364 EXPECT(!Dart_IsError(retval)); | 364 EXPECT(!Dart_IsError(retval)); |
| 365 EXPECT(Dart_IsInteger(retval)); | 365 EXPECT(Dart_IsInteger(retval)); |
| 366 int64_t int_value = 0; | 366 int64_t int_value = 0; |
| 367 Dart_IntegerToInt64(retval, &int_value); | 367 Dart_IntegerToInt64(retval, &int_value); |
| 368 EXPECT_EQ(7, int_value); | 368 EXPECT_EQ(7, int_value); |
| 369 EXPECT(breakpoint_hit == true); | 369 EXPECT(breakpoint_hit == true); |
| 370 } | 370 } |
| 371 | 371 |
| 372 | 372 |
| 373 void TestIgnoreBPHandler(Dart_Breakpoint bpt, Dart_StackTrace trace) { | 373 static void StepIntoHandler(Dart_Breakpoint bpt, Dart_StackTrace trace) { |
| 374 if (verbose) { | 374 if (verbose) { |
| 375 OS::Print(">>> Breakpoint nr. %d in %s <<<\n", | 375 OS::Print(">>> Breakpoint nr. %d in %s <<<\n", |
| 376 breakpoint_hit_counter, BreakpointInfo(trace)); | 376 breakpoint_hit_counter, BreakpointInfo(trace)); |
| 377 PrintStackTrace(trace); | 377 PrintStackTrace(trace); |
| 378 } | 378 } |
| 379 breakpoint_hit = true; | 379 breakpoint_hit = true; |
| 380 breakpoint_hit_counter++; | 380 breakpoint_hit_counter++; |
| 381 Dart_SetStepInto(); | 381 Dart_SetStepInto(); |
| 382 } | 382 } |
| 383 | 383 |
| 384 | 384 |
| 385 TEST_CASE(Debug_IgnoreBP) { | 385 TEST_CASE(Debug_IgnoreBP) { |
| 386 const char* kScriptChars = | 386 const char* kScriptChars = |
| 387 "class B { \n" | 387 "class B { \n" |
| 388 " static var z = 0; \n" | 388 " static var z = 0; \n" |
| 389 " var i = 100; \n" | 389 " var i = 100; \n" |
| 390 " var d = 3.14; \n" | 390 " var d = 3.14; \n" |
| 391 " var s = 'Dr Seuss'; \n" | 391 " var s = 'Dr Seuss'; \n" |
| 392 "} \n" | 392 "} \n" |
| 393 " \n" | 393 " \n" |
| 394 "void main() { \n" | 394 "void main() { \n" |
| 395 " var x = new B(); \n" | 395 " var x = new B(); \n" |
| 396 " return x.i + 1; \n" | 396 " return x.i + 1; \n" |
| 397 "} \n"; | 397 "} \n"; |
| 398 | 398 |
| 399 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | 399 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 400 EXPECT(!Dart_IsError(lib)); | 400 EXPECT(!Dart_IsError(lib)); |
| 401 | 401 |
| 402 Dart_SetBreakpointHandler(&TestIgnoreBPHandler); | 402 Dart_SetBreakpointHandler(&StepIntoHandler); |
| 403 | 403 |
| 404 Dart_Handle c_name = Dart_NewString(""); | 404 Dart_Handle c_name = Dart_NewString(""); |
| 405 Dart_Handle f_name = Dart_NewString("main"); | 405 Dart_Handle f_name = Dart_NewString("main"); |
| 406 Dart_Breakpoint bpt; | 406 Dart_Breakpoint bpt; |
| 407 Dart_Handle res = Dart_SetBreakpointAtEntry(lib, c_name, f_name, &bpt); | 407 Dart_Handle res = Dart_SetBreakpointAtEntry(lib, c_name, f_name, &bpt); |
| 408 EXPECT_NOT_ERROR(res); | 408 EXPECT_NOT_ERROR(res); |
| 409 | 409 |
| 410 breakpoint_hit = false; | 410 breakpoint_hit = false; |
| 411 breakpoint_hit_counter = 0; | 411 breakpoint_hit_counter = 0; |
| 412 Dart_Handle retval = Invoke(lib, "main"); | 412 Dart_Handle retval = Invoke(lib, "main"); |
| 413 EXPECT(!Dart_IsError(retval)); | 413 EXPECT(!Dart_IsError(retval)); |
| 414 EXPECT(Dart_IsInteger(retval)); | 414 EXPECT(Dart_IsInteger(retval)); |
| 415 int64_t int_value = 0; | 415 int64_t int_value = 0; |
| 416 Dart_IntegerToInt64(retval, &int_value); | 416 Dart_IntegerToInt64(retval, &int_value); |
| 417 EXPECT_EQ(101, int_value); | 417 EXPECT_EQ(101, int_value); |
| 418 EXPECT(breakpoint_hit == true); | 418 EXPECT(breakpoint_hit == true); |
| 419 } | 419 } |
| 420 | 420 |
| 421 | 421 |
| 422 TEST_CASE(Debug_DeoptimizeFunction) { |
| 423 const char* kScriptChars = |
| 424 "foo(x) => 2 * x; \n" |
| 425 " \n" |
| 426 "warmup() { \n" |
| 427 " for (int i = 0; i < 5000; i++) { \n" |
| 428 " foo(i); \n" |
| 429 " } \n" |
| 430 "} \n" |
| 431 " \n" |
| 432 "void main() { \n" |
| 433 " return foo(99); \n" |
| 434 "} \n"; |
| 435 |
| 436 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 437 EXPECT(!Dart_IsError(lib)); |
| 438 |
| 439 Dart_SetBreakpointHandler(&StepIntoHandler); |
| 440 |
| 441 |
| 442 // Cause function foo to be optimized before we set a BP. |
| 443 Dart_Handle res = Invoke(lib, "warmup"); |
| 444 EXPECT_NOT_ERROR(res); |
| 445 |
| 446 // Now set breakpoint in main and then step into optimized function foo. |
| 447 Dart_Handle c_name = Dart_NewString(""); |
| 448 Dart_Handle f_name = Dart_NewString("main"); |
| 449 Dart_Breakpoint bpt; |
| 450 res = Dart_SetBreakpointAtEntry(lib, c_name, f_name, &bpt); |
| 451 EXPECT_NOT_ERROR(res); |
| 452 |
| 453 breakpoint_hit = false; |
| 454 breakpoint_hit_counter = 0; |
| 455 Dart_Handle retval = Invoke(lib, "main"); |
| 456 EXPECT(!Dart_IsError(retval)); |
| 457 EXPECT(Dart_IsInteger(retval)); |
| 458 int64_t int_value = 0; |
| 459 Dart_IntegerToInt64(retval, &int_value); |
| 460 EXPECT_EQ(2 * 99, int_value); |
| 461 EXPECT(breakpoint_hit == true); |
| 462 } |
| 463 |
| 464 |
| 422 void TestSingleStepHandler(Dart_Breakpoint bpt, Dart_StackTrace trace) { | 465 void TestSingleStepHandler(Dart_Breakpoint bpt, Dart_StackTrace trace) { |
| 423 const char* expected_bpts[] = { | 466 const char* expected_bpts[] = { |
| 424 "moo", "foo", "moo", "foo", "moo", "foo", "main"}; | 467 "moo", "foo", "moo", "foo", "moo", "foo", "main"}; |
| 425 const intptr_t expected_bpts_length = ARRAY_SIZE(expected_bpts); | 468 const intptr_t expected_bpts_length = ARRAY_SIZE(expected_bpts); |
| 426 intptr_t trace_len; | 469 intptr_t trace_len; |
| 427 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); | 470 Dart_Handle res = Dart_StackTraceLength(trace, &trace_len); |
| 428 EXPECT_NOT_ERROR(res); | 471 EXPECT_NOT_ERROR(res); |
| 429 EXPECT(breakpoint_hit_counter < expected_bpts_length); | 472 EXPECT(breakpoint_hit_counter < expected_bpts_length); |
| 430 Dart_ActivationFrame frame; | 473 Dart_ActivationFrame frame; |
| 431 res = Dart_GetActivationFrame(trace, 0, &frame); | 474 res = Dart_GetActivationFrame(trace, 0, &frame); |
| (...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 EXPECT(Dart_IsString(source)); | 843 EXPECT(Dart_IsString(source)); |
| 801 char const* source_chars; | 844 char const* source_chars; |
| 802 Dart_StringToCString(source, &source_chars); | 845 Dart_StringToCString(source, &source_chars); |
| 803 OS::Print("\n=== source: ===\n%s", source_chars); | 846 OS::Print("\n=== source: ===\n%s", source_chars); |
| 804 EXPECT_STREQ(kScriptChars, source_chars); | 847 EXPECT_STREQ(kScriptChars, source_chars); |
| 805 } | 848 } |
| 806 | 849 |
| 807 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 850 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 808 | 851 |
| 809 } // namespace dart | 852 } // namespace dart |
| OLD | NEW |