Files: 4d1cb1ad70b607a809129de298594beb4d82ba71 / debugInterface.js
1135 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 (offset, length) { |
16 | console.log(`<DEBUG(str): ${this.getMemoryBuffer(offset, length).toString()}>`) |
17 | }.bind(this), |
18 | |
19 | 'printHex': function (offset, length) { |
20 | console.log(`<DEBUG(hex): ${this.getMemoryBuffer(offset, length).toString('hex')}>`) |
21 | }.bind(this), |
22 | |
23 | 'evmStackTrace': function (sp, op) { |
24 | const opcode = opcodes(op) |
25 | if (opcode.number) { |
26 | opcode.name += opcode.number |
27 | } |
28 | console.error(opcode.name) |
29 | console.log('-------------stack--------------') |
30 | for (let i = sp; i > 0; i -= 32) { |
31 | console.log(`${(sp - i) / 32} ${this.getMemoryBuffer(i - 24, 32).toString('hex')}`) |
32 | } |
33 | return sp |
34 | }.bind(this) |
35 | } |
36 | } |
37 | |
38 | getMemoryBuffer (offset, length) { |
39 | return new Buffer(new Uint8Array(this.module.exports.memory, offset, length)) |
40 | } |
41 | } |
42 |
Built with git-ssb-web