move debugger UI; out of debugger class

pull/3094/head
Iuri Matias 6 years ago committed by yann300
parent 56591612b6
commit e96f879efb
  1. 58
      src/app/debugger/debugger.js
  2. 21
      src/app/debugger/debuggerUI.js

@ -1,5 +1,5 @@
'use strict' 'use strict'
var EthdebuggerUI = require('./remix-debugger/src/ui/EthdebuggerUI') // var EthdebuggerUI = require('./remix-debugger/src/ui/EthdebuggerUI')
var Ethdebugger = require('remix-debug').EthDebugger var Ethdebugger = require('remix-debug').EthDebugger
var remixLib = require('remix-lib') var remixLib = require('remix-lib')
var EventManager = remixLib.EventManager var EventManager = remixLib.EventManager
@ -33,17 +33,15 @@ function Debugger (container, sourceHighlighter, localRegistry) {
return null return null
} }
}) })
this.debugger_ui = new EthdebuggerUI({debugger: this.debugger}) // this.debugger_ui = new EthdebuggerUI({debugger: this.debugger})
this.sourceMappingDecoder = new remixLib.SourceMappingDecoder() this.sourceMappingDecoder = new remixLib.SourceMappingDecoder()
// // container.appendChild(this.debugger_ui.render())
// TODO: render doesn't exist anymore
container.appendChild(this.debugger_ui.render())
//
this.breakPointManager = new remixLib.code.BreakpointManager(this.debugger, (sourceLocation) => { 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) return self._deps.offsetToLineColumnConverter.offsetToLineColumn(sourceLocation, sourceLocation.file, this._deps.compiler.lastCompilationResult.source.sources, this._deps.compiler.lastCompilationResult.data.sources)
}, (step) => { }, (step) => {
this.debugger_ui.stepManager.jumpTo(step) self.event.trigger('breakpointStep', [step])
// this.debugger_ui.stepManager.jumpTo(step)
}) })
this.debugger.setBreakpointManager(this.breakPointManager) this.debugger.setBreakpointManager(this.breakPointManager)
@ -65,23 +63,7 @@ function Debugger (container, sourceHighlighter, localRegistry) {
self.debugger.unLoad() self.debugger.unLoad()
}) })
// register selected code item, highlight the corresponding source location //
this.debugger_ui.event.register('indexChanged', function (index) {
if (self._deps.compiler.lastCompilationResult) {
self.debugger.traceManager.getCurrentCalledAddressAt(index, (error, address) => {
if (error) return console.log(error)
self.debugger.callTree.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, index, self._deps.compiler.lastCompilationResult.data.contracts, function (error, rawLocation) {
if (!error && self._deps.compiler.lastCompilationResult && self._deps.compiler.lastCompilationResult.data) {
var lineColumnPos = self._deps.offsetToLineColumnConverter.offsetToLineColumn(rawLocation, rawLocation.file, self._deps.compiler.lastCompilationResult.source.sources, self._deps.compiler.lastCompilationResult.data.sources)
self._components.sourceHighlighter.currentSourceLocation(lineColumnPos, rawLocation)
} else {
self._components.sourceHighlighter.currentSourceLocation(null)
}
})
})
}
})
// ==================== // ====================
// listen to events // listen to events
this.debugger.event.register('newTraceLoaded', this, function () { this.debugger.event.register('newTraceLoaded', this, function () {
@ -101,19 +83,31 @@ function Debugger (container, sourceHighlighter, localRegistry) {
this.debugger.switchProvider(executionContext.getProvider()) this.debugger.switchProvider(executionContext.getProvider())
} }
Debugger.prototype.registerAndHighlightCodeItem = function (index) {
const self = this
// register selected code item, highlight the corresponding source location
if (self._deps.compiler.lastCompilationResult) {
self.debugger.traceManager.getCurrentCalledAddressAt(index, (error, address) => {
if (error) return console.log(error)
self.debugger.callTree.sourceLocationTracker.getSourceLocationFromVMTraceIndex(address, index, self._deps.compiler.lastCompilationResult.data.contracts, function (error, rawLocation) {
if (!error && self._deps.compiler.lastCompilationResult && self._deps.compiler.lastCompilationResult.data) {
var lineColumnPos = self._deps.offsetToLineColumnConverter.offsetToLineColumn(rawLocation, rawLocation.file, self._deps.compiler.lastCompilationResult.source.sources)
self._components.sourceHighlighter.currentSourceLocation(lineColumnPos, rawLocation)
} else {
self._components.sourceHighlighter.currentSourceLocation(null)
}
})
})
}
}
/** /**
* Start debugging using Remix * Start debugging using Remix
* *
* @param {String} txHash - hash of the transaction * @param {String} txHash - hash of the transaction
*/ */
Debugger.prototype.debug = function (txHash) { Debugger.prototype.debug = function (txHash, cb) {
var self = this this.debugger.web3.eth.getTransaction(txHash, cb)
this.debugger.web3.eth.getTransaction(txHash, function (error, tx) {
if (!error) {
self.debugger_ui.debug(tx)
}
})
} }
module.exports = Debugger module.exports = Debugger

@ -1,3 +1,4 @@
var OldEthdebuggerUI = require('./remix-debugger/src/ui/EthdebuggerUI')
var Debugger = require('../debugger/debugger') var Debugger = require('../debugger/debugger')
var SourceHighlighter = require('../editor/sourceHighlighter') var SourceHighlighter = require('../editor/sourceHighlighter')
@ -6,6 +7,10 @@ class DebuggerUI {
constructor (container) { constructor (container) {
this.transactionDebugger = new Debugger(container, new SourceHighlighter()) this.transactionDebugger = new Debugger(container, new SourceHighlighter())
this.isActive = false this.isActive = false
this.debugger_ui = new OldEthdebuggerUI({debugger: this.transactionDebugger.debugger})
container.appendChild(this.debugger_ui.render())
this.listenToEvents() this.listenToEvents()
} }
@ -14,6 +19,14 @@ class DebuggerUI {
this.transactionDebugger.event.register('debuggerStatus', function (isActive) { this.transactionDebugger.event.register('debuggerStatus', function (isActive) {
self.isActive = isActive self.isActive = isActive
}) })
this.transactionDebugger.event.register('breakpointStep', function (step) {
self.debugger_ui.stepManager.jumpTo(step)
})
this.debugger_ui.event.register('indexChanged', function (index) {
self.transactionDebugger.registerAndHighlightCodeItem(index)
})
} }
view () { view () {
@ -25,7 +38,13 @@ class DebuggerUI {
} }
debug (txHash) { debug (txHash) {
this.transactionDebugger.debug(txHash) const self = this
this.transactionDebugger.debug(txHash, (error, tx) => {
if (error) {
return console.error("coudn't get txHash: " + error)
}
self.debugger_ui.debug(tx)
})
} }
} }

Loading…
Cancel
Save