Merge pull request #2166 from ethereum/fix_debugger_step

Fix debugger step
pull/2162/head
Rob 3 years ago committed by GitHub
commit fbcad476b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      libs/remix-core-plugin/src/lib/helpers/fetch-etherscan.ts
  2. 53
      libs/remix-debug/src/debugger/VmDebugger.ts
  3. 11
      libs/remix-debug/src/debugger/debugger.ts
  4. 11
      libs/remix-debug/src/debugger/solidityLocals.ts
  5. 13
      libs/remix-debug/src/debugger/solidityState.ts

@ -10,7 +10,7 @@ export const fetchContractFromEtherscan = async (plugin, network, contractAddres
// etherscan api doc https://docs.etherscan.io/api-endpoints/contracts // etherscan api doc https://docs.etherscan.io/api-endpoints/contracts
if (data.message === 'OK' && data.status === "1") { if (data.message === 'OK' && data.status === "1") {
if (data.result.length) { if (data.result.length) {
if (data.result[0].SourceCode === '') throw new Error('contract not verified') if (data.result[0].SourceCode === '') throw new Error('contract not verified in Etherscan')
if (data.result[0].SourceCode.startsWith('{')) { if (data.result[0].SourceCode.startsWith('{')) {
data.result[0].SourceCode = JSON.parse(data.result[0].SourceCode.replace(/(?:\r\n|\r|\n)/g, '').replace(/^{{/,'{').replace(/}}$/,'}')) data.result[0].SourceCode = JSON.parse(data.result[0].SourceCode.replace(/(?:\r\n|\r|\n)/g, '').replace(/^{{/,'{').replace(/}}$/,'}'))
} }

@ -65,14 +65,13 @@ export class VmDebuggerLogic {
} }
listenToTraceManagerEvents () { listenToTraceManagerEvents () {
let triggerStorageUpdateStampId
this.event.register('indexChanged', this, (index) => { this.event.register('indexChanged', this, (index) => {
if (index < 0) return if (index < 0) return
if (this.stepManager.currentStepIndex !== index) return if (this.stepManager.currentStepIndex !== index) return
this.event.trigger('indexUpdate', [index]) this.event.trigger('indexUpdate', [index])
this.event.trigger('functionsStackUpdate', [this._callTree.retrieveFunctionsStack(index)])
try { try {
const calldata = this._traceManager.getCallDataAt(index) const calldata = this._traceManager.getCallDataAt(index)
if (this.stepManager.currentStepIndex === index) { if (this.stepManager.currentStepIndex === index) {
@ -82,15 +81,6 @@ export class VmDebuggerLogic {
this.event.trigger('traceManagerCallDataUpdate', [{}]) this.event.trigger('traceManagerCallDataUpdate', [{}])
} }
try {
const memory = this._traceManager.getMemoryAt(index)
if (this.stepManager.currentStepIndex === index) {
this.event.trigger('traceManagerMemoryUpdate', [ui.formatMemory(memory, 16)])
}
} catch (error) {
this.event.trigger('traceManagerMemoryUpdate', [{}])
}
try { try {
const callstack = this._traceManager.getCallStackAt(index) const callstack = this._traceManager.getCallStackAt(index)
if (this.stepManager.currentStepIndex === index) { if (this.stepManager.currentStepIndex === index) {
@ -109,6 +99,27 @@ export class VmDebuggerLogic {
this.event.trigger('traceManagerStackUpdate', [{}]) this.event.trigger('traceManagerStackUpdate', [{}])
} }
if (triggerStorageUpdateStampId) {
clearTimeout(triggerStorageUpdateStampId)
triggerStorageUpdateStampId = null
}
triggerStorageUpdateStampId = setTimeout(() => {
(() => {
try {
this.event.trigger('functionsStackUpdate', [this._callTree.retrieveFunctionsStack(index)])
} catch (e) {
console.log(e)
}
try {
const memory = this._traceManager.getMemoryAt(index)
if (this.stepManager.currentStepIndex === index) {
this.event.trigger('traceManagerMemoryUpdate', [ui.formatMemory(memory, 16)])
}
} catch (error) {
this.event.trigger('traceManagerMemoryUpdate', [{}])
}
try { try {
const address = this._traceManager.getCurrentCalledAddressAt(index) const address = this._traceManager.getCurrentCalledAddressAt(index)
if (!this.storageResolver) return if (!this.storageResolver) return
@ -127,6 +138,17 @@ export class VmDebuggerLogic {
this.event.trigger('traceManagerStorageUpdate', [{}]) this.event.trigger('traceManagerStorageUpdate', [{}])
} }
try {
const returnValue = this._traceManager.getReturnValue(index)
if (this.stepManager.currentStepIndex === index) {
this.event.trigger('traceReturnValueUpdate', [[returnValue]])
}
} catch (error) {
this.event.trigger('traceReturnValueUpdate', [[error]])
}
})()
}, 1000)
try { try {
const step = this._traceManager.getCurrentStep(index) const step = this._traceManager.getCurrentStep(index)
this.event.trigger('traceCurrentStepUpdate', [null, step]) this.event.trigger('traceCurrentStepUpdate', [null, step])
@ -161,15 +183,6 @@ export class VmDebuggerLogic {
} catch (error) { } catch (error) {
this.event.trigger('traceRemainingGasUpdate', [error]) this.event.trigger('traceRemainingGasUpdate', [error])
} }
try {
const returnValue = this._traceManager.getReturnValue(index)
if (this.stepManager.currentStepIndex === index) {
this.event.trigger('traceReturnValueUpdate', [[returnValue]])
}
} catch (error) {
this.event.trigger('traceReturnValueUpdate', [[error]])
}
}) })
} }

@ -89,15 +89,19 @@ export class Debugger {
} }
const lineColumnPos = await this.offsetToLineColumnConverter.offsetToLineColumn(rawLocation, rawLocation.file, sources, astSources) const lineColumnPos = await this.offsetToLineColumnConverter.offsetToLineColumn(rawLocation, rawLocation.file, sources, astSources)
this.event.trigger('newSourceLocation', [lineColumnPos, rawLocation, generatedSources, address]) this.event.trigger('newSourceLocation', [lineColumnPos, rawLocation, generatedSources, address])
this.vmDebuggerLogic.event.trigger('sourceLocationChanged', [rawLocation])
} else { } else {
this.event.trigger('newSourceLocation', [null]) this.event.trigger('newSourceLocation', [null])
this.vmDebuggerLogic.event.trigger('sourceLocationChanged', [null])
} }
}).catch((_error) => { }).catch((_error) => {
this.event.trigger('newSourceLocation', [null]) this.event.trigger('newSourceLocation', [null])
this.vmDebuggerLogic.event.trigger('sourceLocationChanged', [null])
}) })
// }) // })
} catch (error) { } catch (error) {
this.event.trigger('newSourceLocation', [null]) this.event.trigger('newSourceLocation', [null])
this.vmDebuggerLogic.event.trigger('sourceLocationChanged', [null])
return console.log(error) return console.log(error)
} }
} }
@ -133,13 +137,6 @@ export class Debugger {
async debugTx (tx, loadingCb) { async debugTx (tx, loadingCb) {
this.step_manager = new DebuggerStepManager(this.debugger, this.debugger.traceManager) this.step_manager = new DebuggerStepManager(this.debugger, this.debugger.traceManager)
this.debugger.codeManager.event.register('changed', this, (code, address, instIndex) => {
if (!this.debugger.solidityProxy.contracts) return
this.debugger.callTree.sourceLocationTracker.getValidSourceLocationFromVMTraceIndex(address, this.step_manager.currentStepIndex, this.debugger.solidityProxy.contracts).then((sourceLocation) => {
this.vmDebuggerLogic.event.trigger('sourceLocationChanged', [sourceLocation])
})
})
this.vmDebuggerLogic = new VmDebuggerLogic(this.debugger, tx, this.step_manager, this.debugger.traceManager, this.debugger.codeManager, this.debugger.solidityProxy, this.debugger.callTree) this.vmDebuggerLogic = new VmDebuggerLogic(this.debugger, tx, this.step_manager, this.debugger.traceManager, this.debugger.codeManager, this.debugger.solidityProxy, this.debugger.callTree)
this.vmDebuggerLogic.start() this.vmDebuggerLogic.start()

@ -10,6 +10,7 @@ export class DebuggerSolidityLocals {
traceManager traceManager
tx tx
_sourceLocation _sourceLocation
decodeTimeout
constructor (tx, _stepManager, _traceManager, _internalTreeCall) { constructor (tx, _stepManager, _traceManager, _internalTreeCall) {
this.event = new EventManager() this.event = new EventManager()
@ -18,21 +19,21 @@ export class DebuggerSolidityLocals {
this.storageResolver = null this.storageResolver = null
this.traceManager = _traceManager this.traceManager = _traceManager
this.tx = tx this.tx = tx
this.decodeTimeout = null
} }
init (sourceLocation) { init (sourceLocation) {
this._sourceLocation = sourceLocation this._sourceLocation = sourceLocation
let decodeTimeout = null
if (!this.storageResolver) { if (!this.storageResolver) {
return this.event.trigger('solidityLocalsMessage', ['storage not ready']) return this.event.trigger('solidityLocalsMessage', ['storage not ready'])
} }
if (decodeTimeout) { if (this.decodeTimeout) {
window.clearTimeout(decodeTimeout) window.clearTimeout(this.decodeTimeout)
} }
this.event.trigger('solidityLocalsUpdating') this.event.trigger('solidityLocalsUpdating')
decodeTimeout = setTimeout(() => { this.decodeTimeout = setTimeout(() => {
this.decode(sourceLocation) this.decode(sourceLocation)
}, 500) }, 1000)
} }
decode (sourceLocation, cursor?) { decode (sourceLocation, cursor?) {

@ -1,3 +1,4 @@
import { timeStamp } from 'console'
import { EventManager } from '../eventManager' import { EventManager } from '../eventManager'
import { decodeState } from '../solidity-decoder/stateDecoder' import { decodeState } from '../solidity-decoder/stateDecoder'
import { StorageViewer } from '../storage/storageViewer' import { StorageViewer } from '../storage/storageViewer'
@ -11,6 +12,7 @@ export class DebuggerSolidityState {
solidityProxy solidityProxy
stateVariablesByAddresses stateVariablesByAddresses
tx tx
decodeTimeout
constructor (tx, _stepManager, _traceManager, _codeManager, _solidityProxy) { constructor (tx, _stepManager, _traceManager, _codeManager, _solidityProxy) {
this.event = new EventManager() this.event = new EventManager()
@ -21,10 +23,10 @@ export class DebuggerSolidityState {
this.solidityProxy = _solidityProxy this.solidityProxy = _solidityProxy
this.stateVariablesByAddresses = {} this.stateVariablesByAddresses = {}
this.tx = tx this.tx = tx
this.decodeTimeout = null
} }
init (index) { init (index) {
let decodeTimeout = null
if (index < 0) { if (index < 0) {
return this.event.trigger('solidityStateMessage', ['invalid step index']) return this.event.trigger('solidityStateMessage', ['invalid step index'])
} }
@ -37,19 +39,18 @@ export class DebuggerSolidityState {
if (!this.storageResolver) { if (!this.storageResolver) {
return return
} }
if (decodeTimeout) { if (this.decodeTimeout) {
window.clearTimeout(decodeTimeout) window.clearTimeout(this.decodeTimeout)
} }
this.event.trigger('solidityStateUpdating') this.event.trigger('solidityStateUpdating')
decodeTimeout = setTimeout(() => { this.decodeTimeout = setTimeout(() => {
// necessary due to some states that can crash the debugger // necessary due to some states that can crash the debugger
try { try {
this.decode(index) this.decode(index)
} catch (err) { } catch (err) {
console.dir('====> error')
console.dir(err) console.dir(err)
} }
}, 500) }, 1000)
} }
reset () { reset () {

Loading…
Cancel
Save