embark/lib/modules/debugger/debugger_manager.js

104 lines
2.5 KiB
JavaScript
Raw Normal View History

var RemixDebug = require('remix-debug-debugtest');
var CmdLine = RemixDebug.CmdLine;
const async = require('async');
class DebuggerManager {
constructor(nodeUrl) {
2018-10-29 13:15:48 +00:00
this.nodeUrl = nodeUrl;
this.outputJson = {};
this.inputJson = {};
}
setInputJson(inputJson) {
2018-10-29 13:15:48 +00:00
this.inputJson = inputJson;
}
setOutputJson(outputJson) {
2018-10-29 13:15:48 +00:00
this.outputJson = outputJson;
}
createDebuggerSession(txHash, filename, cb) {
2018-10-29 13:15:48 +00:00
return this.debug(txHash, filename, cb);
}
debug(txHash, filename, cb) {
2018-10-29 13:15:48 +00:00
console.dir("debugging tx " + txHash);
2018-10-29 13:15:48 +00:00
var cmd_line = new CmdLine();
this.cmd_line = cmd_line;
cmd_line.connect("http", this.nodeUrl);
cmd_line.loadCompilationData(this.inputJson, this.outputJson);
cmd_line.initDebugger(() => {
2018-10-29 13:15:48 +00:00
this.isDebugging = true;
cmd_line.startDebug(txHash, filename, () => {
if (cb) {
2018-10-29 13:15:48 +00:00
cmd_line.triggerSourceUpdate();
cb();
}
2018-10-29 13:15:48 +00:00
});
});
return cmd_line;
}
getLastLine(txHash, filename, outputCb) {
const self = this;
2018-10-29 13:15:48 +00:00
let cmd_line = new CmdLine();
async.waterfall([
function initDebugger(next) {
2018-10-29 13:15:48 +00:00
cmd_line = new CmdLine();
cmd_line.connect("http", self.nodeUrl);
cmd_line.loadCompilationData(self.inputJson, self.outputJson);
cmd_line.initDebugger(() => {
// self.isDebugging = true
2018-10-29 13:15:48 +00:00
next();
});
},
function startDebug(next) {
2018-10-29 14:33:12 +00:00
let debuggerData = {};
cmd_line.events.on("locals", (data) => {
debuggerData.locals = self.simplifyDebuggerVars(data);
});
2018-10-29 14:33:12 +00:00
cmd_line.events.on("globals", (data) => {
debuggerData.contract = self.simplifyDebuggerVars(data);
});
cmd_line.startDebug(txHash, filename, () => {
cmd_line.events.on("source", () => {
2018-10-29 14:33:12 +00:00
let lines = cmd_line.getSource();
// TODO: this is a bit of a hack
let line = lines.filter((x) => x.indexOf("=>") === 0)[0];
2018-10-29 13:15:48 +00:00
outputCb(lines, line, debuggerData);
});
2018-10-29 13:15:48 +00:00
let total_size = cmd_line.getTraceLength();
cmd_line.jumpTo(total_size - 1);
cmd_line.unload();
2018-10-29 13:15:48 +00:00
next();
});
}
], () => {
2018-10-29 13:15:48 +00:00
});
}
2018-10-29 14:33:12 +00:00
// TODO: this is duplicated in debugger/index.js
simplifyDebuggerVars(data) {
let new_data = {};
2018-10-29 14:33:12 +00:00
for (let key in data) {
let field = data[key];
new_data[`${key} (${field.type})`] = field.value;
}
2018-10-29 14:33:12 +00:00
return new_data;
}
}
module.exports = DebuggerManager;