OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 |
(...skipping 838 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 v8::Handle<v8::Function> fun(v8::Handle<v8::Function>::Cast(data)); |
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 v8::Local<v8::Function> bar( |
1451 CompileFunction(&env, "function foo(){}", "foo"); | 1451 CompileFunction(&env, "function foo(){}", "foo")); |
1452 foo = CompileFunction(&env, "function foo(){bar=0;}", "foo"); | 1452 foo = CompileFunction(&env, "function foo(){bar=0;}", "foo"); |
1453 SetBreakPoint(foo, 0); | 1453 SetBreakPoint(foo, 0); |
1454 } | 1454 } |
1455 CallAndGC(env->Global(), foo); | 1455 CallAndGC(env->Global(), foo); |
1456 | 1456 |
1457 // Test IC load break point with garbage collection. | 1457 // Test IC load break point with garbage collection. |
1458 { | 1458 { |
1459 v8::Local<v8::Function> bar = | 1459 v8::Local<v8::Function> bar( |
1460 CompileFunction(&env, "function foo(){}", "foo"); | 1460 CompileFunction(&env, "function foo(){}", "foo")); |
1461 foo = CompileFunction(&env, "bar=1;function foo(){var x=bar;}", "foo"); | 1461 foo = CompileFunction(&env, "bar=1;function foo(){var x=bar;}", "foo"); |
1462 SetBreakPoint(foo, 0); | 1462 SetBreakPoint(foo, 0); |
1463 } | 1463 } |
1464 CallAndGC(env->Global(), foo); | 1464 CallAndGC(env->Global(), foo); |
1465 | 1465 |
1466 // Test IC call break point with garbage collection. | 1466 // Test IC call break point with garbage collection. |
1467 { | 1467 { |
1468 v8::Local<v8::Function> bar = | 1468 v8::Local<v8::Function> bar( |
1469 CompileFunction(&env, "function foo(){}", "foo"); | 1469 CompileFunction(&env, "function foo(){}", "foo")); |
1470 foo = CompileFunction(&env, | 1470 foo = CompileFunction(&env, |
1471 "function bar(){};function foo(){bar();}", | 1471 "function bar(){};function foo(){bar();}", |
1472 "foo"); | 1472 "foo"); |
1473 SetBreakPoint(foo, 0); | 1473 SetBreakPoint(foo, 0); |
1474 } | 1474 } |
1475 CallAndGC(env->Global(), foo); | 1475 CallAndGC(env->Global(), foo); |
1476 | 1476 |
1477 // Test return break point with garbage collection. | 1477 // Test return break point with garbage collection. |
1478 { | 1478 { |
1479 v8::Local<v8::Function> bar = | 1479 v8::Local<v8::Function> bar( |
1480 CompileFunction(&env, "function foo(){}", "foo"); | 1480 CompileFunction(&env, "function foo(){}", "foo")); |
1481 foo = CompileFunction(&env, "function foo(){}", "foo"); | 1481 foo = CompileFunction(&env, "function foo(){}", "foo"); |
1482 SetBreakPoint(foo, 0); | 1482 SetBreakPoint(foo, 0); |
1483 } | 1483 } |
1484 CallAndGC(env->Global(), foo); | 1484 CallAndGC(env->Global(), foo); |
1485 | 1485 |
1486 // Test non IC break point with garbage collection. | 1486 // Test non IC break point with garbage collection. |
1487 { | 1487 { |
1488 v8::Local<v8::Function> bar = | 1488 v8::Local<v8::Function> bar( |
1489 CompileFunction(&env, "function foo(){}", "foo"); | 1489 CompileFunction(&env, "function foo(){}", "foo")); |
1490 foo = CompileFunction(&env, "function foo(){var bar=0;}", "foo"); | 1490 foo = CompileFunction(&env, "function foo(){var bar=0;}", "foo"); |
1491 SetBreakPoint(foo, 0); | 1491 SetBreakPoint(foo, 0); |
1492 } | 1492 } |
1493 CallAndGC(env->Global(), foo); | 1493 CallAndGC(env->Global(), foo); |
1494 | 1494 |
1495 | 1495 |
1496 v8::Debug::SetDebugEventListener(NULL); | 1496 v8::Debug::SetDebugEventListener(NULL); |
1497 CheckDebuggerUnloaded(); | 1497 CheckDebuggerUnloaded(); |
1498 } | 1498 } |
1499 | 1499 |
(...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 | 3744 // check that uncaught exceptions are still returned even if there is a break |
3745 // for them. | 3745 // for them. |
3746 TEST(BreakOnException) { | 3746 TEST(BreakOnException) { |
3747 v8::HandleScope scope; | 3747 v8::HandleScope scope; |
3748 DebugLocalContext env; | 3748 DebugLocalContext env; |
3749 env.ExposeDebug(); | 3749 env.ExposeDebug(); |
3750 | 3750 |
3751 v8::internal::Isolate::Current()->TraceException(false); | 3751 v8::internal::Isolate::Current()->TraceException(false); |
3752 | 3752 |
3753 // Create functions for testing break on exception. | 3753 // Create functions for testing break on exception. |
3754 v8::Local<v8::Function> throws = | 3754 v8::Local<v8::Function> throws( |
3755 CompileFunction(&env, "function throws(){throw 1;}", "throws"); | 3755 CompileFunction(&env, "function throws(){throw 1;}", "throws")); |
3756 v8::Local<v8::Function> caught = | 3756 v8::Local<v8::Function> caught = |
3757 CompileFunction(&env, | 3757 CompileFunction(&env, |
3758 "function caught(){try {throws();} catch(e) {};}", | 3758 "function caught(){try {throws();} catch(e) {};}", |
3759 "caught"); | 3759 "caught"); |
3760 v8::Local<v8::Function> notCaught = | 3760 v8::Local<v8::Function> notCaught = |
3761 CompileFunction(&env, "function notCaught(){throws();}", "notCaught"); | 3761 CompileFunction(&env, "function notCaught(){throws();}", "notCaught"); |
3762 | 3762 |
3763 v8::V8::AddMessageListener(MessageCallbackCount); | 3763 v8::V8::AddMessageListener(MessageCallbackCount); |
3764 v8::Debug::SetDebugEventListener(DebugEventCounter); | 3764 v8::Debug::SetDebugEventListener(DebugEventCounter); |
3765 | 3765 |
(...skipping 1774 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5540 v8::Debug::SetDebugEventListener(NULL); | 5540 v8::Debug::SetDebugEventListener(NULL); |
5541 CheckDebuggerUnloaded(true); | 5541 CheckDebuggerUnloaded(true); |
5542 | 5542 |
5543 // Now set a debug message handler. | 5543 // Now set a debug message handler. |
5544 break_point_hit_count = 0; | 5544 break_point_hit_count = 0; |
5545 v8::Debug::SetMessageHandler2(MessageHandlerBreakPointHitCount); | 5545 v8::Debug::SetMessageHandler2(MessageHandlerBreakPointHitCount); |
5546 { | 5546 { |
5547 v8::HandleScope scope; | 5547 v8::HandleScope scope; |
5548 | 5548 |
5549 // Get the test functions again. | 5549 // Get the test functions again. |
5550 v8::Local<v8::Function> foo = | 5550 v8::Local<v8::Function> foo(v8::Local<v8::Function>::Cast( |
5551 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); | 5551 env->Global()->Get(v8::String::New("foo")))); |
5552 v8::Local<v8::Function> bar = | 5552 v8::Local<v8::Function> bar(v8::Local<v8::Function>::Cast( |
5553 v8::Local<v8::Function>::Cast(env->Global()->Get(v8::String::New("foo"))); | 5553 env->Global()->Get(v8::String::New("foo")))); |
5554 | 5554 |
5555 foo->Call(env->Global(), 0, NULL); | 5555 foo->Call(env->Global(), 0, NULL); |
5556 CHECK_EQ(0, break_point_hit_count); | 5556 CHECK_EQ(0, break_point_hit_count); |
5557 | 5557 |
5558 // Set break points and run again. | 5558 // Set break points and run again. |
5559 SetBreakPoint(foo, 0); | 5559 SetBreakPoint(foo, 0); |
5560 SetBreakPoint(foo, 4); | 5560 SetBreakPoint(foo, 4); |
5561 foo->Call(env->Global(), 0, NULL); | 5561 foo->Call(env->Global(), 0, NULL); |
5562 CHECK_EQ(2, break_point_hit_count); | 5562 CHECK_EQ(2, break_point_hit_count); |
5563 } | 5563 } |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6020 }; | 6020 }; |
6021 | 6021 |
6022 | 6022 |
6023 TEST(DebugGetLoadedScripts) { | 6023 TEST(DebugGetLoadedScripts) { |
6024 v8::HandleScope scope; | 6024 v8::HandleScope scope; |
6025 DebugLocalContext env; | 6025 DebugLocalContext env; |
6026 env.ExposeDebug(); | 6026 env.ExposeDebug(); |
6027 | 6027 |
6028 EmptyExternalStringResource source_ext_str; | 6028 EmptyExternalStringResource source_ext_str; |
6029 v8::Local<v8::String> source = v8::String::NewExternal(&source_ext_str); | 6029 v8::Local<v8::String> source = v8::String::NewExternal(&source_ext_str); |
6030 v8::Handle<v8::Script> evil_script = v8::Script::Compile(source); | 6030 v8::Handle<v8::Script> evil_script(v8::Script::Compile(source)); |
6031 Handle<i::ExternalTwoByteString> i_source( | 6031 Handle<i::ExternalTwoByteString> i_source( |
6032 i::ExternalTwoByteString::cast(*v8::Utils::OpenHandle(*source))); | 6032 i::ExternalTwoByteString::cast(*v8::Utils::OpenHandle(*source))); |
6033 // This situation can happen if source was an external string disposed | 6033 // This situation can happen if source was an external string disposed |
6034 // by its owner. | 6034 // by its owner. |
6035 i_source->set_resource(0); | 6035 i_source->set_resource(0); |
6036 | 6036 |
6037 bool allow_natives_syntax = i::FLAG_allow_natives_syntax; | 6037 bool allow_natives_syntax = i::FLAG_allow_natives_syntax; |
6038 i::FLAG_allow_natives_syntax = true; | 6038 i::FLAG_allow_natives_syntax = true; |
6039 CompileRun( | 6039 CompileRun( |
6040 "var scripts = %DebugGetLoadedScripts();" | 6040 "var scripts = %DebugGetLoadedScripts();" |
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6668 } | 6668 } |
6669 | 6669 |
6670 | 6670 |
6671 static void BreakMessageHandler(const v8::Debug::Message& message) { | 6671 static void BreakMessageHandler(const v8::Debug::Message& message) { |
6672 i::Isolate* isolate = i::Isolate::Current(); | 6672 i::Isolate* isolate = i::Isolate::Current(); |
6673 if (message.IsEvent() && message.GetEvent() == v8::Break) { | 6673 if (message.IsEvent() && message.GetEvent() == v8::Break) { |
6674 // Count the number of breaks. | 6674 // Count the number of breaks. |
6675 break_point_hit_count++; | 6675 break_point_hit_count++; |
6676 | 6676 |
6677 v8::HandleScope scope; | 6677 v8::HandleScope scope; |
6678 v8::Handle<v8::String> json = message.GetJSON(); | 6678 v8::Handle<v8::String> json(message.GetJSON()); |
6679 | 6679 |
6680 SendContinueCommand(); | 6680 SendContinueCommand(); |
6681 } else if (message.IsEvent() && message.GetEvent() == v8::AfterCompile) { | 6681 } else if (message.IsEvent() && message.GetEvent() == v8::AfterCompile) { |
6682 v8::HandleScope scope; | 6682 v8::HandleScope scope; |
6683 | 6683 |
6684 bool is_debug_break = isolate->stack_guard()->IsDebugBreak(); | 6684 bool is_debug_break = isolate->stack_guard()->IsDebugBreak(); |
6685 // Force DebugBreak flag while serializer is working. | 6685 // Force DebugBreak flag while serializer is working. |
6686 isolate->stack_guard()->DebugBreak(); | 6686 isolate->stack_guard()->DebugBreak(); |
6687 | 6687 |
6688 // Force serialization to trigger some internal JS execution. | 6688 // Force serialization to trigger some internal JS execution. |
6689 v8::Handle<v8::String> json = message.GetJSON(); | 6689 v8::Handle<v8::String> json(message.GetJSON()); |
6690 | 6690 |
6691 // Restore previous state. | 6691 // Restore previous state. |
6692 if (is_debug_break) { | 6692 if (is_debug_break) { |
6693 isolate->stack_guard()->DebugBreak(); | 6693 isolate->stack_guard()->DebugBreak(); |
6694 } else { | 6694 } else { |
6695 isolate->stack_guard()->Continue(i::DEBUGBREAK); | 6695 isolate->stack_guard()->Continue(i::DEBUGBREAK); |
6696 } | 6696 } |
6697 } | 6697 } |
6698 } | 6698 } |
6699 | 6699 |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7286 TestDebugBreakInLoop("for (;;) {", loop_bodies, "}"); | 7286 TestDebugBreakInLoop("for (;;) {", loop_bodies, "}"); |
7287 TestDebugBreakInLoop("for (;a == 1;) {", loop_bodies, "}"); | 7287 TestDebugBreakInLoop("for (;a == 1;) {", loop_bodies, "}"); |
7288 | 7288 |
7289 // Get rid of the debug event listener. | 7289 // Get rid of the debug event listener. |
7290 v8::Debug::SetDebugEventListener(NULL); | 7290 v8::Debug::SetDebugEventListener(NULL); |
7291 CheckDebuggerUnloaded(); | 7291 CheckDebuggerUnloaded(); |
7292 } | 7292 } |
7293 | 7293 |
7294 | 7294 |
7295 #endif // ENABLE_DEBUGGER_SUPPORT | 7295 #endif // ENABLE_DEBUGGER_SUPPORT |
OLD | NEW |