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