git ssb

0+

wanderer🌟 / js-primea-hypervisor



Tree: ab4bcb92ec8d9a3fcaf593891c8069812603e70f

Files: ab4bcb92ec8d9a3fcaf593891c8069812603e70f / debugInterface.js

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

Built with git-ssb-web