Files: 9815c3cee36f62eacffbd32f58584ac348296edd / debugInterface.js
1177 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 | // This is ASCII only |
9 | function Uint8ArrayToString (input) { |
10 | return String.fromCharCode.apply(null, input) |
11 | } |
12 | |
13 | function Uint8ArrayToHexString (input) { |
14 | return new Buffer(input).toString('hex') |
15 | } |
16 | |
17 | module.exports = class DebugInterface { |
18 | setModule (mod) { |
19 | this.module = mod |
20 | } |
21 | |
22 | get exportTable () { |
23 | return { |
24 | 'print': function (a) { |
25 | console.log(a) |
26 | }, |
27 | 'printHex': function (offset, length) { |
28 | console.log(`<DEBUG(hex): ${Uint8ArrayToHexString(new Uint8Array(this.module.exports.memory, offset, length))}>`) |
29 | }.bind(this), |
30 | |
31 | 'evmStackTrace': function (sp, op) { |
32 | const opcode = opcodes(op) |
33 | if (opcode.number) { |
34 | opcode.name += opcode.number |
35 | } |
36 | console.error(opcode.name) |
37 | console.log('-------------stack--------------') |
38 | for (let i = sp; i > 0; i -= 32) { |
39 | console.log(`${(sp - i) / 32} ${Uint8ArrayToHexString(new Uint8Array(this.module.exports.memory, i - 24, 32))}`) |
40 | } |
41 | return sp |
42 | }.bind(this) |
43 | } |
44 | } |
45 | } |
46 |
Built with git-ssb-web