Commit 137b6a7c authored by aniket-engg's avatar aniket-engg Committed by Aniket

breakpointManager and codeManager updated

parent 02e12cdc
...@@ -8,7 +8,16 @@ const helper = require('../trace/traceHelper') ...@@ -8,7 +8,16 @@ const helper = require('../trace/traceHelper')
* *
* Trigger events: breakpointHit, breakpointAdded, breakpointRemoved * Trigger events: breakpointHit, breakpointAdded, breakpointRemoved
*/ */
class BreakpointManager { export class BreakpointManager {
event
traceManager
callTree
solidityProxy
breakpoints
locationToRowConverter
previousLine
/** /**
* constructor * constructor
* *
...@@ -189,5 +198,3 @@ class BreakpointManager { ...@@ -189,5 +198,3 @@ class BreakpointManager {
} }
} }
} }
module.exports = BreakpointManager
...@@ -12,7 +12,14 @@ const CodeResolver = require('./codeResolver') ...@@ -12,7 +12,14 @@ const CodeResolver = require('./codeResolver')
- resolvingStep: when CodeManager resolves code/selected instruction of a new step - resolvingStep: when CodeManager resolves code/selected instruction of a new step
*/ */
function CodeManager (_traceManager) { export class CodeManager {
event
isLoading: boolean
traceManager
codeResolver
constructor(_traceManager) {
this.event = new EventManager() this.event = new EventManager()
this.isLoading = false this.isLoading = false
this.traceManager = _traceManager this.traceManager = _traceManager
...@@ -26,43 +33,43 @@ function CodeManager (_traceManager) { ...@@ -26,43 +33,43 @@ function CodeManager (_traceManager) {
}) })
}) })
}}) }})
} }
/** /**
* clear the cache * clear the cache
* *
*/ */
CodeManager.prototype.clear = function () { clear () {
this.codeResolver.clear() this.codeResolver.clear()
} }
/** /**
* resolve the code of the given @arg stepIndex and trigger appropriate event * resolve the code of the given @arg stepIndex and trigger appropriate event
* *
* @param {String} stepIndex - vm trace step * @param {String} stepIndex - vm trace step
* @param {Object} tx - transaction (given by web3) * @param {Object} tx - transaction (given by web3)
*/ */
CodeManager.prototype.resolveStep = function (stepIndex, tx) { resolveStep (stepIndex, tx) {
if (stepIndex < 0) return if (stepIndex < 0) return
this.event.trigger('resolvingStep') this.event.trigger('resolvingStep')
if (stepIndex === 0) { if (stepIndex === 0) {
return retrieveCodeAndTrigger(this, tx.to, stepIndex, tx) return this.retrieveCodeAndTrigger(this, tx.to, stepIndex, tx)
} }
try { try {
const address = this.traceManager.getCurrentCalledAddressAt(stepIndex) const address = this.traceManager.getCurrentCalledAddressAt(stepIndex)
retrieveCodeAndTrigger(this, address, stepIndex, tx) this.retrieveCodeAndTrigger(this, address, stepIndex, tx)
} catch (error) { } catch (error) {
return console.log(error) return console.log(error)
} }
} }
/** /**
* Retrieve the code located at the given @arg address * Retrieve the code located at the given @arg address
* *
* @param {String} address - address of the contract to get the code from * @param {String} address - address of the contract to get the code from
* @param {Function} cb - callback function, return the bytecode * @param {Function} cb - callback function, return the bytecode
*/ */
CodeManager.prototype.getCode = async function (address) { async getCode (address) {
if (!traceHelper.isContractCreation(address)) { if (!traceHelper.isContractCreation(address)) {
const code = await this.codeResolver.resolveCode(address) const code = await this.codeResolver.resolveCode(address)
return code return code
...@@ -74,9 +81,9 @@ CodeManager.prototype.getCode = async function (address) { ...@@ -74,9 +81,9 @@ CodeManager.prototype.getCode = async function (address) {
const hexCode = this.traceManager.getContractCreationCode(address) const hexCode = this.traceManager.getContractCreationCode(address)
codes = this.codeResolver.cacheExecutingCode(address, hexCode) codes = this.codeResolver.cacheExecutingCode(address, hexCode)
return codes return codes
} }
/** /**
* Retrieve the called function for the current vm step for the given @arg address * Retrieve the called function for the current vm step for the given @arg address
* *
* @param {String} stepIndex - vm trace step * @param {String} stepIndex - vm trace step
...@@ -84,7 +91,7 @@ CodeManager.prototype.getCode = async function (address) { ...@@ -84,7 +91,7 @@ CodeManager.prototype.getCode = async function (address) {
* @param {Object} ast - ast given by the compilation result * @param {Object} ast - ast given by the compilation result
* @return {Object} return the ast node of the function * @return {Object} return the ast node of the function
*/ */
CodeManager.prototype.getFunctionFromStep = function (stepIndex, sourceMap, ast) { getFunctionFromStep (stepIndex, sourceMap, ast) {
try { try {
const address = this.traceManager.getCurrentCalledAddressAt(stepIndex) const address = this.traceManager.getCurrentCalledAddressAt(stepIndex)
const pc = this.traceManager.getCurrentPC(stepIndex) const pc = this.traceManager.getCurrentPC(stepIndex)
...@@ -93,16 +100,16 @@ CodeManager.prototype.getFunctionFromStep = function (stepIndex, sourceMap, ast) ...@@ -93,16 +100,16 @@ CodeManager.prototype.getFunctionFromStep = function (stepIndex, sourceMap, ast)
console.log(error) console.log(error)
return { error: 'Cannot retrieve current address or PC for ' + stepIndex } return { error: 'Cannot retrieve current address or PC for ' + stepIndex }
} }
} }
/** /**
* Retrieve the instruction index of the given @arg step * Retrieve the instruction index of the given @arg step
* *
* @param {String} address - address of the current context * @param {String} address - address of the current context
* @param {String} step - vm trace step * @param {String} step - vm trace step
* @param {Function} callback - instruction index * @param {Function} callback - instruction index
*/ */
CodeManager.prototype.getInstructionIndex = function (address, step) { getInstructionIndex (address, step) {
try { try {
const pc = this.traceManager.getCurrentPC(step) const pc = this.traceManager.getCurrentPC(step)
const itemIndex = this.codeResolver.getInstructionIndex(address, pc) const itemIndex = this.codeResolver.getInstructionIndex(address, pc)
...@@ -111,9 +118,9 @@ CodeManager.prototype.getInstructionIndex = function (address, step) { ...@@ -111,9 +118,9 @@ CodeManager.prototype.getInstructionIndex = function (address, step) {
console.log(error) console.log(error)
throw new Error('Cannot retrieve current PC for ' + step) throw new Error('Cannot retrieve current PC for ' + step)
} }
} }
/** /**
* Retrieve the called function for the given @arg pc and @arg address * Retrieve the called function for the given @arg pc and @arg address
* *
* @param {String} address - address of the current context (used to resolve instruction index) * @param {String} address - address of the current context (used to resolve instruction index)
...@@ -122,20 +129,20 @@ CodeManager.prototype.getInstructionIndex = function (address, step) { ...@@ -122,20 +129,20 @@ CodeManager.prototype.getInstructionIndex = function (address, step) {
* @param {Object} ast - ast given by the compilation result * @param {Object} ast - ast given by the compilation result
* @return {Object} return the ast node of the function * @return {Object} return the ast node of the function
*/ */
CodeManager.prototype.getFunctionFromPC = function (address, pc, sourceMap, ast) { getFunctionFromPC (address, pc, sourceMap, ast) {
const instIndex = this.codeResolver.getInstructionIndex(address, pc) const instIndex = this.codeResolver.getInstructionIndex(address, pc)
return SourceMappingDecoder.findNodeAtInstructionIndex('FunctionDefinition', instIndex, sourceMap, ast) return SourceMappingDecoder.findNodeAtInstructionIndex('FunctionDefinition', instIndex, sourceMap, ast)
} }
function retrieveCodeAndTrigger (codeMananger, address, stepIndex, tx) { private retrieveCodeAndTrigger (codeMananger, address, stepIndex, tx) {
codeMananger.getCode(address).then((result) => { codeMananger.getCode(address).then((result) => {
retrieveIndexAndTrigger(codeMananger, address, stepIndex, result.instructions) this.retrieveIndexAndTrigger(codeMananger, address, stepIndex, result.instructions)
}).catch((error) => { }).catch((error) => {
return console.log(error) return console.log(error)
}) })
} }
function retrieveIndexAndTrigger (codeMananger, address, step, code) { private retrieveIndexAndTrigger (codeMananger, address, step, code) {
let result let result
try { try {
result = codeMananger.getInstructionIndex(address, step) result = codeMananger.getInstructionIndex(address, step)
...@@ -147,6 +154,5 @@ function retrieveIndexAndTrigger (codeMananger, address, step, code) { ...@@ -147,6 +154,5 @@ function retrieveIndexAndTrigger (codeMananger, address, step, code) {
} catch (e) { } catch (e) {
console.log('dispatching event failed', e) console.log('dispatching event failed', e)
} }
}
} }
module.exports = CodeManager
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment