git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: 8ced6c46cc8f744d128a65d00c117a79e68918b8

Files: 8ced6c46cc8f744d128a65d00c117a79e68918b8 / debugInterface.js

1313 bytesRaw
1const opcodes = require('./opcodes.js')
2
3/**
4 * Debug Interface
5 * This expose some functions that can help with debugging wast
6 */
7module.exports = class DebugInterface {
8 constructor (kernel) {
9 this.kernel = kernel
10 }
11
12 static get name () {
13 return 'debug'
14 }
15
16 get exports () {
17 return {
18 'print': function (a) {
19 console.log(a)
20 },
21 'printMem': function (offset, length) {
22 console.log(`<DEBUG(str): ${this.getMemoryBuffer(offset, length).toString()}>`)
23 }.bind(this),
24
25 'printMemHex': function (offset, length) {
26 console.log(`<DEBUG(hex): ${this.getMemoryBuffer(offset, length).toString('hex')}>`)
27 }.bind(this),
28
29 'evmStackTrace': function (sp, op) {
30 const opcode = opcodes(op)
31 if (opcode.number) {
32 opcode.name += opcode.number
33 }
34 console.error(`op: ${opcode.name} gas: ${this.kernel.environment.gasLeft} sp: ${sp}`)
35 console.log('-------------stack--------------')
36 for (let i = sp; i >= 0; i -= 32) {
37 console.log(`${(sp - i) / 32} ${this.getMemoryBuffer(i).toString('hex')}`)
38 }
39 }.bind(this)
40 }
41 }
42
43 getMemoryBuffer (offset, length = 32) {
44 const mem = this.kernel.memory.slice(offset, offset + length)
45 return Buffer.from(mem).reverse()
46 }
47}
48

Built with git-ssb-web