add local decoder

pull/7/head
yann300 8 years ago
parent f0b3458648
commit 074e2ee57e
  1. 58
      src/solidity/localDecoder.js
  2. 4
      src/ui/Ethdebugger.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

@ -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
}
}

Loading…
Cancel
Save