Commit ea51b8a7 authored by clemensh's avatar clemensh Committed by Commit bot

[debug] [reland] Consistently use script from FrameMirror

... instead of getting it from the FunctionMirror. For WASM frames
(including asm.js -> WASM), the function is either unresolved or does
not contain the script.

The added test case failed before this CL.

R=kozyatinskiy@chromium.org, yangguo@chromium.org, titzer@chromium.org
BUG=v8:4203, chromium:656622

Committed: https://crrev.com/ce32e2ffd835062d764f3c0ee6a32543417cb615
Review-Url: https://codereview.chromium.org/2415073003
Cr-Original-Commit-Position: refs/heads/master@{#40348}
Cr-Commit-Position: refs/heads/master@{#40387}
parent 1107aa8b
......@@ -1539,7 +1539,7 @@ PropertyMirror.prototype.value = function() {
/**
* Returns whether this property value is an exception.
* @return {booolean} True if this property value is an exception
* @return {boolean} True if this property value is an exception
*/
PropertyMirror.prototype.isException = function() {
return this.exception_ ? true : false;
......@@ -1558,7 +1558,7 @@ PropertyMirror.prototype.propertyType = function() {
/**
* Returns whether this property has a getter defined through __defineGetter__.
* @return {booolean} True if this property has a getter
* @return {boolean} True if this property has a getter
*/
PropertyMirror.prototype.hasGetter = function() {
return this.getter_ ? true : false;
......@@ -1567,7 +1567,7 @@ PropertyMirror.prototype.hasGetter = function() {
/**
* Returns whether this property has a setter defined through __defineSetter__.
* @return {booolean} True if this property has a setter
* @return {boolean} True if this property has a setter
*/
PropertyMirror.prototype.hasSetter = function() {
return this.setter_ ? true : false;
......
......@@ -416,6 +416,7 @@ DebuggerScript._frameMirrorToJSCallFrame = function(frameMirror)
var frameDetails = frameMirror.details();
var funcObject = frameDetails.func();
var scriptObject = frameDetails.script();
var sourcePosition = frameDetails.sourcePosition();
var thisObject = frameDetails.receiver();
......@@ -448,6 +449,7 @@ DebuggerScript._frameMirrorToJSCallFrame = function(frameMirror)
// Calculated lazily.
var scopeChain;
var funcMirror;
var scriptMirror;
var location;
/** @type {!Array<?RawLocation>} */
var scopeStartLocations;
......@@ -516,7 +518,7 @@ DebuggerScript._frameMirrorToJSCallFrame = function(frameMirror)
{
if (!details) {
var scopeObjects = ensureScopeChain();
var script = ensureFuncMirror().script();
var script = ensureScriptMirror();
/** @type {!Array<Scope>} */
var scopes = [];
for (var i = 0; i < scopeObjects.length; ++i) {
......@@ -569,15 +571,25 @@ DebuggerScript._frameMirrorToJSCallFrame = function(frameMirror)
return /** @type {!FunctionMirror} */(funcMirror);
}
/**
* @return {!ScriptMirror}
*/
function ensureScriptMirror()
{
if (!scriptMirror) {
scriptMirror = MakeMirror(scriptObject);
}
return /** @type {!ScriptMirror} */(scriptMirror);
}
/**
* @return {!{line: number, column: number}}
*/
function ensureLocation()
{
if (!location) {
var script = ensureFuncMirror().script();
if (script)
location = script.locationFromPosition(sourcePosition, true);
var script = ensureScriptMirror();
location = script.locationFromPosition(sourcePosition, true);
if (!location)
location = { line: 0, column: 0 };
}
......@@ -616,12 +628,12 @@ DebuggerScript._frameMirrorToJSCallFrame = function(frameMirror)
}
/**
* @return {number|undefined}
* @return {number}
*/
function sourceID()
{
var script = ensureFuncMirror().script();
return script && script.id();
var script = ensureScriptMirror();
return script.id();
}
/**
......
......@@ -44,7 +44,7 @@ var FormattedScript;
var JavaScriptCallFrameDetails;
/** @typedef {{
sourceID: function():(number|undefined),
sourceID: function():(number),
line: function():number,
column: function():number,
thisObject: !Object,
......@@ -288,6 +288,9 @@ FrameDetails.prototype.receiver = function() {}
/** @return {function()} */
FrameDetails.prototype.func = function() {}
/** @return {!Object} */
FrameDetails.prototype.script = function() {}
/** @return {boolean} */
FrameDetails.prototype.isAtReturn = function() {}
......@@ -466,6 +469,9 @@ FrameMirror.prototype.allScopes = function(ignoreNestedScopes) {}
/** @return {!FrameDetails} */
FrameMirror.prototype.details = function() {}
/** @return {!ScriptMirror} */
FrameMirror.prototype.script = function() {}
/**
* @param {string} source
* @param {boolean} disableBreak
......
Paused on 'debugger;'
Number of frames: 5
- [0] {"functionName":"call_debugger","function_lineNumber":13,"function_columnNumber":24,"lineNumber":14,"columnNumber":4}
- [1] {"functionName":"callDebugger","lineNumber":5,"columnNumber":6}
- [2] {"functionName":"redirectFun","lineNumber":8,"columnNumber":6}
- [3] {"functionName":"testFunction","function_lineNumber":0,"function_columnNumber":21,"lineNumber":18,"columnNumber":2}
- [4] {"functionName":"","function_lineNumber":0,"function_columnNumber":0,"lineNumber":0,"columnNumber":0}
Getting v8-generated stack trace...
Result of evaluate (string):
Error: getting stack trace
-- skipped --
at call_debugger (<anonymous>:15:5)
at callDebugger (<anonymous>:6:7)
at redirectFun (<anonymous>:9:7)
at testFunction (<anonymous>:19:3)
at <anonymous>:1:1
Finished!
// 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
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;
}
var fun = generateAsmJs(this, {'call_debugger': call_debugger}, undefined);
fun();
}
InspectorTest.addScript(testFunction.toString());
Protocol.Debugger.enable();
Protocol.Debugger.oncePaused().then(handleDebuggerPaused);
Protocol.Runtime.evaluate({'expression': 'testFunction()'});
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;
InspectorTest.log('Number of frames: ' + frames.length);
for (var i = 0; i < frames.length; ++i) {
InspectorTest.log(' - [' + i + '] ' + locationToString(frames[i]));
}
}
function handleDebuggerPaused(messageObject)
{
InspectorTest.log('Paused on \'debugger;\'');
logStackTrace(messageObject);
InspectorTest.log('Getting v8-generated stack trace...');
var topFrameId = messageObject.params.callFrames[0].callFrameId;
Protocol.Debugger
.evaluateOnCallFrame({
callFrameId: topFrameId,
expression: '(new Error("getting stack trace")).stack'
})
.then(callbackEvaluate);
}
function callbackEvaluate(response)
{
InspectorTest.log(
'Result of evaluate (' + response.result.result.type + '):');
var result_lines = response.result.result.value.split("\n");
// Skip the second line, containing the 'evaluate' position.
result_lines[1] = " -- skipped --";
InspectorTest.log(result_lines.join('\n'));
InspectorTest.log('Finished!');
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