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 "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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 void V8StackTraceImpl::setCaptureStackTraceForUncaughtExceptions( | 110 void V8StackTraceImpl::setCaptureStackTraceForUncaughtExceptions( |
111 v8::Isolate* isolate, bool capture) { | 111 v8::Isolate* isolate, bool capture) { |
112 isolate->SetCaptureStackTraceForUncaughtExceptions( | 112 isolate->SetCaptureStackTraceForUncaughtExceptions( |
113 capture, V8StackTraceImpl::maxCallStackSizeToCapture, stackTraceOptions); | 113 capture, V8StackTraceImpl::maxCallStackSizeToCapture, stackTraceOptions); |
114 } | 114 } |
115 | 115 |
116 // static | 116 // static |
117 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::create( | 117 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::create( |
118 V8Debugger* debugger, int contextGroupId, | 118 V8Debugger* debugger, int contextGroupId, |
119 v8::Local<v8::StackTrace> stackTrace, size_t maxStackSize, | 119 v8::Local<v8::StackTrace> stackTrace, size_t maxStackSize, |
120 const String16& description) { | 120 const String16& description, |
121 std::unique_ptr<V8StackTraceImpl> creationStackTrace) { | |
121 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 122 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
122 v8::HandleScope scope(isolate); | 123 v8::HandleScope scope(isolate); |
123 std::vector<V8StackTraceImpl::Frame> frames; | 124 std::vector<V8StackTraceImpl::Frame> frames; |
124 if (!stackTrace.IsEmpty()) | 125 if (!stackTrace.IsEmpty()) |
125 toFramesVector(stackTrace, frames, maxStackSize, isolate, debugger, | 126 toFramesVector(stackTrace, frames, maxStackSize, isolate, debugger, |
126 contextGroupId); | 127 contextGroupId); |
127 | 128 |
128 int maxAsyncCallChainDepth = 1; | 129 int maxAsyncCallChainDepth = 1; |
129 V8StackTraceImpl* asyncCallChain = nullptr; | 130 V8StackTraceImpl* asyncCallChain = nullptr; |
131 V8StackTraceImpl* creationCallChain = nullptr; | |
dgozman
2017/01/24 01:02:41
Remove.
kozy
2017/01/24 21:43:39
Done.
| |
130 if (debugger && maxStackSize > 1) { | 132 if (debugger && maxStackSize > 1) { |
131 asyncCallChain = debugger->currentAsyncCallChain(); | 133 asyncCallChain = debugger->currentAsyncCallChain(); |
132 maxAsyncCallChainDepth = debugger->maxAsyncCallChainDepth(); | 134 maxAsyncCallChainDepth = debugger->maxAsyncCallChainDepth(); |
133 } | 135 } |
134 // Do not accidentally append async call chain from another group. This should | 136 // Do not accidentally append async call chain from another group. This should |
135 // not | 137 // not |
136 // happen if we have proper instrumentation, but let's double-check to be | 138 // happen if we have proper instrumentation, but let's double-check to be |
137 // safe. | 139 // safe. |
138 if (contextGroupId && asyncCallChain && asyncCallChain->m_contextGroupId && | 140 if (contextGroupId && asyncCallChain && asyncCallChain->m_contextGroupId && |
139 asyncCallChain->m_contextGroupId != contextGroupId) { | 141 asyncCallChain->m_contextGroupId != contextGroupId) { |
140 asyncCallChain = nullptr; | 142 asyncCallChain = nullptr; |
141 maxAsyncCallChainDepth = 1; | 143 maxAsyncCallChainDepth = 1; |
142 } | 144 } |
143 | 145 |
144 // Only the top stack in the chain may be empty, so ensure that second stack | 146 // Only the top stack in the chain may be empty, so ensure that second stack |
dgozman
2017/01/24 01:02:41
Amend the comment.
kozy
2017/01/24 21:43:39
Done.
| |
145 // is non-empty (it's the top of appended chain). | 147 // is non-empty (it's the top of appended chain). |
146 if (asyncCallChain && asyncCallChain->isEmpty()) | 148 if (asyncCallChain && asyncCallChain->isEmpty() && |
149 !asyncCallChain->m_creation) | |
147 asyncCallChain = asyncCallChain->m_parent.get(); | 150 asyncCallChain = asyncCallChain->m_parent.get(); |
148 | 151 |
149 if (stackTrace.IsEmpty() && !asyncCallChain) return nullptr; | 152 if (stackTrace.IsEmpty() && !asyncCallChain && !creationCallChain) |
153 return nullptr; | |
150 | 154 |
151 std::unique_ptr<V8StackTraceImpl> result(new V8StackTraceImpl( | 155 std::unique_ptr<V8StackTraceImpl> result(new V8StackTraceImpl( |
152 contextGroupId, description, frames, | 156 contextGroupId, description, frames, |
153 asyncCallChain ? asyncCallChain->cloneImpl() : nullptr)); | 157 asyncCallChain ? asyncCallChain->cloneImpl() : nullptr, |
158 std::move(creationStackTrace))); | |
154 | 159 |
155 // Crop to not exceed maxAsyncCallChainDepth. | 160 // Crop to not exceed maxAsyncCallChainDepth. |
156 V8StackTraceImpl* deepest = result.get(); | 161 V8StackTraceImpl* deepest = result.get(); |
157 while (deepest && maxAsyncCallChainDepth) { | 162 while (deepest && maxAsyncCallChainDepth) { |
158 deepest = deepest->m_parent.get(); | 163 deepest = deepest->m_parent.get(); |
159 maxAsyncCallChainDepth--; | 164 maxAsyncCallChainDepth--; |
160 } | 165 } |
161 if (deepest) deepest->m_parent.reset(); | 166 if (deepest) deepest->m_parent.reset(); |
162 | 167 |
163 return result; | 168 return result; |
164 } | 169 } |
165 | 170 |
166 // static | 171 // static |
167 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::capture( | 172 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::capture( |
168 V8Debugger* debugger, int contextGroupId, size_t maxStackSize, | 173 V8Debugger* debugger, int contextGroupId, size_t maxStackSize, |
169 const String16& description) { | 174 const String16& description, |
175 std::unique_ptr<V8StackTraceImpl> creationStackTrace) { | |
170 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 176 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
171 v8::HandleScope handleScope(isolate); | 177 v8::HandleScope handleScope(isolate); |
172 v8::Local<v8::StackTrace> stackTrace; | 178 v8::Local<v8::StackTrace> stackTrace; |
173 if (isolate->InContext()) { | 179 if (isolate->InContext()) { |
174 stackTrace = v8::StackTrace::CurrentStackTrace( | 180 stackTrace = v8::StackTrace::CurrentStackTrace( |
175 isolate, static_cast<int>(maxStackSize), stackTraceOptions); | 181 isolate, static_cast<int>(maxStackSize), stackTraceOptions); |
176 } | 182 } |
177 return V8StackTraceImpl::create(debugger, contextGroupId, stackTrace, | 183 return V8StackTraceImpl::create(debugger, contextGroupId, stackTrace, |
178 maxStackSize, description); | 184 maxStackSize, description, |
185 std::move(creationStackTrace)); | |
179 } | 186 } |
180 | 187 |
181 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::cloneImpl() { | 188 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::cloneImpl() { |
182 std::vector<Frame> framesCopy(m_frames); | 189 std::vector<Frame> framesCopy(m_frames); |
183 return std::unique_ptr<V8StackTraceImpl>( | 190 return std::unique_ptr<V8StackTraceImpl>( |
184 new V8StackTraceImpl(m_contextGroupId, m_description, framesCopy, | 191 new V8StackTraceImpl(m_contextGroupId, m_description, framesCopy, |
185 m_parent ? m_parent->cloneImpl() : nullptr)); | 192 m_parent ? m_parent->cloneImpl() : nullptr, |
193 m_creation ? m_creation->cloneImpl() : nullptr)); | |
186 } | 194 } |
187 | 195 |
188 std::unique_ptr<V8StackTrace> V8StackTraceImpl::clone() { | 196 std::unique_ptr<V8StackTrace> V8StackTraceImpl::clone() { |
189 std::vector<Frame> frames; | 197 std::vector<Frame> frames; |
190 for (size_t i = 0; i < m_frames.size(); i++) | 198 for (size_t i = 0; i < m_frames.size(); i++) |
191 frames.push_back(m_frames.at(i).clone()); | 199 frames.push_back(m_frames.at(i).clone()); |
192 return std::unique_ptr<V8StackTraceImpl>( | 200 return std::unique_ptr<V8StackTraceImpl>(new V8StackTraceImpl( |
193 new V8StackTraceImpl(m_contextGroupId, m_description, frames, nullptr)); | 201 m_contextGroupId, m_description, frames, nullptr, nullptr)); |
194 } | 202 } |
195 | 203 |
196 V8StackTraceImpl::V8StackTraceImpl(int contextGroupId, | 204 V8StackTraceImpl::V8StackTraceImpl(int contextGroupId, |
197 const String16& description, | 205 const String16& description, |
198 std::vector<Frame>& frames, | 206 std::vector<Frame>& frames, |
199 std::unique_ptr<V8StackTraceImpl> parent) | 207 std::unique_ptr<V8StackTraceImpl> parent, |
208 std::unique_ptr<V8StackTraceImpl> creation) | |
200 : m_contextGroupId(contextGroupId), | 209 : m_contextGroupId(contextGroupId), |
201 m_description(description), | 210 m_description(description), |
202 m_parent(std::move(parent)) { | 211 m_parent(std::move(parent)), |
212 m_creation(std::move(creation)) { | |
203 m_frames.swap(frames); | 213 m_frames.swap(frames); |
204 } | 214 } |
205 | 215 |
206 V8StackTraceImpl::~V8StackTraceImpl() {} | 216 V8StackTraceImpl::~V8StackTraceImpl() {} |
207 | 217 |
208 StringView V8StackTraceImpl::topSourceURL() const { | 218 StringView V8StackTraceImpl::topSourceURL() const { |
209 DCHECK(m_frames.size()); | 219 DCHECK(m_frames.size()); |
210 return toStringView(m_frames[0].m_scriptName); | 220 return toStringView(m_frames[0].m_scriptName); |
211 } | 221 } |
212 | 222 |
(...skipping 23 matching lines...) Expand all Loading... | |
236 protocol::Array<protocol::Runtime::CallFrame>::create(); | 246 protocol::Array<protocol::Runtime::CallFrame>::create(); |
237 for (size_t i = 0; i < m_frames.size(); i++) | 247 for (size_t i = 0; i < m_frames.size(); i++) |
238 frames->addItem(m_frames.at(i).buildInspectorObject()); | 248 frames->addItem(m_frames.at(i).buildInspectorObject()); |
239 | 249 |
240 std::unique_ptr<protocol::Runtime::StackTrace> stackTrace = | 250 std::unique_ptr<protocol::Runtime::StackTrace> stackTrace = |
241 protocol::Runtime::StackTrace::create() | 251 protocol::Runtime::StackTrace::create() |
242 .setCallFrames(std::move(frames)) | 252 .setCallFrames(std::move(frames)) |
243 .build(); | 253 .build(); |
244 if (!m_description.isEmpty()) stackTrace->setDescription(m_description); | 254 if (!m_description.isEmpty()) stackTrace->setDescription(m_description); |
245 if (m_parent) stackTrace->setParent(m_parent->buildInspectorObjectImpl()); | 255 if (m_parent) stackTrace->setParent(m_parent->buildInspectorObjectImpl()); |
256 if (m_creation && m_creation->m_frames.size()) { | |
257 stackTrace->setCreationFrame( | |
258 m_creation->m_frames[0].buildInspectorObject()); | |
259 } | |
246 return stackTrace; | 260 return stackTrace; |
247 } | 261 } |
248 | 262 |
249 std::unique_ptr<protocol::Runtime::StackTrace> | 263 std::unique_ptr<protocol::Runtime::StackTrace> |
250 V8StackTraceImpl::buildInspectorObjectForTail(V8Debugger* debugger) const { | 264 V8StackTraceImpl::buildInspectorObjectForTail(V8Debugger* debugger) const { |
251 v8::HandleScope handleScope(v8::Isolate::GetCurrent()); | 265 v8::HandleScope handleScope(v8::Isolate::GetCurrent()); |
252 // Next call collapses possible empty stack and ensures | 266 // Next call collapses possible empty stack and ensures |
253 // maxAsyncCallChainDepth. | 267 // maxAsyncCallChainDepth. |
254 std::unique_ptr<V8StackTraceImpl> fullChain = V8StackTraceImpl::create( | 268 std::unique_ptr<V8StackTraceImpl> fullChain = V8StackTraceImpl::create( |
255 debugger, m_contextGroupId, v8::Local<v8::StackTrace>(), | 269 debugger, m_contextGroupId, v8::Local<v8::StackTrace>(), |
(...skipping 20 matching lines...) Expand all Loading... | |
276 stackTrace.append(String16::fromInteger(frame.lineNumber())); | 290 stackTrace.append(String16::fromInteger(frame.lineNumber())); |
277 stackTrace.append(':'); | 291 stackTrace.append(':'); |
278 stackTrace.append(String16::fromInteger(frame.columnNumber())); | 292 stackTrace.append(String16::fromInteger(frame.columnNumber())); |
279 stackTrace.append(')'); | 293 stackTrace.append(')'); |
280 } | 294 } |
281 String16 string = stackTrace.toString(); | 295 String16 string = stackTrace.toString(); |
282 return StringBufferImpl::adopt(string); | 296 return StringBufferImpl::adopt(string); |
283 } | 297 } |
284 | 298 |
285 } // namespace v8_inspector | 299 } // namespace v8_inspector |
OLD | NEW |