From 4acd6ccf56ff9547d1026f2f243b4645e6d88e56 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Fri, 30 Nov 2018 17:56:21 -0500 Subject: [PATCH] add methods needed for solidity code navigation --- remix-debug/src/cmdline/index.js | 46 +++++++++++++++++++++++++ remix-debug/src/debugger/stepManager.js | 33 ++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/remix-debug/src/cmdline/index.js b/remix-debug/src/cmdline/index.js index 51d979f7e5..c4b6e7c032 100644 --- a/remix-debug/src/cmdline/index.js +++ b/remix-debug/src/cmdline/index.js @@ -81,9 +81,18 @@ class CmdLine { return source } + getCurrentLine() { + let lineColumnPos = this.lineColumnPos + if (!lineColumnPos) return "" + let currentLineNumber = lineColumnPos.start.line + let content = this.compilation.lastCompilationResult.source.sources[this.filename].content.split("\n") + return content[currentLineNumber] + } + startDebug(txNumber, filename, cb) { const self = this this.filename = filename + this.txHash = txNumber this.debugger.debug(null, txNumber, null, () => { self.debugger.event.register('newSourceLocation', function (lineColumnPos, rawLocation) { @@ -111,6 +120,13 @@ class CmdLine { }) } + getVars() { + return { + locals: this.solidityLocals, + contract: this.solidityState + } + } + triggerSourceUpdate() { this.events.emit("source", [this.lineColumnPos, this.rawLocation]) } @@ -144,13 +160,43 @@ class CmdLine { } getTraceLength() { + if (!this.debugger.step_manager) return 0; return this.debugger.step_manager.traceLength } + getCodeFirstStep() { + if (!this.debugger.step_manager) return 0; + return this.debugger.step_manager.calculateFirstStep() + } + + getCodeTraceLength() { + if (!this.debugger.step_manager) return 0; + return this.debugger.step_manager.calculateCodeLength() + } + + nextStep() { + if (!this.debugger.step_manager) return 0; + return this.debugger.step_manager.nextStep() + } + + previousStep() { + if (!this.debugger.step_manager) return 0; + return this.debugger.step_manager.previousStep() + } + currentStep() { + if (!this.debugger.step_manager) return 0; return this.debugger.step_manager.currentStepIndex } + canGoNext() { + return this.currentStep() < this.getCodeTraceLength() + } + + canGoPrevious() { + return this.currentStep() > this.getCodeFirstStep() + } + unload() { return this.debugger.unload() } diff --git a/remix-debug/src/debugger/stepManager.js b/remix-debug/src/debugger/stepManager.js index eb64ffe401..84fa44e227 100644 --- a/remix-debug/src/debugger/stepManager.js +++ b/remix-debug/src/debugger/stepManager.js @@ -10,6 +10,7 @@ class DebuggerStepManager { this.traceManager = traceManager this.currentStepIndex = 0 this.traceLength = 0 + this.codeTraceLength = 0 this.revertionPoint = null this.listenToEvents() @@ -26,6 +27,7 @@ class DebuggerStepManager { if (self.traceLength !== newLength) { self.event.trigger('traceLengthChanged', [newLength]) self.traceLength = newLength + self.codeTraceLength = self.calculateCodeLength() } self.jumpTo(0) }) @@ -156,6 +158,37 @@ class DebuggerStepManager { this.debugger.breakpointManager.jumpPreviousBreakpoint(this.currentStepIndex, true) } + calculateFirstStep() { + let step = this.resolveToReducedTrace(0, 1) + return this.resolveToReducedTrace(step, 1) + } + + calculateCodeStepList() { + let step = 0 + let steps = [] + while (step < this.traceLength) { + let _step = this.resolveToReducedTrace(step, 1) + if (!_step) break; + steps.push(_step) + step += 1 + } + steps = steps.filter((item, pos, self) => { return steps.indexOf(item) === pos }) + return steps + } + + calculateCodeLength() { + let steps = this.calculateCodeStepList().reverse() + return this.calculateCodeStepList().reverse()[1] || this.traceLength; + } + + nextStep() { + return this.resolveToReducedTrace(this.currentStepIndex, 1); + } + + previousStep() { + return this.resolveToReducedTrace(this.currentStepIndex, -1); + } + resolveToReducedTrace (value, incr) { if (this.debugger.callTree.reducedTrace.length) { var nextSource = util.findClosestIndex(value, this.debugger.callTree.reducedTrace)