Skip to content

Commit 9c37f97

Browse files
jrainvilleiurimatias
authored andcommitted
fix(debugger): fix debugger displays
1 parent e207537 commit 9c37f97

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/lib/modules/debugger/index.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,15 @@ class TransactionDebugger {
217217
this.cmdDebugger = false;
218218
this.currentCmdTxHash = "";
219219

220+
const self = this;
221+
function startDebug(txHash: string, filename: string, callback: (err?: string|object, output?: string) => void) {
222+
self.currentCmdTxHash = txHash;
223+
self.embark.logger.info("debugging tx " + txHash);
224+
self.cmdDebugger = self.debuggerManager.createDebuggerSession(txHash, filename, () => {
225+
self.displayStepInfo(callback);
226+
});
227+
}
228+
220229
this.embark.registerConsoleCommand({
221230
description: __("Debug the last transaction or the transaction specified by a hash"),
222231
matches: (cmd: string) => {
@@ -232,21 +241,13 @@ class TransactionDebugger {
232241
return callback();
233242
}
234243
this.currentCmdTxHash = txHash;
235-
this.embark.logger.info("debugging tx " + txHash);
236-
this.cmdDebugger = this.debuggerManager.createDebuggerSession(txHash, contract.filename, () => {
237-
this.displayStepInfo();
238-
callback();
239-
});
244+
startDebug(txHash, contract.filename, callback);
240245
});
241246
return;
242247
}
243248
this.currentCmdTxHash = this.lastTx;
244249
const filename: string = this.txTracker[this.lastTx].contract.filename;
245-
this.embark.logger.info("debugging tx " + this.lastTx);
246-
this.cmdDebugger = this.debuggerManager.createDebuggerSession(this.lastTx, filename, () => {
247-
this.displayStepInfo();
248-
callback();
249-
});
250+
startDebug(txHash, filename, callback);
250251
},
251252
usage: "debug <txHash>",
252253
});
@@ -268,8 +269,7 @@ class TransactionDebugger {
268269
return callback();
269270
}
270271
this.cmdDebugger.stepOverForward(true);
271-
this.displayStepInfo();
272-
callback();
272+
this.displayStepInfo(callback);
273273
},
274274
usage: " next/n",
275275
});
@@ -290,8 +290,7 @@ class TransactionDebugger {
290290
return this.cmdDebugger.unload();
291291
}
292292
this.cmdDebugger.stepOverBack(true);
293-
this.displayStepInfo();
294-
callback();
293+
this.displayStepInfo(callback);
295294
},
296295
usage: " previous/p",
297296
});
@@ -337,7 +336,7 @@ class TransactionDebugger {
337336
this.embark.logger.error(err);
338337
return callback();
339338
}
340-
this.embark.logger.info(globals);
339+
this.embark.logger.info(JSON.stringify(globals, null, 2));
341340
callback();
342341
});
343342
},
@@ -406,7 +405,9 @@ class TransactionDebugger {
406405
}
407406

408407
this.findVarsInLine(txHash, line, knownVars, (foundVars: any) => {
409-
if (!foundVars) { return; }
408+
if (!foundVars) {
409+
return cb ? cb() : null;
410+
}
410411
this.embark.logger.info("vars:");
411412
foundVars.forEach((variable: any) => {
412413
this.embark.logger.info(`${variable.name}: ${variable.value}`);
@@ -415,12 +416,13 @@ class TransactionDebugger {
415416
});
416417
}
417418

418-
private displayStepInfo() {
419+
private displayStepInfo(cb?: any) {
419420
this.cmdDebugger.getSource().forEach((line: string) => {
420421
this.embark.logger.info(line);
421422
});
422423
this.displayVarsInLine(() => {
423424
this.displayPossibleActions();
425+
if (cb) { cb(); }
424426
});
425427
}
426428

0 commit comments

Comments
 (0)