diff --git a/src/solidity/localDecoder.js b/src/solidity/localDecoder.js index a6d041a60f..28f3a8de41 100644 --- a/src/solidity/localDecoder.js +++ b/src/solidity/localDecoder.js @@ -1,6 +1,6 @@ 'use strict' -function solidityLocals (vmtraceIndex, internalTreeCall, stack, memory, storage) { +function solidityLocals (vmtraceIndex, internalTreeCall, stack, memory, storage, currentSourceLocation) { var scope = internalTreeCall.findScope(vmtraceIndex) if (!scope) { var error = { 'message': 'Can\'t display locals. reason: compilation result might not have been provided' } @@ -11,7 +11,7 @@ function solidityLocals (vmtraceIndex, internalTreeCall, stack, memory, storage) var anonymousIncr = 1 for (var local in scope.locals) { let variable = scope.locals[local] - if (variable.stackDepth < stack.length) { + if (variable.stackDepth < stack.length && variable.sourceLocation.start <= currentSourceLocation.start) { var name = variable.name if (name === '') { name = '<' + anonymousIncr + '>' diff --git a/src/ui/Ethdebugger.js b/src/ui/Ethdebugger.js index 9c2f49b886..cdd037f6e7 100644 --- a/src/ui/Ethdebugger.js +++ b/src/ui/Ethdebugger.js @@ -52,6 +52,14 @@ function Ethdebugger () { self.stepChanged(stepIndex) }) this.vmDebugger = new VmDebugger(this, this.traceManager, this.codeManager, this.solidityProxy, callTree) + + this.codeManager.event.register('changed', this, (code, address, instIndex) => { + this.callTree.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, this.currentStepIndex, this.solidityProxy.contracts, (error, sourceLocation) => { + if (!error) { + this.event.trigger('sourceLocationChanged', [sourceLocation]) + } + }) + }) } Ethdebugger.prototype.web3 = function () { diff --git a/src/ui/SolidityLocals.js b/src/ui/SolidityLocals.js index d13dff4355..4c47e8a0a6 100644 --- a/src/ui/SolidityLocals.js +++ b/src/ui/SolidityLocals.js @@ -28,28 +28,21 @@ class SolidityLocals { } init () { - this.parent.event.register('indexChanged', this, (index) => { + this.parent.event.register('sourceLocationChanged', this, (sourceLocation) => { var warningDiv = this.view.querySelector('#warning') warningDiv.innerHTML = '' - if (index < 0) { - warningDiv.innerHTML = 'invalid step index' - return - } - - if (this.parent.currentStepIndex !== index) return - this.traceManager.waterfall([ this.traceManager.getStackAt, this.traceManager.getMemoryAt], - index, + this.parent.currentStepIndex, (error, result) => { if (!error) { var stack = result[0].value var memory = result[1].value try { - this.traceManager.getStorageAt(index, this.parent.tx, (error, storage) => { + this.traceManager.getStorageAt(this.parent.currentStepIndex, this.parent.tx, (error, storage) => { if (!error) { - var locals = localDecoder.solidityLocals(index, this.internalTreeCall, stack, memory, storage) + var locals = localDecoder.solidityLocals(this.parent.currentStepIndex, this.internalTreeCall, stack, memory, storage, sourceLocation) this.basicPanel.update(locals) } }) diff --git a/src/util/internalCallTree.js b/src/util/internalCallTree.js index d6f13466f3..03782482eb 100644 --- a/src/util/internalCallTree.js +++ b/src/util/internalCallTree.js @@ -132,7 +132,8 @@ function includeVariableDeclaration (tree, step, sourceLocation, scopeId) { tree.scopes[scopeId].locals[variableDeclaration.attributes.name] = { name: variableDeclaration.attributes.name, type: decodeInfo.parseType(variableDeclaration.attributes.type, states, contractName), - stackDepth: stack.length + stackDepth: stack.length, + sourceLocation: sourceLocation } } }) diff --git a/test/solidity/localsTests/helper.js b/test/solidity/localsTests/helper.js index b5b8e1fc0d..b27de0a7a6 100644 --- a/test/solidity/localsTests/helper.js +++ b/test/solidity/localsTests/helper.js @@ -12,7 +12,7 @@ function decodeLocal (st, index, traceManager, callTree, verifier) { index, function (error, result) { if (!error) { - var locals = localDecoder.solidityLocals(index, callTree, result[0].value, result[1].value) + var locals = localDecoder.solidityLocals(index, callTree, result[0].value, result[1].value, {}, {start: 5000}) verifier(locals) } else { st.fail(error)