src updated

pull/5370/head
aniket-engg 4 years ago committed by Aniket
parent 7fc6a94109
commit 4e10d1895f
  1. 89
      libs/remix-debug/src/Ethdebugger.ts
  2. 34
      libs/remix-debug/src/eventManager.ts
  3. 12
      libs/remix-debug/src/index.ts
  4. 17
      libs/remix-debug/src/init.ts

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

@ -1,19 +1,24 @@
'use strict' 'use strict'
function eventManager () { export class eventManager {
registered
anonymous
constructor() {
this.registered = {} this.registered = {}
this.anonymous = {} this.anonymous = {}
} }
/* /*
* Unregister a listener. * Unregister a listener.
* Note that if obj is a function. the unregistration will be applied to the dummy obj {}. * Note that if obj is a function. the unregistration will be applied to the dummy obj {}.
* *
* @param {String} eventName - the event name * @param {String} eventName - the event name
* @param {Object or Func} obj - object that will listen on this event * @param {Object or Func} obj - object that will listen on this event
* @param {Func} func - function of the listeners that will be executed * @param {Func} func - function of the listeners that will be executed
*/ */
eventManager.prototype.unregister = function (eventName, obj, func) { unregister (eventName, obj, func) {
if (!this.registered[eventName]) { if (!this.registered[eventName]) {
return return
} }
@ -26,17 +31,17 @@ eventManager.prototype.unregister = function (eventName, obj, func) {
this.registered[eventName].splice(reg, 1) this.registered[eventName].splice(reg, 1)
} }
} }
} }
/* /*
* Register a new listener. * Register a new listener.
* Note that if obj is a function, the function registration will be associated with the dummy object {} * Note that if obj is a function, the function registration will be associated with the dummy object {}
* *
* @param {String} eventName - the event name * @param {String} eventName - the event name
* @param {Object or Func} obj - object that will listen on this event * @param {Object or Func} obj - object that will listen on this event
* @param {Func} func - function of the listeners that will be executed * @param {Func} func - function of the listeners that will be executed
*/ */
eventManager.prototype.register = function (eventName, obj, func) { register (eventName, obj, func) {
if (!this.registered[eventName]) { if (!this.registered[eventName]) {
this.registered[eventName] = [] this.registered[eventName] = []
} }
@ -48,16 +53,16 @@ eventManager.prototype.register = function (eventName, obj, func) {
obj: obj, obj: obj,
func: func func: func
}) })
} }
/* /*
* trigger event. * trigger event.
* Every listener have their associated function executed * Every listener have their associated function executed
* *
* @param {String} eventName - the event name * @param {String} eventName - the event name
* @param {Array}j - argument that will be passed to the executed function. * @param {Array}j - argument that will be passed to the executed function.
*/ */
eventManager.prototype.trigger = function (eventName, args) { trigger (eventName, args) {
if (!this.registered[eventName]) { if (!this.registered[eventName]) {
return return
} }
@ -65,6 +70,5 @@ eventManager.prototype.trigger = function (eventName, args) {
const l = this.registered[eventName][listener] const l = this.registered[eventName][listener]
l.func.apply(l.obj === this.anonymous ? {} : l.obj, args) l.func.apply(l.obj === this.anonymous ? {} : l.obj, args)
} }
}
} }
module.exports = eventManager

@ -23,23 +23,23 @@ const traceHelper = require('./src/trace/traceHelper')
}) })
this.debugger.setBreakpointManager(breakPointManager) this.debugger.setBreakpointManager(breakPointManager)
*/ */
module.exports = { export = {
init, init,
traceHelper, traceHelper,
SourceMappingDecoder, SourceMappingDecoder,
EthDebugger: EthDebugger, EthDebugger,
TransactionDebugger: TransactionDebugger, TransactionDebugger,
/** /**
* constructor * constructor
* *
* @param {Object} _debugger - type of EthDebugger * @param {Object} _debugger - type of EthDebugger
* @return {Function} _locationToRowConverter - function implemented by editor which return a column/line position for a char source location * @return {Function} _locationToRowConverter - function implemented by editor which return a column/line position for a char source location
*/ */
BreakpointManager: BreakpointManager, BreakpointManager,
SolidityDecoder: SolidityDecoder, SolidityDecoder,
storage: { storage: {
StorageViewer: StorageViewer, StorageViewer: StorageViewer,
StorageResolver: StorageResolver StorageResolver: StorageResolver
}, },
CmdLine: CmdLine CmdLine
} }

@ -1,7 +1,7 @@
'use strict' 'use strict'
const Web3 = require('web3') const Web3 = require('web3')
module.exports = { export = {
loadWeb3: function (url) { loadWeb3: function (url) {
if (!url) url = 'http://localhost:8545' if (!url) url = 'http://localhost:8545'
const web3 = new Web3() const web3 = new Web3()
@ -19,6 +19,13 @@ module.exports = {
}, },
web3DebugNode: function (network) { web3DebugNode: function (network) {
const web3DebugNodes = {
'Main': 'https://rpc.archivenode.io/e50zmkroshle2e2e50zm0044i7ao04ym',
'Rinkeby': 'https://remix-rinkeby.ethdevops.io',
'Ropsten': 'https://remix-ropsten.ethdevops.io',
'Goerli': 'https://remix-goerli.ethdevops.io',
'Kovan': 'https://remix-kovan.ethdevops.io'
}
if (web3DebugNodes[network]) { if (web3DebugNodes[network]) {
return this.loadWeb3(web3DebugNodes[network]) return this.loadWeb3(web3DebugNodes[network])
} }
@ -66,11 +73,3 @@ module.exports = {
} }
} }
} }
const web3DebugNodes = {
'Main': 'https://rpc.archivenode.io/e50zmkroshle2e2e50zm0044i7ao04ym',
'Rinkeby': 'https://remix-rinkeby.ethdevops.io',
'Ropsten': 'https://remix-ropsten.ethdevops.io',
'Goerli': 'https://remix-goerli.ethdevops.io',
'Kovan': 'https://remix-kovan.ethdevops.io'
}

Loading…
Cancel
Save