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