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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 246 |
247 void V8Debugger::setPauseOnExceptionsState( | 247 void V8Debugger::setPauseOnExceptionsState( |
248 v8::debug::ExceptionBreakState pauseOnExceptionsState) { | 248 v8::debug::ExceptionBreakState pauseOnExceptionsState) { |
249 DCHECK(enabled()); | 249 DCHECK(enabled()); |
250 if (m_pauseOnExceptionsState == pauseOnExceptionsState) return; | 250 if (m_pauseOnExceptionsState == pauseOnExceptionsState) return; |
251 v8::debug::ChangeBreakOnException(m_isolate, pauseOnExceptionsState); | 251 v8::debug::ChangeBreakOnException(m_isolate, pauseOnExceptionsState); |
252 m_pauseOnExceptionsState = pauseOnExceptionsState; | 252 m_pauseOnExceptionsState = pauseOnExceptionsState; |
253 } | 253 } |
254 | 254 |
255 void V8Debugger::setPauseOnNextStatement(bool pause) { | 255 void V8Debugger::setPauseOnNextStatement(bool pause) { |
256 if (m_runningNestedMessageLoop) return; | 256 if (isPaused()) return; |
257 if (pause) | 257 if (pause) |
258 v8::debug::DebugBreak(m_isolate); | 258 v8::debug::DebugBreak(m_isolate); |
259 else | 259 else |
260 v8::debug::CancelDebugBreak(m_isolate); | 260 v8::debug::CancelDebugBreak(m_isolate); |
261 } | 261 } |
262 | 262 |
263 bool V8Debugger::canBreakProgram() { | 263 bool V8Debugger::canBreakProgram() { |
264 if (!m_breakpointsActivated) return false; | 264 if (!m_breakpointsActivated) return false; |
265 return v8::debug::HasNonBlackboxedFrameOnStack(m_isolate); | 265 return v8::debug::HasNonBlackboxedFrameOnStack(m_isolate); |
266 } | 266 } |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 v8::Local<v8::Object>::Cast(info[0]), exception, | 467 v8::Local<v8::Object>::Cast(info[0]), exception, |
468 hitBreakpoints); | 468 hitBreakpoints); |
469 } | 469 } |
470 | 470 |
471 void V8Debugger::handleProgramBreak(v8::Local<v8::Context> pausedContext, | 471 void V8Debugger::handleProgramBreak(v8::Local<v8::Context> pausedContext, |
472 v8::Local<v8::Object> executionState, | 472 v8::Local<v8::Object> executionState, |
473 v8::Local<v8::Value> exception, | 473 v8::Local<v8::Value> exception, |
474 v8::Local<v8::Array> hitBreakpointNumbers, | 474 v8::Local<v8::Array> hitBreakpointNumbers, |
475 bool isPromiseRejection, bool isUncaught) { | 475 bool isPromiseRejection, bool isUncaught) { |
476 // Don't allow nested breaks. | 476 // Don't allow nested breaks. |
477 if (m_runningNestedMessageLoop) return; | 477 if (isPaused()) return; |
478 | 478 |
479 V8DebuggerAgentImpl* agent = m_inspector->enabledDebuggerAgentForGroup( | 479 V8DebuggerAgentImpl* agent = m_inspector->enabledDebuggerAgentForGroup( |
480 m_inspector->contextGroupId(pausedContext)); | 480 m_inspector->contextGroupId(pausedContext)); |
481 if (!agent) return; | 481 if (!agent || (agent->skipAllPauses() && !m_scheduledOOMBreak)) return; |
482 | 482 |
483 std::vector<String16> breakpointIds; | 483 std::vector<String16> breakpointIds; |
484 if (!hitBreakpointNumbers.IsEmpty()) { | 484 if (!hitBreakpointNumbers.IsEmpty()) { |
485 breakpointIds.reserve(hitBreakpointNumbers->Length()); | 485 breakpointIds.reserve(hitBreakpointNumbers->Length()); |
486 for (uint32_t i = 0; i < hitBreakpointNumbers->Length(); i++) { | 486 for (uint32_t i = 0; i < hitBreakpointNumbers->Length(); i++) { |
487 v8::Local<v8::Value> hitBreakpointNumber = | 487 v8::Local<v8::Value> hitBreakpointNumber = |
488 hitBreakpointNumbers->Get(debuggerContext(), i).ToLocalChecked(); | 488 hitBreakpointNumbers->Get(debuggerContext(), i).ToLocalChecked(); |
489 DCHECK(hitBreakpointNumber->IsInt32()); | 489 DCHECK(hitBreakpointNumber->IsInt32()); |
490 breakpointIds.push_back(String16::fromInteger( | 490 breakpointIds.push_back(String16::fromInteger( |
491 hitBreakpointNumber->Int32Value(debuggerContext()).FromJust())); | 491 hitBreakpointNumber->Int32Value(debuggerContext()).FromJust())); |
492 } | 492 } |
493 } | 493 } |
494 | 494 |
495 m_pausedContext = pausedContext; | 495 m_pausedContext = pausedContext; |
496 m_executionState = executionState; | 496 m_executionState = executionState; |
497 bool shouldPause = | 497 m_runningNestedMessageLoop = true; |
498 agent->didPause(pausedContext, exception, breakpointIds, | 498 agent->didPause(InspectedContext::contextId(pausedContext), exception, |
499 isPromiseRejection, isUncaught, m_scheduledOOMBreak); | 499 breakpointIds, isPromiseRejection, isUncaught, |
500 if (shouldPause) { | 500 m_scheduledOOMBreak); |
501 m_runningNestedMessageLoop = true; | 501 int groupId = m_inspector->contextGroupId(pausedContext); |
502 int groupId = m_inspector->contextGroupId(pausedContext); | 502 DCHECK(groupId); |
503 DCHECK(groupId); | 503 { |
504 v8::Context::Scope scope(pausedContext); | 504 v8::Context::Scope scope(pausedContext); |
505 v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); | 505 v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); |
506 CHECK(!context.IsEmpty() && | 506 CHECK(!context.IsEmpty() && |
507 context != v8::debug::GetDebugContext(m_isolate)); | 507 context != v8::debug::GetDebugContext(m_isolate)); |
508 m_inspector->client()->runMessageLoopOnPause(groupId); | 508 m_inspector->client()->runMessageLoopOnPause(groupId); |
509 // The agent may have been removed in the nested loop. | |
510 agent = m_inspector->enabledDebuggerAgentForGroup( | |
511 m_inspector->contextGroupId(pausedContext)); | |
512 if (agent) agent->didContinue(); | |
513 m_runningNestedMessageLoop = false; | 509 m_runningNestedMessageLoop = false; |
514 } | 510 } |
| 511 // The agent may have been removed in the nested loop. |
| 512 agent = m_inspector->enabledDebuggerAgentForGroup(groupId); |
| 513 if (agent) agent->didContinue(); |
515 if (m_scheduledOOMBreak) m_isolate->RestoreOriginalHeapLimit(); | 514 if (m_scheduledOOMBreak) m_isolate->RestoreOriginalHeapLimit(); |
516 m_scheduledOOMBreak = false; | 515 m_scheduledOOMBreak = false; |
517 m_pausedContext.Clear(); | 516 m_pausedContext.Clear(); |
518 m_executionState.Clear(); | 517 m_executionState.Clear(); |
519 } | 518 } |
520 | 519 |
521 void V8Debugger::v8OOMCallback(void* data) { | 520 void V8Debugger::v8OOMCallback(void* data) { |
522 V8Debugger* thisPtr = static_cast<V8Debugger*>(data); | 521 V8Debugger* thisPtr = static_cast<V8Debugger*>(data); |
523 thisPtr->m_isolate->IncreaseHeapLimitForDebugging(); | 522 thisPtr->m_isolate->IncreaseHeapLimitForDebugging(); |
524 thisPtr->m_scheduledOOMBreak = true; | 523 thisPtr->m_scheduledOOMBreak = true; |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
829 if (!createDataProperty(context, location, | 828 if (!createDataProperty(context, location, |
830 toV8StringInternalized(m_isolate, "columnNumber"), | 829 toV8StringInternalized(m_isolate, "columnNumber"), |
831 v8::Integer::New(m_isolate, columnNumber)) | 830 v8::Integer::New(m_isolate, columnNumber)) |
832 .FromMaybe(false)) | 831 .FromMaybe(false)) |
833 return v8::Null(m_isolate); | 832 return v8::Null(m_isolate); |
834 if (!markAsInternal(context, location, V8InternalValueType::kLocation)) | 833 if (!markAsInternal(context, location, V8InternalValueType::kLocation)) |
835 return v8::Null(m_isolate); | 834 return v8::Null(m_isolate); |
836 return location; | 835 return location; |
837 } | 836 } |
838 | 837 |
839 bool V8Debugger::isPaused() { return !m_pausedContext.IsEmpty(); } | |
840 | |
841 std::unique_ptr<V8StackTraceImpl> V8Debugger::createStackTrace( | 838 std::unique_ptr<V8StackTraceImpl> V8Debugger::createStackTrace( |
842 v8::Local<v8::StackTrace> stackTrace) { | 839 v8::Local<v8::StackTrace> stackTrace) { |
843 int contextGroupId = | 840 int contextGroupId = |
844 m_isolate->InContext() | 841 m_isolate->InContext() |
845 ? m_inspector->contextGroupId(m_isolate->GetCurrentContext()) | 842 ? m_inspector->contextGroupId(m_isolate->GetCurrentContext()) |
846 : 0; | 843 : 0; |
847 return V8StackTraceImpl::create(this, contextGroupId, stackTrace, | 844 return V8StackTraceImpl::create(this, contextGroupId, stackTrace, |
848 V8StackTraceImpl::maxCallStackSizeToCapture); | 845 V8StackTraceImpl::maxCallStackSizeToCapture); |
849 } | 846 } |
850 | 847 |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
998 | 995 |
999 size_t stackSize = | 996 size_t stackSize = |
1000 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1; | 997 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1; |
1001 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId)) | 998 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId)) |
1002 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture; | 999 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture; |
1003 | 1000 |
1004 return V8StackTraceImpl::capture(this, contextGroupId, stackSize); | 1001 return V8StackTraceImpl::capture(this, contextGroupId, stackSize); |
1005 } | 1002 } |
1006 | 1003 |
1007 } // namespace v8_inspector | 1004 } // namespace v8_inspector |
OLD | NEW |