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/inspector/v8-debugger.cc

Issue 2668763003: [inspector] V8DebuggerAgent cleanup (Closed)
Patch Set: Created 3 years, 10 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
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/inspector/v8-debugger.h" 5 #include "src/inspector/v8-debugger.h"
6 6
7 #include "src/inspector/debugger-script.h" 7 #include "src/inspector/debugger-script.h"
8 #include "src/inspector/inspected-context.h" 8 #include "src/inspector/inspected-context.h"
9 #include "src/inspector/protocol/Protocol.h" 9 #include "src/inspector/protocol/Protocol.h"
10 #include "src/inspector/script-breakpoint.h" 10 #include "src/inspector/script-breakpoint.h"
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 if (--m_enableCount) return; 97 if (--m_enableCount) return;
98 DCHECK(enabled()); 98 DCHECK(enabled());
99 clearBreakpoints(); 99 clearBreakpoints();
100 m_debuggerScript.Reset(); 100 m_debuggerScript.Reset();
101 m_debuggerContext.Reset(); 101 m_debuggerContext.Reset();
102 allAsyncTasksCanceled(); 102 allAsyncTasksCanceled();
103 m_wasmTranslation.Clear(); 103 m_wasmTranslation.Clear();
104 v8::debug::SetDebugDelegate(m_isolate, nullptr); 104 v8::debug::SetDebugDelegate(m_isolate, nullptr);
105 v8::debug::SetOutOfMemoryCallback(m_isolate, nullptr, nullptr); 105 v8::debug::SetOutOfMemoryCallback(m_isolate, nullptr, nullptr);
106 m_isolate->RestoreOriginalHeapLimit(); 106 m_isolate->RestoreOriginalHeapLimit();
107 m_skipAllPauses = false;
107 } 108 }
108 109
109 bool V8Debugger::enabled() const { return !m_debuggerScript.IsEmpty(); } 110 bool V8Debugger::enabled() const { return !m_debuggerScript.IsEmpty(); }
110 111
111 void V8Debugger::getCompiledScripts( 112 void V8Debugger::getCompiledScripts(
112 int contextGroupId, 113 int contextGroupId,
113 std::vector<std::unique_ptr<V8DebuggerScript>>& result) { 114 std::vector<std::unique_ptr<V8DebuggerScript>>& result) {
114 v8::HandleScope scope(m_isolate); 115 v8::HandleScope scope(m_isolate);
115 v8::PersistentValueVector<v8::debug::Script> scripts(m_isolate); 116 v8::PersistentValueVector<v8::debug::Script> scripts(m_isolate);
116 v8::debug::GetLoadedScripts(m_isolate, scripts); 117 v8::debug::GetLoadedScripts(m_isolate, scripts);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 void V8Debugger::setPauseOnExceptionsState( 245 void V8Debugger::setPauseOnExceptionsState(
245 v8::debug::ExceptionBreakState pauseOnExceptionsState) { 246 v8::debug::ExceptionBreakState pauseOnExceptionsState) {
246 DCHECK(enabled()); 247 DCHECK(enabled());
247 if (m_pauseOnExceptionsState == pauseOnExceptionsState) return; 248 if (m_pauseOnExceptionsState == pauseOnExceptionsState) return;
248 v8::debug::ChangeBreakOnException(m_isolate, pauseOnExceptionsState); 249 v8::debug::ChangeBreakOnException(m_isolate, pauseOnExceptionsState);
249 m_pauseOnExceptionsState = pauseOnExceptionsState; 250 m_pauseOnExceptionsState = pauseOnExceptionsState;
250 } 251 }
251 252
252 void V8Debugger::setPauseOnNextStatement(bool pause) { 253 void V8Debugger::setPauseOnNextStatement(bool pause) {
253 if (m_runningNestedMessageLoop) return; 254 if (m_runningNestedMessageLoop) return;
255 if (m_skipAllPauses) return;
254 if (pause) 256 if (pause)
255 v8::debug::DebugBreak(m_isolate); 257 v8::debug::DebugBreak(m_isolate);
256 else 258 else
257 v8::debug::CancelDebugBreak(m_isolate); 259 v8::debug::CancelDebugBreak(m_isolate);
258 } 260 }
259 261
260 bool V8Debugger::canBreakProgram() { 262 bool V8Debugger::canBreakProgram() {
261 if (!m_breakpointsActivated) return false; 263 if (!m_breakpointsActivated) return false;
262 return v8::debug::HasNonBlackboxedFrameOnStack(m_isolate); 264 return v8::debug::HasNonBlackboxedFrameOnStack(m_isolate);
263 } 265 }
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 hitBreakpoints); 467 hitBreakpoints);
466 } 468 }
467 469
468 void V8Debugger::handleProgramBreak(v8::Local<v8::Context> pausedContext, 470 void V8Debugger::handleProgramBreak(v8::Local<v8::Context> pausedContext,
469 v8::Local<v8::Object> executionState, 471 v8::Local<v8::Object> executionState,
470 v8::Local<v8::Value> exception, 472 v8::Local<v8::Value> exception,
471 v8::Local<v8::Array> hitBreakpointNumbers, 473 v8::Local<v8::Array> hitBreakpointNumbers,
472 bool isPromiseRejection, bool isUncaught) { 474 bool isPromiseRejection, bool isUncaught) {
473 // Don't allow nested breaks. 475 // Don't allow nested breaks.
474 if (m_runningNestedMessageLoop) return; 476 if (m_runningNestedMessageLoop) return;
477 if (m_skipAllPauses && !m_scheduledOOMBreak) return;
475 478
476 V8DebuggerAgentImpl* agent = m_inspector->enabledDebuggerAgentForGroup( 479 V8DebuggerAgentImpl* agent = m_inspector->enabledDebuggerAgentForGroup(
477 m_inspector->contextGroupId(pausedContext)); 480 m_inspector->contextGroupId(pausedContext));
478 if (!agent) return; 481 if (!agent) return;
479 482
480 std::vector<String16> breakpointIds; 483 std::vector<String16> breakpointIds;
481 if (!hitBreakpointNumbers.IsEmpty()) { 484 if (!hitBreakpointNumbers.IsEmpty()) {
482 breakpointIds.reserve(hitBreakpointNumbers->Length()); 485 breakpointIds.reserve(hitBreakpointNumbers->Length());
483 for (uint32_t i = 0; i < hitBreakpointNumbers->Length(); i++) { 486 for (uint32_t i = 0; i < hitBreakpointNumbers->Length(); i++) {
484 v8::Local<v8::Value> hitBreakpointNumber = 487 v8::Local<v8::Value> hitBreakpointNumber =
485 hitBreakpointNumbers->Get(debuggerContext(), i).ToLocalChecked(); 488 hitBreakpointNumbers->Get(debuggerContext(), i).ToLocalChecked();
486 DCHECK(hitBreakpointNumber->IsInt32()); 489 DCHECK(hitBreakpointNumber->IsInt32());
487 breakpointIds.push_back(String16::fromInteger( 490 breakpointIds.push_back(String16::fromInteger(
488 hitBreakpointNumber->Int32Value(debuggerContext()).FromJust())); 491 hitBreakpointNumber->Int32Value(debuggerContext()).FromJust()));
489 } 492 }
490 } 493 }
491 494
492 m_pausedContext = pausedContext; 495 m_pausedContext = pausedContext;
493 m_executionState = executionState; 496 m_executionState = executionState;
494 bool shouldPause = 497 agent->didPause(InspectedContext::contextId(pausedContext), exception,
495 agent->didPause(pausedContext, exception, breakpointIds, 498 breakpointIds, isPromiseRejection, isUncaught,
496 isPromiseRejection, isUncaught, m_scheduledOOMBreak); 499 m_scheduledOOMBreak);
497 if (shouldPause) { 500 m_runningNestedMessageLoop = true;
498 m_runningNestedMessageLoop = true; 501 {
499 int groupId = m_inspector->contextGroupId(pausedContext);
500 DCHECK(groupId);
501 v8::Context::Scope scope(pausedContext); 502 v8::Context::Scope scope(pausedContext);
502 v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); 503 v8::Local<v8::Context> context = m_isolate->GetCurrentContext();
503 CHECK(!context.IsEmpty() && 504 CHECK(!context.IsEmpty() &&
504 context != v8::debug::GetDebugContext(m_isolate)); 505 context != v8::debug::GetDebugContext(m_isolate));
506 int groupId = m_inspector->contextGroupId(pausedContext);
507 DCHECK(groupId);
505 m_inspector->client()->runMessageLoopOnPause(groupId); 508 m_inspector->client()->runMessageLoopOnPause(groupId);
506 // The agent may have been removed in the nested loop.
507 agent = m_inspector->enabledDebuggerAgentForGroup(
508 m_inspector->contextGroupId(pausedContext));
509 if (agent) agent->didContinue();
510 m_runningNestedMessageLoop = false;
511 } 509 }
510 m_runningNestedMessageLoop = false;
511 // The agent may have been removed in the nested loop.
512 agent = m_inspector->enabledDebuggerAgentForGroup(
513 m_inspector->contextGroupId(pausedContext));
514 if (agent) agent->didContinue();
512 if (m_scheduledOOMBreak) m_isolate->RestoreOriginalHeapLimit(); 515 if (m_scheduledOOMBreak) m_isolate->RestoreOriginalHeapLimit();
513 m_scheduledOOMBreak = false; 516 m_scheduledOOMBreak = false;
514 m_pausedContext.Clear(); 517 m_pausedContext.Clear();
515 m_executionState.Clear(); 518 m_executionState.Clear();
516 } 519 }
517 520
518 void V8Debugger::v8OOMCallback(void* data) { 521 void V8Debugger::v8OOMCallback(void* data) {
519 V8Debugger* thisPtr = static_cast<V8Debugger*>(data); 522 V8Debugger* thisPtr = static_cast<V8Debugger*>(data);
520 thisPtr->m_isolate->IncreaseHeapLimitForDebugging(); 523 thisPtr->m_isolate->IncreaseHeapLimitForDebugging();
521 thisPtr->m_scheduledOOMBreak = true; 524 thisPtr->m_scheduledOOMBreak = true;
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 998
996 size_t stackSize = 999 size_t stackSize =
997 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1; 1000 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1;
998 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId)) 1001 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId))
999 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture; 1002 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture;
1000 1003
1001 return V8StackTraceImpl::capture(this, contextGroupId, stackSize); 1004 return V8StackTraceImpl::capture(this, contextGroupId, stackSize);
1002 } 1005 }
1003 1006
1004 } // namespace v8_inspector 1007 } // namespace v8_inspector
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698