OLD | NEW |
1 // Copyright 2007-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2008 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 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 return debugged_functions; | 383 return debugged_functions; |
384 } | 384 } |
385 | 385 |
386 | 386 |
387 static Handle<Code> ComputeCallDebugBreak(int argc) { | 387 static Handle<Code> ComputeCallDebugBreak(int argc) { |
388 CALL_HEAP_FUNCTION(v8::internal::StubCache::ComputeCallDebugBreak(argc), | 388 CALL_HEAP_FUNCTION(v8::internal::StubCache::ComputeCallDebugBreak(argc), |
389 Code); | 389 Code); |
390 } | 390 } |
391 | 391 |
392 | 392 |
393 // Check that the debugger is loaded. | |
394 static void CheckDebuggerLoaded() { | |
395 CHECK(Debug::debug_context().is_null()); | |
396 } | |
397 | |
398 | |
399 // Check that the debugger has been fully unloaded. | 393 // Check that the debugger has been fully unloaded. |
400 void CheckDebuggerUnloaded(bool check_functions) { | 394 void CheckDebuggerUnloaded(bool check_functions) { |
401 // Check that the debugger context is cleared and that there is no debug | 395 // Check that the debugger context is cleared and that there is no debug |
402 // information stored for the debugger. | 396 // information stored for the debugger. |
403 CHECK(Debug::debug_context().is_null()); | 397 CHECK(Debug::debug_context().is_null()); |
404 CHECK_EQ(NULL, Debug::debug_info_list_); | 398 CHECK_EQ(NULL, Debug::debug_info_list_); |
405 | 399 |
406 // Collect garbage to ensure weak handles are cleared. | 400 // Collect garbage to ensure weak handles are cleared. |
407 Heap::CollectAllGarbage(); | 401 Heap::CollectAllGarbage(); |
408 Heap::CollectAllGarbage(); | 402 Heap::CollectAllGarbage(); |
(...skipping 21 matching lines...) Expand all Loading... |
430 } | 424 } |
431 } | 425 } |
432 } | 426 } |
433 } | 427 } |
434 } | 428 } |
435 | 429 |
436 | 430 |
437 } } // namespace v8::internal | 431 } } // namespace v8::internal |
438 | 432 |
439 | 433 |
440 // Check that the debugger is loaded. | |
441 static void CheckDebuggerLoaded() { | |
442 v8::internal::CheckDebuggerLoaded(); | |
443 } | |
444 | |
445 | |
446 // Check that the debugger has been fully unloaded. | 434 // Check that the debugger has been fully unloaded. |
447 static void CheckDebuggerUnloaded(bool check_functions = false) { | 435 static void CheckDebuggerUnloaded(bool check_functions = false) { |
448 v8::internal::CheckDebuggerUnloaded(check_functions); | 436 v8::internal::CheckDebuggerUnloaded(check_functions); |
449 } | 437 } |
450 | 438 |
451 | 439 |
452 // Inherit from BreakLocationIterator to get access to protected parts for | 440 // Inherit from BreakLocationIterator to get access to protected parts for |
453 // testing. | 441 // testing. |
454 class TestBreakLocationIterator: public v8::internal::BreakLocationIterator { | 442 class TestBreakLocationIterator: public v8::internal::BreakLocationIterator { |
455 public: | 443 public: |
(...skipping 3277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3733 TEST(DebuggerUnload) { | 3721 TEST(DebuggerUnload) { |
3734 v8::HandleScope scope; | 3722 v8::HandleScope scope; |
3735 DebugLocalContext env; | 3723 DebugLocalContext env; |
3736 | 3724 |
3737 // Check debugger is unloaded before it is used. | 3725 // Check debugger is unloaded before it is used. |
3738 CheckDebuggerUnloaded(); | 3726 CheckDebuggerUnloaded(); |
3739 | 3727 |
3740 // Add debug event listener. | 3728 // Add debug event listener. |
3741 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 3729 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, |
3742 v8::Undefined()); | 3730 v8::Undefined()); |
3743 CheckDebuggerLoaded(); | |
3744 | |
3745 // Create a couple of functions for the test. | 3731 // Create a couple of functions for the test. |
3746 v8::Local<v8::Function> foo = | 3732 v8::Local<v8::Function> foo = |
3747 CompileFunction(&env, "function foo(){x=1}", "foo"); | 3733 CompileFunction(&env, "function foo(){x=1}", "foo"); |
3748 v8::Local<v8::Function> bar = | 3734 v8::Local<v8::Function> bar = |
3749 CompileFunction(&env, "function bar(){y=2}", "bar"); | 3735 CompileFunction(&env, "function bar(){y=2}", "bar"); |
3750 | 3736 |
3751 // Set some break points. | 3737 // Set some break points. |
3752 SetBreakPoint(foo, 0); | 3738 SetBreakPoint(foo, 0); |
3753 SetBreakPoint(foo, 4); | 3739 SetBreakPoint(foo, 4); |
3754 SetBreakPoint(bar, 0); | 3740 SetBreakPoint(bar, 0); |
3755 SetBreakPoint(bar, 4); | 3741 SetBreakPoint(bar, 4); |
3756 | 3742 |
3757 // Make sure that the break points are there. | 3743 // Make sure that the break points are there. |
3758 break_point_hit_count = 0; | 3744 break_point_hit_count = 0; |
3759 foo->Call(env->Global(), 0, NULL); | 3745 foo->Call(env->Global(), 0, NULL); |
3760 CHECK_EQ(2, break_point_hit_count); | 3746 CHECK_EQ(2, break_point_hit_count); |
3761 bar->Call(env->Global(), 0, NULL); | 3747 bar->Call(env->Global(), 0, NULL); |
3762 CHECK_EQ(4, break_point_hit_count); | 3748 CHECK_EQ(4, break_point_hit_count); |
3763 | 3749 |
3764 // Remove the debug event listener without clearing breakpoints. | 3750 // Remove the debug event listener without clearing breakpoints. |
3765 v8::Debug::SetDebugEventListener(NULL); | 3751 v8::Debug::SetDebugEventListener(NULL); |
3766 CheckDebuggerUnloaded(true); | 3752 CheckDebuggerUnloaded(true); |
3767 | 3753 |
3768 // Set a new debug event listener. | 3754 // Set a new debug event listener. |
3769 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, | 3755 v8::Debug::SetDebugEventListener(DebugEventBreakPointHitCount, |
3770 v8::Undefined()); | 3756 v8::Undefined()); |
3771 CheckDebuggerLoaded(); | |
3772 | |
3773 // Check that the break points was actually cleared. | 3757 // Check that the break points was actually cleared. |
3774 break_point_hit_count = 0; | 3758 break_point_hit_count = 0; |
3775 foo->Call(env->Global(), 0, NULL); | 3759 foo->Call(env->Global(), 0, NULL); |
3776 CHECK_EQ(0, break_point_hit_count); | 3760 CHECK_EQ(0, break_point_hit_count); |
3777 | 3761 |
3778 // Set break points and run again. | 3762 // Set break points and run again. |
3779 SetBreakPoint(foo, 0); | 3763 SetBreakPoint(foo, 0); |
3780 SetBreakPoint(foo, 4); | 3764 SetBreakPoint(foo, 4); |
3781 foo->Call(env->Global(), 0, NULL); | 3765 foo->Call(env->Global(), 0, NULL); |
3782 CHECK_EQ(2, break_point_hit_count); | 3766 CHECK_EQ(2, break_point_hit_count); |
3783 | 3767 |
3784 // Remove the debug event listener without clearing breakpoints again. | 3768 // Remove the debug event listener without clearing breakpoints again. |
3785 v8::Debug::SetDebugEventListener(NULL); | 3769 v8::Debug::SetDebugEventListener(NULL); |
3786 CheckDebuggerUnloaded(true); | 3770 CheckDebuggerUnloaded(true); |
3787 } | 3771 } |
3788 | 3772 |
3789 | 3773 |
| 3774 // Debugger message handler which counts the number of times it is called. |
| 3775 static int message_handler_hit_count = 0; |
| 3776 static void MessageHandlerHitCount(const uint16_t* message, |
| 3777 int length, void* data) { |
| 3778 message_handler_hit_count++; |
| 3779 |
| 3780 const int kBufferSize = 1000; |
| 3781 uint16_t buffer[kBufferSize]; |
| 3782 const char* command_continue = |
| 3783 "{\"seq\":0," |
| 3784 "\"type\":\"request\"," |
| 3785 "\"command\":\"continue\"}"; |
| 3786 |
| 3787 v8::Debug::SendCommand(buffer, AsciiToUtf16(command_continue, buffer)); |
| 3788 } |
| 3789 |
| 3790 |
| 3791 // Test clearing the debug message handler. |
| 3792 TEST(DebuggerClearMessageHandler) { |
| 3793 v8::HandleScope scope; |
| 3794 DebugLocalContext env; |
| 3795 |
| 3796 // Check debugger is unloaded before it is used. |
| 3797 CheckDebuggerUnloaded(); |
| 3798 |
| 3799 // Set a debug message handler. |
| 3800 v8::Debug::SetMessageHandler(MessageHandlerHitCount); |
| 3801 |
| 3802 // Run code to throw a unhandled exception. This should end up in the message |
| 3803 // handler. |
| 3804 CompileRun("throw 1"); |
| 3805 |
| 3806 // The message handler should be called. |
| 3807 CHECK_GT(message_handler_hit_count, 0); |
| 3808 |
| 3809 // Clear debug message handler. |
| 3810 message_handler_hit_count = 0; |
| 3811 v8::Debug::SetMessageHandler(NULL); |
| 3812 |
| 3813 // Run code to throw a unhandled exception. This should end up in the message |
| 3814 // handler. |
| 3815 CompileRun("throw 1"); |
| 3816 |
| 3817 // The message handler should not be called more. |
| 3818 CHECK_EQ(0, message_handler_hit_count); |
| 3819 |
| 3820 CheckDebuggerUnloaded(true); |
| 3821 } |
| 3822 |
| 3823 |
| 3824 // Debugger message handler which clears the message handler while active. |
| 3825 static void MessageHandlerClearingMessageHandler(const uint16_t* message, |
| 3826 int length, |
| 3827 void* data) { |
| 3828 message_handler_hit_count++; |
| 3829 |
| 3830 // Clear debug message handler. |
| 3831 v8::Debug::SetMessageHandler(NULL); |
| 3832 } |
| 3833 |
| 3834 |
| 3835 // Test clearing the debug message handler while processing a debug event. |
| 3836 TEST(DebuggerClearMessageHandlerWhileActive) { |
| 3837 v8::HandleScope scope; |
| 3838 DebugLocalContext env; |
| 3839 |
| 3840 // Check debugger is unloaded before it is used. |
| 3841 CheckDebuggerUnloaded(); |
| 3842 |
| 3843 // Set a debug message handler. |
| 3844 v8::Debug::SetMessageHandler(MessageHandlerClearingMessageHandler); |
| 3845 |
| 3846 // Run code to throw a unhandled exception. This should end up in the message |
| 3847 // handler. |
| 3848 CompileRun("throw 1"); |
| 3849 |
| 3850 // The message handler should be called. |
| 3851 CHECK_EQ(1, message_handler_hit_count); |
| 3852 |
| 3853 CheckDebuggerUnloaded(true); |
| 3854 } |
| 3855 |
| 3856 |
3790 int host_dispatch_hit_count = 0; | 3857 int host_dispatch_hit_count = 0; |
3791 static void HostDispatchHandlerHitCount(void* dispatch, void *data) { | 3858 static void HostDispatchHandlerHitCount(void* dispatch, void *data) { |
3792 host_dispatch_hit_count++; | 3859 host_dispatch_hit_count++; |
3793 } | 3860 } |
3794 | 3861 |
3795 | 3862 |
3796 // Test that clearing the debug event listener actually clears all break points | 3863 // Test that clearing the debug event listener actually clears all break points |
3797 // and related information. | 3864 // and related information. |
3798 TEST(DebuggerHostDispatch) { | 3865 TEST(DebuggerHostDispatch) { |
3799 i::FLAG_debugger_auto_break = true; | 3866 i::FLAG_debugger_auto_break = true; |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4011 bool allow_natives_syntax = i::FLAG_allow_natives_syntax; | 4078 bool allow_natives_syntax = i::FLAG_allow_natives_syntax; |
4012 i::FLAG_allow_natives_syntax = true; | 4079 i::FLAG_allow_natives_syntax = true; |
4013 CompileRun( | 4080 CompileRun( |
4014 "var scripts = %DebugGetLoadedScripts();" | 4081 "var scripts = %DebugGetLoadedScripts();" |
4015 "for (var i = 0; i < scripts.length; ++i) {" | 4082 "for (var i = 0; i < scripts.length; ++i) {" |
4016 " scripts[i].line_ends;" | 4083 " scripts[i].line_ends;" |
4017 "}"); | 4084 "}"); |
4018 // Must not crash while accessing line_ends. | 4085 // Must not crash while accessing line_ends. |
4019 i::FLAG_allow_natives_syntax = allow_natives_syntax; | 4086 i::FLAG_allow_natives_syntax = allow_natives_syntax; |
4020 } | 4087 } |
OLD | NEW |