add solidity locals panel

pull/7/head
yann300 8 years ago
parent 9a30bb5b2e
commit 2f2fd70a27
  1. 70
      src/solidity/localDecoder.js
  2. 44
      src/ui/SolidityLocals.js

@ -1,72 +1,16 @@
'use strict' 'use strict'
var SourceLocationTracker = require('../code/sourceLocationTracker')
var AstWalker = require('../util/astWalker')
var decodeInfo = require('../solidity/decodeInfo')
class LocalDecoder { class LocalDecoder {
constructor (codeManager, traceAnalyserEvent, solidityProxy) { solidityLocals (vmtraceIndex, internalTreeCall, stack, memory) {
this.astWalker = new AstWalker() var scope = this.internalTreeCall.findScope(vmtraceIndex)
this.sourceLocationTracker = new SourceLocationTracker(codeManager) var locals = {}
this.solidityProxy = solidityProxy for (var local of scope.locals) {
this.locals = {} if (local.type.decodeLocals) {
var self = this locals[local.name] = local.type.decodeLocals(local.stackHeight, stack, memory)
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
}
}
}
}
})
} }
}) 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 module.exports = LocalDecoder

@ -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`<div id='soliditylocals' >${this.basicPanel.render()}</div>`
}
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
Loading…
Cancel
Save