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 #include "src/inspector/v8-profiler-agent-impl.h" | 11 #include "src/inspector/v8-profiler-agent-impl.h" |
11 | 12 |
12 #include "include/v8-debug.h" | 13 #include "include/v8-debug.h" |
13 #include "include/v8-profiler.h" | 14 #include "include/v8-profiler.h" |
14 #include "include/v8-version.h" | 15 #include "include/v8-version.h" |
15 | 16 |
16 namespace v8_inspector { | 17 namespace v8_inspector { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 static const v8::StackTrace::StackTraceOptions stackTraceOptions = | 21 static const v8::StackTrace::StackTraceOptions stackTraceOptions = |
21 static_cast<v8::StackTrace::StackTraceOptions>( | 22 static_cast<v8::StackTrace::StackTraceOptions>( |
22 v8::StackTrace::kLineNumber | v8::StackTrace::kColumnOffset | | 23 v8::StackTrace::kLineNumber | v8::StackTrace::kColumnOffset | |
23 v8::StackTrace::kScriptId | v8::StackTrace::kScriptNameOrSourceURL | | 24 v8::StackTrace::kScriptId | v8::StackTrace::kScriptNameOrSourceURL | |
24 v8::StackTrace::kFunctionName); | 25 v8::StackTrace::kFunctionName); |
25 | 26 |
26 V8StackTraceImpl::Frame toFrame(v8::Local<v8::StackFrame> frame) { | 27 V8StackTraceImpl::Frame toFrame(V8DebuggerAgentImpl* agent, |
28 v8::Local<v8::StackFrame> frame) { | |
27 String16 scriptId = String16::fromInteger(frame->GetScriptId()); | 29 String16 scriptId = String16::fromInteger(frame->GetScriptId()); |
28 String16 sourceName; | 30 String16 sourceName; |
29 v8::Local<v8::String> sourceNameValue(frame->GetScriptNameOrSourceURL()); | 31 v8::Local<v8::String> sourceNameValue(frame->GetScriptNameOrSourceURL()); |
30 if (!sourceNameValue.IsEmpty()) | 32 if (!sourceNameValue.IsEmpty()) |
31 sourceName = toProtocolString(sourceNameValue); | 33 sourceName = toProtocolString(sourceNameValue); |
32 | 34 |
33 String16 functionName; | 35 String16 functionName; |
34 v8::Local<v8::String> functionNameValue(frame->GetFunctionName()); | 36 v8::Local<v8::String> functionNameValue(frame->GetFunctionName()); |
35 if (!functionNameValue.IsEmpty()) | 37 if (!functionNameValue.IsEmpty()) |
36 functionName = toProtocolString(functionNameValue); | 38 functionName = toProtocolString(functionNameValue); |
37 | 39 |
38 int sourceLineNumber = frame->GetLineNumber(); | 40 int sourceLineNumber = frame->GetLineNumber() - 1; |
39 int sourceColumn = frame->GetColumn(); | 41 int sourceColumn = frame->GetColumn() - 1; |
42 if (agent) | |
43 agent->wasmTranslation()->TranslateProtocolLocationToWasmScriptLocation( | |
dgozman
2016/11/16 19:00:10
This is a wrong place for translation - it could b
Clemens Hammacher
2016/11/16 20:31:30
Not sure if this is fixed with the switch from deb
dgozman
2016/11/16 22:01:27
We can translate here when debugger is disabled, a
Clemens Hammacher
2016/11/16 22:43:31
As discussed in chat: We postpone this, as it seem
| |
44 &scriptId, &sourceLineNumber, &sourceColumn); | |
40 return V8StackTraceImpl::Frame(functionName, scriptId, sourceName, | 45 return V8StackTraceImpl::Frame(functionName, scriptId, sourceName, |
41 sourceLineNumber, sourceColumn); | 46 sourceLineNumber + 1, sourceColumn + 1); |
42 } | 47 } |
43 | 48 |
44 void toFramesVector(v8::Local<v8::StackTrace> stackTrace, | 49 void toFramesVector(V8DebuggerAgentImpl* agent, |
50 v8::Local<v8::StackTrace> stackTrace, | |
45 std::vector<V8StackTraceImpl::Frame>& frames, | 51 std::vector<V8StackTraceImpl::Frame>& frames, |
46 size_t maxStackSize, v8::Isolate* isolate) { | 52 size_t maxStackSize, v8::Isolate* isolate) { |
47 DCHECK(isolate->InContext()); | 53 DCHECK(isolate->InContext()); |
48 int frameCount = stackTrace->GetFrameCount(); | 54 int frameCount = stackTrace->GetFrameCount(); |
49 if (frameCount > static_cast<int>(maxStackSize)) | 55 if (frameCount > static_cast<int>(maxStackSize)) |
50 frameCount = static_cast<int>(maxStackSize); | 56 frameCount = static_cast<int>(maxStackSize); |
51 for (int i = 0; i < frameCount; i++) { | 57 for (int i = 0; i < frameCount; i++) { |
52 v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(i); | 58 v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(i); |
53 frames.push_back(toFrame(stackFrame)); | 59 frames.push_back(toFrame(agent, stackFrame)); |
54 } | 60 } |
55 } | 61 } |
56 | 62 |
57 } // namespace | 63 } // namespace |
58 | 64 |
59 V8StackTraceImpl::Frame::Frame() | 65 V8StackTraceImpl::Frame::Frame() |
60 : m_functionName("undefined"), | 66 : m_functionName("undefined"), |
61 m_scriptId(""), | 67 m_scriptId(""), |
62 m_scriptName("undefined"), | 68 m_scriptName("undefined"), |
63 m_lineNumber(0), | 69 m_lineNumber(0), |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 } | 111 } |
106 | 112 |
107 // static | 113 // static |
108 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::create( | 114 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::create( |
109 V8Debugger* debugger, int contextGroupId, | 115 V8Debugger* debugger, int contextGroupId, |
110 v8::Local<v8::StackTrace> stackTrace, size_t maxStackSize, | 116 v8::Local<v8::StackTrace> stackTrace, size_t maxStackSize, |
111 const String16& description) { | 117 const String16& description) { |
112 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 118 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
113 v8::HandleScope scope(isolate); | 119 v8::HandleScope scope(isolate); |
114 std::vector<V8StackTraceImpl::Frame> frames; | 120 std::vector<V8StackTraceImpl::Frame> frames; |
121 V8DebuggerAgentImpl* agent = | |
122 debugger | |
123 ? debugger->inspector()->enabledDebuggerAgentForGroup(contextGroupId) | |
124 : nullptr; | |
115 if (!stackTrace.IsEmpty()) | 125 if (!stackTrace.IsEmpty()) |
116 toFramesVector(stackTrace, frames, maxStackSize, isolate); | 126 toFramesVector(agent, stackTrace, frames, maxStackSize, isolate); |
117 | 127 |
118 int maxAsyncCallChainDepth = 1; | 128 int maxAsyncCallChainDepth = 1; |
119 V8StackTraceImpl* asyncCallChain = nullptr; | 129 V8StackTraceImpl* asyncCallChain = nullptr; |
120 if (debugger && maxStackSize > 1) { | 130 if (debugger && maxStackSize > 1) { |
121 asyncCallChain = debugger->currentAsyncCallChain(); | 131 asyncCallChain = debugger->currentAsyncCallChain(); |
122 maxAsyncCallChainDepth = debugger->maxAsyncCallChainDepth(); | 132 maxAsyncCallChainDepth = debugger->maxAsyncCallChainDepth(); |
123 } | 133 } |
124 // 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 |
125 // not | 135 // not |
126 // 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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
272 stackTrace.append(String16::fromInteger(frame.lineNumber())); | 282 stackTrace.append(String16::fromInteger(frame.lineNumber())); |
273 stackTrace.append(':'); | 283 stackTrace.append(':'); |
274 stackTrace.append(String16::fromInteger(frame.columnNumber())); | 284 stackTrace.append(String16::fromInteger(frame.columnNumber())); |
275 stackTrace.append(')'); | 285 stackTrace.append(')'); |
276 } | 286 } |
277 String16 string = stackTrace.toString(); | 287 String16 string = stackTrace.toString(); |
278 return StringBufferImpl::adopt(string); | 288 return StringBufferImpl::adopt(string); |
279 } | 289 } |
280 | 290 |
281 } // namespace v8_inspector | 291 } // namespace v8_inspector |
OLD | NEW |