2018-10-12 22:22:17 +00:00
|
|
|
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 = {};
|
2018-10-12 22:22:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setInputJson(inputJson) {
|
2018-10-29 13:15:48 +00:00
|
|
|
this.inputJson = inputJson;
|
2018-10-12 22:22:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setOutputJson(outputJson) {
|
2018-10-29 13:15:48 +00:00
|
|
|
this.outputJson = outputJson;
|
2018-10-12 22:22:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
createDebuggerSession(txHash, filename, cb) {
|
2018-10-29 13:15:48 +00:00
|
|
|
return this.debug(txHash, filename, cb);
|
2018-10-12 22:22:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
debug(txHash, filename, cb) {
|
2018-10-29 13:15:48 +00:00
|
|
|
console.dir("debugging tx " + txHash);
|
2018-10-12 22:22:17 +00:00
|
|
|
|
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);
|
2018-10-12 22:22:17 +00:00
|
|
|
|
|
|
|
cmd_line.initDebugger(() => {
|
2018-10-29 13:15:48 +00:00
|
|
|
this.isDebugging = true;
|
2018-10-12 22:22:17 +00:00
|
|
|
|
|
|
|
cmd_line.startDebug(txHash, filename, () => {
|
|
|
|
if (cb) {
|
2018-10-29 13:15:48 +00:00
|
|
|
cmd_line.triggerSourceUpdate();
|
|
|
|
cb();
|
2018-10-12 22:22:17 +00:00
|
|
|
}
|
2018-10-29 13:15:48 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
return cmd_line;
|
2018-10-12 22:22:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
getLastLine(txHash, filename, outputCb) {
|
|
|
|
const self = this;
|
2018-10-29 13:15:48 +00:00
|
|
|
let cmd_line = new CmdLine();
|
2018-10-12 22:22:17 +00:00
|
|
|
|
|
|
|
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);
|
2018-10-12 22:22:17 +00:00
|
|
|
cmd_line.initDebugger(() => {
|
|
|
|
// self.isDebugging = true
|
2018-10-29 13:15:48 +00:00
|
|
|
next();
|
|
|
|
});
|
2018-10-12 22:22:17 +00:00
|
|
|
},
|
|
|
|
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-27 19:31:13 +00:00
|
|
|
|
2018-10-29 14:33:12 +00:00
|
|
|
cmd_line.events.on("globals", (data) => {
|
|
|
|
debuggerData.contract = self.simplifyDebuggerVars(data);
|
|
|
|
});
|
2018-10-27 19:31:13 +00:00
|
|
|
|
2018-10-12 22:22:17 +00:00
|
|
|
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-12 22:22:17 +00:00
|
|
|
|
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-12 22:22:17 +00:00
|
|
|
|
2018-10-29 13:15:48 +00:00
|
|
|
next();
|
|
|
|
});
|
2018-10-12 22:22:17 +00:00
|
|
|
}
|
|
|
|
], () => {
|
2018-10-29 13:15:48 +00:00
|
|
|
});
|
2018-10-12 22:22:17 +00:00
|
|
|
}
|
2018-10-27 19:31:13 +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-27 19:31:13 +00:00
|
|
|
|
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-27 19:31:13 +00:00
|
|
|
|
2018-10-29 14:33:12 +00:00
|
|
|
return new_data;
|
|
|
|
}
|
2018-10-27 19:31:13 +00:00
|
|
|
|
2018-10-12 22:22:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = DebuggerManager;
|