v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
v8-stack-trace-impl.h
Go to the documentation of this file.
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
3// found in the LICENSE file.
4
5#ifndef V8_INSPECTOR_V8_STACK_TRACE_IMPL_H_
6#define V8_INSPECTOR_V8_STACK_TRACE_IMPL_H_
7
8#include <memory>
9#include <vector>
10
13#include "src/base/macros.h"
14#include "src/inspector/protocol/Runtime.h"
16
17namespace v8 {
18class StackFrame;
19class StackTrace;
20} // namespace v8
21
22namespace v8_inspector {
23
24class AsyncStackTrace;
25class V8Debugger;
26struct V8StackTraceId;
27
29 public:
31 int lineNumber, int columnNumber, bool hasSourceURLComment);
32 ~StackFrame() = default;
33
34 const String16& functionName() const;
35 int scriptId() const;
36 const String16& sourceURL() const;
37 int lineNumber() const; // 0-based.
38 int columnNumber() const; // 0-based.
39 std::unique_ptr<protocol::Runtime::CallFrame> buildInspectorObject(
40 V8InspectorClient* client) const;
41 bool isEqual(StackFrame* frame) const;
42
43 private:
47 int m_lineNumber; // 0-based.
48 int m_columnNumber; // 0-based.
50};
51
53 public:
54 static constexpr int kDefaultMaxCallStackSizeToCapture = 200;
55
56 static std::unique_ptr<V8StackTraceImpl> create(V8Debugger*,
58 int maxStackSize);
59 static std::unique_ptr<V8StackTraceImpl> capture(V8Debugger*,
60 int maxStackSize);
61
65 std::unique_ptr<protocol::Runtime::StackTrace> buildInspectorObjectImpl(
66 V8Debugger* debugger) const;
67
68 std::unique_ptr<protocol::Runtime::StackTrace> buildInspectorObjectImpl(
69 V8Debugger* debugger, int maxAsyncDepth) const;
70
71 // V8StackTrace implementation.
72 // This method drops the async stack trace.
73 std::unique_ptr<V8StackTrace> clone() override;
74 StringView firstNonEmptySourceURL() const override;
75 bool isEmpty() const override;
76 StringView topSourceURL() const override;
77 int topLineNumber() const override; // 1-based.
78 int topColumnNumber() const override; // 1-based.
79 int topScriptId() const override;
80 StringView topFunctionName() const override;
81 std::unique_ptr<protocol::Runtime::API::StackTrace> buildInspectorObject(
82 int maxAsyncDepth) const override;
83 std::unique_ptr<StringBuffer> toString() const override;
84
85 bool isEqualIgnoringTopFrame(V8StackTraceImpl* stackTrace) const;
86
87 std::vector<V8StackFrame> frames() const override;
88
89 private:
90 V8StackTraceImpl(std::vector<std::shared_ptr<StackFrame>> frames,
91 int maxAsyncDepth,
92 std::shared_ptr<AsyncStackTrace> asyncParent,
93 const V8StackTraceId& externalParent);
94
96 public:
97 explicit StackFrameIterator(const V8StackTraceImpl* stackTrace);
98
99 void next();
100 StackFrame* frame();
101 bool done();
102
103 private:
104 std::vector<std::shared_ptr<StackFrame>>::const_iterator m_currentIt;
105 std::vector<std::shared_ptr<StackFrame>>::const_iterator m_currentEnd;
107 };
108
109 std::vector<std::shared_ptr<StackFrame>> m_frames;
111 std::weak_ptr<AsyncStackTrace> m_asyncParent;
113};
114
116 public:
119 static std::shared_ptr<AsyncStackTrace> capture(V8Debugger*,
120 const String16& description,
121 bool skipTopFrame = false);
122 static uintptr_t store(V8Debugger* debugger,
123 std::shared_ptr<AsyncStackTrace> stack);
124
125 std::unique_ptr<protocol::Runtime::StackTrace> buildInspectorObject(
126 V8Debugger* debugger, int maxAsyncDepth) const;
127
128 const String16& description() const;
129 std::weak_ptr<AsyncStackTrace> parent() const;
130 bool isEmpty() const;
132
133 const std::vector<std::shared_ptr<StackFrame>>& frames() const {
134 return m_frames;
135 }
136
137 private:
139 std::vector<std::shared_ptr<StackFrame>> frames,
140 std::shared_ptr<AsyncStackTrace> asyncParent,
142
143 uintptr_t m_id;
145
146 std::vector<std::shared_ptr<StackFrame>> m_frames;
147 std::weak_ptr<AsyncStackTrace> m_asyncParent;
149};
150
151} // namespace v8_inspector
152
153#endif // V8_INSPECTOR_V8_STACK_TRACE_IMPL_H_
std::weak_ptr< AsyncStackTrace > parent() const
static std::shared_ptr< AsyncStackTrace > capture(V8Debugger *, const String16 &description, bool skipTopFrame=false)
const String16 & description() const
std::vector< std::shared_ptr< StackFrame > > m_frames
static uintptr_t store(V8Debugger *debugger, std::shared_ptr< AsyncStackTrace > stack)
const std::vector< std::shared_ptr< StackFrame > > & frames() const
std::unique_ptr< protocol::Runtime::StackTrace > buildInspectorObject(V8Debugger *debugger, int maxAsyncDepth) const
const V8StackTraceId & externalParent() const
AsyncStackTrace(const AsyncStackTrace &)=delete
AsyncStackTrace & operator=(const AsyncStackTrace &)=delete
std::weak_ptr< AsyncStackTrace > m_asyncParent
StackFrame(String16 &&functionName, int scriptId, String16 &&sourceURL, int lineNumber, int columnNumber, bool hasSourceURLComment)
bool isEqual(StackFrame *frame) const
std::unique_ptr< protocol::Runtime::CallFrame > buildInspectorObject(V8InspectorClient *client) const
const String16 & functionName() const
const String16 & sourceURL() const
std::vector< std::shared_ptr< StackFrame > >::const_iterator m_currentIt
StackFrameIterator(const V8StackTraceImpl *stackTrace)
std::vector< std::shared_ptr< StackFrame > >::const_iterator m_currentEnd
static std::unique_ptr< V8StackTraceImpl > capture(V8Debugger *, int maxStackSize)
StringView firstNonEmptySourceURL() const override
std::unique_ptr< protocol::Runtime::StackTrace > buildInspectorObjectImpl(V8Debugger *debugger) const
std::unique_ptr< StringBuffer > toString() const override
static std::unique_ptr< V8StackTraceImpl > create(V8Debugger *, v8::Local< v8::StackTrace >, int maxStackSize)
V8StackTraceImpl & operator=(const V8StackTraceImpl &)=delete
StringView topSourceURL() const override
V8StackTraceImpl(const V8StackTraceImpl &)=delete
std::unique_ptr< protocol::Runtime::API::StackTrace > buildInspectorObject(int maxAsyncDepth) const override
bool isEqualIgnoringTopFrame(V8StackTraceImpl *stackTrace) const
std::unique_ptr< V8StackTrace > clone() override
std::vector< V8StackFrame > frames() const override
StringView topFunctionName() const override
std::weak_ptr< AsyncStackTrace > m_asyncParent
std::vector< std::shared_ptr< StackFrame > > m_frames
static constexpr int kDefaultMaxCallStackSizeToCapture