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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 } | |
151 | |
152 // When async call chain is empty but doesn't contain useful schedule stack | |
153 // and parent async call chain contains creationg stack but doesn't | |
154 // synchronous we can merge them together. | |
155 // e.g. Promise ThenableJob. | |
156 if (asyncCallChain && asyncCallChain->isEmpty() && asyncCallChain->m_parent) { | |
dgozman
2017/01/24 23:57:44
Let's move this logic to setCreationStack to avoid
kozy
2017/01/25 00:45:43
Done.
| |
157 if (asyncCallChain->m_creation && asyncCallChain->isEmpty() && | |
158 !asyncCallChain->m_parent->m_creation && | |
159 asyncCallChain->m_description == | |
160 asyncCallChain->m_parent->m_description) { | |
161 asyncCallChain->m_parent->m_creation = | |
162 std::move(asyncCallChain->m_creation); | |
163 asyncCallChain = asyncCallChain->m_parent.get(); | |
164 } | |
165 } | |
148 | 166 |
149 if (stackTrace.IsEmpty() && !asyncCallChain) return nullptr; | 167 if (stackTrace.IsEmpty() && !asyncCallChain) return nullptr; |
150 | 168 |
151 std::unique_ptr<V8StackTraceImpl> result(new V8StackTraceImpl( | 169 std::unique_ptr<V8StackTraceImpl> result(new V8StackTraceImpl( |
152 contextGroupId, description, frames, | 170 contextGroupId, description, frames, |
153 asyncCallChain ? asyncCallChain->cloneImpl() : nullptr)); | 171 asyncCallChain ? asyncCallChain->cloneImpl() : nullptr, nullptr)); |
154 | 172 |
155 // Crop to not exceed maxAsyncCallChainDepth. | 173 // Crop to not exceed maxAsyncCallChainDepth. |
156 V8StackTraceImpl* deepest = result.get(); | 174 V8StackTraceImpl* deepest = result.get(); |
157 while (deepest && maxAsyncCallChainDepth) { | 175 while (deepest && maxAsyncCallChainDepth) { |
158 deepest = deepest->m_parent.get(); | 176 deepest = deepest->m_parent.get(); |
159 maxAsyncCallChainDepth--; | 177 maxAsyncCallChainDepth--; |
160 } | 178 } |
161 if (deepest) deepest->m_parent.reset(); | 179 if (deepest) deepest->m_parent.reset(); |
162 | 180 |
163 return result; | 181 return result; |
(...skipping 11 matching lines...) Expand all Loading... | |
175 isolate, static_cast<int>(maxStackSize), stackTraceOptions); | 193 isolate, static_cast<int>(maxStackSize), stackTraceOptions); |
176 } | 194 } |
177 return V8StackTraceImpl::create(debugger, contextGroupId, stackTrace, | 195 return V8StackTraceImpl::create(debugger, contextGroupId, stackTrace, |
178 maxStackSize, description); | 196 maxStackSize, description); |
179 } | 197 } |
180 | 198 |
181 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::cloneImpl() { | 199 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::cloneImpl() { |
182 std::vector<Frame> framesCopy(m_frames); | 200 std::vector<Frame> framesCopy(m_frames); |
183 return std::unique_ptr<V8StackTraceImpl>( | 201 return std::unique_ptr<V8StackTraceImpl>( |
184 new V8StackTraceImpl(m_contextGroupId, m_description, framesCopy, | 202 new V8StackTraceImpl(m_contextGroupId, m_description, framesCopy, |
185 m_parent ? m_parent->cloneImpl() : nullptr)); | 203 m_parent ? m_parent->cloneImpl() : nullptr, |
204 m_creation ? m_creation->cloneImpl() : nullptr)); | |
186 } | 205 } |
187 | 206 |
188 std::unique_ptr<V8StackTrace> V8StackTraceImpl::clone() { | 207 std::unique_ptr<V8StackTrace> V8StackTraceImpl::clone() { |
189 std::vector<Frame> frames; | 208 std::vector<Frame> frames; |
190 for (size_t i = 0; i < m_frames.size(); i++) | 209 for (size_t i = 0; i < m_frames.size(); i++) |
191 frames.push_back(m_frames.at(i).clone()); | 210 frames.push_back(m_frames.at(i).clone()); |
192 return std::unique_ptr<V8StackTraceImpl>( | 211 return std::unique_ptr<V8StackTraceImpl>(new V8StackTraceImpl( |
193 new V8StackTraceImpl(m_contextGroupId, m_description, frames, nullptr)); | 212 m_contextGroupId, m_description, frames, nullptr, nullptr)); |
194 } | 213 } |
195 | 214 |
196 V8StackTraceImpl::V8StackTraceImpl(int contextGroupId, | 215 V8StackTraceImpl::V8StackTraceImpl(int contextGroupId, |
197 const String16& description, | 216 const String16& description, |
198 std::vector<Frame>& frames, | 217 std::vector<Frame>& frames, |
199 std::unique_ptr<V8StackTraceImpl> parent) | 218 std::unique_ptr<V8StackTraceImpl> parent, |
219 std::unique_ptr<V8StackTraceImpl> creation) | |
200 : m_contextGroupId(contextGroupId), | 220 : m_contextGroupId(contextGroupId), |
201 m_description(description), | 221 m_description(description), |
202 m_parent(std::move(parent)) { | 222 m_parent(std::move(parent)), |
223 m_creation(std::move(creation)) { | |
203 m_frames.swap(frames); | 224 m_frames.swap(frames); |
204 } | 225 } |
205 | 226 |
206 V8StackTraceImpl::~V8StackTraceImpl() {} | 227 V8StackTraceImpl::~V8StackTraceImpl() {} |
207 | 228 |
208 StringView V8StackTraceImpl::topSourceURL() const { | 229 StringView V8StackTraceImpl::topSourceURL() const { |
209 DCHECK(m_frames.size()); | 230 DCHECK(m_frames.size()); |
210 return toStringView(m_frames[0].m_scriptName); | 231 return toStringView(m_frames[0].m_scriptName); |
211 } | 232 } |
212 | 233 |
(...skipping 23 matching lines...) Expand all Loading... | |
236 protocol::Array<protocol::Runtime::CallFrame>::create(); | 257 protocol::Array<protocol::Runtime::CallFrame>::create(); |
237 for (size_t i = 0; i < m_frames.size(); i++) | 258 for (size_t i = 0; i < m_frames.size(); i++) |
238 frames->addItem(m_frames.at(i).buildInspectorObject()); | 259 frames->addItem(m_frames.at(i).buildInspectorObject()); |
239 | 260 |
240 std::unique_ptr<protocol::Runtime::StackTrace> stackTrace = | 261 std::unique_ptr<protocol::Runtime::StackTrace> stackTrace = |
241 protocol::Runtime::StackTrace::create() | 262 protocol::Runtime::StackTrace::create() |
242 .setCallFrames(std::move(frames)) | 263 .setCallFrames(std::move(frames)) |
243 .build(); | 264 .build(); |
244 if (!m_description.isEmpty()) stackTrace->setDescription(m_description); | 265 if (!m_description.isEmpty()) stackTrace->setDescription(m_description); |
245 if (m_parent) stackTrace->setParent(m_parent->buildInspectorObjectImpl()); | 266 if (m_parent) stackTrace->setParent(m_parent->buildInspectorObjectImpl()); |
267 if (m_creation && m_creation->m_frames.size()) { | |
268 stackTrace->setPromiseCreationFrame( | |
269 m_creation->m_frames[0].buildInspectorObject()); | |
270 } | |
246 return stackTrace; | 271 return stackTrace; |
247 } | 272 } |
248 | 273 |
249 std::unique_ptr<protocol::Runtime::StackTrace> | 274 std::unique_ptr<protocol::Runtime::StackTrace> |
250 V8StackTraceImpl::buildInspectorObjectForTail(V8Debugger* debugger) const { | 275 V8StackTraceImpl::buildInspectorObjectForTail(V8Debugger* debugger) const { |
251 v8::HandleScope handleScope(v8::Isolate::GetCurrent()); | 276 v8::HandleScope handleScope(v8::Isolate::GetCurrent()); |
252 // Next call collapses possible empty stack and ensures | 277 // Next call collapses possible empty stack and ensures |
253 // maxAsyncCallChainDepth. | 278 // maxAsyncCallChainDepth. |
254 std::unique_ptr<V8StackTraceImpl> fullChain = V8StackTraceImpl::create( | 279 std::unique_ptr<V8StackTraceImpl> fullChain = V8StackTraceImpl::create( |
255 debugger, m_contextGroupId, v8::Local<v8::StackTrace>(), | 280 debugger, m_contextGroupId, v8::Local<v8::StackTrace>(), |
(...skipping 20 matching lines...) Expand all Loading... | |
276 stackTrace.append(String16::fromInteger(frame.lineNumber())); | 301 stackTrace.append(String16::fromInteger(frame.lineNumber())); |
277 stackTrace.append(':'); | 302 stackTrace.append(':'); |
278 stackTrace.append(String16::fromInteger(frame.columnNumber())); | 303 stackTrace.append(String16::fromInteger(frame.columnNumber())); |
279 stackTrace.append(')'); | 304 stackTrace.append(')'); |
280 } | 305 } |
281 String16 string = stackTrace.toString(); | 306 String16 string = stackTrace.toString(); |
282 return StringBufferImpl::adopt(string); | 307 return StringBufferImpl::adopt(string); |
283 } | 308 } |
284 | 309 |
285 } // namespace v8_inspector | 310 } // namespace v8_inspector |
OLD | NEW |