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 22 matching lines...) Expand all Loading... |
33 | 33 |
34 String16 functionName; | 34 String16 functionName; |
35 v8::Local<v8::String> functionNameValue(frame->GetFunctionName()); | 35 v8::Local<v8::String> functionNameValue(frame->GetFunctionName()); |
36 if (!functionNameValue.IsEmpty()) | 36 if (!functionNameValue.IsEmpty()) |
37 functionName = toProtocolString(functionNameValue); | 37 functionName = toProtocolString(functionNameValue); |
38 | 38 |
39 int sourceLineNumber = frame->GetLineNumber() - 1; | 39 int sourceLineNumber = frame->GetLineNumber() - 1; |
40 int sourceColumn = frame->GetColumn() - 1; | 40 int sourceColumn = frame->GetColumn() - 1; |
41 // TODO(clemensh): Figure out a way to do this translation only right before | 41 // TODO(clemensh): Figure out a way to do this translation only right before |
42 // sending the stack trace over wire. | 42 // sending the stack trace over wire. |
43 if (wasmTranslation) | 43 wasmTranslation->TranslateWasmScriptLocationToProtocolLocation( |
44 wasmTranslation->TranslateWasmScriptLocationToProtocolLocation( | 44 &scriptId, &sourceLineNumber, &sourceColumn); |
45 &scriptId, &sourceLineNumber, &sourceColumn); | |
46 return V8StackTraceImpl::Frame(functionName, scriptId, sourceName, | 45 return V8StackTraceImpl::Frame(functionName, scriptId, sourceName, |
47 sourceLineNumber + 1, sourceColumn + 1); | 46 sourceLineNumber + 1, sourceColumn + 1); |
48 } | 47 } |
49 | 48 |
50 void toFramesVector(v8::Local<v8::StackTrace> stackTrace, | 49 void toFramesVector(v8::Local<v8::StackTrace> stackTrace, |
51 std::vector<V8StackTraceImpl::Frame>& frames, | 50 std::vector<V8StackTraceImpl::Frame>& frames, |
52 size_t maxStackSize, v8::Isolate* isolate, | 51 size_t maxStackSize, v8::Isolate* isolate, |
53 V8Debugger* debugger, int contextGroupId) { | 52 V8Debugger* debugger, int contextGroupId) { |
54 DCHECK(isolate->InContext()); | 53 DCHECK(isolate->InContext()); |
55 int frameCount = stackTrace->GetFrameCount(); | 54 int frameCount = stackTrace->GetFrameCount(); |
56 if (frameCount > static_cast<int>(maxStackSize)) | 55 if (frameCount > static_cast<int>(maxStackSize)) |
57 frameCount = static_cast<int>(maxStackSize); | 56 frameCount = static_cast<int>(maxStackSize); |
58 WasmTranslation* wasmTranslation = | 57 WasmTranslation* wasmTranslation = debugger->wasmTranslation(); |
59 debugger ? debugger->wasmTranslation() : nullptr; | |
60 for (int i = 0; i < frameCount; i++) { | 58 for (int i = 0; i < frameCount; i++) { |
61 v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(i); | 59 v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(i); |
62 frames.push_back(toFrame(stackFrame, wasmTranslation, contextGroupId)); | 60 frames.push_back(toFrame(stackFrame, wasmTranslation, contextGroupId)); |
63 } | 61 } |
64 } | 62 } |
65 | 63 |
66 } // namespace | 64 } // namespace |
67 | 65 |
68 V8StackTraceImpl::Frame::Frame() | 66 V8StackTraceImpl::Frame::Frame() |
69 : m_functionName("undefined"), | 67 : m_functionName("undefined"), |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 v8::Isolate* isolate, bool capture) { | 109 v8::Isolate* isolate, bool capture) { |
112 isolate->SetCaptureStackTraceForUncaughtExceptions( | 110 isolate->SetCaptureStackTraceForUncaughtExceptions( |
113 capture, V8StackTraceImpl::maxCallStackSizeToCapture, stackTraceOptions); | 111 capture, V8StackTraceImpl::maxCallStackSizeToCapture, stackTraceOptions); |
114 } | 112 } |
115 | 113 |
116 // static | 114 // static |
117 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::create( | 115 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::create( |
118 V8Debugger* debugger, int contextGroupId, | 116 V8Debugger* debugger, int contextGroupId, |
119 v8::Local<v8::StackTrace> stackTrace, size_t maxStackSize, | 117 v8::Local<v8::StackTrace> stackTrace, size_t maxStackSize, |
120 const String16& description) { | 118 const String16& description) { |
121 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 119 DCHECK(debugger); |
| 120 v8::Isolate* isolate = debugger->inspector()->isolate(); |
122 v8::HandleScope scope(isolate); | 121 v8::HandleScope scope(isolate); |
123 std::vector<V8StackTraceImpl::Frame> frames; | 122 std::vector<V8StackTraceImpl::Frame> frames; |
124 if (!stackTrace.IsEmpty()) | 123 if (!stackTrace.IsEmpty()) |
125 toFramesVector(stackTrace, frames, maxStackSize, isolate, debugger, | 124 toFramesVector(stackTrace, frames, maxStackSize, isolate, debugger, |
126 contextGroupId); | 125 contextGroupId); |
127 | 126 |
128 int maxAsyncCallChainDepth = 1; | 127 int maxAsyncCallChainDepth = 1; |
129 V8StackTraceImpl* asyncCallChain = nullptr; | 128 V8StackTraceImpl* asyncCallChain = nullptr; |
130 if (debugger && maxStackSize > 1) { | 129 if (maxStackSize > 1) { |
131 asyncCallChain = debugger->currentAsyncCallChain(); | 130 asyncCallChain = debugger->currentAsyncCallChain(); |
132 maxAsyncCallChainDepth = debugger->maxAsyncCallChainDepth(); | 131 maxAsyncCallChainDepth = debugger->maxAsyncCallChainDepth(); |
133 } | 132 } |
134 // Do not accidentally append async call chain from another group. This should | 133 // Do not accidentally append async call chain from another group. This should |
135 // not | 134 // not |
136 // happen if we have proper instrumentation, but let's double-check to be | 135 // happen if we have proper instrumentation, but let's double-check to be |
137 // safe. | 136 // safe. |
138 if (contextGroupId && asyncCallChain && asyncCallChain->m_contextGroupId && | 137 if (contextGroupId && asyncCallChain && asyncCallChain->m_contextGroupId && |
139 asyncCallChain->m_contextGroupId != contextGroupId) { | 138 asyncCallChain->m_contextGroupId != contextGroupId) { |
140 asyncCallChain = nullptr; | 139 asyncCallChain = nullptr; |
(...skipping 22 matching lines...) Expand all Loading... |
163 } | 162 } |
164 if (deepest) deepest->m_parent.reset(); | 163 if (deepest) deepest->m_parent.reset(); |
165 | 164 |
166 return result; | 165 return result; |
167 } | 166 } |
168 | 167 |
169 // static | 168 // static |
170 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::capture( | 169 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::capture( |
171 V8Debugger* debugger, int contextGroupId, size_t maxStackSize, | 170 V8Debugger* debugger, int contextGroupId, size_t maxStackSize, |
172 const String16& description) { | 171 const String16& description) { |
173 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 172 DCHECK(debugger); |
| 173 v8::Isolate* isolate = debugger->inspector()->isolate(); |
174 v8::HandleScope handleScope(isolate); | 174 v8::HandleScope handleScope(isolate); |
175 v8::Local<v8::StackTrace> stackTrace; | 175 v8::Local<v8::StackTrace> stackTrace; |
176 if (isolate->InContext()) { | 176 if (isolate->InContext()) { |
177 stackTrace = v8::StackTrace::CurrentStackTrace( | 177 stackTrace = v8::StackTrace::CurrentStackTrace( |
178 isolate, static_cast<int>(maxStackSize), stackTraceOptions); | 178 isolate, static_cast<int>(maxStackSize), stackTraceOptions); |
179 } | 179 } |
180 return V8StackTraceImpl::create(debugger, contextGroupId, stackTrace, | 180 return V8StackTraceImpl::create(debugger, contextGroupId, stackTrace, |
181 maxStackSize, description); | 181 maxStackSize, description); |
182 } | 182 } |
183 | 183 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 if (m_parent) stackTrace->setParent(m_parent->buildInspectorObjectImpl()); | 263 if (m_parent) stackTrace->setParent(m_parent->buildInspectorObjectImpl()); |
264 if (m_creation && m_creation->m_frames.size()) { | 264 if (m_creation && m_creation->m_frames.size()) { |
265 stackTrace->setPromiseCreationFrame( | 265 stackTrace->setPromiseCreationFrame( |
266 m_creation->m_frames[0].buildInspectorObject()); | 266 m_creation->m_frames[0].buildInspectorObject()); |
267 } | 267 } |
268 return stackTrace; | 268 return stackTrace; |
269 } | 269 } |
270 | 270 |
271 std::unique_ptr<protocol::Runtime::StackTrace> | 271 std::unique_ptr<protocol::Runtime::StackTrace> |
272 V8StackTraceImpl::buildInspectorObjectForTail(V8Debugger* debugger) const { | 272 V8StackTraceImpl::buildInspectorObjectForTail(V8Debugger* debugger) const { |
273 v8::HandleScope handleScope(v8::Isolate::GetCurrent()); | 273 DCHECK(debugger); |
| 274 v8::HandleScope handleScope(debugger->inspector()->isolate()); |
274 // Next call collapses possible empty stack and ensures | 275 // Next call collapses possible empty stack and ensures |
275 // maxAsyncCallChainDepth. | 276 // maxAsyncCallChainDepth. |
276 std::unique_ptr<V8StackTraceImpl> fullChain = V8StackTraceImpl::create( | 277 std::unique_ptr<V8StackTraceImpl> fullChain = V8StackTraceImpl::create( |
277 debugger, m_contextGroupId, v8::Local<v8::StackTrace>(), | 278 debugger, m_contextGroupId, v8::Local<v8::StackTrace>(), |
278 V8StackTraceImpl::maxCallStackSizeToCapture); | 279 V8StackTraceImpl::maxCallStackSizeToCapture); |
279 if (!fullChain || !fullChain->m_parent) return nullptr; | 280 if (!fullChain || !fullChain->m_parent) return nullptr; |
280 return fullChain->m_parent->buildInspectorObjectImpl(); | 281 return fullChain->m_parent->buildInspectorObjectImpl(); |
281 } | 282 } |
282 | 283 |
283 std::unique_ptr<protocol::Runtime::API::StackTrace> | 284 std::unique_ptr<protocol::Runtime::API::StackTrace> |
(...skipping 14 matching lines...) Expand all Loading... |
298 stackTrace.append(String16::fromInteger(frame.lineNumber())); | 299 stackTrace.append(String16::fromInteger(frame.lineNumber())); |
299 stackTrace.append(':'); | 300 stackTrace.append(':'); |
300 stackTrace.append(String16::fromInteger(frame.columnNumber())); | 301 stackTrace.append(String16::fromInteger(frame.columnNumber())); |
301 stackTrace.append(')'); | 302 stackTrace.append(')'); |
302 } | 303 } |
303 String16 string = stackTrace.toString(); | 304 String16 string = stackTrace.toString(); |
304 return StringBufferImpl::adopt(string); | 305 return StringBufferImpl::adopt(string); |
305 } | 306 } |
306 | 307 |
307 } // namespace v8_inspector | 308 } // namespace v8_inspector |
OLD | NEW |