parent
3acf410da4
commit
c72cc3fbc0
@ -1,240 +0,0 @@ |
|||||||
var remixDebug = require('remix-debug') |
|
||||||
var remixLib = require('remix-lib') |
|
||||||
var EventManager = remixLib.EventManager |
|
||||||
var ui = remixLib.helpers.ui |
|
||||||
var StorageResolver = remixDebug.storage.StorageResolver |
|
||||||
var StorageViewer = remixDebug.storage.StorageViewer |
|
||||||
|
|
||||||
var DebuggerSolidityState = require('./solidityState') |
|
||||||
var DebuggerSolidityLocals = require('./solidityLocals') |
|
||||||
|
|
||||||
class VmDebuggerLogic { |
|
||||||
|
|
||||||
constructor (_debugger, tx, _stepManager, _traceManager, _codeManager, _solidityProxy, _callTree) { |
|
||||||
this.event = new EventManager() |
|
||||||
this.debugger = _debugger |
|
||||||
this.stepManager = _stepManager |
|
||||||
this._traceManager = _traceManager |
|
||||||
this._codeManager = _codeManager |
|
||||||
this._solidityProxy = _solidityProxy |
|
||||||
this._callTree = _callTree |
|
||||||
this.storageResolver = null |
|
||||||
this.tx = tx |
|
||||||
|
|
||||||
this.debuggerSolidityState = new DebuggerSolidityState(tx, _stepManager, _traceManager, _codeManager, _solidityProxy) |
|
||||||
this.debuggerSolidityLocals = new DebuggerSolidityLocals(tx, _stepManager, _traceManager, _callTree) |
|
||||||
} |
|
||||||
|
|
||||||
start () { |
|
||||||
this.listenToEvents() |
|
||||||
this.listenToCodeManagerEvents() |
|
||||||
this.listenToTraceManagerEvents() |
|
||||||
this.listenToFullStorageChanges() |
|
||||||
this.listenToNewChanges() |
|
||||||
|
|
||||||
this.listenToSolidityStateEvents() |
|
||||||
this.listenToSolidityLocalsEvents() |
|
||||||
} |
|
||||||
|
|
||||||
listenToEvents () { |
|
||||||
const self = this |
|
||||||
this.debugger.event.register('traceUnloaded', function () { |
|
||||||
self.event.trigger('traceUnloaded') |
|
||||||
}) |
|
||||||
|
|
||||||
this.debugger.event.register('newTraceLoaded', function () { |
|
||||||
self.event.trigger('newTraceLoaded') |
|
||||||
}) |
|
||||||
} |
|
||||||
|
|
||||||
listenToCodeManagerEvents () { |
|
||||||
const self = this |
|
||||||
this._codeManager.event.register('changed', function (code, address, index) { |
|
||||||
self.event.trigger('codeManagerChanged', [code, address, index]) |
|
||||||
}) |
|
||||||
} |
|
||||||
|
|
||||||
listenToTraceManagerEvents () { |
|
||||||
const self = this |
|
||||||
|
|
||||||
this.event.register('indexChanged', this, function (index) { |
|
||||||
if (index < 0) return |
|
||||||
if (self.stepManager.currentStepIndex !== index) return |
|
||||||
|
|
||||||
self.event.trigger('indexUpdate', [index]) |
|
||||||
|
|
||||||
self._traceManager.getCallDataAt(index, function (error, calldata) { |
|
||||||
if (error) { |
|
||||||
console.log(error) |
|
||||||
self.event.trigger('traceManagerCallDataUpdate', [{}]) |
|
||||||
} else if (self.stepManager.currentStepIndex === index) { |
|
||||||
self.event.trigger('traceManagerCallDataUpdate', [calldata]) |
|
||||||
} |
|
||||||
}) |
|
||||||
|
|
||||||
self._traceManager.getMemoryAt(index, function (error, memory) { |
|
||||||
if (error) { |
|
||||||
console.log(error) |
|
||||||
self.event.trigger('traceManagerMemoryUpdate', [{}]) |
|
||||||
} else if (self.stepManager.currentStepIndex === index) { |
|
||||||
self.event.trigger('traceManagerMemoryUpdate', [ui.formatMemory(memory, 16)]) |
|
||||||
} |
|
||||||
}) |
|
||||||
|
|
||||||
self._traceManager.getCallStackAt(index, function (error, callstack) { |
|
||||||
if (error) { |
|
||||||
console.log(error) |
|
||||||
self.event.trigger('traceManagerCallStackUpdate', [{}]) |
|
||||||
} else if (self.stepManager.currentStepIndex === index) { |
|
||||||
self.event.trigger('traceManagerCallStackUpdate', [callstack]) |
|
||||||
} |
|
||||||
}) |
|
||||||
|
|
||||||
self._traceManager.getStackAt(index, function (error, callstack) { |
|
||||||
if (error) { |
|
||||||
console.log(error) |
|
||||||
self.event.trigger('traceManagerStackUpdate', [{}]) |
|
||||||
} else if (self.stepManager.currentStepIndex === index) { |
|
||||||
self.event.trigger('traceManagerStackUpdate', [callstack]) |
|
||||||
} |
|
||||||
}) |
|
||||||
|
|
||||||
self._traceManager.getCurrentCalledAddressAt(index, (error, address) => { |
|
||||||
if (error) return |
|
||||||
if (!self.storageResolver) return |
|
||||||
|
|
||||||
var storageViewer = new StorageViewer({ stepIndex: self.stepManager.currentStepIndex, tx: self.tx, address: address }, self.storageResolver, self._traceManager) |
|
||||||
|
|
||||||
storageViewer.storageRange((error, storage) => { |
|
||||||
if (error) { |
|
||||||
console.log(error) |
|
||||||
self.event.trigger('traceManagerStorageUpdate', [{}]) |
|
||||||
} else if (self.stepManager.currentStepIndex === index) { |
|
||||||
var header = storageViewer.isComplete(address) ? 'completely loaded' : 'partially loaded...' |
|
||||||
self.event.trigger('traceManagerStorageUpdate', [storage, header]) |
|
||||||
} |
|
||||||
}) |
|
||||||
}) |
|
||||||
|
|
||||||
self._traceManager.getCurrentStep(index, function (error, step) { |
|
||||||
self.event.trigger('traceCurrentStepUpdate', [error, step]) |
|
||||||
}) |
|
||||||
|
|
||||||
self._traceManager.getMemExpand(index, function (error, addmem) { |
|
||||||
self.event.trigger('traceMemExpandUpdate', [error, addmem]) |
|
||||||
}) |
|
||||||
|
|
||||||
self._traceManager.getStepCost(index, function (error, gas) { |
|
||||||
self.event.trigger('traceStepCostUpdate', [error, gas]) |
|
||||||
}) |
|
||||||
|
|
||||||
self._traceManager.getCurrentCalledAddressAt(index, function (error, address) { |
|
||||||
self.event.trigger('traceCurrentCalledAddressAtUpdate', [error, address]) |
|
||||||
}) |
|
||||||
|
|
||||||
self._traceManager.getRemainingGas(index, function (error, remaining) { |
|
||||||
self.event.trigger('traceRemainingGasUpdate', [error, remaining]) |
|
||||||
}) |
|
||||||
|
|
||||||
self._traceManager.getReturnValue(index, function (error, returnValue) { |
|
||||||
if (error) { |
|
||||||
self.event.trigger('traceReturnValueUpdate', [[error]]) |
|
||||||
} else if (self.stepManager.currentStepIndex === index) { |
|
||||||
self.event.trigger('traceReturnValueUpdate', [[returnValue]]) |
|
||||||
} |
|
||||||
}) |
|
||||||
}) |
|
||||||
} |
|
||||||
|
|
||||||
listenToFullStorageChanges () { |
|
||||||
const self = this |
|
||||||
|
|
||||||
this.address = [] |
|
||||||
this.traceLength = 0 |
|
||||||
|
|
||||||
self.debugger.event.register('newTraceLoaded', function (length) { |
|
||||||
self._traceManager.getAddresses(function (error, addresses) { |
|
||||||
if (error) return |
|
||||||
self.event.trigger('traceAddressesUpdate', [addresses]) |
|
||||||
self.addresses = addresses |
|
||||||
}) |
|
||||||
|
|
||||||
self._traceManager.getLength(function (error, length) { |
|
||||||
if (error) return |
|
||||||
self.event.trigger('traceLengthUpdate', [length]) |
|
||||||
self.traceLength = length |
|
||||||
}) |
|
||||||
}) |
|
||||||
|
|
||||||
self.event.register('indexChanged', this, function (index) { |
|
||||||
if (index < 0) return |
|
||||||
if (self.stepManager.currentStepIndex !== index) return |
|
||||||
if (!self.storageResolver) return |
|
||||||
|
|
||||||
// Full storage changes are queried for each step (not only at the end of the trace as it was before)
|
|
||||||
let storageJSON = {} |
|
||||||
for (var k in self.addresses) { |
|
||||||
let address = self.addresses[k] |
|
||||||
let storage = {} |
|
||||||
self._traceManager.accumulateStorageChanges(self.stepManager.currentStepIndex, address, storage, (error, result) => { |
|
||||||
if (!error) { |
|
||||||
storageJSON[address] = result |
|
||||||
self.event.trigger('traceStorageUpdate', [storageJSON]) |
|
||||||
} |
|
||||||
}) |
|
||||||
} |
|
||||||
}) |
|
||||||
} |
|
||||||
|
|
||||||
listenToNewChanges () { |
|
||||||
const self = this |
|
||||||
self.debugger.event.register('newTraceLoaded', this, function () { |
|
||||||
self.storageResolver = new StorageResolver({web3: self.debugger.web3}) |
|
||||||
self.debuggerSolidityState.storageResolver = self.storageResolver |
|
||||||
self.debuggerSolidityLocals.storageResolver = self.storageResolver |
|
||||||
self.event.trigger('newTrace', []) |
|
||||||
}) |
|
||||||
|
|
||||||
self.debugger.event.register('callTreeReady', this, function () { |
|
||||||
if (self.debugger.callTree.reducedTrace.length) { |
|
||||||
return self.event.trigger('newCallTree', []) |
|
||||||
} |
|
||||||
}) |
|
||||||
} |
|
||||||
|
|
||||||
listenToSolidityStateEvents () { |
|
||||||
const self = this |
|
||||||
this.event.register('indexChanged', this.debuggerSolidityState.init.bind(this.debuggerSolidityState)) |
|
||||||
this.debuggerSolidityState.event.register('solidityState', function (state) { |
|
||||||
self.event.trigger('solidityState', [state]) |
|
||||||
}) |
|
||||||
this.debuggerSolidityState.event.register('solidityStateMessage', function (message) { |
|
||||||
self.event.trigger('solidityStateMessage', [message]) |
|
||||||
}) |
|
||||||
this.debuggerSolidityState.event.register('solidityStateUpdating', function () { |
|
||||||
self.event.trigger('solidityStateUpdating', []) |
|
||||||
}) |
|
||||||
this.event.register('traceUnloaded', this.debuggerSolidityState.reset.bind(this.debuggerSolidityState)) |
|
||||||
this.event.register('newTraceLoaded', this.debuggerSolidityState.reset.bind(this.debuggerSolidityState)) |
|
||||||
} |
|
||||||
|
|
||||||
listenToSolidityLocalsEvents () { |
|
||||||
const self = this |
|
||||||
this.event.register('sourceLocationChanged', this.debuggerSolidityLocals.init.bind(this.debuggerSolidityLocals)) |
|
||||||
this.debuggerSolidityLocals.event.register('solidityLocals', function (state) { |
|
||||||
self.event.trigger('solidityLocals', [state]) |
|
||||||
}) |
|
||||||
this.debuggerSolidityLocals.event.register('solidityLocalsMessage', function (message) { |
|
||||||
self.event.trigger('solidityLocalsMessage', [message]) |
|
||||||
}) |
|
||||||
this.debuggerSolidityLocals.event.register('solidityLocalsUpdating', function () { |
|
||||||
self.event.trigger('solidityLocalsUpdating', []) |
|
||||||
}) |
|
||||||
this.debuggerSolidityLocals.event.register('traceReturnValueUpdate', function (data, header) { |
|
||||||
self.event.trigger('traceReturnValueUpdate', [data, header]) |
|
||||||
}) |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
module.exports = VmDebuggerLogic |
|
@ -1,69 +0,0 @@ |
|||||||
'use strict' |
|
||||||
var Ethdebugger = require('remix-debug').EthDebugger |
|
||||||
var remixLib = require('remix-lib') |
|
||||||
var EventManager = remixLib.EventManager |
|
||||||
|
|
||||||
function Debugger (options) { |
|
||||||
var self = this |
|
||||||
this.event = new EventManager() |
|
||||||
|
|
||||||
this.executionContext = options.executionContext |
|
||||||
this.offsetToLineColumnConverter = options.offsetToLineColumnConverter |
|
||||||
this.compiler = options.compiler |
|
||||||
|
|
||||||
this.debugger = new Ethdebugger({ |
|
||||||
executionContext: this.executionContext, |
|
||||||
compilationResult: () => { |
|
||||||
var compilationResult = this.compiler.lastCompilationResult |
|
||||||
if (compilationResult) { |
|
||||||
return compilationResult.data |
|
||||||
} |
|
||||||
return null |
|
||||||
} |
|
||||||
}) |
|
||||||
|
|
||||||
this.breakPointManager = new remixLib.code.BreakpointManager(this.debugger, (sourceLocation) => { |
|
||||||
return self.offsetToLineColumnConverter.offsetToLineColumn(sourceLocation, sourceLocation.file, this.compiler.lastCompilationResult.source.sources, this.compiler.lastCompilationResult.data.sources) |
|
||||||
}, (step) => { |
|
||||||
self.event.trigger('breakpointStep', [step]) |
|
||||||
}) |
|
||||||
|
|
||||||
this.debugger.setBreakpointManager(this.breakPointManager) |
|
||||||
|
|
||||||
this.executionContext.event.register('contextChanged', this, function (context) { |
|
||||||
// TODO: was already broken
|
|
||||||
// self.switchProvider(context)
|
|
||||||
}) |
|
||||||
|
|
||||||
this.debugger.event.register('newTraceLoaded', this, function () { |
|
||||||
self.event.trigger('debuggerStatus', [true]) |
|
||||||
}) |
|
||||||
|
|
||||||
this.debugger.event.register('traceUnloaded', this, function () { |
|
||||||
self.event.trigger('debuggerStatus', [false]) |
|
||||||
}) |
|
||||||
|
|
||||||
this.debugger.addProvider('vm', this.executionContext.vm()) |
|
||||||
this.debugger.addProvider('injected', this.executionContext.internalWeb3()) |
|
||||||
this.debugger.addProvider('web3', this.executionContext.internalWeb3()) |
|
||||||
this.debugger.switchProvider(this.executionContext.getProvider()) |
|
||||||
} |
|
||||||
|
|
||||||
Debugger.prototype.registerAndHighlightCodeItem = function (index) { |
|
||||||
const self = this |
|
||||||
// register selected code item, highlight the corresponding source location
|
|
||||||
if (!self.compiler.lastCompilationResult) return |
|
||||||
self.debugger.traceManager.getCurrentCalledAddressAt(index, (error, address) => { |
|
||||||
if (error) return console.log(error) |
|
||||||
self.debugger.callTree.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, index, self.compiler.lastCompilationResult.data.contracts, function (error, rawLocation) { |
|
||||||
if (!error && self.compiler.lastCompilationResult && self.compiler.lastCompilationResult.data) { |
|
||||||
var lineColumnPos = self.offsetToLineColumnConverter.offsetToLineColumn(rawLocation, rawLocation.file, self.compiler.lastCompilationResult.source.sources, self.compiler.lastCompilationResult.data.sources) |
|
||||||
self.event.trigger('newSourceLocation', [lineColumnPos, rawLocation]) |
|
||||||
} else { |
|
||||||
self.event.trigger('newSourceLocation', [null]) |
|
||||||
} |
|
||||||
}) |
|
||||||
}) |
|
||||||
} |
|
||||||
|
|
||||||
module.exports = Debugger |
|
@ -1,65 +0,0 @@ |
|||||||
var remixLib = require('remix-lib') |
|
||||||
var EventManager = remixLib.EventManager |
|
||||||
var remixDebug = require('remix-debug') |
|
||||||
var localDecoder = remixDebug.SolidityDecoder.localDecoder |
|
||||||
var StorageViewer = remixDebug.storage.StorageViewer |
|
||||||
|
|
||||||
class DebuggerSolidityLocals { |
|
||||||
|
|
||||||
constructor (tx, _stepManager, _traceManager, _internalTreeCall) { |
|
||||||
this.event = new EventManager() |
|
||||||
this.stepManager = _stepManager |
|
||||||
this.internalTreeCall = _internalTreeCall |
|
||||||
this.storageResolver = null |
|
||||||
this.traceManager = _traceManager |
|
||||||
this.tx = tx |
|
||||||
} |
|
||||||
|
|
||||||
init (sourceLocation) { |
|
||||||
const self = this |
|
||||||
var decodeTimeout = null |
|
||||||
if (!this.storageResolver) { |
|
||||||
return self.event.trigger('solidityLocalsMessage', ['storage not ready']) |
|
||||||
} |
|
||||||
if (decodeTimeout) { |
|
||||||
window.clearTimeout(decodeTimeout) |
|
||||||
} |
|
||||||
self.event.trigger('solidityLocalsUpdating') |
|
||||||
decodeTimeout = setTimeout(function () { |
|
||||||
self.decode(sourceLocation) |
|
||||||
}, 500) |
|
||||||
} |
|
||||||
|
|
||||||
decode (sourceLocation) { |
|
||||||
const self = this |
|
||||||
self.event.trigger('solidityLocalsMessage', ['']) |
|
||||||
self.traceManager.waterfall([ |
|
||||||
self.traceManager.getStackAt, |
|
||||||
self.traceManager.getMemoryAt, |
|
||||||
self.traceManager.getCurrentCalledAddressAt], |
|
||||||
self.stepManager.currentStepIndex, |
|
||||||
(error, result) => { |
|
||||||
if (error) { |
|
||||||
return console.log(error) |
|
||||||
} |
|
||||||
var stack = result[0].value |
|
||||||
var memory = result[1].value |
|
||||||
try { |
|
||||||
var storageViewer = new StorageViewer({ stepIndex: self.stepManager.currentStepIndex, tx: self.tx, address: result[2].value }, self.storageResolver, self.traceManager) |
|
||||||
localDecoder.solidityLocals(self.stepManager.currentStepIndex, self.internalTreeCall, stack, memory, storageViewer, sourceLocation).then((locals) => { |
|
||||||
if (!locals.error) { |
|
||||||
self.event.trigger('solidityLocals', [locals]) |
|
||||||
} |
|
||||||
if (!Object.keys(locals).length) { |
|
||||||
self.event.trigger('solidityLocalsMessage', ['no locals']) |
|
||||||
} |
|
||||||
}) |
|
||||||
} catch (e) { |
|
||||||
self.event.trigger('solidityLocalsMessage', [e.message]) |
|
||||||
} |
|
||||||
}) |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
module.exports = DebuggerSolidityLocals |
|
Loading…
Reference in new issue