Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 "vm/dart_api_impl.h" | 5 #include "vm/dart_api_impl.h" |
| 6 #include "vm/dart_api_message.h" | 6 #include "vm/dart_api_message.h" |
| 7 #include "vm/debugger.h" | 7 #include "vm/debugger.h" |
| 8 #include "vm/message.h" | 8 #include "vm/message.h" |
| 9 #include "vm/unit_test.h" | 9 #include "vm/unit_test.h" |
| 10 | 10 |
| 11 namespace dart { | 11 namespace dart { |
| 12 | 12 |
| 13 #ifndef PRODUCT | 13 #ifndef PRODUCT |
| 14 | 14 |
| 15 DECLARE_FLAG(bool, background_compilation); | |
| 16 DECLARE_FLAG(bool, enable_inlining_annotations); | |
| 17 DECLARE_FLAG(bool, prune_dead_locals); | |
| 15 DECLARE_FLAG(bool, remove_script_timestamps_for_test); | 18 DECLARE_FLAG(bool, remove_script_timestamps_for_test); |
| 16 DECLARE_FLAG(bool, trace_rewind); | 19 DECLARE_FLAG(bool, trace_rewind); |
| 20 DECLARE_FLAG(int, optimization_counter_threshold); | |
| 17 | 21 |
| 18 // Search for the formatted string in buffer. | 22 // Search for the formatted string in buffer. |
| 19 // | 23 // |
| 20 // TODO(turnidge): This function obscures the line number of failing | 24 // TODO(turnidge): This function obscures the line number of failing |
| 21 // EXPECTs. Rework this. | 25 // EXPECTs. Rework this. |
| 22 static void ExpectSubstringF(const char* buff, const char* fmt, ...) { | 26 static void ExpectSubstringF(const char* buff, const char* fmt, ...) { |
| 23 va_list args; | 27 va_list args; |
| 24 va_start(args, fmt); | 28 va_start(args, fmt); |
| 25 intptr_t len = OS::VSNPrint(NULL, 0, fmt, args); | 29 intptr_t len = OS::VSNPrint(NULL, 0, fmt, args); |
| 26 va_end(args); | 30 va_end(args); |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 EXPECT(Dart_IsString(result)); | 300 EXPECT(Dart_IsString(result)); |
| 297 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); | 301 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); |
| 298 EXPECT_STREQ("enter(main) enter(foo) enter(foo) exit(foo) exit(main) ", | 302 EXPECT_STREQ("enter(main) enter(foo) enter(foo) exit(foo) exit(main) ", |
| 299 result_cstr); | 303 result_cstr); |
| 300 EXPECT(saw_paused_event); | 304 EXPECT(saw_paused_event); |
| 301 } | 305 } |
| 302 | 306 |
| 303 | 307 |
| 304 TEST_CASE(Debugger_RewindTwoFrames_Unoptimized) { | 308 TEST_CASE(Debugger_RewindTwoFrames_Unoptimized) { |
| 305 SetFlagScope<bool> sfs(&FLAG_trace_rewind, true); | 309 SetFlagScope<bool> sfs(&FLAG_trace_rewind, true); |
| 306 saw_paused_event = false; | 310 saw_paused_event = false; |
|
Cutch
2017/01/31 21:42:43
A comment that you're modifying global state that
turnidge
2017/01/31 21:50:49
Done.
| |
| 307 rewind_frame_index = "2"; | 311 rewind_frame_index = "2"; |
| 308 | 312 |
| 309 const char* kScriptChars = | 313 const char* kScriptChars = |
| 310 "import 'dart:developer';\n" | 314 "import 'dart:developer';\n" |
| 311 "\n" | 315 "\n" |
| 312 "var msg = new StringBuffer();\n" | 316 "var msg = new StringBuffer();\n" |
| 313 "\n" | 317 "\n" |
| 314 "foo() {\n" | 318 "foo() {\n" |
| 315 " msg.write('enter(foo) ');\n" | 319 " msg.write('enter(foo) ');\n" |
| 316 " debugger();\n" | 320 " debugger();\n" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 338 EXPECT_VALID(result); | 342 EXPECT_VALID(result); |
| 339 EXPECT(Dart_IsString(result)); | 343 EXPECT(Dart_IsString(result)); |
| 340 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); | 344 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); |
| 341 EXPECT_STREQ( | 345 EXPECT_STREQ( |
| 342 "enter(main) enter(bar) enter(foo) enter(bar) enter(foo) " | 346 "enter(main) enter(bar) enter(foo) enter(bar) enter(foo) " |
| 343 "exit(foo) exit(bar) exit(main) ", | 347 "exit(foo) exit(bar) exit(main) ", |
| 344 result_cstr); | 348 result_cstr); |
| 345 EXPECT(saw_paused_event); | 349 EXPECT(saw_paused_event); |
| 346 } | 350 } |
| 347 | 351 |
| 352 | |
| 353 TEST_CASE(Debugger_Rewind_Optimized) { | |
| 354 SetFlagScope<bool> sfs1(&FLAG_trace_rewind, true); | |
| 355 SetFlagScope<bool> sfs2(&FLAG_prune_dead_locals, false); | |
| 356 SetFlagScope<bool> sfs3(&FLAG_enable_inlining_annotations, true); | |
| 357 SetFlagScope<bool> sfs4(&FLAG_background_compilation, false); | |
| 358 SetFlagScope<int> sfs5(&FLAG_optimization_counter_threshold, 10); | |
| 359 | |
| 360 saw_paused_event = false; | |
| 361 rewind_frame_index = "2"; | |
|
Cutch
2017/01/31 21:42:43
same for rewind_frame_index.
turnidge
2017/01/31 21:50:49
Done.
| |
| 362 | |
| 363 const char* kScriptChars = | |
| 364 "import 'dart:developer';\n" | |
| 365 "\n" | |
| 366 "const alwaysInline = \"AlwaysInline\";\n" | |
| 367 "const noInline = \"NeverInline\";\n" | |
| 368 "\n" | |
| 369 "var msg = new StringBuffer();\n" | |
| 370 "int i;\n" | |
| 371 "\n" | |
| 372 "@noInline\n" | |
| 373 "foo() {\n" | |
| 374 " msg.write('enter(foo) ');\n" | |
| 375 " if (i > 15) {\n" | |
| 376 " debugger();\n" | |
| 377 " msg.write('exit(foo) ');\n" | |
| 378 " return true;\n" | |
| 379 " } else {\n" | |
| 380 " msg.write('exit(foo) ');\n" | |
| 381 " return false;\n" | |
| 382 " }\n" | |
| 383 "}\n" | |
| 384 "\n" | |
| 385 "@alwaysInline\n" | |
| 386 "bar3() {\n" | |
| 387 " msg.write('enter(bar3) ');\n" | |
| 388 " var result = foo();\n" | |
| 389 " msg.write('exit(bar3) ');\n" | |
| 390 " return result;\n" | |
| 391 "}\n" | |
| 392 "\n" | |
| 393 "@alwaysInline\n" | |
| 394 "bar2() {\n" | |
| 395 " msg.write('enter(bar2) ');\n" | |
| 396 " var result = bar3();\n" | |
| 397 " msg.write('exit(bar2) ');\n" | |
| 398 " return result;\n" | |
| 399 "}\n" | |
| 400 "\n" | |
| 401 "@alwaysInline\n" | |
| 402 "bar1() {\n" | |
| 403 " msg.write('enter(bar1) ');\n" | |
| 404 " var result = bar2();\n" | |
| 405 " msg.write('exit(bar1) ');\n" | |
| 406 " return result;\n" | |
| 407 "}\n" | |
| 408 "\n" | |
| 409 "main() {\n" | |
| 410 " for (i = 0; i < 20; i++) {\n" | |
| 411 " msg.clear();\n" | |
| 412 " if (bar1()) break;\n;" | |
| 413 " }\n" | |
| 414 " return msg.toString();\n" | |
| 415 "}\n"; | |
| 416 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); | |
| 417 EXPECT_VALID(lib); | |
| 418 | |
| 419 Dart_SetPausedEventHandler(RewindOnce); | |
| 420 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); | |
| 421 const char* result_cstr; | |
| 422 EXPECT_VALID(result); | |
| 423 EXPECT(Dart_IsString(result)); | |
| 424 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); | |
| 425 EXPECT_STREQ( | |
| 426 "enter(bar1) enter(bar2) enter(bar3) enter(foo) " | |
| 427 "enter(bar3) enter(foo) " | |
| 428 "exit(foo) exit(bar3) exit(bar2) exit(bar1) ", | |
| 429 result_cstr); | |
| 430 EXPECT(saw_paused_event); | |
| 431 } | |
| 432 | |
| 348 #endif // !PRODUCT | 433 #endif // !PRODUCT |
| 349 | 434 |
| 350 } // namespace dart | 435 } // namespace dart |
| OLD | NEW |