| OLD | NEW |
| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 V8Debugger::~V8Debugger() {} | 65 V8Debugger::~V8Debugger() {} |
| 66 | 66 |
| 67 void V8Debugger::enable() { | 67 void V8Debugger::enable() { |
| 68 if (m_enableCount++) return; | 68 if (m_enableCount++) return; |
| 69 DCHECK(!enabled()); | 69 DCHECK(!enabled()); |
| 70 v8::HandleScope scope(m_isolate); | 70 v8::HandleScope scope(m_isolate); |
| 71 v8::debug::SetDebugEventListener(m_isolate, &V8Debugger::v8DebugEventCallback, | 71 v8::debug::SetDebugEventListener(m_isolate, &V8Debugger::v8DebugEventCallback, |
| 72 v8::External::New(m_isolate, this)); | 72 v8::External::New(m_isolate, this)); |
| 73 v8::debug::SetAsyncTaskListener(m_isolate, &V8Debugger::v8AsyncTaskListener, | 73 v8::debug::SetAsyncTaskListener(m_isolate, &V8Debugger::v8AsyncTaskListener, |
| 74 this); | 74 this); |
| 75 v8::debug::SetOutOfMemoryCallback(m_isolate, &V8Debugger::v8OOMCallback, |
| 76 this); |
| 75 m_debuggerContext.Reset(m_isolate, v8::debug::GetDebugContext(m_isolate)); | 77 m_debuggerContext.Reset(m_isolate, v8::debug::GetDebugContext(m_isolate)); |
| 76 v8::debug::ChangeBreakOnException(m_isolate, v8::debug::NoBreakOnException); | 78 v8::debug::ChangeBreakOnException(m_isolate, v8::debug::NoBreakOnException); |
| 77 m_pauseOnExceptionsState = v8::debug::NoBreakOnException; | 79 m_pauseOnExceptionsState = v8::debug::NoBreakOnException; |
| 78 compileDebuggerScript(); | 80 compileDebuggerScript(); |
| 79 } | 81 } |
| 80 | 82 |
| 81 void V8Debugger::disable() { | 83 void V8Debugger::disable() { |
| 82 if (--m_enableCount) return; | 84 if (--m_enableCount) return; |
| 83 DCHECK(enabled()); | 85 DCHECK(enabled()); |
| 84 clearBreakpoints(); | 86 clearBreakpoints(); |
| 85 m_debuggerScript.Reset(); | 87 m_debuggerScript.Reset(); |
| 86 m_debuggerContext.Reset(); | 88 m_debuggerContext.Reset(); |
| 87 allAsyncTasksCanceled(); | 89 allAsyncTasksCanceled(); |
| 88 m_wasmTranslation.Clear(); | 90 m_wasmTranslation.Clear(); |
| 89 v8::debug::SetDebugEventListener(m_isolate, nullptr); | 91 v8::debug::SetDebugEventListener(m_isolate, nullptr); |
| 90 v8::debug::SetAsyncTaskListener(m_isolate, nullptr, nullptr); | 92 v8::debug::SetAsyncTaskListener(m_isolate, nullptr, nullptr); |
| 93 v8::debug::SetOutOfMemoryCallback(m_isolate, &V8Debugger::v8OOMCallback, |
| 94 nullptr); |
| 95 m_isolate->RestoreOriginalHeapLimit(); |
| 91 } | 96 } |
| 92 | 97 |
| 93 bool V8Debugger::enabled() const { return !m_debuggerScript.IsEmpty(); } | 98 bool V8Debugger::enabled() const { return !m_debuggerScript.IsEmpty(); } |
| 94 | 99 |
| 95 void V8Debugger::getCompiledScripts( | 100 void V8Debugger::getCompiledScripts( |
| 96 int contextGroupId, | 101 int contextGroupId, |
| 97 std::vector<std::unique_ptr<V8DebuggerScript>>& result) { | 102 std::vector<std::unique_ptr<V8DebuggerScript>>& result) { |
| 98 v8::HandleScope scope(m_isolate); | 103 v8::HandleScope scope(m_isolate); |
| 99 v8::PersistentValueVector<v8::debug::Script> scripts(m_isolate); | 104 v8::PersistentValueVector<v8::debug::Script> scripts(m_isolate); |
| 100 v8::debug::GetLoadedScripts(m_isolate, scripts); | 105 v8::debug::GetLoadedScripts(m_isolate, scripts); |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 v8::Local<v8::Value> hitBreakpointNumber = | 478 v8::Local<v8::Value> hitBreakpointNumber = |
| 474 hitBreakpointNumbers->Get(debuggerContext(), i).ToLocalChecked(); | 479 hitBreakpointNumbers->Get(debuggerContext(), i).ToLocalChecked(); |
| 475 DCHECK(hitBreakpointNumber->IsInt32()); | 480 DCHECK(hitBreakpointNumber->IsInt32()); |
| 476 breakpointIds.push_back(String16::fromInteger( | 481 breakpointIds.push_back(String16::fromInteger( |
| 477 hitBreakpointNumber->Int32Value(debuggerContext()).FromJust())); | 482 hitBreakpointNumber->Int32Value(debuggerContext()).FromJust())); |
| 478 } | 483 } |
| 479 } | 484 } |
| 480 | 485 |
| 481 m_pausedContext = pausedContext; | 486 m_pausedContext = pausedContext; |
| 482 m_executionState = executionState; | 487 m_executionState = executionState; |
| 483 V8DebuggerAgentImpl::SkipPauseRequest result = agent->didPause( | 488 V8DebuggerAgentImpl::SkipPauseRequest result = |
| 484 pausedContext, exception, breakpointIds, isPromiseRejection, isUncaught); | 489 agent->didPause(pausedContext, exception, breakpointIds, |
| 490 isPromiseRejection, isUncaught, m_scheduledOOMBreak); |
| 485 if (result == V8DebuggerAgentImpl::RequestNoSkip) { | 491 if (result == V8DebuggerAgentImpl::RequestNoSkip) { |
| 486 m_runningNestedMessageLoop = true; | 492 m_runningNestedMessageLoop = true; |
| 487 int groupId = m_inspector->contextGroupId(pausedContext); | 493 int groupId = m_inspector->contextGroupId(pausedContext); |
| 488 DCHECK(groupId); | 494 DCHECK(groupId); |
| 489 v8::Context::Scope scope(pausedContext); | 495 v8::Context::Scope scope(pausedContext); |
| 490 v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); | 496 v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); |
| 491 CHECK(!context.IsEmpty() && | 497 CHECK(!context.IsEmpty() && |
| 492 context != v8::debug::GetDebugContext(m_isolate)); | 498 context != v8::debug::GetDebugContext(m_isolate)); |
| 493 m_inspector->client()->runMessageLoopOnPause(groupId); | 499 m_inspector->client()->runMessageLoopOnPause(groupId); |
| 494 // The agent may have been removed in the nested loop. | 500 // The agent may have been removed in the nested loop. |
| 495 agent = m_inspector->enabledDebuggerAgentForGroup( | 501 agent = m_inspector->enabledDebuggerAgentForGroup( |
| 496 m_inspector->contextGroupId(pausedContext)); | 502 m_inspector->contextGroupId(pausedContext)); |
| 497 if (agent) agent->didContinue(); | 503 if (agent) agent->didContinue(); |
| 498 m_runningNestedMessageLoop = false; | 504 m_runningNestedMessageLoop = false; |
| 499 } | 505 } |
| 506 if (m_scheduledOOMBreak) m_isolate->RestoreOriginalHeapLimit(); |
| 507 m_scheduledOOMBreak = false; |
| 500 m_pausedContext.Clear(); | 508 m_pausedContext.Clear(); |
| 501 m_executionState.Clear(); | 509 m_executionState.Clear(); |
| 502 | 510 |
| 503 if (result == V8DebuggerAgentImpl::RequestStepFrame) { | 511 if (result == V8DebuggerAgentImpl::RequestStepFrame) { |
| 504 v8::debug::PrepareStep(m_isolate, v8::debug::StepFrame); | 512 v8::debug::PrepareStep(m_isolate, v8::debug::StepFrame); |
| 505 } else if (result == V8DebuggerAgentImpl::RequestStepInto) { | 513 } else if (result == V8DebuggerAgentImpl::RequestStepInto) { |
| 506 v8::debug::PrepareStep(m_isolate, v8::debug::StepIn); | 514 v8::debug::PrepareStep(m_isolate, v8::debug::StepIn); |
| 507 } else if (result == V8DebuggerAgentImpl::RequestStepOut) { | 515 } else if (result == V8DebuggerAgentImpl::RequestStepOut) { |
| 508 v8::debug::PrepareStep(m_isolate, v8::debug::StepOut); | 516 v8::debug::PrepareStep(m_isolate, v8::debug::StepOut); |
| 509 } | 517 } |
| 510 } | 518 } |
| 511 | 519 |
| 520 void V8Debugger::v8OOMCallback(void* data) { |
| 521 V8Debugger* thisPtr = static_cast<V8Debugger*>(data); |
| 522 thisPtr->m_isolate->IncreaseHeapLimitForDebugging(); |
| 523 thisPtr->m_scheduledOOMBreak = true; |
| 524 thisPtr->setPauseOnNextStatement(true); |
| 525 } |
| 526 |
| 512 void V8Debugger::v8DebugEventCallback( | 527 void V8Debugger::v8DebugEventCallback( |
| 513 const v8::debug::EventDetails& eventDetails) { | 528 const v8::debug::EventDetails& eventDetails) { |
| 514 V8Debugger* thisPtr = toV8Debugger(eventDetails.GetCallbackData()); | 529 V8Debugger* thisPtr = toV8Debugger(eventDetails.GetCallbackData()); |
| 515 thisPtr->handleV8DebugEvent(eventDetails); | 530 thisPtr->handleV8DebugEvent(eventDetails); |
| 516 } | 531 } |
| 517 | 532 |
| 518 v8::Local<v8::Value> V8Debugger::callInternalGetterFunction( | 533 v8::Local<v8::Value> V8Debugger::callInternalGetterFunction( |
| 519 v8::Local<v8::Object> object, const char* functionName) { | 534 v8::Local<v8::Object> object, const char* functionName) { |
| 520 v8::MicrotasksScope microtasks(m_isolate, | 535 v8::MicrotasksScope microtasks(m_isolate, |
| 521 v8::MicrotasksScope::kDoNotRunMicrotasks); | 536 v8::MicrotasksScope::kDoNotRunMicrotasks); |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 | 1009 |
| 995 size_t stackSize = | 1010 size_t stackSize = |
| 996 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1; | 1011 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1; |
| 997 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId)) | 1012 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId)) |
| 998 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture; | 1013 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture; |
| 999 | 1014 |
| 1000 return V8StackTraceImpl::capture(this, contextGroupId, stackSize); | 1015 return V8StackTraceImpl::capture(this, contextGroupId, stackSize); |
| 1001 } | 1016 } |
| 1002 | 1017 |
| 1003 } // namespace v8_inspector | 1018 } // namespace v8_inspector |
| OLD | NEW |