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

Side by Side Diff: test/inspector/debugger/wasm-get-breakable-locations.js

Issue 2655653003: [inspector] Expose GetPossibleBreakpoints for wasm (Closed)
Patch Set: Created 3 years, 10 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
OLDNEW
(Empty)
1 // Copyright 2016 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 // Flags: --expose-wasm
6
7 load('test/mjsunit/wasm/wasm-constants.js');
8 load('test/mjsunit/wasm/wasm-module-builder.js');
9
10 var builder = new WasmModuleBuilder();
11
12 // clang-format off
13 var func_idx = builder.addFunction('helper', kSig_v_v)
14 .addLocals({i32_count: 1})
15 .addBody([
16 kExprNop,
17 kExprI32Const, 12,
18 kExprSetLocal, 0,
19 ]).index;
20
21 builder.addFunction('main', kSig_v_i)
22 .addBody([
23 kExprGetLocal, 0,
24 kExprIf, kWasmStmt,
25 kExprBlock, kWasmStmt,
26 kExprCallFunction, func_idx,
27 kExprEnd,
28 kExprEnd
29 ]).exportAs('main');
30 // clang-format on
31
32 var module_bytes = builder.toArray();
33
34 function testFunction(bytes) {
35 var buffer = new ArrayBuffer(bytes.length);
36 var view = new Uint8Array(buffer);
37 for (var i = 0; i < bytes.length; i++) {
38 view[i] = bytes[i] | 0;
39 }
40
41 var module = new WebAssembly.Module(buffer);
42 }
43
44 var addSourceUrl = (code, url) => '//# sourceURL=' + url + '\n' + code;
45
46 InspectorTest.addScript(
47 addSourceUrl(testFunction.toString(), 'v8://test/testFunction'));
48 InspectorTest.addScript('var module_bytes = ' + JSON.stringify(module_bytes));
49
50 Protocol.Debugger.enable();
51 Protocol.Debugger.onScriptParsed(handleScriptParsed);
52 InspectorTest.log('Running testFunction...');
53 Protocol.Runtime
54 .evaluate({
55 'expression': addSourceUrl(
56 'testFunction(module_bytes)', 'v8://test/runTestFunction')
57 })
58 .then(getBreakableLocationsForAllWasmScripts)
59 .then(() => InspectorTest.log('Finished!'))
60 .then(InspectorTest.completeTest);
61
62 var numScripts = 0;
63 var wasmScripts = [];
64 function handleScriptParsed(messageObject) {
65 var scriptId = messageObject.params.scriptId;
66 var url = messageObject.params.url;
67 InspectorTest.log('Script nr ' + numScripts + ' parsed. URL: ' + url);
68 ++numScripts;
69
70 if (url.startsWith('wasm://')) {
71 InspectorTest.log('This is a wasm script (nr ' + wasmScripts.length + ').');
72 wasmScripts.push(scriptId);
73 }
74 }
75
76 function printBreakableLocations(message, expectedScriptId, source) {
77 if (!message.result || !message.result.locations) {
78 InspectorTest.logMessage(message);
79 return;
80 }
81 var lines = source.split('\n');
82 var locations = message.result.locations;
83 InspectorTest.log(locations.length + ' breakable location(s):');
84 for (var i = 0; i < locations.length; ++i) {
85 if (locations[i].scriptId != expectedScriptId) {
86 InspectorTest.log(
87 'SCRIPT ID MISMATCH!! ' + locations[i].scriptId + ' != ' +
88 expectedScriptId);
89 }
90 var line = '<illegal line number>';
91 if (locations[i].lineNumber < lines.length) {
92 line = lines[locations[i].lineNumber];
93 if (locations[i].columnNumber < line.length) {
94 line = line.substr(0, locations[i].columnNumber) + '>' +
95 line.substr(locations[i].columnNumber);
96 }
97 }
98 InspectorTest.log(
99 '[' + i + '] ' + locations[i].lineNumber + ':' +
100 locations[i].columnNumber + ' || ' + line);
101 }
102 }
103
104 function getSourceFromMessage(message) {
105 if (!message.result || !message.result.scriptSource) {
kozy 2017/01/25 18:34:19 Why do you need this method? If you have only vali
Clemens Hammacher 2017/01/25 20:23:54 I thought it helps debugging in the error case. Re
106 InspectorTest.logMessage(message);
107 return '';
108 }
109 return message.result.scriptSource;
110 }
111
112 function checkGetBreakableLocations(wasmScriptNr) {
113 InspectorTest.log(
114 'Requesting all breakable locations in wasm script ' + wasmScriptNr);
115 var scriptId = wasmScripts[wasmScriptNr];
116 var source;
117 return Protocol.Debugger.getScriptSource({scriptId: scriptId})
118 .then((message) => source = getSourceFromMessage(message))
119 .then(
120 () => Protocol.Debugger.getPossibleBreakpoints(
121 {start: {lineNumber: 0, columnNumber: 0, scriptId: scriptId}}))
122 .then((message) => printBreakableLocations(message, scriptId, source))
123 .then(
124 () => InspectorTest.log(
125 'Requesting breakable locations in lines [0,3)'))
126 .then(() => Protocol.Debugger.getPossibleBreakpoints({
127 start: {lineNumber: 0, columnNumber: 0, scriptId: scriptId},
128 end: {lineNumber: 3, columnNumber: 0, scriptId: scriptId}
129 }))
130 .then((message) => printBreakableLocations(message, scriptId, source))
131 .then(
132 () => InspectorTest.log(
133 'Requesting breakable locations in lines [4,6)'))
134 .then(() => Protocol.Debugger.getPossibleBreakpoints({
kozy 2017/01/25 18:34:19 Could we add following test: getPossibleBreakpoint
Clemens Hammacher 2017/01/25 20:23:54 Fair enough :) Added this test, moving over two fi
135 start: {lineNumber: 4, columnNumber: 0, scriptId: scriptId},
136 end: {lineNumber: 6, columnNumber: 0, scriptId: scriptId}
137 }))
138 .then((message) => printBreakableLocations(message, scriptId, source));
139 }
140
141 function getBreakableLocationsForAllWasmScripts() {
142 InspectorTest.log('Querying breakable locations for all wasm scripts now...');
143 var promise = Promise.resolve();
144 for (var wasmScriptNr = 0; wasmScriptNr < wasmScripts.length;
145 ++wasmScriptNr) {
146 promise = promise.then(checkGetBreakableLocations.bind(null, wasmScriptNr));
147 }
148 return promise;
149 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698