From 2f2fd70a27dd57a748c8fdc25fe746b8f6d1cc0a Mon Sep 17 00:00:00 2001 From: yann300 Date: Thu, 8 Dec 2016 15:17:20 +0100 Subject: [PATCH] add solidity locals panel --- src/solidity/localDecoder.js | 72 ++++-------------------------------- src/ui/SolidityLocals.js | 44 ++++++++++++++++++++++ 2 files changed, 52 insertions(+), 64 deletions(-) create mode 100644 src/ui/SolidityLocals.js diff --git a/src/solidity/localDecoder.js b/src/solidity/localDecoder.js index 57d19aedfe..c5f0d447df 100644 --- a/src/solidity/localDecoder.js +++ b/src/solidity/localDecoder.js @@ -1,72 +1,16 @@ 'use strict' -var SourceLocationTracker = require('../code/sourceLocationTracker') -var AstWalker = require('../util/astWalker') -var decodeInfo = require('../solidity/decodeInfo') class LocalDecoder { - constructor (codeManager, traceAnalyserEvent, solidityProxy) { - this.astWalker = new AstWalker() - this.sourceLocationTracker = new SourceLocationTracker(codeManager) - this.solidityProxy = solidityProxy - this.locals = {} - 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) {}) - this.variableDeclarationByFile = {} - } - - push (index, step, callStack, cache) { - if (!this.solidityProxy.loaded()) return - if (step.op.indexOf('PUSH') === 0) { - var address = callStack[callStack.length - 1] - this.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, index, this.solidityProxy.contracts, (error, result) => { - if (error) { - console.log(error) - } else { - if (!this.variableDeclarationByFile[result.file]) { - var ast = this.solidityProxy.ast(result) - this.variableDeclarationByFile[result.file] = extractVariableDeclarations(ast, this.astWalker) - } - var variableDeclarations = this.variableDeclarationByFile[result.file] - this.solidityProxy.extractStateVariablesAt(index, (error, stateVars) => { // cached - if (error) { - console.log(error) - } else { - for (var dec of variableDeclarations) { - if (dec.src.indexOf(result.start + ':' + result.length) === 0) { - this.locals[dec.attributes.name] = { - type: decodeInfo.parseType(dec.attributes.type, stateVars), - stack: step.stack - } - } - } - } - }) - } - }) + solidityLocals (vmtraceIndex, internalTreeCall, stack, memory) { + var scope = this.internalTreeCall.findScope(vmtraceIndex) + var locals = {} + for (var local of scope.locals) { + if (local.type.decodeLocals) { + locals[local.name] = local.type.decodeLocals(local.stackHeight, stack, memory) + } } + return locals } - - clear () { - this.locals = {} - this.variableDeclarationByFile = {} - } -} - -function extractVariableDeclarations (ast, astWalker) { - var ret = [] - astWalker.walk(ast, (node) => { - if (node.name === 'VariableDeclaration') { - ret.push(node) - } - return true - }) - return ret } module.exports = LocalDecoder diff --git a/src/ui/SolidityLocals.js b/src/ui/SolidityLocals.js new file mode 100644 index 0000000000..aadc4280c3 --- /dev/null +++ b/src/ui/SolidityLocals.js @@ -0,0 +1,44 @@ +'use strict' +var DropdownPanel = require('./DropdownPanel') +var localDecoder = require('../solidity/localDecoder') +var yo = require('yo-yo') + +class SolidityLocals { + + constructor (_parent, _traceManager, internalTreeCall) { + this.parent = _parent + this.internalTreeCall = internalTreeCall + this.traceManager = _traceManager + this.basicPanel = new DropdownPanel('Solidity Locals') + this.init() + } + + render () { + return yo`
${this.basicPanel.render()}
` + } + + init () { + this.parent.event.register('indexChanged', this, (index) => { + if (index < 0) { + this.basicPanel.update({info: 'invalid step index'}) + return + } + if (this.parent.currentStepIndex !== index) return + + this.traceManager.waterfall([ + this.traceManager.getStackAt, + this.traceManager.getMemoryAt], + index, + function (error, result) { + if (!error) { + var stack = result[0].value + var memory = result[1].value + var locals = localDecoder.soliditylocals(index, this.internalTreeCall, stack, memory) + this.basicPanel.update(locals) + } + }) + }) + } +} + +module.exports = SolidityLocals