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

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: Add test case 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
« src/objects-inl.h ('K') | « 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")) {
ahaas 2016/06/17 06:57:50 What's the idea behind this condition? Can you add
Clemens Hammacher 2016/06/17 18:01:55 Done.
49 expected_string = "kExprCallImport,";
50 } else if (name.endsWith("/1")) {
51 expected_string = "kExprCallFunction,";
52 } else {
53 assertTrue(false, "Unexpected wasm script: " + name);
54 }
55 assertTrue(line.substr(columnNr).startsWith(expected_string),
56 "offset " + columnNr + " should start with '" + expected_string
57 + "': " + line);
58 }
59 }
60 } else if (event == Debug.DebugEvent.AfterCompile) {
61 var script = event_data.script();
62 if (script.scriptType() == Debug.ScriptType.Wasm) {
63 ++num_wasm_scripts;
64 }
65 }
66 } catch (e) {
67 print("exception: " + e);
68 exception = e;
69 }
70 };
71
72 var builder = new WasmModuleBuilder();
73
74 builder.addImport("func", kSig_v_v);
75
76 builder.addFunction("call_import", kSig_v_v)
77 .addBody([kExprCallImport, kArity0, 0])
78 .exportFunc();
79
80 // Add a bit of unneccessary code to increase the byte offset.
81 builder.addFunction("call_call_import", kSig_v_v)
82 .addLocals({i32_count: 2})
83 .addBody([
84 kExprI32Const, 27, kExprSetLocal, 0,
85 kExprI32Const, (-7 & 0x7f), kExprSetLocal, 1,
86 kExprGetLocal, 0, kExprGetLocal, 1, kExprI32Add, kExprI64UConvertI32,
87 kExprI64Const, 0,
88 kExprI64Ne, kExprIf,
89 kExprCallFunction, kArity0, 0,
90 kExprEnd
91 ])
92 .exportFunc();
93
94 function call_debugger() {
95 debugger;
96 }
97
98 function setup() {
99 module = builder.instantiate({func: call_debugger});
100 exception = null;
101 break_count = 0;
102 num_wasm_scripts = 0;
103 }
104
105 (function testRegisteredWasmScripts1() {
106 setup();
107 Debug.setListener(listener);
108 // Initially 0 scripts.
109 assertEquals(0, num_wasm_scripts);
110 // Call the "call_import" function -> 1 script.
111 module.exports.call_import();
112 assertEquals(1, num_wasm_scripts);
113 // Call "call_import" again -> still just 1 script.
114 module.exports.call_import();
115 assertEquals(1, num_wasm_scripts);
116 // Call "call_call_import" -> now 2 scripts.
117 module.exports.call_call_import();
118 assertEquals(2, num_wasm_scripts);
119 Debug.setListener(null);
120
121 assertEquals(3, break_count);
122 if (exception) throw exception;
123 })();
124
125 (function testRegisteredWasmScripts2() {
126 setup();
127 Debug.setListener(listener);
128 // Initially 0 scripts.
129 assertEquals(0, num_wasm_scripts);
130 // Call the "call_call_import" function -> 2 scripts should be registered.
131 module.exports.call_call_import();
132 assertEquals(2, num_wasm_scripts);
133 Debug.setListener(null);
134
135 assertEquals(1, break_count);
136 if (exception) throw exception;
137 })();
OLDNEW
« src/objects-inl.h ('K') | « src/wasm/wasm-debug.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698