git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 53d0a8449b654d395b0965a2e0d05bb3cd6782fa

Files: 53d0a8449b654d395b0965a2e0d05bb3cd6782fa / debugInterface.js

1305 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.gasLimit}`)
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 return sp
41 }.bind(this)
42 }
43 }
44
45 getMemoryBuffer (offset) {
46 return new Buffer(this.module.exports.memory.slice(offset, offset + 32)).reverse()
47 }
48}
49

Built with git-ssb-web