Commit 9758552a authored by Hidy Han's avatar Hidy Han Committed by Commit Bot

Add more support for flexible stack trace capturing.

1) Let firstNonEmptySourceURL traverse async stack trace (if any).
2) Expose Runtime.setMaxCallStackSizeToCapture API to control the number of frames to capture.

Cq-Include-Trybots: luci.chromium.try:linux_chromium_headless_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I72f021c6ae9e317af67c3114fd4860ce0f06d977
Reviewed-on: https://chromium-review.googlesource.com/1085643
Commit-Queue: Hidy Han <hidyhan@chromium.org>
Reviewed-by: 's avatarAleksey Kozyatinskiy <kozyatinskiy@chromium.org>
Reviewed-by: 's avatarPavel Feldman <pfeldman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53506}
parent 51c9123e
......@@ -2880,6 +2880,16 @@
}
]
},
{
"name": "setMaxCallStackSizeToCapture",
"experimental": true,
"parameters": [
{
"name": "size",
"type": "integer"
}
]
},
{
"name": "terminateExecution",
"description": "Terminate current or next JavaScript execution.\nWill cancel the termination when the outer-most script execution ends.",
......
......@@ -1326,6 +1326,10 @@ domain Runtime
parameters
boolean enabled
experimental command setMaxCallStackSizeToCapture
parameters
integer size
# Terminate current or next JavaScript execution.
# Will cancel the termination when the outer-most script execution ends.
experimental command terminateExecution
......
......@@ -461,6 +461,14 @@ Response V8RuntimeAgentImpl::setCustomObjectFormatterEnabled(bool enabled) {
return Response::OK();
}
Response V8RuntimeAgentImpl::setMaxCallStackSizeToCapture(int size) {
if (size < 0) {
return Response::Error("maxCallStackSizeToCapture should be non-negative");
}
V8StackTraceImpl::maxCallStackSizeToCapture = size;
return Response::OK();
}
Response V8RuntimeAgentImpl::discardConsoleEntries() {
V8ConsoleMessageStorage* storage =
m_inspector->ensureConsoleMessageStorage(m_session->contextGroupId());
......
......@@ -89,6 +89,7 @@ class V8RuntimeAgentImpl : public protocol::Runtime::Backend {
Response releaseObjectGroup(const String16& objectGroup) override;
Response runIfWaitingForDebugger() override;
Response setCustomObjectFormatterEnabled(bool) override;
Response setMaxCallStackSizeToCapture(int) override;
Response discardConsoleEntries() override;
Response compileScript(const String16& expression, const String16& sourceURL,
bool persistScript, Maybe<int> executionContextId,
......
......@@ -11,6 +11,8 @@
namespace v8_inspector {
int V8StackTraceImpl::maxCallStackSizeToCapture = 200;
namespace {
static const v8::StackTrace::StackTraceOptions stackTraceOptions =
......@@ -216,10 +218,12 @@ std::unique_ptr<V8StackTrace> V8StackTraceImpl::clone() {
}
StringView V8StackTraceImpl::firstNonEmptySourceURL() const {
for (size_t i = 0; i < m_frames.size(); ++i) {
if (m_frames[i]->sourceURL().length()) {
return toStringView(m_frames[i]->sourceURL());
StackFrameIterator current(this);
while (!current.done()) {
if (current.frame()->sourceURL().length()) {
return toStringView(current.frame()->sourceURL());
}
current.next();
}
return StringView();
}
......
......@@ -48,7 +48,7 @@ class V8StackTraceImpl : public V8StackTrace {
public:
static void setCaptureStackTraceForUncaughtExceptions(v8::Isolate*,
bool capture);
static const int maxCallStackSizeToCapture = 200;
static int maxCallStackSizeToCapture;
static std::unique_ptr<V8StackTraceImpl> create(V8Debugger*,
int contextGroupId,
v8::Local<v8::StackTrace>,
......
Checks Runtime.setMaxCallStackSizeToCapture.
Test with max size 0.
{
args : [
[0] : {
type : string
value : Nested call.
}
]
executionContextId : <executionContextId>
timestamp : <timestamp>
type : log
}
Test with max size 1.
{
args : [
[0] : {
type : string
value : Nested call.
}
]
executionContextId : <executionContextId>
stackTrace : {
callFrames : [
[0] : {
columnNumber : 10
functionName : bar
lineNumber : 2
scriptId : <scriptId>
url : test.js
}
]
parent : {
callFrames : [
[0] : {
columnNumber : 2
functionName : test
lineNumber : 10
scriptId : <scriptId>
url : test.js
}
]
description : setTimeout
}
}
timestamp : <timestamp>
type : log
}
Test with max size 2.
{
args : [
[0] : {
type : string
value : Nested call.
}
]
executionContextId : <executionContextId>
stackTrace : {
callFrames : [
[0] : {
columnNumber : 10
functionName : bar
lineNumber : 2
scriptId : <scriptId>
url : test.js
}
[1] : {
columnNumber : 2
functionName : foo
lineNumber : 6
scriptId : <scriptId>
url : test.js
}
]
parent : {
callFrames : [
[0] : {
columnNumber : 2
functionName : test
lineNumber : 10
scriptId : <scriptId>
url : test.js
}
[1] : {
columnNumber : 0
functionName :
lineNumber : 0
scriptId : <scriptId>
url : expr.js
}
]
description : setTimeout
}
}
timestamp : <timestamp>
type : log
}
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
let {session, contextGroup, Protocol} = InspectorTest.start('Checks Runtime.setMaxCallStackSizeToCapture.');
Protocol.Runtime.enable();
Protocol.Runtime.onConsoleAPICalled(
message => InspectorTest.logMessage(message.params));
contextGroup.addScript(`
function bar() {
console.log("Nested call.");
}
function foo() {
bar();
}
async function test() {
setTimeout(foo, 0);
}
//# sourceURL=test.js`);
Protocol.Runtime.setAsyncCallStackDepth({maxDepth: 10});
(async function test() {
await Protocol.Runtime.setMaxCallStackSizeToCapture({size: 0});
InspectorTest.log('Test with max size 0.');
await Protocol.Runtime.evaluate({ expression: 'test()//# sourceURL=expr.js'});
await Protocol.Runtime.setMaxCallStackSizeToCapture({size: 1});
InspectorTest.log('Test with max size 1.');
await Protocol.Runtime.evaluate({ expression: 'test()//# sourceURL=expr.js'});
await Protocol.Runtime.setMaxCallStackSizeToCapture({size: 2});
InspectorTest.log('Test with max size 2.');
await Protocol.Runtime.evaluate({ expression: 'test()//# sourceURL=expr.js'});
InspectorTest.completeTest();
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment