Files: e23661111510428ac4d7fe48b9567b29183f0c6b / debugInterface.js
1204 bytesRaw
1 | const opcodes = require('./opcodes.js') |
2 | |
3 | /** |
4 | * Debug Interface |
5 | * This expose some functions that can help with debugging wast |
6 | */ |
7 | |
8 | module.exports = class DebugInterface { |
9 | setModule (mod) { |
10 | this.module = mod |
11 | } |
12 | |
13 | get exportTable () { |
14 | return { |
15 | 'print': function (a) { |
16 | console.log(a) |
17 | }, |
18 | |
19 | 'printMem': function (offset, length) { |
20 | console.log(`<DEBUG(str): ${this.getMemoryBuffer(offset, length).toString()}>`) |
21 | }.bind(this), |
22 | |
23 | 'printMemHex': function (offset, length) { |
24 | console.log(`<DEBUG(hex): ${this.getMemoryBuffer(offset, length).toString('hex')}>`) |
25 | }.bind(this), |
26 | |
27 | 'evmStackTrace': function (sp, op) { |
28 | const opcode = opcodes(op) |
29 | if (opcode.number) { |
30 | opcode.name += opcode.number |
31 | } |
32 | console.error(opcode.name) |
33 | console.log('-------------stack--------------') |
34 | for (let i = sp; i > 0; i -= 32) { |
35 | console.log(`${(sp - i) / 32} ${this.getMemoryBuffer(i - 24, 32).toString('hex')}`) |
36 | } |
37 | return sp |
38 | }.bind(this) |
39 | } |
40 | } |
41 | |
42 | getMemoryBuffer (offset, length) { |
43 | return new Buffer(new Uint8Array(this.module.exports.memory, offset, length)) |
44 | } |
45 | } |
46 |
Built with git-ssb-web