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

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

Issue 2357423002: Improve stack traces for async functions (Closed)
Patch Set: Format Created 4 years, 3 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 bool skipInitialFrame) {
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 = skipInitialFrame ? 1 : 0; 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, bool skipInitialFrame) {
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, skipInitialFrame);
117 118
118 int maxAsyncCallChainDepth = 1; 119 int maxAsyncCallChainDepth = 1;
119 V8StackTraceImpl* asyncCallChain = nullptr; 120 V8StackTraceImpl* asyncCallChain = nullptr;
120 if (debugger && maxStackSize > 1) { 121 if (debugger && maxStackSize > 1) {
121 asyncCallChain = debugger->currentAsyncCallChain(); 122 asyncCallChain = debugger->currentAsyncCallChain();
122 maxAsyncCallChainDepth = debugger->maxAsyncCallChainDepth(); 123 maxAsyncCallChainDepth = debugger->maxAsyncCallChainDepth();
123 } 124 }
124 // Do not accidentally append async call chain from another group. This should 125 // Do not accidentally append async call chain from another group. This should
125 // not 126 // not
126 // happen if we have proper instrumentation, but let's double-check to be 127 // happen if we have proper instrumentation, but let's double-check to be
(...skipping 19 matching lines...) Expand all
146 V8StackTraceImpl* deepest = result.get(); 147 V8StackTraceImpl* deepest = result.get();
147 while (deepest && maxAsyncCallChainDepth) { 148 while (deepest && maxAsyncCallChainDepth) {
148 deepest = deepest->m_parent.get(); 149 deepest = deepest->m_parent.get();
149 maxAsyncCallChainDepth--; 150 maxAsyncCallChainDepth--;
150 } 151 }
151 if (deepest) deepest->m_parent.reset(); 152 if (deepest) deepest->m_parent.reset();
152 153
153 return result; 154 return result;
154 } 155 }
155 156
157 // static
156 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::capture( 158 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::capture(
157 V8Debugger* debugger, int contextGroupId, size_t maxStackSize, 159 V8Debugger* debugger, int contextGroupId, size_t maxStackSize,
158 const String16& description) { 160 const String16& description, bool skipInitialFrame) {
159 v8::Isolate* isolate = v8::Isolate::GetCurrent(); 161 v8::Isolate* isolate = v8::Isolate::GetCurrent();
160 v8::HandleScope handleScope(isolate); 162 v8::HandleScope handleScope(isolate);
161 v8::Local<v8::StackTrace> stackTrace; 163 v8::Local<v8::StackTrace> stackTrace;
162 if (isolate->InContext()) { 164 if (isolate->InContext()) {
163 if (debugger) { 165 if (debugger) {
164 V8InspectorImpl* inspector = debugger->inspector(); 166 V8InspectorImpl* inspector = debugger->inspector();
165 V8ProfilerAgentImpl* profilerAgent = 167 V8ProfilerAgentImpl* profilerAgent =
166 inspector->enabledProfilerAgentForGroup(contextGroupId); 168 inspector->enabledProfilerAgentForGroup(contextGroupId);
167 if (profilerAgent) profilerAgent->collectSample(); 169 if (profilerAgent) profilerAgent->collectSample();
168 } 170 }
169 stackTrace = v8::StackTrace::CurrentStackTrace( 171 stackTrace = v8::StackTrace::CurrentStackTrace(
170 isolate, static_cast<int>(maxStackSize), stackTraceOptions); 172 isolate, static_cast<int>(maxStackSize), stackTraceOptions);
171 } 173 }
172 return V8StackTraceImpl::create(debugger, contextGroupId, stackTrace, 174 return V8StackTraceImpl::create(debugger, contextGroupId, stackTrace,
173 maxStackSize, description); 175 maxStackSize, description, skipInitialFrame);
174 } 176 }
175 177
176 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::cloneImpl() { 178 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::cloneImpl() {
177 std::vector<Frame> framesCopy(m_frames); 179 std::vector<Frame> framesCopy(m_frames);
178 return wrapUnique( 180 return wrapUnique(
179 new V8StackTraceImpl(m_contextGroupId, m_description, framesCopy, 181 new V8StackTraceImpl(m_contextGroupId, m_description, framesCopy,
180 m_parent ? m_parent->cloneImpl() : nullptr)); 182 m_parent ? m_parent->cloneImpl() : nullptr));
181 } 183 }
182 184
183 std::unique_ptr<V8StackTrace> V8StackTraceImpl::clone() { 185 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())); 273 stackTrace.append(String16::fromInteger(frame.lineNumber()));
272 stackTrace.append(':'); 274 stackTrace.append(':');
273 stackTrace.append(String16::fromInteger(frame.columnNumber())); 275 stackTrace.append(String16::fromInteger(frame.columnNumber()));
274 stackTrace.append(')'); 276 stackTrace.append(')');
275 } 277 }
276 String16 string = stackTrace.toString(); 278 String16 string = stackTrace.toString();
277 return StringBufferImpl::adopt(string); 279 return StringBufferImpl::adopt(string);
278 } 280 }
279 281
280 } // namespace v8_inspector 282 } // namespace v8_inspector
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698