simplify BreakpointManager

pull/5370/head
Iuri Matias 4 years ago
parent b830d9c77b
commit 30cac8f2a7
  1. 1
      libs/remix-debug/src/Ethdebugger.js
  2. 22
      libs/remix-debug/src/code/breakpointManager.js
  3. 8
      libs/remix-debug/src/debugger/debugger.js
  4. 8
      libs/remix-debug/test/debugger.js

@ -46,6 +46,7 @@ Ethdebugger.prototype.setManagers = function () {
this.storageResolver = null
this.callTree = new InternalCallTree(this.event, this.traceManager, this.solidityProxy, this.codeManager, { includeLocalVariables: true })
this.event.trigger('managersChanged')
}
Ethdebugger.prototype.resolveStep = function (index) {

@ -15,14 +15,22 @@ class BreakpointManager {
* @param {Object} _debugger - type of EthDebugger
* @return {Function} _locationToRowConverter - function implemented by editor which return a column/line position for a char source location
*/
constructor (_debugger, _locationToRowConverter) {
constructor ({traceManager, callTree, solidityProxy, locationToRowConverter}) {
this.event = new EventManager()
this.debugger = _debugger
this.traceManager = traceManager
this.callTree = callTree
this.solidityProxy = solidityProxy
this.breakpoints = {}
this.locationToRowConverter = _locationToRowConverter
this.locationToRowConverter = locationToRowConverter
this.previousLine
}
setManagers({traceManager, callTree, solidityProxy}) {
this.traceManager = traceManager
this.callTree = callTree
this.solidityProxy = solidityProxy
}
/**
* start looking for the next breakpoint
* @param {Bool} defaultToLimit - if true jump to the end of the trace if no more breakpoint found
@ -32,7 +40,7 @@ class BreakpointManager {
if (!this.locationToRowConverter) {
return console.log('row converter not provided')
}
this.jump(fromStep || 0, 1, defaultToLimit, this.debugger.traceManager.trace)
this.jump(fromStep || 0, 1, defaultToLimit, this.traceManager.trace)
}
/**
@ -44,7 +52,7 @@ class BreakpointManager {
if (!this.locationToRowConverter) {
return console.log('row converter not provided')
}
this.jump(fromStep || 0, -1, defaultToLimit, this.debugger.traceManager.trace)
this.jump(fromStep || 0, -1, defaultToLimit, this.traceManager.trace)
}
depthChange (step, trace) {
@ -80,7 +88,7 @@ class BreakpointManager {
while (currentStep > 0 && currentStep < trace.length) {
try {
previousSourceLocation = sourceLocation
sourceLocation = await this.debugger.callTree.extractValidSourceLocation(currentStep)
sourceLocation = await this.callTree.extractValidSourceLocation(currentStep)
} catch (e) {
return console.log('cannot jump to breakpoint ' + e)
}
@ -121,7 +129,7 @@ class BreakpointManager {
* @return {Bool} return true if the given @arg fileIndex @arg line refers to a breakpoint
*/
hasBreakpointAtLine (fileIndex, line) {
const filename = this.debugger.solidityProxy.fileNameFromIndex(fileIndex)
const filename = this.solidityProxy.fileNameFromIndex(fileIndex)
if (!(filename && this.breakpoints[filename])) {
return false
}

@ -21,10 +21,16 @@ function Debugger (options) {
compilationResult: this.compilationResult
})
this.breakPointManager = new BreakpointManager(this.debugger, async (sourceLocation) => {
const {traceManager, callTree, solidityProxy} = this.debugger
this.breakPointManager = new BreakpointManager({traceManager, callTree, solidityProxy, locationToRowConverter: async (sourceLocation) => {
const compilationResult = await this.compilationResult()
if (!compilationResult) return { start: null, end: null }
return this.offsetToLineColumnConverter.offsetToLineColumn(sourceLocation, sourceLocation.file, compilationResult.source.sources, compilationResult.data.sources)
}})
this.breakPointManager.event.register('managersChanged', () => {
const {traceManager, callTree, solidityProxy} = this.debugger
this.breakPointManager.setManagers({traceManager, callTree, solidityProxy})
})
this.breakPointManager.event.register('breakpointStep', (step) => {

@ -273,8 +273,14 @@ function testDebugging (debugManager) {
tape('breakPointManager', (t) => {
t.plan(2)
var sourceMappingDecoder = new SourceMappingDecoder()
var breakPointManager = new BreakpointManager(debugManager, (rawLocation) => {
const {traceManager, callTree, solidityProxy} = debugManager
var breakPointManager = new BreakpointManager({traceManager, callTree, solidityProxy, locationToRowConverter: async (rawLocation) => {
return sourceMappingDecoder.convertOffsetToLineColumn(rawLocation, sourceMappingDecoder.getLinebreakPositions(ballot))
}})
breakPointManager.event.register('managersChanged', () => {
const {traceManager, callTree, solidityProxy} = debugManager
breakPointManager.setManagers({traceManager, callTree, solidityProxy})
})
breakPointManager.add({fileName: 'test.sol', row: 38})

Loading…
Cancel
Save