Commit 1cac34ed authored by clemensh's avatar clemensh Committed by Commit bot

Fix detection of BUILTIN functions

In the asm.js to wasm pipeline, we generate an entry function with
BUILTIN code, but still attached to a TYPE_NORMAL script.
This fix avoids trying to set a breakpoint there, resulting in a crash
on DCHECK(shared->HasDebugInfo()).

Also add two inspector tests to track regressions.

BUG=v8:5568
R=titzer@chromium.org,mstarzinger@chromium.org

Review-Url: https://codereview.chromium.org/2457433002
Cr-Commit-Position: refs/heads/master@{#40633}
parent 77ae6884
......@@ -6495,9 +6495,9 @@ bool SharedFunctionInfo::IsBuiltin() {
return type != Script::TYPE_NORMAL;
}
bool SharedFunctionInfo::IsSubjectToDebugging() { return !IsBuiltin(); }
bool SharedFunctionInfo::IsSubjectToDebugging() {
return !IsBuiltin() && !HasAsmWasmData();
}
bool SharedFunctionInfo::OptimizedCodeMapIsCleared() const {
return optimized_code_map() == GetHeap()->empty_fixed_array();
......
This test runs asm.js which calls back to JS. Before executing (after the script is parsed) we set breakpoints in the asm.js code.
Running test: enableDebugger
Running test: addScript
Script nr 1 parsed!
First script; assuming testFunction.
Flooding script with breakpoints for all lines (0 - 20)...
Setting breakpoint on line 0
error: undefined
Setting breakpoint on line 1
error: undefined
Setting breakpoint on line 2
error: undefined
Setting breakpoint on line 3
error: undefined
Setting breakpoint on line 4
error: undefined
Setting breakpoint on line 5
error: undefined
Setting breakpoint on line 6
error: undefined
Setting breakpoint on line 7
error: undefined
Setting breakpoint on line 8
error: undefined
Setting breakpoint on line 9
error: undefined
Setting breakpoint on line 10
error: undefined
Setting breakpoint on line 11
error: undefined
Setting breakpoint on line 12
error: undefined
Setting breakpoint on line 13
error: undefined
Setting breakpoint on line 14
error: undefined
Setting breakpoint on line 15
error: undefined
Setting breakpoint on line 16
error: undefined
Setting breakpoint on line 17
error: undefined
Setting breakpoint on line 18
error: undefined
Setting breakpoint on line 19
error: undefined
Running test: runTestFunction
Script nr 2 parsed!
Paused #1
- [0] {"functionName":"testFunction","function_lineNumber":0,"function_columnNumber":21,"lineNumber":17,"columnNumber":2}
- [1] {"functionName":"","function_lineNumber":0,"function_columnNumber":0,"lineNumber":0,"columnNumber":0}
Paused #2
- [0] {"functionName":"testFunction","function_lineNumber":0,"function_columnNumber":21,"lineNumber":18,"columnNumber":12}
- [1] {"functionName":"","function_lineNumber":0,"function_columnNumber":0,"lineNumber":0,"columnNumber":0}
Paused #3
- [0] {"functionName":"testFunction","function_lineNumber":0,"function_columnNumber":21,"lineNumber":19,"columnNumber":2}
- [1] {"functionName":"","function_lineNumber":0,"function_columnNumber":0,"lineNumber":0,"columnNumber":0}
Paused #4
- [0] {"functionName":"call_debugger","function_lineNumber":13,"function_columnNumber":24,"lineNumber":14,"columnNumber":4}
- [1] {"functionName":"callDebugger","function_lineNumber":4,"function_columnNumber":25,"lineNumber":5,"columnNumber":6}
- [2] {"functionName":"redirectFun","function_lineNumber":7,"function_columnNumber":24,"lineNumber":8,"columnNumber":6}
- [3] {"functionName":"testFunction","function_lineNumber":0,"function_columnNumber":21,"lineNumber":19,"columnNumber":2}
- [4] {"functionName":"","function_lineNumber":0,"function_columnNumber":0,"lineNumber":0,"columnNumber":0}
Paused #5
- [0] {"functionName":"call_debugger","function_lineNumber":13,"function_columnNumber":24,"lineNumber":15,"columnNumber":2}
- [1] {"functionName":"callDebugger","function_lineNumber":4,"function_columnNumber":25,"lineNumber":5,"columnNumber":6}
- [2] {"functionName":"redirectFun","function_lineNumber":7,"function_columnNumber":24,"lineNumber":8,"columnNumber":6}
- [3] {"functionName":"testFunction","function_lineNumber":0,"function_columnNumber":21,"lineNumber":19,"columnNumber":2}
- [4] {"functionName":"","function_lineNumber":0,"function_columnNumber":0,"lineNumber":0,"columnNumber":0}
Running test: finished
Finished TestSuite.
// Copyright 2016 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.
// Flags: --validate-asm --allow-natives-syntax
InspectorTest.log(
'This test runs asm.js which calls back to JS. Before executing (after ' +
'the script is parsed) we set breakpoints in the asm.js code.');
function testFunction() {
function generateAsmJs(stdlib, foreign, heap) {
'use asm';
var debugger_fun = foreign.call_debugger;
function callDebugger() {
debugger_fun();
}
function redirectFun() {
callDebugger();
}
return redirectFun;
}
function call_debugger() {
debugger;
}
%OptimizeFunctionOnNextCall(generateAsmJs);
var fun = generateAsmJs(this, {'call_debugger': call_debugger}, undefined);
fun();
}
Protocol.Debugger.onPaused(handleDebuggerPaused);
Protocol.Debugger.onScriptParsed(handleScriptParsed);
function printResultAndContinue(next, message) {
if (message.result && message.result.exceptionDetails)
InspectorTest.logMessage(message.result.exceptionDetails);
else if (message.error)
InspectorTest.logMessage(message.error);
else if (message.result && message.result.type !== undefined)
InspectorTest.logMessage(message.result);
next();
}
InspectorTest.runTestSuite([
function enableDebugger(next) {
Protocol.Debugger.enable().then(next);
},
function addScript(next) {
afterScriptParsedCallback = next;
InspectorTest.addScript(testFunction.toString());
},
function runTestFunction(next) {
Protocol.Runtime.evaluate({'expression': 'testFunction()'})
.then(printResultAndContinue.bind(null, next));
},
function finished(next) {
InspectorTest.log('Finished TestSuite.');
next();
},
]);
function locationToString(callFrame) {
var res = {functionName: callFrame.functionName};
for (var attr in callFrame.functionLocation) {
if (attr == 'scriptId') continue;
res['function_' + attr] = callFrame.functionLocation[attr];
}
for (var attr in callFrame.location) {
if (attr == 'scriptId') continue;
res[attr] = callFrame.location[attr];
}
return JSON.stringify(res);
}
function logStackTrace(messageObject) {
var frames = messageObject.params.callFrames;
for (var i = 0; i < frames.length; ++i) {
InspectorTest.log(' - [' + i + '] ' + locationToString(frames[i]));
}
}
var numPaused = 0;
function handleDebuggerPaused(messageObject)
{
++numPaused;
InspectorTest.log('Paused #' + numPaused);
logStackTrace(messageObject);
Protocol.Debugger.resume();
}
var numScripts = 0;
function handleScriptParsed(messageObject)
{
var scriptId = messageObject.params.scriptId;
++numScripts;
InspectorTest.log('Script nr ' + numScripts + ' parsed!');
if (numScripts > 1) return;
var startLine = messageObject.params.startLine;
var endLine = messageObject.params.endLine;
InspectorTest.log('First script; assuming testFunction.');
InspectorTest.log(
'Flooding script with breakpoints for all lines (' + startLine + ' - ' +
endLine + ')...');
var currentLine = startLine;
function setNextBreakpoint(message) {
if (message) InspectorTest.logMessage('error: ' + message.error);
if (currentLine == endLine) {
afterScriptParsedCallback();
return;
}
var thisLine = currentLine;
currentLine += 1;
InspectorTest.log('Setting breakpoint on line ' + thisLine);
Protocol.Debugger
.setBreakpoint(
{'location': {'scriptId': scriptId, 'lineNumber': thisLine}})
.then(setNextBreakpoint);
}
setNextBreakpoint();
}
This test runs asm.js which calls back to JS. JS triggers a break, on pause we set breakpoints in the asm.js code.
Running test: enableDebugger
Running test: addScript
Script nr 1 parsed!
Running test: runTestFunction
Script nr 2 parsed!
Paused #1
- [0] {"functionName":"call_debugger","function_lineNumber":13,"function_columnNumber":24,"lineNumber":14,"columnNumber":4}
- [1] {"functionName":"callDebugger","function_lineNumber":4,"function_columnNumber":25,"lineNumber":5,"columnNumber":6}
- [2] {"functionName":"redirectFun","function_lineNumber":7,"function_columnNumber":24,"lineNumber":8,"columnNumber":6}
- [3] {"functionName":"testFunction","function_lineNumber":0,"function_columnNumber":21,"lineNumber":19,"columnNumber":2}
- [4] {"functionName":"","function_lineNumber":0,"function_columnNumber":0,"lineNumber":0,"columnNumber":0}
First time paused, setting breakpoints!
Flooding script with breakpoints for all lines (0 - 23)...
Setting breakpoint on line 0
error: undefined
Setting breakpoint on line 1
error: undefined
Setting breakpoint on line 2
error: undefined
Setting breakpoint on line 3
error: undefined
Setting breakpoint on line 4
error: undefined
Setting breakpoint on line 5
error: undefined
Setting breakpoint on line 6
error: undefined
Setting breakpoint on line 7
error: undefined
Setting breakpoint on line 8
error: undefined
Setting breakpoint on line 9
error: undefined
Setting breakpoint on line 10
error: undefined
Setting breakpoint on line 11
error: undefined
Setting breakpoint on line 12
error: undefined
Setting breakpoint on line 13
error: undefined
Setting breakpoint on line 14
error: undefined
Setting breakpoint on line 15
error: undefined
Setting breakpoint on line 16
error: undefined
Setting breakpoint on line 17
error: undefined
Setting breakpoint on line 18
error: undefined
Setting breakpoint on line 19
error: undefined
Setting breakpoint on line 20
error: undefined
Setting breakpoint on line 21
error: undefined
Setting breakpoint on line 22
error: undefined
Script nr 3 parsed!
Resuming...
Paused #2
- [0] {"functionName":"call_debugger","function_lineNumber":13,"function_columnNumber":24,"lineNumber":15,"columnNumber":2}
- [1] {"functionName":"callDebugger","function_lineNumber":4,"function_columnNumber":25,"lineNumber":5,"columnNumber":6}
- [2] {"functionName":"redirectFun","function_lineNumber":7,"function_columnNumber":24,"lineNumber":8,"columnNumber":6}
- [3] {"functionName":"testFunction","function_lineNumber":0,"function_columnNumber":21,"lineNumber":19,"columnNumber":2}
- [4] {"functionName":"","function_lineNumber":0,"function_columnNumber":0,"lineNumber":0,"columnNumber":0}
Script nr 4 parsed!
Resuming...
Paused #3
- [0] {"functionName":"callDebugger","function_lineNumber":4,"function_columnNumber":25,"lineNumber":6,"columnNumber":4}
- [1] {"functionName":"redirectFun","function_lineNumber":7,"function_columnNumber":24,"lineNumber":8,"columnNumber":6}
- [2] {"functionName":"testFunction","function_lineNumber":0,"function_columnNumber":21,"lineNumber":19,"columnNumber":2}
- [3] {"functionName":"","function_lineNumber":0,"function_columnNumber":0,"lineNumber":0,"columnNumber":0}
Script nr 5 parsed!
Resuming...
Paused #4
- [0] {"functionName":"redirectFun","function_lineNumber":7,"function_columnNumber":24,"lineNumber":9,"columnNumber":4}
- [1] {"functionName":"testFunction","function_lineNumber":0,"function_columnNumber":21,"lineNumber":19,"columnNumber":2}
- [2] {"functionName":"","function_lineNumber":0,"function_columnNumber":0,"lineNumber":0,"columnNumber":0}
Script nr 6 parsed!
Resuming...
Paused #5
- [0] {"functionName":"testFunction","function_lineNumber":0,"function_columnNumber":21,"lineNumber":21,"columnNumber":17}
- [1] {"functionName":"","function_lineNumber":0,"function_columnNumber":0,"lineNumber":0,"columnNumber":0}
Script nr 7 parsed!
Resuming...
Paused #6
- [0] {"functionName":"testFunction","function_lineNumber":0,"function_columnNumber":21,"lineNumber":22,"columnNumber":2}
- [1] {"functionName":"","function_lineNumber":0,"function_columnNumber":0,"lineNumber":0,"columnNumber":0}
Script nr 8 parsed!
Resuming...
Running test: finished
Finished TestSuite.
// Copyright 2016 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.
// Flags: --validate-asm --allow-natives-syntax
InspectorTest.log(
'This test runs asm.js which calls back to JS. JS triggers a break, on ' +
'pause we set breakpoints in the asm.js code.');
function testFunction() {
function generateAsmJs(stdlib, foreign, heap) {
'use asm';
var debugger_fun = foreign.call_debugger;
function callDebugger() {
debugger_fun();
}
function redirectFun() {
callDebugger();
}
return redirectFun;
}
function call_debugger() {
debugger;
}
%OptimizeFunctionOnNextCall(generateAsmJs);
var fun = generateAsmJs(this, {'call_debugger': call_debugger}, undefined);
fun();
var finished = 'finished';
debugger;
}
Protocol.Debugger.onPaused(handleDebuggerPaused);
Protocol.Debugger.onScriptParsed(handleScriptParsed);
function printResultAndContinue(next, message) {
if (message.result && message.result.exceptionDetails)
InspectorTest.logMessage(message.result.exceptionDetails);
else if (message.error)
InspectorTest.logMessage(message.error);
else if (message.result && message.result.type !== undefined)
InspectorTest.logMessage(message.result);
if (next) next();
}
InspectorTest.runTestSuite([
function enableDebugger(next) {
Protocol.Debugger.enable().then(next);
},
function addScript(next) {
afterScriptParsedCallback = next;
InspectorTest.addScript(testFunction.toString());
},
function runTestFunction(next) {
afterFinishedTestFunctionCallback = next;
Protocol.Runtime.evaluate({'expression': 'testFunction()'})
.then(printResultAndContinue.bind(null, null));
},
function finished(next) {
InspectorTest.log('Finished TestSuite.');
next();
},
]);
function locationToString(callFrame) {
var res = {functionName: callFrame.functionName};
for (var attr in callFrame.functionLocation) {
if (attr == 'scriptId') continue;
res['function_' + attr] = callFrame.functionLocation[attr];
}
for (var attr in callFrame.location) {
if (attr == 'scriptId') continue;
res[attr] = callFrame.location[attr];
}
return JSON.stringify(res);
}
function logStackTrace(messageObject) {
var frames = messageObject.params.callFrames;
for (var i = 0; i < frames.length; ++i) {
InspectorTest.log(' - [' + i + '] ' + locationToString(frames[i]));
}
}
var numPaused = 0;
var parsedScriptParams;
function handleDebuggerPaused(messageObject)
{
++numPaused;
InspectorTest.log('Paused #' + numPaused);
logStackTrace(messageObject);
function cont() {
var topFrameId = messageObject.params.callFrames[0].callFrameId;
Protocol.Debugger
.evaluateOnCallFrame({
callFrameId: topFrameId,
expression: 'typeof finished'
})
.then(callbackEvaluate);
function callbackEvaluate(message) {
var finished = message.result && message.result.result &&
message.result.result.value === 'string';
InspectorTest.log('Resuming...');
Protocol.Debugger.resume();
if (finished)
afterFinishedTestFunctionCallback();
}
}
if (numPaused > 1) {
cont();
return;
}
InspectorTest.log('First time paused, setting breakpoints!');
var startLine = parsedScriptParams.startLine;
var endLine = parsedScriptParams.endLine;
InspectorTest.log(
'Flooding script with breakpoints for all lines (' + startLine + ' - ' +
endLine + ')...');
var currentLine = startLine;
function setNextBreakpoint(message) {
if (message) InspectorTest.logMessage('error: ' + message.error);
if (currentLine == endLine) {
cont();
return;
}
var thisLine = currentLine;
currentLine += 1;
InspectorTest.log('Setting breakpoint on line ' + thisLine);
Protocol.Debugger
.setBreakpoint({
'location': {
'scriptId': parsedScriptParams.scriptId,
'lineNumber': thisLine
}
})
.then(setNextBreakpoint);
}
setNextBreakpoint();
}
var numScripts = 0;
function handleScriptParsed(messageObject)
{
var scriptId = messageObject.params.scriptId;
++numScripts;
InspectorTest.log('Script nr ' + numScripts + ' parsed!');
if (numScripts == 1) {
parsedScriptParams = JSON.parse(JSON.stringify(messageObject.params));
afterScriptParsedCallback();
}
}
......@@ -96,7 +96,7 @@ InspectorTest.logObject = function(object, title)
lines.push(prefix + "]");
}
dumpValue(object, "", title);
dumpValue(object, "", title || "");
InspectorTest.log(lines.join("\n"));
}
......
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