| 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->translateLocation(&scriptId, &sourceLineNumber, &sourceColumn); |
| 40 return V8StackTraceImpl::Frame(functionName, scriptId, sourceName, | 44 return V8StackTraceImpl::Frame(functionName, scriptId, sourceName, |
| 41 sourceLineNumber, sourceColumn); | 45 sourceLineNumber + 1, sourceColumn + 1); |
| 42 } | 46 } |
| 43 | 47 |
| 44 void toFramesVector(v8::Local<v8::StackTrace> stackTrace, | 48 void toFramesVector(V8DebuggerAgentImpl* agent, |
| 49 v8::Local<v8::StackTrace> stackTrace, |
| 45 std::vector<V8StackTraceImpl::Frame>& frames, | 50 std::vector<V8StackTraceImpl::Frame>& frames, |
| 46 size_t maxStackSize, v8::Isolate* isolate) { | 51 size_t maxStackSize, v8::Isolate* isolate) { |
| 47 DCHECK(isolate->InContext()); | 52 DCHECK(isolate->InContext()); |
| 48 int frameCount = stackTrace->GetFrameCount(); | 53 int frameCount = stackTrace->GetFrameCount(); |
| 49 if (frameCount > static_cast<int>(maxStackSize)) | 54 if (frameCount > static_cast<int>(maxStackSize)) |
| 50 frameCount = static_cast<int>(maxStackSize); | 55 frameCount = static_cast<int>(maxStackSize); |
| 51 for (int i = 0; i < frameCount; i++) { | 56 for (int i = 0; i < frameCount; i++) { |
| 52 v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(i); | 57 v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(i); |
| 53 frames.push_back(toFrame(stackFrame)); | 58 frames.push_back(toFrame(agent, stackFrame)); |
| 54 } | 59 } |
| 55 } | 60 } |
| 56 | 61 |
| 57 } // namespace | 62 } // namespace |
| 58 | 63 |
| 59 V8StackTraceImpl::Frame::Frame() | 64 V8StackTraceImpl::Frame::Frame() |
| 60 : m_functionName("undefined"), | 65 : m_functionName("undefined"), |
| 61 m_scriptId(""), | 66 m_scriptId(""), |
| 62 m_scriptName("undefined"), | 67 m_scriptName("undefined"), |
| 63 m_lineNumber(0), | 68 m_lineNumber(0), |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 110 } |
| 106 | 111 |
| 107 // static | 112 // static |
| 108 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::create( | 113 std::unique_ptr<V8StackTraceImpl> V8StackTraceImpl::create( |
| 109 V8Debugger* debugger, int contextGroupId, | 114 V8Debugger* debugger, int contextGroupId, |
| 110 v8::Local<v8::StackTrace> stackTrace, size_t maxStackSize, | 115 v8::Local<v8::StackTrace> stackTrace, size_t maxStackSize, |
| 111 const String16& description) { | 116 const String16& description) { |
| 112 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 117 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 113 v8::HandleScope scope(isolate); | 118 v8::HandleScope scope(isolate); |
| 114 std::vector<V8StackTraceImpl::Frame> frames; | 119 std::vector<V8StackTraceImpl::Frame> frames; |
| 120 V8DebuggerAgentImpl* agent = |
| 121 debugger |
| 122 ? debugger->inspector()->enabledDebuggerAgentForGroup(contextGroupId) |
| 123 : nullptr; |
| 115 if (!stackTrace.IsEmpty()) | 124 if (!stackTrace.IsEmpty()) |
| 116 toFramesVector(stackTrace, frames, maxStackSize, isolate); | 125 toFramesVector(agent, stackTrace, frames, maxStackSize, isolate); |
| 117 | 126 |
| 118 int maxAsyncCallChainDepth = 1; | 127 int maxAsyncCallChainDepth = 1; |
| 119 V8StackTraceImpl* asyncCallChain = nullptr; | 128 V8StackTraceImpl* asyncCallChain = nullptr; |
| 120 if (debugger && maxStackSize > 1) { | 129 if (debugger && maxStackSize > 1) { |
| 121 asyncCallChain = debugger->currentAsyncCallChain(); | 130 asyncCallChain = debugger->currentAsyncCallChain(); |
| 122 maxAsyncCallChainDepth = debugger->maxAsyncCallChainDepth(); | 131 maxAsyncCallChainDepth = debugger->maxAsyncCallChainDepth(); |
| 123 } | 132 } |
| 124 // 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 |
| 125 // not | 134 // not |
| 126 // 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 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 stackTrace.append(String16::fromInteger(frame.lineNumber())); | 281 stackTrace.append(String16::fromInteger(frame.lineNumber())); |
| 273 stackTrace.append(':'); | 282 stackTrace.append(':'); |
| 274 stackTrace.append(String16::fromInteger(frame.columnNumber())); | 283 stackTrace.append(String16::fromInteger(frame.columnNumber())); |
| 275 stackTrace.append(')'); | 284 stackTrace.append(')'); |
| 276 } | 285 } |
| 277 String16 string = stackTrace.toString(); | 286 String16 string = stackTrace.toString(); |
| 278 return StringBufferImpl::adopt(string); | 287 return StringBufferImpl::adopt(string); |
| 279 } | 288 } |
| 280 | 289 |
| 281 } // namespace v8_inspector | 290 } // namespace v8_inspector |
| OLD | NEW |