From 3ef2e631afd93bb675d79bd2754ba6009a577b2f Mon Sep 17 00:00:00 2001 From: yann300 Date: Wed, 14 Nov 2018 10:49:39 +0100 Subject: [PATCH] fix debugging with source location --- src/app/debugger/debugger/debugger.js | 21 ++++++++++++++------- src/app/debugger/debuggerUI.js | 3 ++- src/app/tabs/debugger-tab.js | 1 - 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/app/debugger/debugger/debugger.js b/src/app/debugger/debugger/debugger.js index c56ea05275..6f23519e42 100644 --- a/src/app/debugger/debugger/debugger.js +++ b/src/app/debugger/debugger/debugger.js @@ -12,20 +12,23 @@ function Debugger (options) { this.event = new EventManager() this.executionContext = options.executionContext + // dependencies this.offsetToLineColumnConverter = options.offsetToLineColumnConverter - this.compiler = options.compiler - this.compilerArtefacts = options.compilersArtefacts + this.compilersArtefacts = options.compilersArtefacts this.debugger = new Ethdebugger({ executionContext: options.executionContext, compilationResult: () => { - if (this.options.compilersArtefacts['__last']) return this.options.compilersArtefacts['__last'].getData() + if (this.compilersArtefacts['__last']) return this.compilersArtefacts['__last'].getData() return null } }) this.breakPointManager = new remixLib.code.BreakpointManager(this.debugger, (sourceLocation) => { - return self._deps.offsetToLineColumnConverter.offsetToLineColumn(sourceLocation, sourceLocation.file, this._deps.compiler.lastCompilationResult.source.sources, this._deps.compiler.lastCompilationResult.data.sources) + if (!this.compilersArtefacts['__last']) return null + let compilationData = this.compilersArtefacts['__last'].getData() + if (!compilationData) return null + return self.offsetToLineColumnConverter.offsetToLineColumn(sourceLocation, sourceLocation.file, compilationData.sources, compilationData.sources) }, (step) => { self.event.trigger('breakpointStep', [step]) }) @@ -57,12 +60,16 @@ function Debugger (options) { Debugger.prototype.registerAndHighlightCodeItem = function (index) { const self = this // register selected code item, highlight the corresponding source location - if (!self._deps.compilersArtefacts['__last']) return + if (!self.compilersArtefacts['__last']) { + self.event.trigger('newSourceLocation', [null]) + return + } + var compilerData = self.compilersArtefacts['__last'].getData() self.debugger.traceManager.getCurrentCalledAddressAt(index, (error, address) => { if (error) return console.log(error) - self.debugger.callTree.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, index, self.compiler.lastCompilationResult.data.contracts, function (error, rawLocation) { + self.debugger.callTree.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, index, compilerData.contracts, function (error, rawLocation) { if (!error) { - var lineColumnPos = self.offsetToLineColumnConverter.offsetToLineColumn(rawLocation, rawLocation.file, compilerData.source.sources, compilerData.data.sources) + var lineColumnPos = self.offsetToLineColumnConverter.offsetToLineColumn(rawLocation, rawLocation.file, compilerData.sources, compilerData.sources) self.event.trigger('newSourceLocation', [lineColumnPos, rawLocation]) } else { self.event.trigger('newSourceLocation', [null]) diff --git a/src/app/debugger/debuggerUI.js b/src/app/debugger/debuggerUI.js index b20f8bfd36..2c1369d5c7 100644 --- a/src/app/debugger/debuggerUI.js +++ b/src/app/debugger/debuggerUI.js @@ -34,7 +34,8 @@ class DebuggerUI { this.debugger = new Debugger({ executionContext: executionContext, offsetToLineColumnConverter: this.registry.get('offsettolinecolumnconverter').api, - compiler: this.registry.get('compiler').api + compiler: this.registry.get('compiler').api, + compilersArtefacts: this.registry.get('compilersartefacts').api }) this.isActive = false diff --git a/src/app/tabs/debugger-tab.js b/src/app/tabs/debugger-tab.js index 8fc69cd5b2..fad957216c 100644 --- a/src/app/tabs/debugger-tab.js +++ b/src/app/tabs/debugger-tab.js @@ -25,7 +25,6 @@ class DebuggerTab { self._view = { el: null } self.data = {} self._components = {} - // TODO: what is this used for? is repated in debugger.js self._components.registry = localRegistry || globalRegistry }