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

Side by Side Diff: src/inspector/v8-debugger.cc

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

Powered by Google App Engine
This is Rietveld 408576698