Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: test/inspector/debugger/wasm-imports.js

Issue 2720813002: [wasm] Fix importing wasm functions which are being debugged (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/wasm/wasm-module.cc ('k') | test/inspector/debugger/wasm-imports-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 load('test/mjsunit/wasm/wasm-constants.js');
6 load('test/mjsunit/wasm/wasm-module-builder.js');
7
8 // Build two modules A and B. A defines function func, which contains a
9 // breakpoint. This function is then imported by B and called via main. The
10 // breakpoint must be hit.
11 // This failed before (http://crbug.com/v8/5971).
12
13 var builder_a = new WasmModuleBuilder();
14 var func_idx = builder_a.addFunction('func', kSig_v_v)
15 .addBody([kExprNop])
16 .exportFunc()
17 .index;
18 var module_a_bytes = builder_a.toArray();
19
20 var builder_b = new WasmModuleBuilder();
21 var import_idx = builder_b.addImport('imp', 'f', kSig_v_v);
22 builder_b.addFunction('main', kSig_v_v)
23 .addBody([kExprCallFunction, import_idx])
24 .exportFunc();
25 var module_b_bytes = builder_b.toArray();
26
27 function instantiate(bytes, imp) {
28 var buffer = new ArrayBuffer(bytes.length);
29 var view = new Uint8Array(buffer);
30 for (var i = 0; i < bytes.length; ++i) {
31 view[i] = bytes[i] | 0;
32 }
33
34 var module = new WebAssembly.Module(buffer);
35 // Add to global instances array.
36 instances.push(new WebAssembly.Instance(module, imp));
37 }
38
39 var evalWithUrl = (code, url) => Protocol.Runtime.evaluate(
40 {'expression': code + '\n//# sourceURL=v8://test/' + url});
41
42 Protocol.Debugger.onPaused(handlePaused);
43 var script_a_id;
44
45 Protocol.Debugger.enable()
46 .then(() => InspectorTest.log('Installing code and global variable.'))
47 .then(
48 () => evalWithUrl(
49 'var instances = [];\n' + instantiate.toString(), 'setup'))
50 .then(() => InspectorTest.log('Calling instantiate function for module A.'))
51 .then(
52 () =>
53 (evalWithUrl(
54 'instantiate(' + JSON.stringify(module_a_bytes) + ')',
55 'instantiateA'),
56 0))
57 .then(waitForWasmScript)
58 .then(() => InspectorTest.log('Setting breakpoint in line 1, column 2'))
59 .then(() => Protocol.Debugger.setBreakpoint({
kozy 2017/02/28 16:47:02 Just wondering, is setBreakpointByUrl supported fo
Clemens Hammacher 2017/03/02 14:02:35 Yes, it is. In order to also cover it, I just chan
60 'location':
kozy 2017/02/28 16:47:01 quotes are optional: 'location' -> location
Clemens Hammacher 2017/03/02 14:02:35 Done.
61 {'scriptId': script_a_id, 'lineNumber': 1, 'columnNumber': 2}
62 }))
63 .then(printFailure)
64 .then(msg => InspectorTest.logMessage(msg.result.actualLocation))
kozy 2017/02/28 16:47:02 You can use here too, but please change argument t
Clemens Hammacher 2017/03/02 14:02:35 Done, but it required some refactoring. logCallFra
65 .then(() => InspectorTest.log('Calling instantiate function for module B.'))
66 .then(
67 () =>
68 (evalWithUrl(
69 'instantiate(' + JSON.stringify(module_b_bytes) +
70 ', {imp: {f: instances[0].exports.func}})',
71 'instantiateB'),
72 0))
73 .then(() => InspectorTest.log('Calling main function on module B.'))
74 .then(() => evalWithUrl('instances[1].exports.main()', 'runWasm'))
kozy 2017/02/28 16:47:02 To handle asynchronous call in onPaused handler yo
Clemens Hammacher 2017/03/02 14:02:35 Done, also inlined the handlePaused method, which
75 .then(() => InspectorTest.log('exports.main returned.'))
76 .then(() => InspectorTest.log('Finished.'))
77 .then(InspectorTest.completeTest);
78
79 function printFailure(message) {
80 if (!message.result) {
81 InspectorTest.logMessage(message);
82 }
83 return message;
84 }
85
86 function waitForWasmScript() {
kozy 2017/02/28 16:47:02 Less symbols with more promise magic: function wa
Clemens Hammacher 2017/03/02 14:02:35 Wow, that's awesome. I now even return the url fro
87 InspectorTest.log('Waiting for wasm script to be parsed.');
88 var got_wasm_script;
89 var promise = new Promise(fulfill => got_wasm_script = fulfill);
90 function waitForMore() {
91 Protocol.Debugger.onceScriptParsed()
92 .then(handleNewScript);
93 }
94 function handleNewScript(msg) {
95 var url = msg.params.url;
96 if (!url.startsWith('wasm://')) {
97 InspectorTest.log('Ignoring script with url ' + url);
kozy 2017/02/28 16:47:01 Could potentially add flakiness if we compile some
Clemens Hammacher 2017/03/02 14:02:35 Done.
98 waitForMore();
99 return;
100 }
101 InspectorTest.log('Got wasm script!');
102 script_a_id = msg.params.scriptId;
103 InspectorTest.log('Source:');
104 Protocol.Debugger.getScriptSource({scriptId: script_a_id})
105 .then(printFailure)
106 .then(msg => InspectorTest.log(msg.result.scriptSource))
107 .then(() => got_wasm_script(script_a_id));
108 }
109 waitForMore();
110 return promise;
111 }
112
113 function handlePaused(msg) {
114 var loc = msg.params.callFrames[0].location;
115 InspectorTest.log(
kozy 2017/02/28 16:47:02 You can use InspectorTest.logCallFrames([msg.param
Clemens Hammacher 2017/03/02 14:02:35 Neverending awesomeness. Done!
116 'Paused at ' + loc.lineNumber + ':' + loc.columnNumber + '.');
117 InspectorTest.log('Getting current stack trace via "new Error().stack".');
118 // TODO(clemensh): The interpreted frame should also show up on this stack
kozy 2017/02/28 16:47:02 Sounds like big TODO, how stepping works in this c
Clemens Hammacher 2017/03/02 14:02:35 Stepping works correctly (on the top interpreter f
119 // trace.
120 evalWithUrl('new Error().stack', 'getStack')
kozy 2017/02/28 16:47:01 This command is asynchronous and it works currentl
kozy 2017/02/28 19:28:26 Oops, please disregard this comment, just change l
Clemens Hammacher 2017/03/02 14:02:35 Good catch! Done.
121 .then(msg => InspectorTest.log(msg.result.result.value))
122 .then(Protocol.Debugger.resume());
123 }
OLDNEW
« no previous file with comments | « src/wasm/wasm-module.cc ('k') | test/inspector/debugger/wasm-imports-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698