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

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

Issue 2648873002: [inspector] added creation frame for async call chains for promises (Closed)
Patch Set: add test for setTimeout Created 3 years, 11 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
« no previous file with comments | « src/inspector/v8-stack-trace-impl.h ('k') | test/inspector/debugger/async-stack-await.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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-agent-impl.h" 8 #include "src/inspector/v8-debugger-agent-impl.h"
9 #include "src/inspector/v8-debugger.h" 9 #include "src/inspector/v8-debugger.h"
10 #include "src/inspector/v8-inspector-impl.h" 10 #include "src/inspector/v8-inspector-impl.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 // Do not accidentally append async call chain from another group. This should 134 // Do not accidentally append async call chain from another group. This should
135 // not 135 // not
136 // happen if we have proper instrumentation, but let's double-check to be 136 // happen if we have proper instrumentation, but let's double-check to be
137 // safe. 137 // safe.
138 if (contextGroupId && asyncCallChain && asyncCallChain->m_contextGroupId && 138 if (contextGroupId && asyncCallChain && asyncCallChain->m_contextGroupId &&
139 asyncCallChain->m_contextGroupId != contextGroupId) { 139 asyncCallChain->m_contextGroupId != contextGroupId) {
140 asyncCallChain = nullptr; 140 asyncCallChain = nullptr;
141 maxAsyncCallChainDepth = 1; 141 maxAsyncCallChainDepth = 1;
142 } 142 }
143 143
144 // Only the top stack in the chain may be empty, so ensure that second stack 144 // Only the top stack in the chain may be empty and doesn't contain creation
145 // is non-empty (it's the top of appended chain). 145 // stack , so ensure that second stack is non-empty (it's the top of appended
146 if (asyncCallChain && asyncCallChain->isEmpty()) 146 // chain).
147 if (asyncCallChain && asyncCallChain->isEmpty() &&
148 !asyncCallChain->m_creation) {
147 asyncCallChain = asyncCallChain->m_parent.get(); 149 asyncCallChain = asyncCallChain->m_parent.get();
150 }
148 151
149 if (stackTrace.IsEmpty() && !asyncCallChain) return nullptr; 152 if (stackTrace.IsEmpty() && !asyncCallChain) return nullptr;
150 153
151 std::unique_ptr<V8StackTraceImpl> result(new V8StackTraceImpl( 154 std::unique_ptr<V8StackTraceImpl> result(new V8StackTraceImpl(
152 contextGroupId, description, frames, 155 contextGroupId, description, frames,
153 asyncCallChain ? asyncCallChain->cloneImpl() : nullptr)); 156 asyncCallChain ? asyncCallChain->cloneImpl() : nullptr));
154 157
155 // Crop to not exceed maxAsyncCallChainDepth. 158 // Crop to not exceed maxAsyncCallChainDepth.
156 V8StackTraceImpl* deepest = result.get(); 159 V8StackTraceImpl* deepest = result.get();
157 while (deepest && maxAsyncCallChainDepth) { 160 while (deepest && maxAsyncCallChainDepth) {
(...skipping 15 matching lines...) Expand all
173 if (isolate->InContext()) { 176 if (isolate->InContext()) {
174 stackTrace = v8::StackTrace::CurrentStackTrace( 177 stackTrace = v8::StackTrace::CurrentStackTrace(
175 isolate, static_cast<int>(maxStackSize), stackTraceOptions); 178 isolate, static_cast<int>(maxStackSize), stackTraceOptions);
176 } 179 }
177 return V8StackTraceImpl::create(debugger, contextGroupId, stackTrace, 180 return V8StackTraceImpl::create(debugger, contextGroupId, stackTrace,
178 maxStackSize, description); 181 maxStackSize, description);
179 } 182 }
180 183
181 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::cloneImpl() { 184 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::cloneImpl() {
182 std::vector<Frame> framesCopy(m_frames); 185 std::vector<Frame> framesCopy(m_frames);
183 return std::unique_ptr<V8StackTraceImpl>( 186 std::unique_ptr<V8StackTraceImpl> copy(
184 new V8StackTraceImpl(m_contextGroupId, m_description, framesCopy, 187 new V8StackTraceImpl(m_contextGroupId, m_description, framesCopy,
185 m_parent ? m_parent->cloneImpl() : nullptr)); 188 m_parent ? m_parent->cloneImpl() : nullptr));
189 if (m_creation) copy->setCreation(m_creation->cloneImpl());
190 return copy;
186 } 191 }
187 192
188 std::unique_ptr<V8StackTrace> V8StackTraceImpl::clone() { 193 std::unique_ptr<V8StackTrace> V8StackTraceImpl::clone() {
189 std::vector<Frame> frames; 194 std::vector<Frame> frames;
190 for (size_t i = 0; i < m_frames.size(); i++) 195 for (size_t i = 0; i < m_frames.size(); i++)
191 frames.push_back(m_frames.at(i).clone()); 196 frames.push_back(m_frames.at(i).clone());
192 return std::unique_ptr<V8StackTraceImpl>( 197 return std::unique_ptr<V8StackTraceImpl>(
193 new V8StackTraceImpl(m_contextGroupId, m_description, frames, nullptr)); 198 new V8StackTraceImpl(m_contextGroupId, m_description, frames, nullptr));
194 } 199 }
195 200
196 V8StackTraceImpl::V8StackTraceImpl(int contextGroupId, 201 V8StackTraceImpl::V8StackTraceImpl(int contextGroupId,
197 const String16& description, 202 const String16& description,
198 std::vector<Frame>& frames, 203 std::vector<Frame>& frames,
199 std::unique_ptr<V8StackTraceImpl> parent) 204 std::unique_ptr<V8StackTraceImpl> parent)
200 : m_contextGroupId(contextGroupId), 205 : m_contextGroupId(contextGroupId),
201 m_description(description), 206 m_description(description),
202 m_parent(std::move(parent)) { 207 m_parent(std::move(parent)) {
203 m_frames.swap(frames); 208 m_frames.swap(frames);
204 } 209 }
205 210
206 V8StackTraceImpl::~V8StackTraceImpl() {} 211 V8StackTraceImpl::~V8StackTraceImpl() {}
207 212
213 void V8StackTraceImpl::setCreation(std::unique_ptr<V8StackTraceImpl> creation) {
214 m_creation = std::move(creation);
215 // When async call chain is empty but doesn't contain useful schedule stack
216 // and parent async call chain contains creationg stack but doesn't
217 // synchronous we can merge them together.
218 // e.g. Promise ThenableJob.
219 if (m_parent && isEmpty() && m_description == m_parent->m_description &&
220 !m_parent->m_creation) {
221 m_frames.swap(m_parent->m_frames);
222 m_parent = std::move(m_parent->m_parent);
223 }
224 }
225
208 StringView V8StackTraceImpl::topSourceURL() const { 226 StringView V8StackTraceImpl::topSourceURL() const {
209 DCHECK(m_frames.size()); 227 DCHECK(m_frames.size());
210 return toStringView(m_frames[0].m_scriptName); 228 return toStringView(m_frames[0].m_scriptName);
211 } 229 }
212 230
213 int V8StackTraceImpl::topLineNumber() const { 231 int V8StackTraceImpl::topLineNumber() const {
214 DCHECK(m_frames.size()); 232 DCHECK(m_frames.size());
215 return m_frames[0].m_lineNumber; 233 return m_frames[0].m_lineNumber;
216 } 234 }
217 235
(...skipping 18 matching lines...) Expand all
236 protocol::Array<protocol::Runtime::CallFrame>::create(); 254 protocol::Array<protocol::Runtime::CallFrame>::create();
237 for (size_t i = 0; i < m_frames.size(); i++) 255 for (size_t i = 0; i < m_frames.size(); i++)
238 frames->addItem(m_frames.at(i).buildInspectorObject()); 256 frames->addItem(m_frames.at(i).buildInspectorObject());
239 257
240 std::unique_ptr<protocol::Runtime::StackTrace> stackTrace = 258 std::unique_ptr<protocol::Runtime::StackTrace> stackTrace =
241 protocol::Runtime::StackTrace::create() 259 protocol::Runtime::StackTrace::create()
242 .setCallFrames(std::move(frames)) 260 .setCallFrames(std::move(frames))
243 .build(); 261 .build();
244 if (!m_description.isEmpty()) stackTrace->setDescription(m_description); 262 if (!m_description.isEmpty()) stackTrace->setDescription(m_description);
245 if (m_parent) stackTrace->setParent(m_parent->buildInspectorObjectImpl()); 263 if (m_parent) stackTrace->setParent(m_parent->buildInspectorObjectImpl());
264 if (m_creation && m_creation->m_frames.size()) {
265 stackTrace->setPromiseCreationFrame(
266 m_creation->m_frames[0].buildInspectorObject());
267 }
246 return stackTrace; 268 return stackTrace;
247 } 269 }
248 270
249 std::unique_ptr<protocol::Runtime::StackTrace> 271 std::unique_ptr<protocol::Runtime::StackTrace>
250 V8StackTraceImpl::buildInspectorObjectForTail(V8Debugger* debugger) const { 272 V8StackTraceImpl::buildInspectorObjectForTail(V8Debugger* debugger) const {
251 v8::HandleScope handleScope(v8::Isolate::GetCurrent()); 273 v8::HandleScope handleScope(v8::Isolate::GetCurrent());
252 // Next call collapses possible empty stack and ensures 274 // Next call collapses possible empty stack and ensures
253 // maxAsyncCallChainDepth. 275 // maxAsyncCallChainDepth.
254 std::unique_ptr<V8StackTraceImpl> fullChain = V8StackTraceImpl::create( 276 std::unique_ptr<V8StackTraceImpl> fullChain = V8StackTraceImpl::create(
255 debugger, m_contextGroupId, v8::Local<v8::StackTrace>(), 277 debugger, m_contextGroupId, v8::Local<v8::StackTrace>(),
(...skipping 20 matching lines...) Expand all
276 stackTrace.append(String16::fromInteger(frame.lineNumber())); 298 stackTrace.append(String16::fromInteger(frame.lineNumber()));
277 stackTrace.append(':'); 299 stackTrace.append(':');
278 stackTrace.append(String16::fromInteger(frame.columnNumber())); 300 stackTrace.append(String16::fromInteger(frame.columnNumber()));
279 stackTrace.append(')'); 301 stackTrace.append(')');
280 } 302 }
281 String16 string = stackTrace.toString(); 303 String16 string = stackTrace.toString();
282 return StringBufferImpl::adopt(string); 304 return StringBufferImpl::adopt(string);
283 } 305 }
284 306
285 } // namespace v8_inspector 307 } // namespace v8_inspector
OLDNEW
« no previous file with comments | « src/inspector/v8-stack-trace-impl.h ('k') | test/inspector/debugger/async-stack-await.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698