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-stack-trace-impl.h" | 5 #include "src/inspector/v8-stack-trace-impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "src/inspector/v8-debugger.h" | 9 #include "src/inspector/v8-debugger.h" |
10 #include "src/inspector/wasm-translation.h" | 10 #include "src/inspector/wasm-translation.h" |
(...skipping 30 matching lines...) Expand all Loading... |
41 *asyncParent = debugger->currentAsyncParent(); | 41 *asyncParent = debugger->currentAsyncParent(); |
42 *asyncCreation = debugger->currentAsyncCreation(); | 42 *asyncCreation = debugger->currentAsyncCreation(); |
43 if (maxAsyncDepth) *maxAsyncDepth = debugger->maxAsyncCallChainDepth(); | 43 if (maxAsyncDepth) *maxAsyncDepth = debugger->maxAsyncCallChainDepth(); |
44 | 44 |
45 DCHECK(!*asyncParent || !*asyncCreation || | 45 DCHECK(!*asyncParent || !*asyncCreation || |
46 (*asyncParent)->contextGroupId() == | 46 (*asyncParent)->contextGroupId() == |
47 (*asyncCreation)->contextGroupId()); | 47 (*asyncCreation)->contextGroupId()); |
48 // Do not accidentally append async call chain from another group. This should | 48 // Do not accidentally append async call chain from another group. This should |
49 // not happen if we have proper instrumentation, but let's double-check to be | 49 // not happen if we have proper instrumentation, but let's double-check to be |
50 // safe. | 50 // safe. |
51 if (contextGroupId && *asyncParent && (*asyncParent)->contextGroupId() && | 51 if (contextGroupId && *asyncParent && |
52 (*asyncParent)->contextGroupId() != contextGroupId) { | 52 (*asyncParent)->contextGroupId() != contextGroupId) { |
53 asyncParent->reset(); | 53 asyncParent->reset(); |
54 asyncCreation->reset(); | 54 asyncCreation->reset(); |
55 if (maxAsyncDepth) *maxAsyncDepth = 0; | 55 if (maxAsyncDepth) *maxAsyncDepth = 0; |
56 return; | 56 return; |
57 } | 57 } |
58 | 58 |
59 // Only the top stack in the chain may be empty and doesn't contain creation | 59 // Only the top stack in the chain may be empty and doesn't contain creation |
60 // stack, so ensure that second stack is non-empty (it's the top of appended | 60 // stack, so ensure that second stack is non-empty (it's the top of appended |
61 // chain). | 61 // chain). |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 | 267 |
268 // When async call chain is empty but doesn't contain useful schedule stack | 268 // When async call chain is empty but doesn't contain useful schedule stack |
269 // and parent async call chain contains creationg stack but doesn't | 269 // and parent async call chain contains creationg stack but doesn't |
270 // synchronous we can merge them together. | 270 // synchronous we can merge them together. |
271 // e.g. Promise ThenableJob. | 271 // e.g. Promise ThenableJob. |
272 if (asyncParent && frames.empty() && | 272 if (asyncParent && frames.empty() && |
273 asyncParent->m_description == description && !asyncCreation) { | 273 asyncParent->m_description == description && !asyncCreation) { |
274 return asyncParent; | 274 return asyncParent; |
275 } | 275 } |
276 | 276 |
| 277 DCHECK(contextGroupId || asyncParent); |
| 278 if (!contextGroupId && asyncParent) { |
| 279 contextGroupId = asyncParent->m_contextGroupId; |
| 280 } |
277 return std::shared_ptr<AsyncStackTrace>(new AsyncStackTrace( | 281 return std::shared_ptr<AsyncStackTrace>(new AsyncStackTrace( |
278 contextGroupId, description, frames, asyncParent, asyncCreation)); | 282 contextGroupId, description, frames, asyncParent, asyncCreation)); |
279 } | 283 } |
280 | 284 |
281 AsyncStackTrace::AsyncStackTrace( | 285 AsyncStackTrace::AsyncStackTrace( |
282 int contextGroupId, const String16& description, | 286 int contextGroupId, const String16& description, |
283 const std::vector<V8StackTraceImpl::Frame>& frames, | 287 const std::vector<V8StackTraceImpl::Frame>& frames, |
284 std::shared_ptr<AsyncStackTrace> asyncParent, | 288 std::shared_ptr<AsyncStackTrace> asyncParent, |
285 std::shared_ptr<AsyncStackTrace> asyncCreation) | 289 std::shared_ptr<AsyncStackTrace> asyncCreation) |
286 : m_contextGroupId(contextGroupId), | 290 : m_contextGroupId(contextGroupId), |
287 m_description(description), | 291 m_description(description), |
288 m_frames(frames), | 292 m_frames(frames), |
289 m_asyncParent(asyncParent), | 293 m_asyncParent(asyncParent), |
290 m_asyncCreation(asyncCreation) {} | 294 m_asyncCreation(asyncCreation) { |
| 295 DCHECK(m_contextGroupId); |
| 296 } |
291 | 297 |
292 std::unique_ptr<protocol::Runtime::StackTrace> | 298 std::unique_ptr<protocol::Runtime::StackTrace> |
293 AsyncStackTrace::buildInspectorObject(AsyncStackTrace* asyncCreation, | 299 AsyncStackTrace::buildInspectorObject(AsyncStackTrace* asyncCreation, |
294 int maxAsyncDepth) const { | 300 int maxAsyncDepth) const { |
295 std::unique_ptr<protocol::Runtime::StackTrace> stackTrace = | 301 std::unique_ptr<protocol::Runtime::StackTrace> stackTrace = |
296 buildInspectorObjectCommon(m_frames, m_asyncParent.lock(), | 302 buildInspectorObjectCommon(m_frames, m_asyncParent.lock(), |
297 m_asyncCreation.lock(), maxAsyncDepth); | 303 m_asyncCreation.lock(), maxAsyncDepth); |
298 if (!m_description.isEmpty()) stackTrace->setDescription(m_description); | 304 if (!m_description.isEmpty()) stackTrace->setDescription(m_description); |
299 if (asyncCreation && !asyncCreation->isEmpty()) { | 305 if (asyncCreation && !asyncCreation->isEmpty()) { |
300 stackTrace->setPromiseCreationFrame( | 306 stackTrace->setPromiseCreationFrame( |
301 asyncCreation->m_frames[0].buildInspectorObject()); | 307 asyncCreation->m_frames[0].buildInspectorObject()); |
302 } | 308 } |
303 return stackTrace; | 309 return stackTrace; |
304 } | 310 } |
305 | 311 |
306 int AsyncStackTrace::contextGroupId() const { return m_contextGroupId; } | 312 int AsyncStackTrace::contextGroupId() const { return m_contextGroupId; } |
307 | 313 |
308 std::weak_ptr<AsyncStackTrace> AsyncStackTrace::parent() const { | 314 std::weak_ptr<AsyncStackTrace> AsyncStackTrace::parent() const { |
309 return m_asyncParent; | 315 return m_asyncParent; |
310 } | 316 } |
311 | 317 |
312 std::weak_ptr<AsyncStackTrace> AsyncStackTrace::creation() const { | 318 std::weak_ptr<AsyncStackTrace> AsyncStackTrace::creation() const { |
313 return m_asyncCreation; | 319 return m_asyncCreation; |
314 } | 320 } |
315 | 321 |
316 bool AsyncStackTrace::isEmpty() const { return m_frames.empty(); } | 322 bool AsyncStackTrace::isEmpty() const { return m_frames.empty(); } |
317 | 323 |
318 } // namespace v8_inspector | 324 } // namespace v8_inspector |
OLD | NEW |