Chromium Code Reviews| 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 #ifndef V8_INSPECTOR_V8STACKTRACEIMPL_H_ | 5 #ifndef V8_INSPECTOR_V8STACKTRACEIMPL_H_ |
| 6 #define V8_INSPECTOR_V8STACKTRACEIMPL_H_ | 6 #define V8_INSPECTOR_V8STACKTRACEIMPL_H_ |
| 7 | 7 |
| 8 #include <memory> | |
| 8 #include <vector> | 9 #include <vector> |
| 9 | 10 |
| 11 #include "include/v8-inspector.h" | |
| 12 #include "include/v8.h" | |
| 10 #include "src/base/macros.h" | 13 #include "src/base/macros.h" |
| 11 #include "src/inspector/protocol/Forward.h" | |
| 12 #include "src/inspector/protocol/Runtime.h" | 14 #include "src/inspector/protocol/Runtime.h" |
| 13 | 15 #include "src/inspector/string-16.h" |
| 14 #include "include/v8-inspector.h" | |
| 15 | 16 |
| 16 namespace v8_inspector { | 17 namespace v8_inspector { |
| 17 | 18 |
| 19 class AsyncStackTrace; | |
| 18 class V8Debugger; | 20 class V8Debugger; |
| 21 class WasmTranslation; | |
| 19 | 22 |
| 20 // Note: async stack trace may have empty top stack with non-empty tail to | 23 class V8StackTraceImpl : public V8StackTrace { |
| 21 // indicate that current native-only state had some async story. | |
| 22 // On the other hand, any non-top async stack is guaranteed to be non-empty. | |
| 23 class V8StackTraceImpl final : public V8StackTrace { | |
| 24 public: | 24 public: |
| 25 static const size_t maxCallStackSizeToCapture = 200; | |
| 26 | |
| 27 class Frame { | |
| 28 public: | |
| 29 Frame(const String16& functionName, const String16& scriptId, | |
| 30 const String16& scriptName, int lineNumber, int column = 0); | |
| 31 ~Frame() = default; | |
| 32 | |
| 33 const String16& functionName() const { return m_functionName; } | |
| 34 const String16& scriptId() const { return m_scriptId; } | |
| 35 const String16& sourceURL() const { return m_scriptName; } | |
| 36 int lineNumber() const { return m_lineNumber; } | |
| 37 int columnNumber() const { return m_columnNumber; } | |
| 38 | |
| 39 private: | |
| 40 friend class V8StackTraceImpl; | |
| 41 std::unique_ptr<protocol::Runtime::CallFrame> buildInspectorObject() const; | |
| 42 | |
| 43 String16 m_functionName; | |
| 44 String16 m_scriptId; | |
| 45 String16 m_scriptName; | |
| 46 int m_lineNumber; | |
| 47 int m_columnNumber; | |
| 48 }; | |
| 49 | |
| 50 static void setCaptureStackTraceForUncaughtExceptions(v8::Isolate*, | 25 static void setCaptureStackTraceForUncaughtExceptions(v8::Isolate*, |
| 51 bool capture); | 26 bool capture); |
| 52 static std::unique_ptr<V8StackTraceImpl> create( | 27 static const int maxCallStackSizeToCapture = 200; |
| 53 V8Debugger*, int contextGroupId, v8::Local<v8::StackTrace>, | 28 static std::unique_ptr<V8StackTraceImpl> create(V8Debugger*, |
| 54 size_t maxStackSize, const String16& description = String16()); | 29 int contextGroupId, |
| 55 static std::unique_ptr<V8StackTraceImpl> capture( | 30 v8::Local<v8::StackTrace>, |
| 56 V8Debugger*, int contextGroupId, size_t maxStackSize, | 31 int maxStackSize); |
| 57 const String16& description = String16()); | 32 static std::unique_ptr<V8StackTraceImpl> capture(V8Debugger*, |
| 33 int contextGroupId, | |
|
dgozman
2017/04/17 17:49:08
Isn't contextGroupId === debugger->CurrentContextG
kozy
2017/04/17 21:34:17
Not always, I think someone can call captureStackt
dgozman
2017/04/17 23:03:15
We should fix that in a follow-up!
| |
| 34 int maxStackSize); | |
| 58 | 35 |
| 59 // This method drops the async chain. Use cloneImpl() instead. | 36 ~V8StackTraceImpl() override; |
| 60 std::unique_ptr<V8StackTrace> clone() override; | |
| 61 std::unique_ptr<V8StackTraceImpl> cloneImpl(); | |
| 62 static std::unique_ptr<protocol::Runtime::StackTrace> | |
| 63 buildInspectorObjectForTail(V8Debugger*); | |
| 64 std::unique_ptr<protocol::Runtime::StackTrace> buildInspectorObjectImpl() | 37 std::unique_ptr<protocol::Runtime::StackTrace> buildInspectorObjectImpl() |
| 65 const; | 38 const; |
| 66 ~V8StackTraceImpl() override; | |
| 67 | 39 |
| 68 // V8StackTrace implementation. | 40 // V8StackTrace implementation. |
| 69 bool isEmpty() const override { return !m_frames.size(); }; | 41 // This method drops the async stack trace. |
| 42 std::unique_ptr<V8StackTrace> clone() override; | |
| 43 bool isEmpty() const override; | |
| 70 StringView topSourceURL() const override; | 44 StringView topSourceURL() const override; |
| 45 // 1-based. | |
| 71 int topLineNumber() const override; | 46 int topLineNumber() const override; |
| 47 // 1-based. | |
| 72 int topColumnNumber() const override; | 48 int topColumnNumber() const override; |
| 73 StringView topScriptId() const override; | 49 StringView topScriptId() const override; |
| 74 StringView topFunctionName() const override; | 50 StringView topFunctionName() const override; |
| 75 std::unique_ptr<protocol::Runtime::API::StackTrace> buildInspectorObject() | 51 std::unique_ptr<protocol::Runtime::API::StackTrace> buildInspectorObject() |
| 76 const override; | 52 const override; |
| 77 std::unique_ptr<StringBuffer> toString() const override; | 53 std::unique_ptr<StringBuffer> toString() const override; |
| 78 | 54 |
| 55 class Frame { | |
| 56 public: | |
| 57 explicit Frame(v8::Local<v8::StackFrame> frame); | |
| 58 ~Frame() = default; | |
| 59 | |
| 60 void translate(WasmTranslation* wasmTranslation); | |
| 61 | |
| 62 const String16& functionName() const; | |
| 63 const String16& scriptId() const; | |
| 64 const String16& sourceURL() const; | |
| 65 // 0-based. | |
| 66 int lineNumber() const; | |
| 67 // 0-based. | |
| 68 int columnNumber() const; | |
| 69 std::unique_ptr<protocol::Runtime::CallFrame> buildInspectorObject() const; | |
| 70 | |
| 71 private: | |
| 72 String16 m_functionName; | |
| 73 String16 m_scriptId; | |
| 74 String16 m_sourceURL; | |
| 75 // 0-based. | |
| 76 int m_lineNumber; | |
| 77 int m_columnNumber; | |
| 78 }; | |
| 79 | |
| 79 private: | 80 private: |
| 80 V8StackTraceImpl(int contextGroupId, const String16& description, | 81 V8StackTraceImpl(const std::vector<Frame> frames, int maxAsyncDepth, |
| 81 std::vector<Frame>& frames, | 82 std::shared_ptr<AsyncStackTrace> asyncParent, |
| 82 std::unique_ptr<V8StackTraceImpl> parent, | 83 std::shared_ptr<AsyncStackTrace> asyncCreation); |
| 83 std::unique_ptr<V8StackTraceImpl> creation); | |
| 84 | 84 |
| 85 std::unique_ptr<protocol::Runtime::StackTrace> buildInspectorObjectImpl( | |
| 86 V8StackTraceImpl* creation) const; | |
| 87 | |
| 88 int m_contextGroupId; | |
| 89 String16 m_description; | |
| 90 std::vector<Frame> m_frames; | 85 std::vector<Frame> m_frames; |
| 91 std::unique_ptr<V8StackTraceImpl> m_parent; | 86 int m_maxAsyncDepth; |
| 92 std::unique_ptr<V8StackTraceImpl> m_creation; | 87 std::weak_ptr<AsyncStackTrace> m_asyncParent; |
| 88 std::weak_ptr<AsyncStackTrace> m_asyncCreation; | |
| 93 | 89 |
| 94 DISALLOW_COPY_AND_ASSIGN(V8StackTraceImpl); | 90 DISALLOW_COPY_AND_ASSIGN(V8StackTraceImpl); |
| 95 }; | 91 }; |
| 96 | 92 |
| 93 class AsyncStackTrace { | |
| 94 public: | |
| 95 static std::shared_ptr<AsyncStackTrace> capture(V8Debugger*, | |
| 96 int contextGroupId, | |
| 97 const String16& description, | |
| 98 int maxStackSize); | |
| 99 | |
| 100 std::unique_ptr<protocol::Runtime::StackTrace> buildInspectorObject( | |
| 101 AsyncStackTrace* asyncCreation, int maxAsyncDepth) const; | |
| 102 | |
| 103 int contextGroupId() const; | |
| 104 std::weak_ptr<AsyncStackTrace> parent() const; | |
| 105 std::weak_ptr<AsyncStackTrace> creation() const; | |
| 106 bool isEmpty() const; | |
| 107 | |
| 108 private: | |
| 109 AsyncStackTrace(int contextGroupId, const String16& description, | |
| 110 const std::vector<V8StackTraceImpl::Frame>& frames, | |
| 111 std::shared_ptr<AsyncStackTrace> asyncParent, | |
| 112 std::shared_ptr<AsyncStackTrace> asyncCreation); | |
| 113 | |
| 114 int m_contextGroupId; | |
| 115 String16 m_description; | |
| 116 | |
| 117 std::vector<V8StackTraceImpl::Frame> m_frames; | |
| 118 std::weak_ptr<AsyncStackTrace> m_asyncParent; | |
| 119 std::weak_ptr<AsyncStackTrace> m_asyncCreation; | |
| 120 | |
| 121 DISALLOW_COPY_AND_ASSIGN(AsyncStackTrace); | |
| 122 }; | |
| 123 | |
| 97 } // namespace v8_inspector | 124 } // namespace v8_inspector |
| 98 | 125 |
| 99 #endif // V8_INSPECTOR_V8STACKTRACEIMPL_H_ | 126 #endif // V8_INSPECTOR_V8STACKTRACEIMPL_H_ |
| OLD | NEW |