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 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 asyncTaskStartedForStepping(task); | 676 asyncTaskStartedForStepping(task); |
677 break; | 677 break; |
678 case v8::debug::kDebugDidHandle: | 678 case v8::debug::kDebugDidHandle: |
679 asyncTaskFinishedForStack(task); | 679 asyncTaskFinishedForStack(task); |
680 asyncTaskFinishedForStepping(task); | 680 asyncTaskFinishedForStepping(task); |
681 break; | 681 break; |
682 } | 682 } |
683 } | 683 } |
684 | 684 |
685 std::shared_ptr<AsyncStackTrace> V8Debugger::currentAsyncParent() { | 685 std::shared_ptr<AsyncStackTrace> V8Debugger::currentAsyncParent() { |
686 // TODO(kozyatinskiy): implement creation chain as parent without hack. | |
687 if (!m_currentAsyncCreation.empty() && m_currentAsyncCreation.back()) { | |
688 return m_currentAsyncCreation.back(); | |
689 } | |
690 return m_currentAsyncParent.empty() ? nullptr : m_currentAsyncParent.back(); | 686 return m_currentAsyncParent.empty() ? nullptr : m_currentAsyncParent.back(); |
691 } | 687 } |
692 | 688 |
693 std::shared_ptr<AsyncStackTrace> V8Debugger::currentAsyncCreation() { | 689 std::shared_ptr<AsyncStackTrace> V8Debugger::currentAsyncCreation() { |
694 return nullptr; | 690 return m_currentAsyncCreation.empty() ? nullptr |
| 691 : m_currentAsyncCreation.back(); |
695 } | 692 } |
696 | 693 |
697 void V8Debugger::compileDebuggerScript() { | 694 void V8Debugger::compileDebuggerScript() { |
698 if (!m_debuggerScript.IsEmpty()) { | 695 if (!m_debuggerScript.IsEmpty()) { |
699 UNREACHABLE(); | 696 UNREACHABLE(); |
700 return; | 697 return; |
701 } | 698 } |
702 | 699 |
703 v8::HandleScope scope(m_isolate); | 700 v8::HandleScope scope(m_isolate); |
704 v8::Context::Scope contextScope(debuggerContext()); | 701 v8::Context::Scope contextScope(debuggerContext()); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 if (m_maxAsyncCallStackDepth == maxAsyncCallStackDepth) return; | 849 if (m_maxAsyncCallStackDepth == maxAsyncCallStackDepth) return; |
853 m_maxAsyncCallStackDepth = maxAsyncCallStackDepth; | 850 m_maxAsyncCallStackDepth = maxAsyncCallStackDepth; |
854 if (!maxAsyncCallStackDepth) allAsyncTasksCanceled(); | 851 if (!maxAsyncCallStackDepth) allAsyncTasksCanceled(); |
855 } | 852 } |
856 | 853 |
857 void V8Debugger::asyncTaskCreatedForStack(void* task, void* parentTask) { | 854 void V8Debugger::asyncTaskCreatedForStack(void* task, void* parentTask) { |
858 if (!m_maxAsyncCallStackDepth) return; | 855 if (!m_maxAsyncCallStackDepth) return; |
859 if (parentTask) m_parentTask[task] = parentTask; | 856 if (parentTask) m_parentTask[task] = parentTask; |
860 v8::HandleScope scope(m_isolate); | 857 v8::HandleScope scope(m_isolate); |
861 std::shared_ptr<AsyncStackTrace> asyncCreation = | 858 std::shared_ptr<AsyncStackTrace> asyncCreation = |
862 AsyncStackTrace::capture(this, currentContextGroupId(), String16(), | 859 AsyncStackTrace::capture(this, currentContextGroupId(), String16(), 1); |
863 V8StackTraceImpl::maxCallStackSizeToCapture); | |
864 // Passing one as maxStackSize forces no async chain for the new stack. | 860 // Passing one as maxStackSize forces no async chain for the new stack. |
865 if (asyncCreation && !asyncCreation->isEmpty()) { | 861 if (asyncCreation && !asyncCreation->isEmpty()) { |
866 m_asyncTaskCreationStacks[task] = asyncCreation; | 862 m_asyncTaskCreationStacks[task] = asyncCreation; |
867 m_allAsyncStacks.push_back(std::move(asyncCreation)); | 863 m_allAsyncStacks.push_back(std::move(asyncCreation)); |
868 ++m_asyncStacksCount; | 864 ++m_asyncStacksCount; |
869 collectOldAsyncStacksIfNeeded(); | 865 collectOldAsyncStacksIfNeeded(); |
870 } | 866 } |
871 } | 867 } |
872 | 868 |
873 void V8Debugger::asyncTaskScheduled(const StringView& taskName, void* task, | 869 void V8Debugger::asyncTaskScheduled(const StringView& taskName, void* task, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 AsyncTaskToStackTrace::iterator stackIt = m_asyncTaskStacks.find( | 925 AsyncTaskToStackTrace::iterator stackIt = m_asyncTaskStacks.find( |
930 parentIt == m_parentTask.end() ? task : parentIt->second); | 926 parentIt == m_parentTask.end() ? task : parentIt->second); |
931 if (stackIt != m_asyncTaskStacks.end()) { | 927 if (stackIt != m_asyncTaskStacks.end()) { |
932 m_currentAsyncParent.push_back(stackIt->second.lock()); | 928 m_currentAsyncParent.push_back(stackIt->second.lock()); |
933 } else { | 929 } else { |
934 m_currentAsyncParent.emplace_back(); | 930 m_currentAsyncParent.emplace_back(); |
935 } | 931 } |
936 auto itCreation = m_asyncTaskCreationStacks.find(task); | 932 auto itCreation = m_asyncTaskCreationStacks.find(task); |
937 if (itCreation != m_asyncTaskCreationStacks.end()) { | 933 if (itCreation != m_asyncTaskCreationStacks.end()) { |
938 m_currentAsyncCreation.push_back(itCreation->second.lock()); | 934 m_currentAsyncCreation.push_back(itCreation->second.lock()); |
939 // TODO(kozyatinskiy): implement it without hack. | |
940 if (m_currentAsyncParent.back()) { | |
941 m_currentAsyncCreation.back()->setDescription( | |
942 m_currentAsyncParent.back()->description()); | |
943 m_currentAsyncParent.back().reset(); | |
944 } | |
945 } else { | 935 } else { |
946 m_currentAsyncCreation.emplace_back(); | 936 m_currentAsyncCreation.emplace_back(); |
947 } | 937 } |
948 } | 938 } |
949 | 939 |
950 void V8Debugger::asyncTaskFinishedForStack(void* task) { | 940 void V8Debugger::asyncTaskFinishedForStack(void* task) { |
951 if (!m_maxAsyncCallStackDepth) return; | 941 if (!m_maxAsyncCallStackDepth) return; |
952 // We could start instrumenting half way and the stack is empty. | 942 // We could start instrumenting half way and the stack is empty. |
953 if (!m_currentTasks.size()) return; | 943 if (!m_currentTasks.size()) return; |
954 DCHECK(m_currentTasks.back() == task); | 944 DCHECK(m_currentTasks.back() == task); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1092 fprintf(stdout, "Async stacks count: %d\n", m_asyncStacksCount); | 1082 fprintf(stdout, "Async stacks count: %d\n", m_asyncStacksCount); |
1093 fprintf(stdout, "Scheduled async tasks: %zu\n", m_asyncTaskStacks.size()); | 1083 fprintf(stdout, "Scheduled async tasks: %zu\n", m_asyncTaskStacks.size()); |
1094 fprintf(stdout, "Created async tasks: %zu\n", | 1084 fprintf(stdout, "Created async tasks: %zu\n", |
1095 m_asyncTaskCreationStacks.size()); | 1085 m_asyncTaskCreationStacks.size()); |
1096 fprintf(stdout, "Async tasks with parent: %zu\n", m_parentTask.size()); | 1086 fprintf(stdout, "Async tasks with parent: %zu\n", m_parentTask.size()); |
1097 fprintf(stdout, "Recurring async tasks: %zu\n", m_recurringTasks.size()); | 1087 fprintf(stdout, "Recurring async tasks: %zu\n", m_recurringTasks.size()); |
1098 fprintf(stdout, "\n"); | 1088 fprintf(stdout, "\n"); |
1099 } | 1089 } |
1100 | 1090 |
1101 } // namespace v8_inspector | 1091 } // namespace v8_inspector |
OLD | NEW |