diff --git a/libs/remix-debug/src/Ethdebugger.js b/libs/remix-debug/src/Ethdebugger.js index e438144a62..2bcbb5f036 100644 --- a/libs/remix-debug/src/Ethdebugger.js +++ b/libs/remix-debug/src/Ethdebugger.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) { diff --git a/libs/remix-debug/src/code/breakpointManager.js b/libs/remix-debug/src/code/breakpointManager.js index 960093d40d..159cbd482e 100644 --- a/libs/remix-debug/src/code/breakpointManager.js +++ b/libs/remix-debug/src/code/breakpointManager.js @@ -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 } diff --git a/libs/remix-debug/src/debugger/debugger.js b/libs/remix-debug/src/debugger/debugger.js index a63f6aa17d..ec94fb5b68 100644 --- a/libs/remix-debug/src/debugger/debugger.js +++ b/libs/remix-debug/src/debugger/debugger.js @@ -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) => { diff --git a/libs/remix-debug/test/debugger.js b/libs/remix-debug/test/debugger.js index 41046d0a02..1e2b208a3c 100644 --- a/libs/remix-debug/test/debugger.js +++ b/libs/remix-debug/test/debugger.js @@ -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})