Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4)

Side by Side Diff: src/debug.cc

Issue 115709: Unload debugger when message handler is cleared (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/debug.h ('k') | test/cctest/test-debug.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-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 1571 matching lines...) Expand 10 before | Expand all | Expand 10 after
1582 } 1582 }
1583 1583
1584 1584
1585 Mutex* Debugger::debugger_access_ = OS::CreateMutex(); 1585 Mutex* Debugger::debugger_access_ = OS::CreateMutex();
1586 Handle<Object> Debugger::event_listener_ = Handle<Object>(); 1586 Handle<Object> Debugger::event_listener_ = Handle<Object>();
1587 Handle<Object> Debugger::event_listener_data_ = Handle<Object>(); 1587 Handle<Object> Debugger::event_listener_data_ = Handle<Object>();
1588 bool Debugger::compiling_natives_ = false; 1588 bool Debugger::compiling_natives_ = false;
1589 bool Debugger::is_loading_debugger_ = false; 1589 bool Debugger::is_loading_debugger_ = false;
1590 bool Debugger::never_unload_debugger_ = false; 1590 bool Debugger::never_unload_debugger_ = false;
1591 v8::Debug::MessageHandler2 Debugger::message_handler_ = NULL; 1591 v8::Debug::MessageHandler2 Debugger::message_handler_ = NULL;
1592 bool Debugger::message_handler_cleared_ = false; 1592 bool Debugger::debugger_unload_pending_ = false;
1593 v8::Debug::HostDispatchHandler Debugger::host_dispatch_handler_ = NULL; 1593 v8::Debug::HostDispatchHandler Debugger::host_dispatch_handler_ = NULL;
1594 int Debugger::host_dispatch_micros_ = 100 * 1000; 1594 int Debugger::host_dispatch_micros_ = 100 * 1000;
1595 DebuggerAgent* Debugger::agent_ = NULL; 1595 DebuggerAgent* Debugger::agent_ = NULL;
1596 LockingCommandMessageQueue Debugger::command_queue_(kQueueInitialSize); 1596 LockingCommandMessageQueue Debugger::command_queue_(kQueueInitialSize);
1597 Semaphore* Debugger::command_received_ = OS::CreateSemaphore(0); 1597 Semaphore* Debugger::command_received_ = OS::CreateSemaphore(0);
1598 1598
1599 1599
1600 Handle<Object> Debugger::MakeJSObject(Vector<const char> constructor_name, 1600 Handle<Object> Debugger::MakeJSObject(Vector<const char> constructor_name,
1601 int argc, Object*** argv, 1601 int argc, Object*** argv,
1602 bool* caught_exception) { 1602 bool* caught_exception) {
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
1974 1974
1975 void Debugger::UnloadDebugger() { 1975 void Debugger::UnloadDebugger() {
1976 // Make sure that there are no breakpoints left. 1976 // Make sure that there are no breakpoints left.
1977 Debug::ClearAllBreakPoints(); 1977 Debug::ClearAllBreakPoints();
1978 1978
1979 // Unload the debugger if feasible. 1979 // Unload the debugger if feasible.
1980 if (!never_unload_debugger_) { 1980 if (!never_unload_debugger_) {
1981 Debug::Unload(); 1981 Debug::Unload();
1982 } 1982 }
1983 1983
1984 // Clear the flag indicating that the message handler was recently cleared. 1984 // Clear the flag indicating that the debugger should be unloaded.
1985 message_handler_cleared_ = false; 1985 debugger_unload_pending_ = false;
1986 } 1986 }
1987 1987
1988 1988
1989 void Debugger::NotifyMessageHandler(v8::DebugEvent event, 1989 void Debugger::NotifyMessageHandler(v8::DebugEvent event,
1990 Handle<JSObject> exec_state, 1990 Handle<JSObject> exec_state,
1991 Handle<JSObject> event_data, 1991 Handle<JSObject> event_data,
1992 bool auto_continue) { 1992 bool auto_continue) {
1993 HandleScope scope; 1993 HandleScope scope;
1994 1994
1995 if (!Debug::Load()) return; 1995 if (!Debug::Load()) return;
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
2162 // If there is a new debug event listener register it together with its data 2162 // If there is a new debug event listener register it together with its data
2163 // object. 2163 // object.
2164 if (!callback->IsUndefined() && !callback->IsNull()) { 2164 if (!callback->IsUndefined() && !callback->IsNull()) {
2165 event_listener_ = Handle<Object>::cast(GlobalHandles::Create(*callback)); 2165 event_listener_ = Handle<Object>::cast(GlobalHandles::Create(*callback));
2166 if (data.is_null()) { 2166 if (data.is_null()) {
2167 data = Factory::undefined_value(); 2167 data = Factory::undefined_value();
2168 } 2168 }
2169 event_listener_data_ = Handle<Object>::cast(GlobalHandles::Create(*data)); 2169 event_listener_data_ = Handle<Object>::cast(GlobalHandles::Create(*data));
2170 } 2170 }
2171 2171
2172 // Unload the debugger if event listener cleared. 2172 ListenersChanged();
2173 if (callback->IsUndefined()) {
2174 UnloadDebugger();
2175 }
2176
2177 // Disable the compilation cache when the debugger is active.
2178 if (IsDebuggerActive()) {
2179 CompilationCache::Disable();
2180 } else {
2181 CompilationCache::Enable();
2182 }
2183 } 2173 }
2184 2174
2185 2175
2186 void Debugger::SetMessageHandler(v8::Debug::MessageHandler2 handler) { 2176 void Debugger::SetMessageHandler(v8::Debug::MessageHandler2 handler) {
2187 ScopedLock with(debugger_access_); 2177 ScopedLock with(debugger_access_);
2188 2178
2189 message_handler_ = handler; 2179 message_handler_ = handler;
2180 ListenersChanged();
2190 if (handler == NULL) { 2181 if (handler == NULL) {
2191 // Indicate that the message handler was recently cleared.
2192 message_handler_cleared_ = true;
2193
2194 // Send an empty command to the debugger if in a break to make JavaScript 2182 // Send an empty command to the debugger if in a break to make JavaScript
2195 // run again if the debugger is closed. 2183 // run again if the debugger is closed.
2196 if (Debug::InDebugger()) { 2184 if (Debug::InDebugger()) {
2197 ProcessCommand(Vector<const uint16_t>::empty()); 2185 ProcessCommand(Vector<const uint16_t>::empty());
2198 } 2186 }
2199 } 2187 }
2188 }
2200 2189
2201 // Disable the compilation cache when the debugger is active. 2190
2191 void Debugger::ListenersChanged() {
2202 if (IsDebuggerActive()) { 2192 if (IsDebuggerActive()) {
2193 // Disable the compilation cache when the debugger is active.
2203 CompilationCache::Disable(); 2194 CompilationCache::Disable();
2204 } else { 2195 } else {
2205 CompilationCache::Enable(); 2196 CompilationCache::Enable();
2197
2198 // Unload the debugger if event listener and message handler cleared.
2199 if (Debug::InDebugger()) {
2200 // If we are in debugger set the flag to unload the debugger when last
2201 // EnterDebugger on the current stack is destroyed.
2202 debugger_unload_pending_ = true;
2203 } else {
2204 UnloadDebugger();
2205 }
2206 } 2206 }
2207 } 2207 }
2208 2208
2209 2209
2210 void Debugger::SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler, 2210 void Debugger::SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler,
2211 int period) { 2211 int period) {
2212 host_dispatch_handler_ = handler; 2212 host_dispatch_handler_ = handler;
2213 host_dispatch_micros_ = period * 1000; 2213 host_dispatch_micros_ = period * 1000;
2214 } 2214 }
2215 2215
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
2523 2523
2524 2524
2525 void LockingCommandMessageQueue::Clear() { 2525 void LockingCommandMessageQueue::Clear() {
2526 ScopedLock sl(lock_); 2526 ScopedLock sl(lock_);
2527 queue_.Clear(); 2527 queue_.Clear();
2528 } 2528 }
2529 2529
2530 #endif // ENABLE_DEBUGGER_SUPPORT 2530 #endif // ENABLE_DEBUGGER_SUPPORT
2531 2531
2532 } } // namespace v8::internal 2532 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/debug.h ('k') | test/cctest/test-debug.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698