display full storages changes

pull/7/head
yann300 8 years ago
parent 14e1dc2e38
commit 9305829ab0
  1. 17
      src/BasicPanel.js
  2. 7
      src/StoragePanel.js
  3. 2
      src/TxBrowser.js
  4. 36
      src/VmDebugger.js
  5. 4
      src/helpers/ui.js
  6. 21
      src/trace/traceAnalyser.js
  7. 16
      src/trace/traceCache.js
  8. 22
      src/trace/traceManager.js

@ -3,9 +3,12 @@ var style = require('./styles/basicStyles')
var yo = require('yo-yo')
var ui = require('./helpers/ui')
function BasicPanel (_name) {
function BasicPanel (_name, _id, _width, _height) {
this.data
this.name = _name
this.id = _id
this.width = _width
this.height = _height
this.view
}
@ -13,12 +16,20 @@ BasicPanel.prototype.update = function () {
yo.update(this.view, this.render())
}
BasicPanel.prototype.hide = function () {
document.getElementById(this.id + 'container').style.display = 'none'
}
BasicPanel.prototype.show = function () {
document.getElementById(this.id + 'container').style.display = 'block'
}
BasicPanel.prototype.render = function () {
var view = yo`<div style=${ui.formatCss(style.panel.container)}>
var view = yo`<div id='${this.id}container' style=${ui.formatCss({'width': this.width}, style.panel.container)}>
<div style=${ui.formatCss(style.panel.title)}>
${this.name}
</div>
<div style=${ui.formatCss(style.panel.tableContainer)}>
<div style=${ui.formatCss({'height': this.height}, style.panel.tableContainer)}>
<pre style=${ui.formatCss(style.panel.table, style.font)} id='basicpanel' >${this.data}</pre>
</div>
</div>`

@ -2,11 +2,13 @@
var BasicPanel = require('./BasicPanel')
var yo = require('yo-yo')
function StoragePanel (_parent, _traceManager) {
function StoragePanel (_parent, _traceManager, _address) {
this.parent = _parent
this.traceManager = _traceManager
this.basicPanel = new BasicPanel('Storage Changes')
this.address = _address
this.init()
this.disabled = false
}
StoragePanel.prototype.render = function () {
@ -16,6 +18,7 @@ StoragePanel.prototype.render = function () {
StoragePanel.prototype.init = function () {
var self = this
this.parent.register('indexChanged', this, function (index) {
if (self.disabled) return
if (index < 0) return
if (self.parent.currentStepIndex !== index) return
@ -27,7 +30,7 @@ StoragePanel.prototype.init = function () {
self.basicPanel.data = self.formatStorage(storage)
}
self.basicPanel.update()
})
}, self.address)
})
}

@ -31,7 +31,7 @@ TxBrowser.prototype.setDefaultValues = function () {
this.to = ' - '
this.hash = ' - '
this.blockNumber = null
this.txNumber = '0xcda2b2835add61af54cf83bd076664d98d7908c6cd98d86423b3b48d8b8e51ff'
this.txNumber = '0x20ef65b8b186ca942fcccd634f37074dde49b541c27994fc7596740ef44cfd51'
this.connectInfo = ''
this.updateWeb3Url(this.web3.currentProvider.host)
}

@ -6,6 +6,8 @@ var MemoryPanel = require('./MemoryPanel')
var CallstackPanel = require('./CallstackPanel')
var StackPanel = require('./StackPanel')
var StoragePanel = require('./StoragePanel')
var BasicPanel = require('./BasicPanel')
var FullStoragesChangesPanel = require('./FullStoragesChanges')
var yo = require('yo-yo')
var ui = require('./helpers/ui')
@ -16,6 +18,28 @@ function VmDebugger (_parent, _traceManager, _web3) {
this.memoryPanel = new MemoryPanel(_parent, _traceManager)
this.calldataPanel = new CalldataPanel(_parent, _traceManager)
this.callstackPanel = new CallstackPanel(_parent, _traceManager)
/* Return values - */
this.returnValuesPanel = new BasicPanel('Return Values', 'returnvalues', 'auto', '100px')
_parent.register('indexChanged', this.returnValuesPanel, function (index) {
var self = this
_traceManager.getReturnValue(index, function (error, returnValue) {
if (error) {
console.log(error)
self.data = ''
} else if (_parent.currentStepIndex === index) {
self.data = returnValue
}
self.update()
if (!returnValue) {
self.hide()
}
})
})
/* Return values - */
this.fullStoragesChangesPanel = new FullStoragesChangesPanel(_parent, _traceManager)
this.view
var self = this
_parent.register('newTraceLoaded', this, function () {
@ -30,7 +54,7 @@ VmDebugger.prototype.render = function () {
var view = yo`<div id='vmdebugger' style='display:none'>
<div style=${ui.formatCss(style.container)}>
<table>
<tbody>
<tbody>
<tr>
<td>
${this.asmCode.render()}
@ -55,6 +79,16 @@ VmDebugger.prototype.render = function () {
${this.callstackPanel.render()}
</td>
</tr>
<tr>
<td colspan='2'>
${this.returnValuesPanel.render()}
</td>
</tr>
<tr>
<td colspan='2'>
${this.fullStoragesChangesPanel.render()}
</td>
</tr>
</tbody>
</table>
</div>

@ -37,7 +37,9 @@ module.exports = {
var ret = ''
for (var arg in arguments) {
for (var k in arguments[arg]) {
ret += k + ':' + arguments[arg][k] + ';'
if (arguments[arg][k] && ret.indexOf(k) === -1) {
ret += k + ':' + arguments[arg][k] + ';'
}
}
}
return ret

@ -29,10 +29,20 @@ TraceAnalyser.prototype.analyse = function (trace, tx, callback) {
this.buildMemory(k, step)
context = this.buildDepth(k, step, tx, callStack, context)
context = this.buildStorage(k, step, context)
this.buildReturnValues(k, step)
}
callback(null, true)
}
TraceAnalyser.prototype.buildReturnValues = function (index, step) {
if (traceHelper.isReturnInstruction(step)) {
var offset = 2 * parseInt(step.stack[step.stack.length - 1])
var size = 2 * parseInt(step.stack[step.stack.length - 2])
var memory = this.trace[this.traceCache.memoryChanges[this.traceCache.memoryChanges.length - 1]].memory
this.traceCache.pushReturnValue(index, '0x' + memory.join('').substr(offset, size))
}
}
TraceAnalyser.prototype.buildCalldata = function (index, step, tx, newContext) {
var calldata = ''
if (index === 0) {
@ -85,20 +95,21 @@ TraceAnalyser.prototype.buildStorage = function (index, step, context) {
TraceAnalyser.prototype.buildDepth = function (index, step, tx, callStack, context) {
if (traceHelper.isCallInstruction(step) && !traceHelper.isCallToPrecompiledContract(index, this.trace)) {
var newAddress
if (traceHelper.isCreateInstruction(step)) {
var contractToken = traceHelper.contractCreationToken(index)
callStack.push(contractToken)
newAddress = traceHelper.contractCreationToken(index)
callStack.push(newAddress)
var lastMemoryChange = this.traceCache.memoryChanges[this.traceCache.memoryChanges.length - 1]
this.traceCache.pushContractCreationFromMemory(index, contractToken, this.trace, lastMemoryChange)
this.traceCache.pushContractCreationFromMemory(index, newAddress, this.trace, lastMemoryChange)
} else {
var newAddress = traceHelper.resolveCalledAddress(index, this.trace)
newAddress = traceHelper.resolveCalledAddress(index, this.trace)
if (newAddress) {
callStack.push(newAddress)
} else {
console.log('unable to build depth changes. ' + index + ' does not match with a CALL. depth changes will be corrupted')
}
}
this.traceCache.pushCallChanges(step, index + 1)
this.traceCache.pushCallChanges(step, index + 1, newAddress)
this.traceCache.pushCallStack(index + 1, {
callStack: callStack.slice(0)
})

@ -6,12 +6,13 @@ function TraceCache () {
TraceCache.prototype.init = function () {
// ...Changes contains index in the vmtrace of the corresponding changes
this.returnValues = {}
this.callChanges = []
this.returnChanges = []
this.calls = {}
this.callsData = {}
this.contractCreation = {}
this.steps = {}
this.addresses = []
this.callDataChanges = []
this.memoryChanges = []
@ -33,13 +34,18 @@ TraceCache.prototype.pushMemoryChanges = function (value) {
this.memoryChanges.push(value)
}
TraceCache.prototype.pushCallChanges = function (step, value) {
TraceCache.prototype.pushCallChanges = function (step, value, address) {
this.callChanges.push(value)
this.calls[value] = {
op: step.op
op: step.op,
address: address
}
}
TraceCache.prototype.pushReturnValue = function (step, value) {
this.returnValues[step] = value
}
TraceCache.prototype.pushContractCreationFromMemory = function (index, token, trace, lastMemoryChange) {
var memory = trace[lastMemoryChange].memory
var stack = trace[index].stack
@ -52,10 +58,6 @@ TraceCache.prototype.pushContractCreation = function (token, code) {
this.contractCreation[token] = code
}
TraceCache.prototype.pushReturnChanges = function (value) {
this.returnChanges.push(value)
}
TraceCache.prototype.pushCallStack = function (index, callStack) {
this.callStack[index] = callStack
}

@ -73,14 +73,16 @@ TraceManager.prototype.getLength = function (callback) {
}
}
TraceManager.prototype.getStorageAt = function (stepIndex, tx, callback) {
TraceManager.prototype.getStorageAt = function (stepIndex, tx, callback, address) {
var check = this.checkRequestedStep(stepIndex)
if (check) {
return callback(check, null)
}
var stoChange = traceHelper.findLowerBound(stepIndex, this.traceCache.storageChanges)
if (stoChange === undefined) return callback('no storage found', null)
var address = this.traceCache.sstore[stoChange].address
if (!address) {
address = this.traceCache.sstore[stoChange].address
}
var storage = {}
storage = this.traceCache.rebuildStorage(address, storage, stepIndex)
callback(null, storage)
@ -104,6 +106,14 @@ TraceManager.prototype.getStorageAt = function (stepIndex, tx, callback) {
*/
}
TraceManager.prototype.getAddresses = function (callback) {
var addresses = {}
for (var k in this.traceCache.calls) {
addresses[this.traceCache.calls[k].address] = ''
}
callback(null, addresses)
}
TraceManager.prototype.getCallDataAt = function (stepIndex, callback) {
var check = this.checkRequestedStep(stepIndex)
if (check) {
@ -203,6 +213,14 @@ TraceManager.prototype.getCurrentPC = function (stepIndex, callback) {
callback(null, this.trace[stepIndex].pc)
}
TraceManager.prototype.getReturnValue = function (stepIndex, callback) {
var check = this.checkRequestedStep(stepIndex)
if (check) {
return callback(check, null)
}
callback(null, this.traceCache.returnValues[stepIndex])
}
TraceManager.prototype.getCurrentStep = function (stepIndex, callback) {
var check = this.checkRequestedStep(stepIndex)
if (check) {

Loading…
Cancel
Save