git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: fad5165be334ea1479fd4d88bd0fa7779765140f

Files: fad5165be334ea1479fd4d88bd0fa7779765140f / debugInterface.js

1304 bytesRaw
1const opcodes = require('./opcodes.js')
2
3/**
4 * Debug Interface
5 * This expose some functions that can help with debugging wast
6 */
7
8module.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 return sp
41 }.bind(this)
42 }
43 }
44
45 getMemoryBuffer (offset) {
46 return new Buffer(this.module.exports.memory.slice(offset, offset + 32))
47 }
48}
49

Built with git-ssb-web