Files: 9b99d153421b050c83a444b213cdd1f70243c05a / debugInterface.js
1286 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 | constructor (environment) { |
10 | this.environment = environment |
11 | } |
12 | |
13 | setModule (mod) { |
14 | this.module = mod |
15 | } |
16 | |
17 | get exportTable () { |
18 | return { |
19 | 'print': function (a) { |
20 | console.log(a) |
21 | }, |
22 | 'printMem': function (offset, length) { |
23 | console.log(`<DEBUG(str): ${this.getMemoryBuffer(offset, length).toString()}>`) |
24 | }.bind(this), |
25 | |
26 | 'printMemHex': function (offset, length) { |
27 | console.log(`<DEBUG(hex): ${this.getMemoryBuffer(offset, length).toString('hex')}>`) |
28 | }.bind(this), |
29 | |
30 | 'evmStackTrace': function (sp, op) { |
31 | const opcode = opcodes(op) |
32 | if (opcode.number) { |
33 | opcode.name += opcode.number |
34 | } |
35 | console.error(`op: ${opcode.name} gas: ${this.environment.gasLeft}`) |
36 | console.log('-------------stack--------------') |
37 | for (let i = sp; i >= 0; i -= 32) { |
38 | console.log(`${(sp - i) / 32} ${this.getMemoryBuffer(i).reverse().toString('hex')}`) |
39 | } |
40 | }.bind(this) |
41 | } |
42 | } |
43 | |
44 | getMemoryBuffer (offset) { |
45 | return new Buffer(this.module.exports.memory.slice(offset, offset + 32)) |
46 | } |
47 | } |
48 |
Built with git-ssb-web