| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. | 11 // with the distribution. |
| (...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 static void DebugEventRemoveBreakPoint(v8::DebugEvent event, | 849 static void DebugEventRemoveBreakPoint(v8::DebugEvent event, |
| 850 v8::Handle<v8::Object> exec_state, | 850 v8::Handle<v8::Object> exec_state, |
| 851 v8::Handle<v8::Object> event_data, | 851 v8::Handle<v8::Object> event_data, |
| 852 v8::Handle<v8::Value> data) { | 852 v8::Handle<v8::Value> data) { |
| 853 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); | 853 v8::internal::Debug* debug = v8::internal::Isolate::Current()->debug(); |
| 854 // When hitting a debug event listener there must be a break set. | 854 // When hitting a debug event listener there must be a break set. |
| 855 CHECK_NE(debug->break_id(), 0); | 855 CHECK_NE(debug->break_id(), 0); |
| 856 | 856 |
| 857 if (event == v8::Break) { | 857 if (event == v8::Break) { |
| 858 break_point_hit_count++; | 858 break_point_hit_count++; |
| 859 v8::Handle<v8::Function> fun(v8::Handle<v8::Function>::Cast(data)); | 859 CHECK(data->IsFunction()); |
| 860 ClearBreakPoint(debug_event_remove_break_point); | 860 ClearBreakPoint(debug_event_remove_break_point); |
| 861 } | 861 } |
| 862 } | 862 } |
| 863 | 863 |
| 864 | 864 |
| 865 // Debug event handler which counts break points hit and performs a step | 865 // Debug event handler which counts break points hit and performs a step |
| 866 // afterwards. | 866 // afterwards. |
| 867 StepAction step_action = StepIn; // Step action to perform when stepping. | 867 StepAction step_action = StepIn; // Step action to perform when stepping. |
| 868 static void DebugEventStep(v8::DebugEvent event, | 868 static void DebugEventStep(v8::DebugEvent event, |
| 869 v8::Handle<v8::Object> exec_state, | 869 v8::Handle<v8::Object> exec_state, |
| (...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1440 break_point_hit_count = 0; | 1440 break_point_hit_count = 0; |
| 1441 v8::HandleScope scope; | 1441 v8::HandleScope scope; |
| 1442 DebugLocalContext env; | 1442 DebugLocalContext env; |
| 1443 | 1443 |
| 1444 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 1444 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, |
| 1445 v8::Undefined()); | 1445 v8::Undefined()); |
| 1446 v8::Local<v8::Function> foo; | 1446 v8::Local<v8::Function> foo; |
| 1447 | 1447 |
| 1448 // Test IC store break point with garbage collection. | 1448 // Test IC store break point with garbage collection. |
| 1449 { | 1449 { |
| 1450 v8::Local<v8::Function> bar( | 1450 CompileFunction(&env, "function foo(){}", "foo"); |
| 1451 CompileFunction(&env, "function foo(){}", "foo")); | |
| 1452 foo = CompileFunction(&env, "function foo(){bar=0;}", "foo"); | 1451 foo = CompileFunction(&env, "function foo(){bar=0;}", "foo"); |
| 1453 SetBreakPoint(foo, 0); | 1452 SetBreakPoint(foo, 0); |
| 1454 } | 1453 } |
| 1455 CallAndGC(env->Global(), foo); | 1454 CallAndGC(env->Global(), foo); |
| 1456 | 1455 |
| 1457 // Test IC load break point with garbage collection. | 1456 // Test IC load break point with garbage collection. |
| 1458 { | 1457 { |
| 1459 v8::Local<v8::Function> bar( | 1458 CompileFunction(&env, "function foo(){}", "foo"); |
| 1460 CompileFunction(&env, "function foo(){}", "foo")); | |
| 1461 foo = CompileFunction(&env, "bar=1;function foo(){var x=bar;}", "foo"); | 1459 foo = CompileFunction(&env, "bar=1;function foo(){var x=bar;}", "foo"); |
| 1462 SetBreakPoint(foo, 0); | 1460 SetBreakPoint(foo, 0); |
| 1463 } | 1461 } |
| 1464 CallAndGC(env->Global(), foo); | 1462 CallAndGC(env->Global(), foo); |
| 1465 | 1463 |
| 1466 // Test IC call break point with garbage collection. | 1464 // Test IC call break point with garbage collection. |
| 1467 { | 1465 { |
| 1468 v8::Local<v8::Function> bar( | 1466 CompileFunction(&env, "function foo(){}", "foo"); |
| 1469 CompileFunction(&env, "function foo(){}", "foo")); | |
| 1470 foo = CompileFunction(&env, | 1467 foo = CompileFunction(&env, |
| 1471 "function bar(){};function foo(){bar();}", | 1468 "function bar(){};function foo(){bar();}", |
| 1472 "foo"); | 1469 "foo"); |
| 1473 SetBreakPoint(foo, 0); | 1470 SetBreakPoint(foo, 0); |
| 1474 } | 1471 } |
| 1475 CallAndGC(env->Global(), foo); | 1472 CallAndGC(env->Global(), foo); |
| 1476 | 1473 |
| 1477 // Test return break point with garbage collection. | 1474 // Test return break point with garbage collection. |
| 1478 { | 1475 { |
| 1479 v8::Local<v8::Function> bar( | 1476 CompileFunction(&env, "function foo(){}", "foo"); |
| 1480 CompileFunction(&env, "function foo(){}", "foo")); | |
| 1481 foo = CompileFunction(&env, "function foo(){}", "foo"); | 1477 foo = CompileFunction(&env, "function foo(){}", "foo"); |
| 1482 SetBreakPoint(foo, 0); | 1478 SetBreakPoint(foo, 0); |
| 1483 } | 1479 } |
| 1484 CallAndGC(env->Global(), foo); | 1480 CallAndGC(env->Global(), foo); |
| 1485 | 1481 |
| 1486 // Test non IC break point with garbage collection. | 1482 // Test non IC break point with garbage collection. |
| 1487 { | 1483 { |
| 1488 v8::Local<v8::Function> bar( | 1484 CompileFunction(&env, "function foo(){}", "foo"); |
| 1489 CompileFunction(&env, "function foo(){}", "foo")); | |
| 1490 foo = CompileFunction(&env, "function foo(){var bar=0;}", "foo"); | 1485 foo = CompileFunction(&env, "function foo(){var bar=0;}", "foo"); |
| 1491 SetBreakPoint(foo, 0); | 1486 SetBreakPoint(foo, 0); |
| 1492 } | 1487 } |
| 1493 CallAndGC(env->Global(), foo); | 1488 CallAndGC(env->Global(), foo); |
| 1494 | 1489 |
| 1495 | 1490 |
| 1496 v8::Debug::SetDebugEventListener(NULL); | 1491 v8::Debug::SetDebugEventListener(NULL); |
| 1497 CheckDebuggerUnloaded(); | 1492 CheckDebuggerUnloaded(); |
| 1498 } | 1493 } |
| 1499 | 1494 |
| (...skipping 2244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3744 // check that uncaught exceptions are still returned even if there is a break | 3739 // check that uncaught exceptions are still returned even if there is a break |
| 3745 // for them. | 3740 // for them. |
| 3746 TEST(BreakOnException) { | 3741 TEST(BreakOnException) { |
| 3747 v8::HandleScope scope; | 3742 v8::HandleScope scope; |
| 3748 DebugLocalContext env; | 3743 DebugLocalContext env; |
| 3749 env.ExposeDebug(); | 3744 env.ExposeDebug(); |
| 3750 | 3745 |
| 3751 v8::internal::Isolate::Current()->TraceException(false); | 3746 v8::internal::Isolate::Current()->TraceException(false); |
| 3752 | 3747 |
| 3753 // Create functions for testing break on exception. | 3748 // Create functions for testing break on exception. |
| 3754 v8::Local<v8::Function> throws( | 3749 CompileFunction(&env, "function throws(){throw 1;}", "throws"); |
| 3755 CompileFunction(&env, "function throws(){throw 1;}", "throws")); | |
| 3756 v8::Local<v8::Function> caught = | 3750 v8::Local<v8::Function> caught = |
| 3757 CompileFunction(&env, | 3751 CompileFunction(&env, |
| 3758 "function caught(){try {throws();} catch(e) {};}", | 3752 "function caught(){try {throws();} catch(e) {};}", |
| 3759 "caught"); | 3753 "caught"); |
| 3760 v8::Local<v8::Function> notCaught = | 3754 v8::Local<v8::Function> notCaught = |
| 3761 CompileFunction(&env, "function notCaught(){throws();}", "notCaught"); | 3755 CompileFunction(&env, "function notCaught(){throws();}", "notCaught"); |
| 3762 | 3756 |
| 3763 v8::V8::AddMessageListener(MessageCallbackCount); | 3757 v8::V8::AddMessageListener(MessageCallbackCount); |
| 3764 v8::Debug::SetDebugEventListener(DebugEventCounter); | 3758 v8::Debug::SetDebugEventListener(DebugEventCounter); |
| 3765 | 3759 |
| (...skipping 1776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5542 | 5536 |
| 5543 // Now set a debug message handler. | 5537 // Now set a debug message handler. |
| 5544 break_point_hit_count = 0; | 5538 break_point_hit_count = 0; |
| 5545 v8::Debug::SetMessageHandler2(MessageHandlerBreakPointHitCount); | 5539 v8::Debug::SetMessageHandler2(MessageHandlerBreakPointHitCount); |
| 5546 { | 5540 { |
| 5547 v8::HandleScope scope; | 5541 v8::HandleScope scope; |
| 5548 | 5542 |
| 5549 // Get the test functions again. | 5543 // Get the test functions again. |
| 5550 v8::Local<v8::Function> foo(v8::Local<v8::Function>::Cast( | 5544 v8::Local<v8::Function> foo(v8::Local<v8::Function>::Cast( |
| 5551 env->Global()->Get(v8::String::New("foo")))); | 5545 env->Global()->Get(v8::String::New("foo")))); |
| 5552 v8::Local<v8::Function> bar(v8::Local<v8::Function>::Cast( | |
| 5553 env->Global()->Get(v8::String::New("foo")))); | |
| 5554 | 5546 |
| 5555 foo->Call(env->Global(), 0, NULL); | 5547 foo->Call(env->Global(), 0, NULL); |
| 5556 CHECK_EQ(0, break_point_hit_count); | 5548 CHECK_EQ(0, break_point_hit_count); |
| 5557 | 5549 |
| 5558 // Set break points and run again. | 5550 // Set break points and run again. |
| 5559 SetBreakPoint(foo, 0); | 5551 SetBreakPoint(foo, 0); |
| 5560 SetBreakPoint(foo, 4); | 5552 SetBreakPoint(foo, 4); |
| 5561 foo->Call(env->Global(), 0, NULL); | 5553 foo->Call(env->Global(), 0, NULL); |
| 5562 CHECK_EQ(2, break_point_hit_count); | 5554 CHECK_EQ(2, break_point_hit_count); |
| 5563 } | 5555 } |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6021 | 6013 |
| 6022 | 6014 |
| 6023 TEST(DebugGetLoadedScripts) { | 6015 TEST(DebugGetLoadedScripts) { |
| 6024 v8::HandleScope scope; | 6016 v8::HandleScope scope; |
| 6025 DebugLocalContext env; | 6017 DebugLocalContext env; |
| 6026 env.ExposeDebug(); | 6018 env.ExposeDebug(); |
| 6027 | 6019 |
| 6028 EmptyExternalStringResource source_ext_str; | 6020 EmptyExternalStringResource source_ext_str; |
| 6029 v8::Local<v8::String> source = v8::String::NewExternal(&source_ext_str); | 6021 v8::Local<v8::String> source = v8::String::NewExternal(&source_ext_str); |
| 6030 v8::Handle<v8::Script> evil_script(v8::Script::Compile(source)); | 6022 v8::Handle<v8::Script> evil_script(v8::Script::Compile(source)); |
| 6023 // "use" evil_script to make the compiler happy. |
| 6024 (void) evil_script; |
| 6031 Handle<i::ExternalTwoByteString> i_source( | 6025 Handle<i::ExternalTwoByteString> i_source( |
| 6032 i::ExternalTwoByteString::cast(*v8::Utils::OpenHandle(*source))); | 6026 i::ExternalTwoByteString::cast(*v8::Utils::OpenHandle(*source))); |
| 6033 // This situation can happen if source was an external string disposed | 6027 // This situation can happen if source was an external string disposed |
| 6034 // by its owner. | 6028 // by its owner. |
| 6035 i_source->set_resource(0); | 6029 i_source->set_resource(0); |
| 6036 | 6030 |
| 6037 bool allow_natives_syntax = i::FLAG_allow_natives_syntax; | 6031 bool allow_natives_syntax = i::FLAG_allow_natives_syntax; |
| 6038 i::FLAG_allow_natives_syntax = true; | 6032 i::FLAG_allow_natives_syntax = true; |
| 6039 CompileRun( | 6033 CompileRun( |
| 6040 "var scripts = %DebugGetLoadedScripts();" | 6034 "var scripts = %DebugGetLoadedScripts();" |
| (...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6668 } | 6662 } |
| 6669 | 6663 |
| 6670 | 6664 |
| 6671 static void BreakMessageHandler(const v8::Debug::Message& message) { | 6665 static void BreakMessageHandler(const v8::Debug::Message& message) { |
| 6672 i::Isolate* isolate = i::Isolate::Current(); | 6666 i::Isolate* isolate = i::Isolate::Current(); |
| 6673 if (message.IsEvent() && message.GetEvent() == v8::Break) { | 6667 if (message.IsEvent() && message.GetEvent() == v8::Break) { |
| 6674 // Count the number of breaks. | 6668 // Count the number of breaks. |
| 6675 break_point_hit_count++; | 6669 break_point_hit_count++; |
| 6676 | 6670 |
| 6677 v8::HandleScope scope; | 6671 v8::HandleScope scope; |
| 6678 v8::Handle<v8::String> json(message.GetJSON()); | 6672 message.GetJSON(); |
| 6679 | 6673 |
| 6680 SendContinueCommand(); | 6674 SendContinueCommand(); |
| 6681 } else if (message.IsEvent() && message.GetEvent() == v8::AfterCompile) { | 6675 } else if (message.IsEvent() && message.GetEvent() == v8::AfterCompile) { |
| 6682 v8::HandleScope scope; | 6676 v8::HandleScope scope; |
| 6683 | 6677 |
| 6684 bool is_debug_break = isolate->stack_guard()->IsDebugBreak(); | 6678 bool is_debug_break = isolate->stack_guard()->IsDebugBreak(); |
| 6685 // Force DebugBreak flag while serializer is working. | 6679 // Force DebugBreak flag while serializer is working. |
| 6686 isolate->stack_guard()->DebugBreak(); | 6680 isolate->stack_guard()->DebugBreak(); |
| 6687 | 6681 |
| 6688 // Force serialization to trigger some internal JS execution. | 6682 // Force serialization to trigger some internal JS execution. |
| 6689 v8::Handle<v8::String> json(message.GetJSON()); | 6683 message.GetJSON(); |
| 6690 | 6684 |
| 6691 // Restore previous state. | 6685 // Restore previous state. |
| 6692 if (is_debug_break) { | 6686 if (is_debug_break) { |
| 6693 isolate->stack_guard()->DebugBreak(); | 6687 isolate->stack_guard()->DebugBreak(); |
| 6694 } else { | 6688 } else { |
| 6695 isolate->stack_guard()->Continue(i::DEBUGBREAK); | 6689 isolate->stack_guard()->Continue(i::DEBUGBREAK); |
| 6696 } | 6690 } |
| 6697 } | 6691 } |
| 6698 } | 6692 } |
| 6699 | 6693 |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7286 TestDebugBreakInLoop("for (;;) {", loop_bodies, "}"); | 7280 TestDebugBreakInLoop("for (;;) {", loop_bodies, "}"); |
| 7287 TestDebugBreakInLoop("for (;a == 1;) {", loop_bodies, "}"); | 7281 TestDebugBreakInLoop("for (;a == 1;) {", loop_bodies, "}"); |
| 7288 | 7282 |
| 7289 // Get rid of the debug event listener. | 7283 // Get rid of the debug event listener. |
| 7290 v8::Debug::SetDebugEventListener(NULL); | 7284 v8::Debug::SetDebugEventListener(NULL); |
| 7291 CheckDebuggerUnloaded(); | 7285 CheckDebuggerUnloaded(); |
| 7292 } | 7286 } |
| 7293 | 7287 |
| 7294 | 7288 |
| 7295 #endif // ENABLE_DEBUGGER_SUPPORT | 7289 #endif // ENABLE_DEBUGGER_SUPPORT |
| OLD | NEW |