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

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

Issue 2578923002: [inspector] async stacks for Promise.then calls... (Closed)
Patch Set: added missing handle scope Created 4 years 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"
11 #include "src/inspector/string-util.h" 11 #include "src/inspector/string-util.h"
12 #include "src/inspector/v8-debugger-agent-impl.h" 12 #include "src/inspector/v8-debugger-agent-impl.h"
13 #include "src/inspector/v8-inspector-impl.h" 13 #include "src/inspector/v8-inspector-impl.h"
14 #include "src/inspector/v8-internal-value-type.h" 14 #include "src/inspector/v8-internal-value-type.h"
15 #include "src/inspector/v8-stack-trace-impl.h" 15 #include "src/inspector/v8-stack-trace-impl.h"
16 #include "src/inspector/v8-value-copier.h" 16 #include "src/inspector/v8-value-copier.h"
17 17
18 #include "include/v8-util.h" 18 #include "include/v8-util.h"
19 19
20 namespace v8_inspector { 20 namespace v8_inspector {
21 21
22 namespace { 22 namespace {
23 static const char v8AsyncTaskEventEnqueue[] = "enqueue";
24 static const char v8AsyncTaskEventEnqueueRecurring[] = "enqueueRecurring";
25 static const char v8AsyncTaskEventWillHandle[] = "willHandle";
26 static const char v8AsyncTaskEventDidHandle[] = "didHandle";
27 static const char v8AsyncTaskEventCancel[] = "cancel";
28 23
29 inline v8::Local<v8::Boolean> v8Boolean(bool value, v8::Isolate* isolate) { 24 inline v8::Local<v8::Boolean> v8Boolean(bool value, v8::Isolate* isolate) {
30 return value ? v8::True(isolate) : v8::False(isolate); 25 return value ? v8::True(isolate) : v8::False(isolate);
31 } 26 }
32 27
33 } // namespace 28 } // namespace
34 29
35 static bool inLiveEditScope = false; 30 static bool inLiveEditScope = false;
36 31
37 v8::MaybeLocal<v8::Value> V8Debugger::callDebuggerMethod( 32 v8::MaybeLocal<v8::Value> V8Debugger::callDebuggerMethod(
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 .ToLocalChecked(); 511 .ToLocalChecked();
517 DCHECK(!getterValue.IsEmpty() && getterValue->IsFunction()); 512 DCHECK(!getterValue.IsEmpty() && getterValue->IsFunction());
518 return v8::Local<v8::Function>::Cast(getterValue) 513 return v8::Local<v8::Function>::Cast(getterValue)
519 ->Call(m_isolate->GetCurrentContext(), object, 0, nullptr) 514 ->Call(m_isolate->GetCurrentContext(), object, 0, nullptr)
520 .ToLocalChecked(); 515 .ToLocalChecked();
521 } 516 }
522 517
523 void V8Debugger::handleV8DebugEvent( 518 void V8Debugger::handleV8DebugEvent(
524 const v8::debug::EventDetails& eventDetails) { 519 const v8::debug::EventDetails& eventDetails) {
525 if (!enabled()) return; 520 if (!enabled()) return;
521 v8::HandleScope scope(m_isolate);
526 v8::DebugEvent event = eventDetails.GetEvent(); 522 v8::DebugEvent event = eventDetails.GetEvent();
527 if (event != v8::AsyncTaskEvent && event != v8::Break && 523 if (event != v8::AsyncTaskEvent && event != v8::Break &&
528 event != v8::Exception && event != v8::AfterCompile && 524 event != v8::Exception && event != v8::AfterCompile &&
529 event != v8::CompileError) 525 event != v8::CompileError)
530 return; 526 return;
531 527
532 v8::Local<v8::Context> eventContext = eventDetails.GetEventContext();
533 DCHECK(!eventContext.IsEmpty());
534
535 if (event == v8::AsyncTaskEvent) { 528 if (event == v8::AsyncTaskEvent) {
536 v8::HandleScope scope(m_isolate); 529 handleV8AsyncTaskEvent(eventDetails.GetEventData());
537 handleV8AsyncTaskEvent(eventContext, eventDetails.GetExecutionState(),
538 eventDetails.GetEventData());
539 return; 530 return;
540 } 531 }
541 532
533 v8::Local<v8::Context> eventContext = eventDetails.GetEventContext();
534 DCHECK(!eventContext.IsEmpty());
542 V8DebuggerAgentImpl* agent = m_inspector->enabledDebuggerAgentForGroup( 535 V8DebuggerAgentImpl* agent = m_inspector->enabledDebuggerAgentForGroup(
543 m_inspector->contextGroupId(eventContext)); 536 m_inspector->contextGroupId(eventContext));
544 if (!agent) return; 537 if (!agent) return;
545 538
546 v8::HandleScope scope(m_isolate);
547 if (event == v8::AfterCompile || event == v8::CompileError) { 539 if (event == v8::AfterCompile || event == v8::CompileError) {
548 v8::Context::Scope contextScope(debuggerContext()); 540 v8::Context::Scope contextScope(debuggerContext());
549 // Determine if the script is a wasm script. 541 // Determine if the script is a wasm script.
550 v8::Local<v8::Value> scriptMirror = 542 v8::Local<v8::Value> scriptMirror =
551 callInternalGetterFunction(eventDetails.GetEventData(), "script"); 543 callInternalGetterFunction(eventDetails.GetEventData(), "script");
552 DCHECK(scriptMirror->IsObject()); 544 DCHECK(scriptMirror->IsObject());
553 v8::Local<v8::Value> scriptWrapper = 545 v8::Local<v8::Value> scriptWrapper =
554 callInternalGetterFunction(scriptMirror.As<v8::Object>(), "value"); 546 callInternalGetterFunction(scriptMirror.As<v8::Object>(), "value");
555 DCHECK(scriptWrapper->IsObject()); 547 DCHECK(scriptWrapper->IsObject());
556 v8::Local<v8::debug::Script> script; 548 v8::Local<v8::debug::Script> script;
(...skipping 25 matching lines...) Expand all
582 } else if (event == v8::Break) { 574 } else if (event == v8::Break) {
583 v8::Local<v8::Value> argv[] = {eventDetails.GetEventData()}; 575 v8::Local<v8::Value> argv[] = {eventDetails.GetEventData()};
584 v8::Local<v8::Value> hitBreakpoints = 576 v8::Local<v8::Value> hitBreakpoints =
585 callDebuggerMethod("getBreakpointNumbers", 1, argv).ToLocalChecked(); 577 callDebuggerMethod("getBreakpointNumbers", 1, argv).ToLocalChecked();
586 DCHECK(hitBreakpoints->IsArray()); 578 DCHECK(hitBreakpoints->IsArray());
587 handleProgramBreak(eventContext, eventDetails.GetExecutionState(), 579 handleProgramBreak(eventContext, eventDetails.GetExecutionState(),
588 v8::Local<v8::Value>(), hitBreakpoints.As<v8::Array>()); 580 v8::Local<v8::Value>(), hitBreakpoints.As<v8::Array>());
589 } 581 }
590 } 582 }
591 583
592 void V8Debugger::handleV8AsyncTaskEvent(v8::Local<v8::Context> context, 584 void V8Debugger::handleV8AsyncTaskEvent(v8::Local<v8::Object> eventData) {
593 v8::Local<v8::Object> executionState,
594 v8::Local<v8::Object> eventData) {
595 if (!m_maxAsyncCallStackDepth) return; 585 if (!m_maxAsyncCallStackDepth) return;
596 586
597 String16 type = toProtocolStringWithTypeCheck( 587 v8::debug::AsyncTaskEventType type =
598 callInternalGetterFunction(eventData, "type")); 588 static_cast<v8::debug::AsyncTaskEventType>(
589 callInternalGetterFunction(eventData, "type")
590 ->ToInteger(m_isolate->GetCurrentContext())
591 .ToLocalChecked()
592 ->Value());
599 String16 name = toProtocolStringWithTypeCheck( 593 String16 name = toProtocolStringWithTypeCheck(
600 callInternalGetterFunction(eventData, "name")); 594 callInternalGetterFunction(eventData, "name"));
601 int id = static_cast<int>(callInternalGetterFunction(eventData, "id") 595 int id = static_cast<int>(callInternalGetterFunction(eventData, "id")
602 ->ToInteger(context) 596 ->ToInteger(m_isolate->GetCurrentContext())
603 .ToLocalChecked() 597 .ToLocalChecked()
604 ->Value()); 598 ->Value());
605 // Async task events from Promises are given misaligned pointers to prevent 599 // Async task events from Promises are given misaligned pointers to prevent
606 // from overlapping with other Blink task identifiers. There is a single 600 // from overlapping with other Blink task identifiers. There is a single
607 // namespace of such ids, managed by src/js/promise.js. 601 // namespace of such ids, managed by src/js/promise.js.
608 void* ptr = reinterpret_cast<void*>(id * 2 + 1); 602 void* ptr = reinterpret_cast<void*>(id * 2 + 1);
609 if (type == v8AsyncTaskEventEnqueue) 603 if (type == v8::debug::EnqueueRecurring)
610 asyncTaskScheduled(name, ptr, false);
611 else if (type == v8AsyncTaskEventEnqueueRecurring)
612 asyncTaskScheduled(name, ptr, true); 604 asyncTaskScheduled(name, ptr, true);
613 else if (type == v8AsyncTaskEventWillHandle) 605 else if (type == v8::debug::WillHandle)
614 asyncTaskStarted(ptr); 606 asyncTaskStarted(ptr);
615 else if (type == v8AsyncTaskEventDidHandle) 607 else if (type == v8::debug::DidHandle)
616 asyncTaskFinished(ptr); 608 asyncTaskFinished(ptr);
617 else if (type == v8AsyncTaskEventCancel) 609 else if (type == v8::debug::Cancel)
618 asyncTaskCanceled(ptr); 610 asyncTaskCanceled(ptr);
619 else 611 else
620 UNREACHABLE(); 612 UNREACHABLE();
621 } 613 }
622 614
623 V8StackTraceImpl* V8Debugger::currentAsyncCallChain() { 615 V8StackTraceImpl* V8Debugger::currentAsyncCallChain() {
624 if (!m_currentStacks.size()) return nullptr; 616 if (!m_currentStacks.size()) return nullptr;
625 return m_currentStacks.back().get(); 617 return m_currentStacks.back().get();
626 } 618 }
627 619
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 959
968 size_t stackSize = 960 size_t stackSize =
969 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1; 961 fullStack ? V8StackTraceImpl::maxCallStackSizeToCapture : 1;
970 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId)) 962 if (m_inspector->enabledRuntimeAgentForGroup(contextGroupId))
971 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture; 963 stackSize = V8StackTraceImpl::maxCallStackSizeToCapture;
972 964
973 return V8StackTraceImpl::capture(this, contextGroupId, stackSize); 965 return V8StackTraceImpl::capture(this, contextGroupId, stackSize);
974 } 966 }
975 967
976 } // namespace v8_inspector 968 } // namespace v8_inspector
OLDNEW
« src/debug/debug.cc ('K') | « src/inspector/v8-debugger.h ('k') | src/isolate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698