diff --git a/src/solidity/localDecoder.js b/src/solidity/localDecoder.js new file mode 100644 index 0000000000..655680a104 --- /dev/null +++ b/src/solidity/localDecoder.js @@ -0,0 +1,58 @@ +'use strict' +var SourceLocationTracker = require('../code/sourceLocationTracker') +var AstWalker = require('../util/astWalker') +var decodeInfo = require('../solidity/decodeInfo') + +function LocalDecoder (parent, codeManager, traceAnalyserEvent) { + this.astWalker = new AstWalker() + this.codeManager = this.codeManager + this.parent = parent + this.locals = {} + this.loading = false + this.sourceLocationTracker = new SourceLocationTracker(this.codeManager) + var self = this + traceAnalyserEvent.register('startAnalysing', function (step) { + self.clear() + }) + traceAnalyserEvent.register('onOp', function (index, step, callStack, cache) { + self.push(index, step, callStack, cache) + }) + traceAnalyserEvent.register('finishAnalysing', function (index, step) { + self.loading = true + }) +} + +LocalDecoder.prototype.push = function (index, step, callStack, cache) { + if (!this.parent.sources) return + if (step.op.indexOf('PUSH') === 0) { + var self = this + var compiledContracts = this.parent.contractsDetail + var address = callStack[callStack.length - 1] + this.sourceLocationTracker.getSourceLocation(address, index, compiledContracts, function (error, result) { + if (error) { + console.log(error) + } else { + var file = self.parent.sourceList[result.file] + var ast = self.parent.sources[file] + this.astWalker.walk(ast, function (node) { + if (node.name === 'VariableDeclaration' && node.src.indexOf(result.start + ':' + result.length) === 0) { + self.locals[node.attributes.name] = { + type: decodeInfo.parseType(node, []), + stack: step.stack + } + return false + } else { + return true + } + }) + } + }) + } +} + +LocalDecoder.prototype.clear = function () { + this.loading = false + this.locals = {} +} + +module.exports = LocalDecoder diff --git a/src/ui/Ethdebugger.js b/src/ui/Ethdebugger.js index c30e2ebbbe..ab4ce43d60 100644 --- a/src/ui/Ethdebugger.js +++ b/src/ui/Ethdebugger.js @@ -12,6 +12,7 @@ var Web3Providers = require('../web3Provider/web3Providers') var DummyProvider = require('../web3Provider/dummyProvider') var CodeManager = require('../code/codeManager') var SourceLocationTracker = require('../code/sourceLocationTracker') +var LocalDecoder = require('../solidity/localDecoder') function Ethdebugger () { this.event = new EventManager() @@ -29,6 +30,7 @@ function Ethdebugger () { this.traceManager = new TraceManager() this.codeManager = new CodeManager(this.traceManager) this.sourceLocationTracker = new SourceLocationTracker(this.codeManager) + this.locals = new LocalDecoder(this, this.codeManager, this.traceManager.traceAnalyser.event) var self = this this.event.register('indexChanged', this, function (index) { @@ -76,10 +78,12 @@ Ethdebugger.prototype.switchProvider = function (type) { Ethdebugger.prototype.setCompilationResult = function (compilationResult) { if (compilationResult && compilationResult.sources && compilationResult.contracts) { this.sources = compilationResult.sources + this.sourceList = compilationResult.sourceList this.contractsDetail = compilationResult.contracts } else { this.sources = null this.contractsDetail = null + this.sourceList = null } }