Commit 5b6e3913 authored by clemensh's avatar clemensh Committed by Commit bot

[wasm] Add inspector test for stack traces

This ensures that the stack traces show up correctly in
DevTools. I will later extend it for source view.

R=kozyatinskiy@chromium.org, yangguo@chromium.org, titzer@chromium.org
BUG=chromium:613110

Review-Url: https://codereview.chromium.org/2420093002
Cr-Commit-Position: refs/heads/master@{#40392}
parent 0655c459
Running testFunction with generated WASM bytes...
Paused on 'debugger;'
Number of frames: 5
- [0] {"functionName":"call_debugger","function_lineNumber":1,"function_columnNumber":24,"lineNumber":2,"columnNumber":4}
- [1] {"functionName":"main","lineNumber":0,"columnNumber":1}
- [2] {"functionName":"main","lineNumber":0,"columnNumber":1}
- [3] {"functionName":"testFunction","function_lineNumber":0,"function_columnNumber":21,"lineNumber":14,"columnNumber":19}
- [4] {"functionName":"","function_lineNumber":0,"function_columnNumber":0,"lineNumber":0,"columnNumber":0}
Getting v8-generated stack trace...
Result of evaluate (string):
Error: this is your stack trace:
-- skipped --
at call_debugger (<anonymous>:3:5)
at main (<WASM>[1]+1)
at main (<WASM>[2]+1)
at testFunction (<anonymous>:15:20)
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: --expose-wasm
load('test/mjsunit/wasm/wasm-constants.js');
load('test/mjsunit/wasm/wasm-module-builder.js');
var builder = new WasmModuleBuilder();
var imported_idx = builder.addImport("func", kSig_v_v);
var call_imported_idx = builder.addFunction("main", kSig_v_v)
.addBody([kExprCallFunction, imported_idx])
.index;
builder.addFunction("main", kSig_v_v)
.addBody([kExprCallFunction, call_imported_idx])
.exportAs("main");
var module_bytes = builder.toArray();
function testFunction(bytes) {
function call_debugger() {
debugger;
}
var buffer = new ArrayBuffer(bytes.length);
var view = new Uint8Array(buffer);
for (var i = 0; i < bytes.length; i++) {
view[i] = bytes[i] | 0;
}
var module = new WebAssembly.Module(buffer);
var instance = new WebAssembly.Instance(module, {func: call_debugger});
instance.exports.main();
}
InspectorTest.addScript(testFunction.toString());
Protocol.Debugger.enable();
Protocol.Debugger.onPaused(handleDebuggerPaused);
InspectorTest.log('Running testFunction with generated WASM bytes...');
Protocol.Runtime.evaluate(
{'expression': 'testFunction(' + JSON.stringify(module_bytes) + ')'});
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("this is your 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();
}
......@@ -33,7 +33,8 @@ class UtilsExtension : public v8::Extension {
: v8::Extension("v8_inspector/utils",
"native function print();"
"native function quit();"
"native function setlocale();") {}
"native function setlocale();"
"native function load();") {}
virtual v8::Local<v8::FunctionTemplate> GetNativeFunctionTemplate(
v8::Isolate* isolate, v8::Local<v8::String> name) {
v8::Local<v8::Context> context = isolate->GetCurrentContext();
......@@ -54,6 +55,12 @@ class UtilsExtension : public v8::Extension {
.ToLocalChecked())
.FromJust()) {
return v8::FunctionTemplate::New(isolate, UtilsExtension::SetLocale);
} else if (name->Equals(context,
v8::String::NewFromUtf8(isolate, "load",
v8::NewStringType::kNormal)
.ToLocalChecked())
.FromJust()) {
return v8::FunctionTemplate::New(isolate, UtilsExtension::Load);
}
return v8::Local<v8::FunctionTemplate>();
}
......@@ -102,6 +109,29 @@ class UtilsExtension : public v8::Extension {
v8::String::Utf8Value str(args[0]);
setlocale(LC_NUMERIC, *str);
}
static void Load(const v8::FunctionCallbackInfo<v8::Value>& args) {
if (args.Length() != 1 || !args[0]->IsString()) {
fprintf(stderr, "Internal error: load gets one string argument.");
Exit();
}
v8::String::Utf8Value str(args[0]);
v8::Isolate* isolate = args.GetIsolate();
bool exists = false;
std::string filename(*str, str.length());
v8::internal::Vector<const char> chars =
v8::internal::ReadFile(filename.c_str(), &exists);
if (!exists) {
isolate->ThrowException(
v8::String::NewFromUtf8(isolate, "Error loading file",
v8::NewStringType::kNormal)
.ToLocalChecked());
return;
}
ExecuteStringTask task(chars);
v8::Global<v8::Context> context(isolate, isolate->GetCurrentContext());
task.Run(isolate, context);
}
};
class SetTimeoutTask : public TaskRunner::Task {
......
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