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

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

Issue 2510093002: [inspector] gracefully handle stack overflows in the inspector. (Closed)
Patch Set: Created 4 years, 1 month 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/protocol/Protocol.h" 8 #include "src/inspector/protocol/Protocol.h"
9 #include "src/inspector/script-breakpoint.h" 9 #include "src/inspector/script-breakpoint.h"
10 #include "src/inspector/string-util.h" 10 #include "src/inspector/string-util.h"
(...skipping 26 matching lines...) Expand all
37 const char* functionName, int argc, v8::Local<v8::Value> argv[]) { 37 const char* functionName, int argc, v8::Local<v8::Value> argv[]) {
38 v8::MicrotasksScope microtasks(m_isolate, 38 v8::MicrotasksScope microtasks(m_isolate,
39 v8::MicrotasksScope::kDoNotRunMicrotasks); 39 v8::MicrotasksScope::kDoNotRunMicrotasks);
40 DCHECK(m_isolate->InContext()); 40 DCHECK(m_isolate->InContext());
41 v8::Local<v8::Context> context = m_isolate->GetCurrentContext(); 41 v8::Local<v8::Context> context = m_isolate->GetCurrentContext();
42 v8::Local<v8::Object> debuggerScript = m_debuggerScript.Get(m_isolate); 42 v8::Local<v8::Object> debuggerScript = m_debuggerScript.Get(m_isolate);
43 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast( 43 v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(
44 debuggerScript 44 debuggerScript
45 ->Get(context, toV8StringInternalized(m_isolate, functionName)) 45 ->Get(context, toV8StringInternalized(m_isolate, functionName))
46 .ToLocalChecked()); 46 .ToLocalChecked());
47 v8::TryCatch try_catch;
47 return function->Call(context, debuggerScript, argc, argv); 48 return function->Call(context, debuggerScript, argc, argv);
48 } 49 }
49 50
50 V8Debugger::V8Debugger(v8::Isolate* isolate, V8InspectorImpl* inspector) 51 V8Debugger::V8Debugger(v8::Isolate* isolate, V8InspectorImpl* inspector)
51 : m_isolate(isolate), 52 : m_isolate(isolate),
52 m_inspector(inspector), 53 m_inspector(inspector),
53 m_lastContextId(0), 54 m_lastContextId(0),
54 m_enableCount(0), 55 m_enableCount(0),
55 m_breakpointsActivated(true), 56 m_breakpointsActivated(true),
56 m_runningNestedMessageLoop(false), 57 m_runningNestedMessageLoop(false),
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 JavaScriptCallFrames V8Debugger::currentCallFrames(int limit) { 431 JavaScriptCallFrames V8Debugger::currentCallFrames(int limit) {
431 if (!m_isolate->InContext()) return JavaScriptCallFrames(); 432 if (!m_isolate->InContext()) return JavaScriptCallFrames();
432 v8::Local<v8::Value> currentCallFramesV8; 433 v8::Local<v8::Value> currentCallFramesV8;
433 if (m_executionState.IsEmpty()) { 434 if (m_executionState.IsEmpty()) {
434 v8::Local<v8::Function> currentCallFramesFunction = 435 v8::Local<v8::Function> currentCallFramesFunction =
435 v8::Local<v8::Function>::Cast( 436 v8::Local<v8::Function>::Cast(
436 m_debuggerScript.Get(m_isolate) 437 m_debuggerScript.Get(m_isolate)
437 ->Get(debuggerContext(), 438 ->Get(debuggerContext(),
438 toV8StringInternalized(m_isolate, "currentCallFrames")) 439 toV8StringInternalized(m_isolate, "currentCallFrames"))
439 .ToLocalChecked()); 440 .ToLocalChecked());
440 currentCallFramesV8 = 441 if (!v8::DebugInterface::Call(debuggerContext(), currentCallFramesFunction,
441 v8::DebugInterface::Call(debuggerContext(), currentCallFramesFunction, 442 v8::Integer::New(m_isolate, limit))
442 v8::Integer::New(m_isolate, limit)) 443 .ToLocal(&currentCallFramesV8))
443 .ToLocalChecked(); 444 return JavaScriptCallFrames();
444 } else { 445 } else {
445 v8::Local<v8::Value> argv[] = {m_executionState, 446 v8::Local<v8::Value> argv[] = {m_executionState,
446 v8::Integer::New(m_isolate, limit)}; 447 v8::Integer::New(m_isolate, limit)};
447 currentCallFramesV8 = 448 if (!callDebuggerMethod("currentCallFrames", arraysize(argv), argv)
448 callDebuggerMethod("currentCallFrames", arraysize(argv), argv) 449 .ToLocal(&currentCallFramesV8))
449 .ToLocalChecked(); 450 return JavaScriptCallFrames();
450 } 451 }
451 DCHECK(!currentCallFramesV8.IsEmpty()); 452 DCHECK(!currentCallFramesV8.IsEmpty());
452 if (!currentCallFramesV8->IsArray()) return JavaScriptCallFrames(); 453 if (!currentCallFramesV8->IsArray()) return JavaScriptCallFrames();
453 v8::Local<v8::Array> callFramesArray = currentCallFramesV8.As<v8::Array>(); 454 v8::Local<v8::Array> callFramesArray = currentCallFramesV8.As<v8::Array>();
454 JavaScriptCallFrames callFrames; 455 JavaScriptCallFrames callFrames;
455 for (uint32_t i = 0; i < callFramesArray->Length(); ++i) { 456 for (uint32_t i = 0; i < callFramesArray->Length(); ++i) {
456 v8::Local<v8::Value> callFrameValue; 457 v8::Local<v8::Value> callFrameValue;
457 if (!callFramesArray->Get(debuggerContext(), i).ToLocal(&callFrameValue)) 458 if (!callFramesArray->Get(debuggerContext(), i).ToLocal(&callFrameValue))
458 return JavaScriptCallFrames(); 459 return JavaScriptCallFrames();
459 if (!callFrameValue->IsObject()) return JavaScriptCallFrames(); 460 if (!callFrameValue->IsObject()) return JavaScriptCallFrames();
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 callInternalGetterFunction(eventData, "promise"); 611 callInternalGetterFunction(eventData, "promise");
611 bool isPromiseRejection = !promise.IsEmpty() && promise->IsObject(); 612 bool isPromiseRejection = !promise.IsEmpty() && promise->IsObject();
612 v8::Local<v8::Value> uncaught = 613 v8::Local<v8::Value> uncaught =
613 callInternalGetterFunction(eventData, "uncaught"); 614 callInternalGetterFunction(eventData, "uncaught");
614 bool isUncaught = uncaught->BooleanValue(context).FromJust(); 615 bool isUncaught = uncaught->BooleanValue(context).FromJust();
615 handleProgramBreak(eventContext, eventDetails.GetExecutionState(), 616 handleProgramBreak(eventContext, eventDetails.GetExecutionState(),
616 exception, v8::Local<v8::Array>(), isPromiseRejection, 617 exception, v8::Local<v8::Array>(), isPromiseRejection,
617 isUncaught); 618 isUncaught);
618 } else if (event == v8::Break) { 619 } else if (event == v8::Break) {
619 v8::Local<v8::Value> argv[] = {eventDetails.GetEventData()}; 620 v8::Local<v8::Value> argv[] = {eventDetails.GetEventData()};
620 v8::Local<v8::Value> hitBreakpoints = 621 v8::Local<v8::Value> hitBreakpoints;
621 callDebuggerMethod("getBreakpointNumbers", 1, argv).ToLocalChecked(); 622 if (!callDebuggerMethod("getBreakpointNumbers", 1, argv)
623 .ToLocal(&hitBreakpoints))
624 return;
622 DCHECK(hitBreakpoints->IsArray()); 625 DCHECK(hitBreakpoints->IsArray());
623 handleProgramBreak(eventContext, eventDetails.GetExecutionState(), 626 handleProgramBreak(eventContext, eventDetails.GetExecutionState(),
624 v8::Local<v8::Value>(), hitBreakpoints.As<v8::Array>()); 627 v8::Local<v8::Value>(), hitBreakpoints.As<v8::Array>());
625 } 628 }
626 } 629 }
627 630
628 void V8Debugger::handleV8AsyncTaskEvent(v8::Local<v8::Context> context, 631 void V8Debugger::handleV8AsyncTaskEvent(v8::Local<v8::Context> context,
629 v8::Local<v8::Object> executionState, 632 v8::Local<v8::Object> executionState,
630 v8::Local<v8::Object> eventData) { 633 v8::Local<v8::Object> eventData) {
631 if (!m_maxAsyncCallStackDepth) return; 634 if (!m_maxAsyncCallStackDepth) return;
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 return properties; 775 return properties;
773 } 776 }
774 777
775 v8::Local<v8::Value> V8Debugger::collectionEntries( 778 v8::Local<v8::Value> V8Debugger::collectionEntries(
776 v8::Local<v8::Context> context, v8::Local<v8::Object> object) { 779 v8::Local<v8::Context> context, v8::Local<v8::Object> object) {
777 if (!enabled()) { 780 if (!enabled()) {
778 UNREACHABLE(); 781 UNREACHABLE();
779 return v8::Undefined(m_isolate); 782 return v8::Undefined(m_isolate);
780 } 783 }
781 v8::Local<v8::Value> argv[] = {object}; 784 v8::Local<v8::Value> argv[] = {object};
782 v8::Local<v8::Value> entriesValue = 785 v8::Local<v8::Value> entriesValue;
783 callDebuggerMethod("getCollectionEntries", 1, argv).ToLocalChecked(); 786 if (!callDebuggerMethod("getCollectionEntries", 1, argv)
784 if (!entriesValue->IsArray()) return v8::Undefined(m_isolate); 787 .ToLocal(&entriesValue) ||
788 !entriesValue->IsArray())
789 return v8::Undefined(m_isolate);
785 790
786 v8::Local<v8::Array> entries = entriesValue.As<v8::Array>(); 791 v8::Local<v8::Array> entries = entriesValue.As<v8::Array>();
787 v8::Local<v8::Array> copiedArray = 792 v8::Local<v8::Array> copiedArray =
788 v8::Array::New(m_isolate, entries->Length()); 793 v8::Array::New(m_isolate, entries->Length());
789 if (!copiedArray->SetPrototype(context, v8::Null(m_isolate)).FromMaybe(false)) 794 if (!copiedArray->SetPrototype(context, v8::Null(m_isolate)).FromMaybe(false))
790 return v8::Undefined(m_isolate); 795 return v8::Undefined(m_isolate);
791 for (uint32_t i = 0; i < entries->Length(); ++i) { 796 for (uint32_t i = 0; i < entries->Length(); ++i) {
792 v8::Local<v8::Value> item; 797 v8::Local<v8::Value> item;
793 if (!entries->Get(debuggerContext(), i).ToLocal(&item)) 798 if (!entries->Get(debuggerContext(), i).ToLocal(&item))
794 return v8::Undefined(m_isolate); 799 return v8::Undefined(m_isolate);
(...skipping 12 matching lines...) Expand all
807 return copiedArray; 812 return copiedArray;
808 } 813 }
809 814
810 v8::Local<v8::Value> V8Debugger::generatorObjectLocation( 815 v8::Local<v8::Value> V8Debugger::generatorObjectLocation(
811 v8::Local<v8::Context> context, v8::Local<v8::Object> object) { 816 v8::Local<v8::Context> context, v8::Local<v8::Object> object) {
812 if (!enabled()) { 817 if (!enabled()) {
813 UNREACHABLE(); 818 UNREACHABLE();
814 return v8::Null(m_isolate); 819 return v8::Null(m_isolate);
815 } 820 }
816 v8::Local<v8::Value> argv[] = {object}; 821 v8::Local<v8::Value> argv[] = {object};
817 v8::Local<v8::Value> location = 822 v8::Local<v8::Value> location;
818 callDebuggerMethod("getGeneratorObjectLocation", 1, argv)
819 .ToLocalChecked();
820 v8::Local<v8::Value> copied; 823 v8::Local<v8::Value> copied;
821 if (!copyValueFromDebuggerContext(m_isolate, debuggerContext(), context, 824 if (!callDebuggerMethod("getGeneratorObjectLocation", 1, argv)
825 .ToLocal(&location) ||
826 !copyValueFromDebuggerContext(m_isolate, debuggerContext(), context,
822 location) 827 location)
823 .ToLocal(&copied) || 828 .ToLocal(&copied) ||
824 !copied->IsObject()) 829 !copied->IsObject())
825 return v8::Null(m_isolate); 830 return v8::Null(m_isolate);
826 if (!markAsInternal(context, v8::Local<v8::Object>::Cast(copied), 831 if (!markAsInternal(context, v8::Local<v8::Object>::Cast(copied),
827 V8InternalValueType::kLocation)) 832 V8InternalValueType::kLocation))
828 return v8::Null(m_isolate); 833 return v8::Null(m_isolate);
829 return copied; 834 return copied;
830 } 835 }
831 836
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 988
984 size_t stackSize = 989 size_t stackSize =
985 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1; 990 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1;
986 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId)) 991 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId))
987 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture; 992 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture;
988 993
989 return V8StackTraceImpl::capture(this, contextGroupId, stackSize); 994 return V8StackTraceImpl::capture(this, contextGroupId, stackSize);
990 } 995 }
991 996
992 } // namespace v8_inspector 997 } // namespace v8_inspector
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698