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.h" | 9 #include "src/inspector/v8-debugger.h" |
9 #include "src/inspector/v8-inspector-impl.h" | 10 #include "src/inspector/v8-inspector-impl.h" |
10 | 11 |
11 #include "include/v8-debug.h" | 12 #include "include/v8-debug.h" |
12 #include "include/v8-version.h" | 13 #include "include/v8-version.h" |
13 | 14 |
14 namespace v8_inspector { | 15 namespace v8_inspector { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 static const v8::StackTrace::StackTraceOptions stackTraceOptions = | 19 static const v8::StackTrace::StackTraceOptions stackTraceOptions = |
19 static_cast<v8::StackTrace::StackTraceOptions>( | 20 static_cast<v8::StackTrace::StackTraceOptions>( |
20 v8::StackTrace::kLineNumber | v8::StackTrace::kColumnOffset | | 21 v8::StackTrace::kLineNumber | v8::StackTrace::kColumnOffset | |
21 v8::StackTrace::kScriptId | v8::StackTrace::kScriptNameOrSourceURL | | 22 v8::StackTrace::kScriptId | v8::StackTrace::kScriptNameOrSourceURL | |
22 v8::StackTrace::kFunctionName); | 23 v8::StackTrace::kFunctionName); |
23 | 24 |
24 V8StackTraceImpl::Frame toFrame(v8::Local<v8::StackFrame> frame) { | 25 V8StackTraceImpl::Frame toFrame(v8::Local<v8::StackFrame> frame, |
| 26 WasmTranslation* wasmTranslation, |
| 27 int contextGroupId) { |
25 String16 scriptId = String16::fromInteger(frame->GetScriptId()); | 28 String16 scriptId = String16::fromInteger(frame->GetScriptId()); |
26 String16 sourceName; | 29 String16 sourceName; |
27 v8::Local<v8::String> sourceNameValue(frame->GetScriptNameOrSourceURL()); | 30 v8::Local<v8::String> sourceNameValue(frame->GetScriptNameOrSourceURL()); |
28 if (!sourceNameValue.IsEmpty()) | 31 if (!sourceNameValue.IsEmpty()) |
29 sourceName = toProtocolString(sourceNameValue); | 32 sourceName = toProtocolString(sourceNameValue); |
30 | 33 |
31 String16 functionName; | 34 String16 functionName; |
32 v8::Local<v8::String> functionNameValue(frame->GetFunctionName()); | 35 v8::Local<v8::String> functionNameValue(frame->GetFunctionName()); |
33 if (!functionNameValue.IsEmpty()) | 36 if (!functionNameValue.IsEmpty()) |
34 functionName = toProtocolString(functionNameValue); | 37 functionName = toProtocolString(functionNameValue); |
35 | 38 |
36 int sourceLineNumber = frame->GetLineNumber(); | 39 int sourceLineNumber = frame->GetLineNumber() - 1; |
37 int sourceColumn = frame->GetColumn(); | 40 int sourceColumn = frame->GetColumn() - 1; |
| 41 // TODO(clemensh): Figure out a way to do this translation only right before |
| 42 // sending the stack trace over wire. |
| 43 if (wasmTranslation) |
| 44 wasmTranslation->TranslateWasmScriptLocationToProtocolLocation( |
| 45 &scriptId, &sourceLineNumber, &sourceColumn, contextGroupId); |
38 return V8StackTraceImpl::Frame(functionName, scriptId, sourceName, | 46 return V8StackTraceImpl::Frame(functionName, scriptId, sourceName, |
39 sourceLineNumber, sourceColumn); | 47 sourceLineNumber + 1, sourceColumn + 1); |
40 } | 48 } |
41 | 49 |
42 void toFramesVector(v8::Local<v8::StackTrace> stackTrace, | 50 void toFramesVector(v8::Local<v8::StackTrace> stackTrace, |
43 std::vector<V8StackTraceImpl::Frame>& frames, | 51 std::vector<V8StackTraceImpl::Frame>& frames, |
44 size_t maxStackSize, v8::Isolate* isolate) { | 52 size_t maxStackSize, v8::Isolate* isolate, |
| 53 V8Debugger* debugger, int contextGroupId) { |
45 DCHECK(isolate->InContext()); | 54 DCHECK(isolate->InContext()); |
46 int frameCount = stackTrace->GetFrameCount(); | 55 int frameCount = stackTrace->GetFrameCount(); |
47 if (frameCount > static_cast<int>(maxStackSize)) | 56 if (frameCount > static_cast<int>(maxStackSize)) |
48 frameCount = static_cast<int>(maxStackSize); | 57 frameCount = static_cast<int>(maxStackSize); |
| 58 WasmTranslation* wasmTranslation = |
| 59 debugger ? debugger->wasmTranslation() : nullptr; |
49 for (int i = 0; i < frameCount; i++) { | 60 for (int i = 0; i < frameCount; i++) { |
50 v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(i); | 61 v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(i); |
51 frames.push_back(toFrame(stackFrame)); | 62 frames.push_back(toFrame(stackFrame, wasmTranslation, contextGroupId)); |
52 } | 63 } |
53 } | 64 } |
54 | 65 |
55 } // namespace | 66 } // namespace |
56 | 67 |
57 V8StackTraceImpl::Frame::Frame() | 68 V8StackTraceImpl::Frame::Frame() |
58 : m_functionName("undefined"), | 69 : m_functionName("undefined"), |
59 m_scriptId(""), | 70 m_scriptId(""), |
60 m_scriptName("undefined"), | 71 m_scriptName("undefined"), |
61 m_lineNumber(0), | 72 m_lineNumber(0), |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 | 115 |
105 // static | 116 // static |
106 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::create( | 117 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::create( |
107 V8Debugger* debugger, int contextGroupId, | 118 V8Debugger* debugger, int contextGroupId, |
108 v8::Local<v8::StackTrace> stackTrace, size_t maxStackSize, | 119 v8::Local<v8::StackTrace> stackTrace, size_t maxStackSize, |
109 const String16& description) { | 120 const String16& description) { |
110 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 121 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
111 v8::HandleScope scope(isolate); | 122 v8::HandleScope scope(isolate); |
112 std::vector<V8StackTraceImpl::Frame> frames; | 123 std::vector<V8StackTraceImpl::Frame> frames; |
113 if (!stackTrace.IsEmpty()) | 124 if (!stackTrace.IsEmpty()) |
114 toFramesVector(stackTrace, frames, maxStackSize, isolate); | 125 toFramesVector(stackTrace, frames, maxStackSize, isolate, debugger, |
| 126 contextGroupId); |
115 | 127 |
116 int maxAsyncCallChainDepth = 1; | 128 int maxAsyncCallChainDepth = 1; |
117 V8StackTraceImpl* asyncCallChain = nullptr; | 129 V8StackTraceImpl* asyncCallChain = nullptr; |
118 if (debugger && maxStackSize > 1) { | 130 if (debugger && maxStackSize > 1) { |
119 asyncCallChain = debugger->currentAsyncCallChain(); | 131 asyncCallChain = debugger->currentAsyncCallChain(); |
120 maxAsyncCallChainDepth = debugger->maxAsyncCallChainDepth(); | 132 maxAsyncCallChainDepth = debugger->maxAsyncCallChainDepth(); |
121 } | 133 } |
122 // 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 |
123 // not | 135 // not |
124 // 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 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 stackTrace.append(String16::fromInteger(frame.lineNumber())); | 276 stackTrace.append(String16::fromInteger(frame.lineNumber())); |
265 stackTrace.append(':'); | 277 stackTrace.append(':'); |
266 stackTrace.append(String16::fromInteger(frame.columnNumber())); | 278 stackTrace.append(String16::fromInteger(frame.columnNumber())); |
267 stackTrace.append(')'); | 279 stackTrace.append(')'); |
268 } | 280 } |
269 String16 string = stackTrace.toString(); | 281 String16 string = stackTrace.toString(); |
270 return StringBufferImpl::adopt(string); | 282 return StringBufferImpl::adopt(string); |
271 } | 283 } |
272 | 284 |
273 } // namespace v8_inspector | 285 } // namespace v8_inspector |
OLD | NEW |