mirror of https://github.com/embarklabs/embark.git
refactor(@embark/debugger): move debugger_manager.js to typescript
This commit is contained in:
parent
6526e83742
commit
227decde0a
File diff suppressed because it is too large
Load Diff
|
@ -172,6 +172,7 @@
|
|||
"@types/i18n": "0.8.3",
|
||||
"@types/node": "10.11.7",
|
||||
"@types/os-locale": "2.1.0",
|
||||
"@types/web3": "1.0.12",
|
||||
"babel-plugin-dynamic-import-node": "2.2.0",
|
||||
"chai": "4.1.2",
|
||||
"chalk": "2.4.1",
|
||||
|
|
|
@ -1,103 +0,0 @@
|
|||
var RemixDebug = require('remix-debug-debugtest');
|
||||
var CmdLine = RemixDebug.CmdLine;
|
||||
const async = require('async');
|
||||
|
||||
class DebuggerManager {
|
||||
|
||||
constructor(nodeUrl) {
|
||||
this.nodeUrl = nodeUrl;
|
||||
this.outputJson = {};
|
||||
this.inputJson = {};
|
||||
}
|
||||
|
||||
setInputJson(inputJson) {
|
||||
this.inputJson = inputJson;
|
||||
}
|
||||
|
||||
setOutputJson(outputJson) {
|
||||
this.outputJson = outputJson;
|
||||
}
|
||||
|
||||
createDebuggerSession(txHash, filename, cb) {
|
||||
return this.debug(txHash, filename, cb);
|
||||
}
|
||||
|
||||
debug(txHash, filename, cb) {
|
||||
console.dir("debugging tx " + txHash);
|
||||
|
||||
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(() => {
|
||||
this.isDebugging = true;
|
||||
|
||||
cmd_line.startDebug(txHash, filename, () => {
|
||||
if (cb) {
|
||||
cmd_line.triggerSourceUpdate();
|
||||
cb();
|
||||
}
|
||||
});
|
||||
});
|
||||
return cmd_line;
|
||||
}
|
||||
|
||||
getLastLine(txHash, filename, outputCb) {
|
||||
const self = this;
|
||||
let cmd_line = new CmdLine();
|
||||
|
||||
async.waterfall([
|
||||
function initDebugger(next) {
|
||||
cmd_line = new CmdLine();
|
||||
cmd_line.connect("http", self.nodeUrl);
|
||||
cmd_line.loadCompilationData(self.inputJson, self.outputJson);
|
||||
cmd_line.initDebugger(() => {
|
||||
// self.isDebugging = true
|
||||
next();
|
||||
});
|
||||
},
|
||||
function startDebug(next) {
|
||||
let debuggerData = {};
|
||||
cmd_line.events.on("locals", (data) => {
|
||||
debuggerData.locals = self.simplifyDebuggerVars(data);
|
||||
});
|
||||
|
||||
cmd_line.events.on("globals", (data) => {
|
||||
debuggerData.contract = self.simplifyDebuggerVars(data);
|
||||
});
|
||||
|
||||
cmd_line.startDebug(txHash, filename, () => {
|
||||
cmd_line.events.on("source", () => {
|
||||
let lines = cmd_line.getSource();
|
||||
// TODO: this is a bit of a hack
|
||||
let line = lines.filter((x) => x.indexOf("=>") === 0)[0];
|
||||
outputCb(lines, line, debuggerData);
|
||||
});
|
||||
|
||||
let total_size = cmd_line.getTraceLength();
|
||||
cmd_line.jumpTo(total_size - 1);
|
||||
cmd_line.unload();
|
||||
|
||||
next();
|
||||
});
|
||||
}
|
||||
], () => {
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: this is duplicated in debugger/index.js
|
||||
simplifyDebuggerVars(data) {
|
||||
let new_data = {};
|
||||
|
||||
for (let key in data) {
|
||||
let field = data[key];
|
||||
new_data[`${key} (${field.type})`] = field.value;
|
||||
}
|
||||
|
||||
return new_data;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = DebuggerManager;
|
|
@ -0,0 +1,103 @@
|
|||
const RemixDebug = require("remix-debug-debugtest");
|
||||
const CmdLine = RemixDebug.CmdLine;
|
||||
const async = require("async");
|
||||
|
||||
export default class DebuggerManager {
|
||||
private nodeUrl: string;
|
||||
private outputJson: any;
|
||||
private inputJson: any;
|
||||
private isDebugging: boolean;
|
||||
|
||||
constructor(nodeUrl: string) {
|
||||
this.nodeUrl = nodeUrl;
|
||||
this.outputJson = {};
|
||||
this.inputJson = {};
|
||||
this.isDebugging = false;
|
||||
}
|
||||
|
||||
public setInputJson(inputJson: any) {
|
||||
this.inputJson = inputJson;
|
||||
}
|
||||
|
||||
public setOutputJson(outputJson: any) {
|
||||
this.outputJson = outputJson;
|
||||
}
|
||||
|
||||
public createDebuggerSession(txHash: string, filename: string, cb: any) {
|
||||
return this.debug(txHash, filename, cb);
|
||||
}
|
||||
|
||||
private debug(txHash: string, filename: string, cb: any) {
|
||||
const cmdLine = new CmdLine();
|
||||
cmdLine.connect("http", this.nodeUrl);
|
||||
cmdLine.loadCompilationData(this.inputJson, this.outputJson);
|
||||
|
||||
cmdLine.initDebugger(() => {
|
||||
this.isDebugging = true;
|
||||
|
||||
cmdLine.startDebug(txHash, filename, () => {
|
||||
if (cb) {
|
||||
cmdLine.triggerSourceUpdate();
|
||||
cb();
|
||||
}
|
||||
});
|
||||
});
|
||||
return cmdLine;
|
||||
}
|
||||
|
||||
public getLastLine(txHash: string, filename: string, outputCb: any) {
|
||||
const self = this;
|
||||
let cmdLine = new CmdLine();
|
||||
|
||||
async.waterfall([
|
||||
function initDebugger(next: any) {
|
||||
cmdLine = new CmdLine();
|
||||
cmdLine.connect("http", self.nodeUrl);
|
||||
cmdLine.loadCompilationData(self.inputJson, self.outputJson);
|
||||
cmdLine.initDebugger(() => {
|
||||
// self.isDebugging = true
|
||||
next();
|
||||
});
|
||||
},
|
||||
function startDebug(next: any) {
|
||||
const debuggerData: any = {};
|
||||
cmdLine.events.on("locals", (data: any) => {
|
||||
debuggerData.locals = self.simplifyDebuggerVars(data);
|
||||
});
|
||||
|
||||
cmdLine.events.on("globals", (data: any) => {
|
||||
debuggerData.contract = self.simplifyDebuggerVars(data);
|
||||
});
|
||||
|
||||
cmdLine.startDebug(txHash, filename, () => {
|
||||
cmdLine.events.on("source", () => {
|
||||
const lines: string[] = cmdLine.getSource();
|
||||
// TODO: this is a bit of a hack
|
||||
const line: string = lines.filter((x: string) => x.indexOf("=>") === 0)[0];
|
||||
outputCb(lines, line, debuggerData);
|
||||
});
|
||||
|
||||
const totalSize = cmdLine.getTraceLength();
|
||||
cmdLine.jumpTo(totalSize - 1);
|
||||
cmdLine.unload();
|
||||
|
||||
next();
|
||||
});
|
||||
},
|
||||
], () => {
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: this is duplicated in debugger/index.js
|
||||
private simplifyDebuggerVars(data: any) {
|
||||
const newData: any = {};
|
||||
|
||||
for (const key of Object.keys(data)) {
|
||||
const field = data[key];
|
||||
newData[`${key} (${field.type})`] = field.value;
|
||||
}
|
||||
|
||||
return newData;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
var DebuggerManager = require('./debugger_manager.js');
|
||||
var DebuggerManager = require('./debugger_manager.js').default;
|
||||
|
||||
class TransactionDebugger {
|
||||
constructor(embark, _options) {
|
||||
|
@ -179,6 +179,7 @@ class TransactionDebugger {
|
|||
}
|
||||
let filename = contract.filename;
|
||||
self.currentCmdTxHash = txHash;
|
||||
self.embark.logger.info("debugging tx " + txHash);
|
||||
self.cmdDebugger = self.debugger_manager.createDebuggerSession(txHash, filename, () => {
|
||||
self.cmdDebugger.getSource().forEach((line) => {
|
||||
console.dir(line);
|
||||
|
@ -189,6 +190,7 @@ class TransactionDebugger {
|
|||
}
|
||||
self.currentCmdTxHash = self.last_tx;
|
||||
let filename = self.tx_tracker[self.last_tx].contract.filename;
|
||||
self.embark.logger.info("debugging tx " + self.last_tx);
|
||||
self.cmdDebugger = self.debugger_manager.createDebuggerSession(self.last_tx, filename, () => {
|
||||
self.cmdDebugger.getSource().forEach((line) => {
|
||||
console.dir(line);
|
||||
|
|
Loading…
Reference in New Issue