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

Side by Side Diff: src/inspector/v8-stack-trace-impl.cc

Issue 2357423002: Improve stack traces for async functions (Closed)
Patch Set: Rebase Created 4 years, 2 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-stack-trace-impl.h" 5 #include "src/inspector/v8-stack-trace-impl.h"
6 6
7 #include "src/inspector/string-util.h" 7 #include "src/inspector/string-util.h"
8 #include "src/inspector/v8-debugger.h" 8 #include "src/inspector/v8-debugger.h"
9 #include "src/inspector/v8-inspector-impl.h" 9 #include "src/inspector/v8-inspector-impl.h"
10 #include "src/inspector/v8-profiler-agent-impl.h" 10 #include "src/inspector/v8-profiler-agent-impl.h"
(...skipping 25 matching lines...) Expand all
36 functionName = toProtocolString(functionNameValue); 36 functionName = toProtocolString(functionNameValue);
37 37
38 int sourceLineNumber = frame->GetLineNumber(); 38 int sourceLineNumber = frame->GetLineNumber();
39 int sourceColumn = frame->GetColumn(); 39 int sourceColumn = frame->GetColumn();
40 return V8StackTraceImpl::Frame(functionName, scriptId, sourceName, 40 return V8StackTraceImpl::Frame(functionName, scriptId, sourceName,
41 sourceLineNumber, sourceColumn); 41 sourceLineNumber, sourceColumn);
42 } 42 }
43 43
44 void toFramesVector(v8::Local<v8::StackTrace> stackTrace, 44 void toFramesVector(v8::Local<v8::StackTrace> stackTrace,
45 std::vector<V8StackTraceImpl::Frame>& frames, 45 std::vector<V8StackTraceImpl::Frame>& frames,
46 size_t maxStackSize, v8::Isolate* isolate) { 46 size_t maxStackSize, v8::Isolate* isolate,
47 int skipInitialFrames) {
47 DCHECK(isolate->InContext()); 48 DCHECK(isolate->InContext());
48 int frameCount = stackTrace->GetFrameCount(); 49 int frameCount = stackTrace->GetFrameCount();
49 if (frameCount > static_cast<int>(maxStackSize)) 50 if (frameCount > static_cast<int>(maxStackSize))
50 frameCount = static_cast<int>(maxStackSize); 51 frameCount = static_cast<int>(maxStackSize);
51 for (int i = 0; i < frameCount; i++) { 52 for (int i = skipInitialFrames; i < frameCount; i++) {
52 v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(i); 53 v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(i);
53 frames.push_back(toFrame(stackFrame)); 54 frames.push_back(toFrame(stackFrame));
54 } 55 }
55 } 56 }
56 57
57 } // namespace 58 } // namespace
58 59
59 V8StackTraceImpl::Frame::Frame() 60 V8StackTraceImpl::Frame::Frame()
60 : m_functionName("undefined"), 61 : m_functionName("undefined"),
61 m_scriptId(""), 62 m_scriptId(""),
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 void V8StackTraceImpl::setCaptureStackTraceForUncaughtExceptions( 102 void V8StackTraceImpl::setCaptureStackTraceForUncaughtExceptions(
102 v8::Isolate* isolate, bool capture) { 103 v8::Isolate* isolate, bool capture) {
103 isolate->SetCaptureStackTraceForUncaughtExceptions( 104 isolate->SetCaptureStackTraceForUncaughtExceptions(
104 capture, V8StackTraceImpl::maxCallStackSizeToCapture, stackTraceOptions); 105 capture, V8StackTraceImpl::maxCallStackSizeToCapture, stackTraceOptions);
105 } 106 }
106 107
107 // static 108 // static
108 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::create( 109 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::create(
109 V8Debugger* debugger, int contextGroupId, 110 V8Debugger* debugger, int contextGroupId,
110 v8::Local<v8::StackTrace> stackTrace, size_t maxStackSize, 111 v8::Local<v8::StackTrace> stackTrace, size_t maxStackSize,
111 const String16& description) { 112 const String16& description, int skipInitialFrames) {
112 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 113 v8::Isolate* isolate = v8::Isolate::GetCurrent();
113 v8::HandleScope scope(isolate); 114 v8::HandleScope scope(isolate);
114 std::vector<V8StackTraceImpl::Frame> frames; 115 std::vector<V8StackTraceImpl::Frame> frames;
115 if (!stackTrace.IsEmpty()) 116 if (!stackTrace.IsEmpty())
116 toFramesVector(stackTrace, frames, maxStackSize, isolate); 117 toFramesVector(stackTrace, frames, maxStackSize, isolate,
118 skipInitialFrames);
117 119
118 int maxAsyncCallChainDepth = 1; 120 int maxAsyncCallChainDepth = 1;
119 V8StackTraceImpl* asyncCallChain = nullptr; 121 V8StackTraceImpl* asyncCallChain = nullptr;
120 if (debugger && maxStackSize > 1) { 122 if (debugger && maxStackSize > 1) {
121 asyncCallChain = debugger->currentAsyncCallChain(); 123 asyncCallChain = debugger->currentAsyncCallChain();
122 maxAsyncCallChainDepth = debugger->maxAsyncCallChainDepth(); 124 maxAsyncCallChainDepth = debugger->maxAsyncCallChainDepth();
123 } 125 }
124 // Do not accidentally append async call chain from another group. This should 126 // Do not accidentally append async call chain from another group. This should
125 // not 127 // not
126 // happen if we have proper instrumentation, but let's double-check to be 128 // happen if we have proper instrumentation, but let's double-check to be
(...skipping 19 matching lines...) Expand all
146 V8StackTraceImpl* deepest = result.get(); 148 V8StackTraceImpl* deepest = result.get();
147 while (deepest && maxAsyncCallChainDepth) { 149 while (deepest && maxAsyncCallChainDepth) {
148 deepest = deepest->m_parent.get(); 150 deepest = deepest->m_parent.get();
149 maxAsyncCallChainDepth--; 151 maxAsyncCallChainDepth--;
150 } 152 }
151 if (deepest) deepest->m_parent.reset(); 153 if (deepest) deepest->m_parent.reset();
152 154
153 return result; 155 return result;
154 } 156 }
155 157
158 // static
156 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::capture( 159 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::capture(
157 V8Debugger* debugger, int contextGroupId, size_t maxStackSize, 160 V8Debugger* debugger, int contextGroupId, size_t maxStackSize,
158 const String16& description) { 161 const String16& description, int skipInitialFrames) {
159 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 162 v8::Isolate* isolate = v8::Isolate::GetCurrent();
160 v8::HandleScope handleScope(isolate); 163 v8::HandleScope handleScope(isolate);
161 v8::Local<v8::StackTrace> stackTrace; 164 v8::Local<v8::StackTrace> stackTrace;
162 if (isolate->InContext()) { 165 if (isolate->InContext()) {
163 if (debugger) { 166 if (debugger) {
164 V8InspectorImpl* inspector = debugger->inspector(); 167 V8InspectorImpl* inspector = debugger->inspector();
165 V8ProfilerAgentImpl* profilerAgent = 168 V8ProfilerAgentImpl* profilerAgent =
166 inspector->enabledProfilerAgentForGroup(contextGroupId); 169 inspector->enabledProfilerAgentForGroup(contextGroupId);
167 if (profilerAgent) profilerAgent->collectSample(); 170 if (profilerAgent) profilerAgent->collectSample();
168 } 171 }
169 stackTrace = v8::StackTrace::CurrentStackTrace( 172 stackTrace = v8::StackTrace::CurrentStackTrace(
170 isolate, static_cast<int>(maxStackSize), stackTraceOptions); 173 isolate, static_cast<int>(maxStackSize), stackTraceOptions);
171 } 174 }
172 return V8StackTraceImpl::create(debugger, contextGroupId, stackTrace, 175 return V8StackTraceImpl::create(debugger, contextGroupId, stackTrace,
173 maxStackSize, description); 176 maxStackSize, description, skipInitialFrames);
174 } 177 }
175 178
176 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::cloneImpl() { 179 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::cloneImpl() {
177 std::vector<Frame> framesCopy(m_frames); 180 std::vector<Frame> framesCopy(m_frames);
178 return wrapUnique( 181 return wrapUnique(
179 new V8StackTraceImpl(m_contextGroupId, m_description, framesCopy, 182 new V8StackTraceImpl(m_contextGroupId, m_description, framesCopy,
180 m_parent ? m_parent->cloneImpl() : nullptr)); 183 m_parent ? m_parent->cloneImpl() : nullptr));
181 } 184 }
182 185
183 std::unique_ptr<V8StackTrace> V8StackTraceImpl::clone() { 186 std::unique_ptr<V8StackTrace> V8StackTraceImpl::clone() {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 stackTrace.append(String16::fromInteger(frame.lineNumber())); 274 stackTrace.append(String16::fromInteger(frame.lineNumber()));
272 stackTrace.append(':'); 275 stackTrace.append(':');
273 stackTrace.append(String16::fromInteger(frame.columnNumber())); 276 stackTrace.append(String16::fromInteger(frame.columnNumber()));
274 stackTrace.append(')'); 277 stackTrace.append(')');
275 } 278 }
276 String16 string = stackTrace.toString(); 279 String16 string = stackTrace.toString();
277 return StringBufferImpl::adopt(string); 280 return StringBufferImpl::adopt(string);
278 } 281 }
279 282
280 } // namespace v8_inspector 283 } // namespace v8_inspector
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698