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

Side by Side Diff: test/mjsunit/wasm/debug-disassembly.js

Issue 2063013004: [wasm] Disassemble wasm code from script (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@wasm-frame-inspection
Patch Set: remove unimplemented wasm SetBreakPoint method Created 4 years, 6 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-debug.cc ('k') | no next file » | 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 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 --expose-debug-as debug
6
7 load("test/mjsunit/wasm/wasm-constants.js");
8 load("test/mjsunit/wasm/wasm-module-builder.js");
9
10 Debug = debug.Debug
11
12 // Initialized in setup().
13 var exception;
14 var break_count;
15 var num_wasm_scripts;
16 var module;
17
18 function listener(event, exec_state, event_data, data) {
19 try {
20 if (event == Debug.DebugEvent.Break) {
21 ++break_count;
22 // Request frame details. This should trigger creation of the Script
23 // objects for all frames on the stack.
24 var num_frames = exec_state.frameCount();
25 for (var i = 0; i < num_frames; ++i) {
26 var frame = exec_state.frame(i);
27 var details = frame.details();
28 var script = details.script();
29 if (script.type == Debug.ScriptType.Wasm) {
30 var pos = frame.sourcePosition();
31 var name = script.nameOrSourceURL();
32 var disassembly = Debug.disassembleWasmFunction(script.id);
33 var offset_table = Debug.getWasmFunctionOffsetTable(script.id);
34 assertEquals(0, offset_table.length % 3);
35 var lineNr = null;
36 var columnNr = null;
37 for (var p = 0; p < offset_table.length; p += 3) {
38 if (offset_table[p] != pos) continue;
39 lineNr = offset_table[p+1];
40 columnNr = offset_table[p+2];
41 }
42 assertNotNull(lineNr, "position should occur in offset table");
43 assertNotNull(columnNr, "position should occur in offset table");
44 var line = disassembly.split("\n")[lineNr];
45 assertTrue(!!line, "line number must occur in disassembly");
46 assertTrue(line.length > columnNr, "column number must be valid");
47 var expected_string;
48 if (name.endsWith("/0")) {
49 // Function 0 calls the imported function.
50 expected_string = "kExprCallImport,";
51 } else if (name.endsWith("/1")) {
52 // Function 1 calls function 0.
53 expected_string = "kExprCallFunction,";
54 } else {
55 assertTrue(false, "Unexpected wasm script: " + name);
56 }
57 assertTrue(line.substr(columnNr).startsWith(expected_string),
58 "offset " + columnNr + " should start with '" + expected_string
59 + "': " + line);
60 }
61 }
62 } else if (event == Debug.DebugEvent.AfterCompile) {
63 var script = event_data.script();
64 if (script.scriptType() == Debug.ScriptType.Wasm) {
65 ++num_wasm_scripts;
66 }
67 }
68 } catch (e) {
69 print("exception: " + e);
70 exception = e;
71 }
72 };
73
74 var builder = new WasmModuleBuilder();
75
76 builder.addImport("func", kSig_v_v);
77
78 builder.addFunction("call_import", kSig_v_v)
79 .addBody([kExprCallImport, kArity0, 0])
80 .exportFunc();
81
82 // Add a bit of unneccessary code to increase the byte offset.
83 builder.addFunction("call_call_import", kSig_v_v)
84 .addLocals({i32_count: 2})
85 .addBody([
86 kExprI32Const, 27, kExprSetLocal, 0,
87 kExprI32Const, (-7 & 0x7f), kExprSetLocal, 1,
88 kExprGetLocal, 0, kExprGetLocal, 1, kExprI32Add, kExprI64UConvertI32,
89 kExprI64Const, 0,
90 kExprI64Ne, kExprIf,
91 kExprCallFunction, kArity0, 0,
92 kExprEnd
93 ])
94 .exportFunc();
95
96 function call_debugger() {
97 debugger;
98 }
99
100 function setup() {
101 module = builder.instantiate({func: call_debugger});
102 exception = null;
103 break_count = 0;
104 num_wasm_scripts = 0;
105 }
106
107 (function testRegisteredWasmScripts1() {
108 setup();
109 Debug.setListener(listener);
110 // Initially 0 scripts.
111 assertEquals(0, num_wasm_scripts);
112 // Call the "call_import" function -> 1 script.
113 module.exports.call_import();
114 assertEquals(1, num_wasm_scripts);
115 // Call "call_import" again -> still just 1 script.
116 module.exports.call_import();
117 assertEquals(1, num_wasm_scripts);
118 // Call "call_call_import" -> now 2 scripts.
119 module.exports.call_call_import();
120 assertEquals(2, num_wasm_scripts);
121 Debug.setListener(null);
122
123 assertEquals(3, break_count);
124 if (exception) throw exception;
125 })();
126
127 (function testRegisteredWasmScripts2() {
128 setup();
129 Debug.setListener(listener);
130 // Initially 0 scripts.
131 assertEquals(0, num_wasm_scripts);
132 // Call the "call_call_import" function -> 2 scripts should be registered.
133 module.exports.call_call_import();
134 assertEquals(2, num_wasm_scripts);
135 Debug.setListener(null);
136
137 assertEquals(1, break_count);
138 if (exception) throw exception;
139 })();
OLDNEW
« no previous file with comments | « src/wasm/wasm-debug.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698