Files: 165f38bff6cbefc46c657670ea89e4f84bf05089 / debugInterface.js
1314 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 (kernel) { |
10 | this.kernel = kernel |
11 | } |
12 | |
13 | static get name () { |
14 | return 'debug' |
15 | } |
16 | |
17 | get exports () { |
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.kernel.environment.gasLeft} sp: ${sp}`) |
36 | console.log('-------------stack--------------') |
37 | for (let i = sp; i >= 0; i -= 32) { |
38 | console.log(`${(sp - i) / 32} ${this.getMemoryBuffer(i).toString('hex')}`) |
39 | } |
40 | }.bind(this) |
41 | } |
42 | } |
43 | |
44 | getMemoryBuffer (offset, length = 32) { |
45 | const mem = this.kernel.memory.slice(offset, offset + length) |
46 | return Buffer.from(mem).reverse() |
47 | } |
48 | } |
49 |
Built with git-ssb-web