src updated

pull/697/head
aniket-engg 4 years ago committed by Aniket
parent 80b87ef2b2
commit 7a8b046396
  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 } //
*/
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

@ -1,19 +1,24 @@
'use strict'
function eventManager () {
export class eventManager {
registered
anonymous
constructor() {
this.registered = {}
this.anonymous = {}
}
}
/*
/*
* Unregister a listener.
* Note that if obj is a function. the unregistration will be applied to the dummy obj {}.
*
* @param {String} eventName - the event name
* @param {Object or Func} obj - object that will listen on this event
* @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]) {
return
}
@ -26,17 +31,17 @@ eventManager.prototype.unregister = function (eventName, obj, func) {
this.registered[eventName].splice(reg, 1)
}
}
}
}
/*
/*
* Register a new listener.
* Note that if obj is a function, the function registration will be associated with the dummy object {}
*
* @param {String} eventName - the event name
* @param {Object or Func} obj - object that will listen on this event
* @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]) {
this.registered[eventName] = []
}
@ -48,16 +53,16 @@ eventManager.prototype.register = function (eventName, obj, func) {
obj: obj,
func: func
})
}
}
/*
/*
* trigger event.
* Every listener have their associated function executed
*
* @param {String} eventName - the event name
* @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]) {
return
}
@ -65,6 +70,5 @@ eventManager.prototype.trigger = function (eventName, args) {
const l = this.registered[eventName][listener]
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)
*/
module.exports = {
export = {
init,
traceHelper,
SourceMappingDecoder,
EthDebugger: EthDebugger,
TransactionDebugger: TransactionDebugger,
EthDebugger,
TransactionDebugger,
/**
* constructor
*
* @param {Object} _debugger - type of EthDebugger
* @return {Function} _locationToRowConverter - function implemented by editor which return a column/line position for a char source location
*/
BreakpointManager: BreakpointManager,
SolidityDecoder: SolidityDecoder,
BreakpointManager,
SolidityDecoder,
storage: {
StorageViewer: StorageViewer,
StorageResolver: StorageResolver
},
CmdLine: CmdLine
CmdLine
}

@ -1,7 +1,7 @@
'use strict'
const Web3 = require('web3')
module.exports = {
export = {
loadWeb3: function (url) {
if (!url) url = 'http://localhost:8545'
const web3 = new Web3()
@ -19,6 +19,13 @@ module.exports = {
},
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]) {
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