|
|
|
@ -23,15 +23,27 @@ const {SolidityProxy, stateDecoder, localDecoder, InternalCallTree} = require('. |
|
|
|
|
* |
|
|
|
|
* @param {Map} opts - { function compilationResult } //
|
|
|
|
|
*/ |
|
|
|
|
function Ethdebugger (opts) { |
|
|
|
|
export class Ethdebugger { |
|
|
|
|
|
|
|
|
|
compilationResult |
|
|
|
|
web3 |
|
|
|
|
opts |
|
|
|
|
event |
|
|
|
|
tx |
|
|
|
|
traceManager |
|
|
|
|
codeManager |
|
|
|
|
solidityProxy |
|
|
|
|
storageResolver |
|
|
|
|
callTree |
|
|
|
|
breakpointManager |
|
|
|
|
statusMessage |
|
|
|
|
|
|
|
|
|
constructor (opts) { |
|
|
|
|
this.compilationResult = opts.compilationResult || function (contractAddress) { return null } |
|
|
|
|
this.web3 = opts.web3 |
|
|
|
|
this.opts = opts |
|
|
|
|
|
|
|
|
|
this.event = new EventManager() |
|
|
|
|
|
|
|
|
|
this.tx |
|
|
|
|
|
|
|
|
|
this.traceManager = new TraceManager({web3: this.web3}) |
|
|
|
|
this.codeManager = new CodeManager(this.traceManager) |
|
|
|
|
this.solidityProxy = new SolidityProxy({getCurrentCalledAddressAt: this.traceManager.getCurrentCalledAddressAt.bind(this.traceManager), getCode: this.codeManager.getCode.bind(this.codeManager)}) |
|
|
|
@ -43,9 +55,9 @@ function Ethdebugger (opts) { |
|
|
|
|
this.solidityProxy, |
|
|
|
|
this.codeManager,
|
|
|
|
|
{ ...opts, includeLocalVariables}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Ethdebugger.prototype.setManagers = function () { |
|
|
|
|
setManagers () { |
|
|
|
|
this.traceManager = new TraceManager({web3: this.web3}) |
|
|
|
|
this.codeManager = new CodeManager(this.traceManager) |
|
|
|
|
this.solidityProxy = new SolidityProxy({getCurrentCalledAddressAt: this.traceManager.getCurrentCalledAddressAt.bind(this.traceManager), getCode: this.codeManager.getCode.bind(this.codeManager)}) |
|
|
|
@ -58,39 +70,39 @@ Ethdebugger.prototype.setManagers = function () { |
|
|
|
|
this.codeManager,
|
|
|
|
|
{ ...this.opts, includeLocalVariables}) |
|
|
|
|
this.event.trigger('managersChanged') |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Ethdebugger.prototype.resolveStep = function (index) { |
|
|
|
|
resolveStep (index) { |
|
|
|
|
this.codeManager.resolveStep(index, this.tx) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Ethdebugger.prototype.setCompilationResult = function (compilationResult) { |
|
|
|
|
setCompilationResult (compilationResult) { |
|
|
|
|
this.solidityProxy.reset((compilationResult && compilationResult.data) || {}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Ethdebugger.prototype.sourceLocationFromVMTraceIndex = async function (address, stepIndex) { |
|
|
|
|
async sourceLocationFromVMTraceIndex (address, stepIndex) { |
|
|
|
|
return this.callTree.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, stepIndex, this.solidityProxy.contracts) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Ethdebugger.prototype.getValidSourceLocationFromVMTraceIndex = async function (address, stepIndex) { |
|
|
|
|
async getValidSourceLocationFromVMTraceIndex (address, stepIndex) { |
|
|
|
|
return this.callTree.sourceLocationTracker.getValidSourceLocationFromVMTraceIndex(address, stepIndex, this.solidityProxy.contracts) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Ethdebugger.prototype.sourceLocationFromInstructionIndex = async function (address, instIndex, callback) { |
|
|
|
|
async sourceLocationFromInstructionIndex (address, instIndex, callback) { |
|
|
|
|
return this.callTree.sourceLocationTracker.getSourceLocationFromInstructionIndex(address, instIndex, this.solidityProxy.contracts) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* breakpoint */ |
|
|
|
|
Ethdebugger.prototype.setBreakpointManager = function (breakpointManager) { |
|
|
|
|
/* breakpoint */ |
|
|
|
|
setBreakpointManager (breakpointManager) { |
|
|
|
|
this.breakpointManager = breakpointManager |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* decode locals */ |
|
|
|
|
Ethdebugger.prototype.extractLocalsAt = function (step) { |
|
|
|
|
/* decode locals */ |
|
|
|
|
extractLocalsAt (step) { |
|
|
|
|
return this.callTree.findScope(step) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Ethdebugger.prototype.decodeLocalsAt = async function (step, sourceLocation, callback) { |
|
|
|
|
async decodeLocalsAt (step, sourceLocation, callback) { |
|
|
|
|
try { |
|
|
|
|
const stack = this.traceManager.getStackAt(step) |
|
|
|
|
const memory = this.traceManager.getMemoryAt(step) |
|
|
|
@ -108,14 +120,14 @@ Ethdebugger.prototype.decodeLocalsAt = async function (step, sourceLocation, cal |
|
|
|
|
} catch (error) { |
|
|
|
|
callback(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* decode state */ |
|
|
|
|
Ethdebugger.prototype.extractStateAt = async function (step) { |
|
|
|
|
/* decode state */ |
|
|
|
|
async extractStateAt (step) { |
|
|
|
|
return this.solidityProxy.extractStateVariablesAt(step) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Ethdebugger.prototype.decodeStateAt = async function (step, stateVars, callback) { |
|
|
|
|
async decodeStateAt (step, stateVars, callback) { |
|
|
|
|
try { |
|
|
|
|
const address = this.traceManager.getCurrentCalledAddressAt(step) |
|
|
|
|
const storageViewer = new StorageViewer({stepIndex: step, tx: this.tx, address: address}, this.storageResolver, this.traceManager) |
|
|
|
@ -124,24 +136,24 @@ Ethdebugger.prototype.decodeStateAt = async function (step, stateVars, callback) |
|
|
|
|
} catch (error) { |
|
|
|
|
callback(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Ethdebugger.prototype.storageViewAt = function (step, address) { |
|
|
|
|
storageViewAt (step, address) { |
|
|
|
|
return new StorageViewer({stepIndex: step, tx: this.tx, address: address}, this.storageResolver, this.traceManager) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Ethdebugger.prototype.updateWeb3 = function (web3) { |
|
|
|
|
updateWeb3 (web3) { |
|
|
|
|
this.web3 = web3 |
|
|
|
|
this.setManagers() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Ethdebugger.prototype.unLoad = function () { |
|
|
|
|
unLoad () { |
|
|
|
|
this.traceManager.init() |
|
|
|
|
this.codeManager.clear() |
|
|
|
|
this.event.trigger('traceUnloaded') |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Ethdebugger.prototype.debug = function (tx) { |
|
|
|
|
debug (tx) { |
|
|
|
|
if (this.traceManager.isLoading) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
@ -158,6 +170,5 @@ Ethdebugger.prototype.debug = function (tx) { |
|
|
|
|
}).catch((error) => { |
|
|
|
|
this.statusMessage = error ? error.message : 'Trace not loaded' |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
module.exports = Ethdebugger |
|
|
|
|