Skip to content

Commit

Permalink
fix(debugger): fix debugger displays
Browse files Browse the repository at this point in the history
  • Loading branch information
jrainville authored and iurimatias committed Dec 21, 2018
1 parent e207537 commit 9c37f97
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/lib/modules/debugger/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ class TransactionDebugger {
this.cmdDebugger = false;
this.currentCmdTxHash = "";

const self = this;
function startDebug(txHash: string, filename: string, callback: (err?: string|object, output?: string) => void) {
self.currentCmdTxHash = txHash;
self.embark.logger.info("debugging tx " + txHash);
self.cmdDebugger = self.debuggerManager.createDebuggerSession(txHash, filename, () => {
self.displayStepInfo(callback);
});
}

this.embark.registerConsoleCommand({
description: __("Debug the last transaction or the transaction specified by a hash"),
matches: (cmd: string) => {
Expand All @@ -232,21 +241,13 @@ class TransactionDebugger {
return callback();
}
this.currentCmdTxHash = txHash;
this.embark.logger.info("debugging tx " + txHash);
this.cmdDebugger = this.debuggerManager.createDebuggerSession(txHash, contract.filename, () => {
this.displayStepInfo();
callback();
});
startDebug(txHash, contract.filename, callback);
});
return;
}
this.currentCmdTxHash = this.lastTx;
const filename: string = this.txTracker[this.lastTx].contract.filename;
this.embark.logger.info("debugging tx " + this.lastTx);
this.cmdDebugger = this.debuggerManager.createDebuggerSession(this.lastTx, filename, () => {
this.displayStepInfo();
callback();
});
startDebug(txHash, filename, callback);
},
usage: "debug <txHash>",
});
Expand All @@ -268,8 +269,7 @@ class TransactionDebugger {
return callback();
}
this.cmdDebugger.stepOverForward(true);
this.displayStepInfo();
callback();
this.displayStepInfo(callback);
},
usage: " next/n",
});
Expand All @@ -290,8 +290,7 @@ class TransactionDebugger {
return this.cmdDebugger.unload();
}
this.cmdDebugger.stepOverBack(true);
this.displayStepInfo();
callback();
this.displayStepInfo(callback);
},
usage: " previous/p",
});
Expand Down Expand Up @@ -337,7 +336,7 @@ class TransactionDebugger {
this.embark.logger.error(err);
return callback();
}
this.embark.logger.info(globals);
this.embark.logger.info(JSON.stringify(globals, null, 2));
callback();
});
},
Expand Down Expand Up @@ -406,7 +405,9 @@ class TransactionDebugger {
}

this.findVarsInLine(txHash, line, knownVars, (foundVars: any) => {
if (!foundVars) { return; }
if (!foundVars) {
return cb ? cb() : null;
}
this.embark.logger.info("vars:");
foundVars.forEach((variable: any) => {
this.embark.logger.info(`${variable.name}: ${variable.value}`);
Expand All @@ -415,12 +416,13 @@ class TransactionDebugger {
});
}

private displayStepInfo() {
private displayStepInfo(cb?: any) {
this.cmdDebugger.getSource().forEach((line: string) => {
this.embark.logger.info(line);
});
this.displayVarsInLine(() => {
this.displayPossibleActions();
if (cb) { cb(); }
});
}

Expand Down

0 comments on commit 9c37f97

Please sign in to comment.