|
|
@ -1,22 +1,16 @@ |
|
|
|
'use strict' |
|
|
|
'use strict' |
|
|
|
|
|
|
|
|
|
|
|
var remix = require('ethereum-remix') |
|
|
|
var remix = require('ethereum-remix') |
|
|
|
var ace = require('brace') |
|
|
|
|
|
|
|
var Range = ace.acequire('ace/range').Range |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Manage remix and source highlighting |
|
|
|
* Manage remix and source highlighting |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
function Debugger (id, editor, compiler, executionContextEvent, switchToFile, offsetToLineColumnConverter) { |
|
|
|
function Debugger (id, appAPI, executionContextEvent, editorEvent) { |
|
|
|
this.el = document.querySelector(id) |
|
|
|
this.el = document.querySelector(id) |
|
|
|
this.offsetToLineColumnConverter = offsetToLineColumnConverter |
|
|
|
|
|
|
|
this.debugger = new remix.ui.Debugger() |
|
|
|
this.debugger = new remix.ui.Debugger() |
|
|
|
this.sourceMappingDecoder = new remix.util.SourceMappingDecoder() |
|
|
|
this.sourceMappingDecoder = new remix.util.SourceMappingDecoder() |
|
|
|
this.el.appendChild(this.debugger.render()) |
|
|
|
this.el.appendChild(this.debugger.render()) |
|
|
|
this.editor = editor |
|
|
|
this.appAPI = appAPI |
|
|
|
this.switchToFile = switchToFile |
|
|
|
|
|
|
|
this.compiler = compiler |
|
|
|
|
|
|
|
this.markers = {} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var self = this |
|
|
|
var self = this |
|
|
|
executionContextEvent.register('contextChanged', this, function (context) { |
|
|
|
executionContextEvent.register('contextChanged', this, function (context) { |
|
|
@ -24,23 +18,23 @@ function Debugger (id, editor, compiler, executionContextEvent, switchToFile, of |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
this.debugger.event.register('traceUnloaded', this, function () { |
|
|
|
this.debugger.event.register('traceUnloaded', this, function () { |
|
|
|
self.removeMarkers() |
|
|
|
self.appAPI.currentSourceLocation(null) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
// unload if a file has changed (but not if tabs were switched)
|
|
|
|
// unload if a file has changed (but not if tabs were switched)
|
|
|
|
editor.event.register('contentChanged', function () { |
|
|
|
editorEvent.register('contentChanged', function () { |
|
|
|
self.debugger.unLoad() |
|
|
|
self.debugger.unLoad() |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
// register selected code item, highlight the corresponding source location
|
|
|
|
// register selected code item, highlight the corresponding source location
|
|
|
|
this.debugger.codeManager.event.register('changed', this, function (code, address, index) { |
|
|
|
this.debugger.codeManager.event.register('changed', this, function (code, address, index) { |
|
|
|
if (self.compiler.lastCompilationResult) { |
|
|
|
if (self.appAPI.lastCompilationResult()) { |
|
|
|
this.debugger.callTree.sourceLocationTracker.getSourceLocationFromInstructionIndex(address, index, self.compiler.lastCompilationResult.data.contracts, function (error, rawLocation) { |
|
|
|
this.debugger.callTree.sourceLocationTracker.getSourceLocationFromInstructionIndex(address, index, self.appAPI.lastCompilationResult().data.contracts, function (error, rawLocation) { |
|
|
|
if (!error) { |
|
|
|
if (!error) { |
|
|
|
var lineColumnPos = self.offsetToLineColumnConverter.offsetToLineColumn(rawLocation, rawLocation.file, self.editor, self.compiler.lastCompilationResult.data) |
|
|
|
var lineColumnPos = self.appAPI.offsetToLineColumn(rawLocation, rawLocation.file) |
|
|
|
self.highlight(lineColumnPos, rawLocation) |
|
|
|
self.appAPI.currentSourceLocation(lineColumnPos, rawLocation) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
self.unhighlight() |
|
|
|
self.appAPI.currentSourceLocation(null) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
@ -56,44 +50,12 @@ Debugger.prototype.debug = function (txHash) { |
|
|
|
var self = this |
|
|
|
var self = this |
|
|
|
this.debugger.web3().eth.getTransaction(txHash, function (error, tx) { |
|
|
|
this.debugger.web3().eth.getTransaction(txHash, function (error, tx) { |
|
|
|
if (!error) { |
|
|
|
if (!error) { |
|
|
|
self.debugger.setCompilationResult(self.compiler.lastCompilationResult.data) |
|
|
|
self.debugger.setCompilationResult(self.appAPI.lastCompilationResult().data) |
|
|
|
self.debugger.debug(tx) |
|
|
|
self.debugger.debug(tx) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* highlight the given @arg lineColumnPos |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param {Object} lineColumnPos - position of the source code to hightlight {start: {line, column}, end: {line, column}} |
|
|
|
|
|
|
|
* @param {Object} rawLocation - raw position of the source code to hightlight {start, length, file, jump} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
Debugger.prototype.highlight = function (lineColumnPos, rawLocation) { |
|
|
|
|
|
|
|
this.unhighlight() |
|
|
|
|
|
|
|
var name = this.editor.getCacheFile() // current opened tab
|
|
|
|
|
|
|
|
var source = this.compiler.lastCompilationResult.data.sourceList[rawLocation.file] // auto switch to that tab
|
|
|
|
|
|
|
|
if (name !== source) { |
|
|
|
|
|
|
|
this.switchToFile(source) // command the app to swicth to the next file
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var range = new Range(lineColumnPos.start.line, lineColumnPos.start.column, lineColumnPos.end.line, lineColumnPos.end.column) |
|
|
|
|
|
|
|
this.markers['highlightcode'] = this.editor.addMarker(range, 'highlightcode') |
|
|
|
|
|
|
|
if (lineColumnPos.start.line === lineColumnPos.end.line) { |
|
|
|
|
|
|
|
var fullrange = new Range(lineColumnPos.start.line, 0, lineColumnPos.start.line + 1, 0) |
|
|
|
|
|
|
|
this.markers['highlightcode_fullLine'] = this.editor.addMarker(fullrange, 'highlightcode_fullLine') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* unhighlight the given @arg lineColumnPos |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param {Object} lineColumnPos - position of the source code to hightlight {start: {line, column}, end: {line, column}} |
|
|
|
|
|
|
|
* @param {Object} rawLocation - raw position of the source code to hightlight {start, length, file, jump} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
Debugger.prototype.unhighlight = function (lineColumnPos, rawLocation, cssCode) { |
|
|
|
|
|
|
|
this.removeMarker('highlightcode') |
|
|
|
|
|
|
|
this.removeMarker('highlightcode_fullLine') |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* add a new web3 provider to remix |
|
|
|
* add a new web3 provider to remix |
|
|
|
* |
|
|
|
* |
|
|
@ -120,23 +82,4 @@ Debugger.prototype.web3 = function (type) { |
|
|
|
return this.debugger.web3() |
|
|
|
return this.debugger.web3() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* unhighlight highlighted statements |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
Debugger.prototype.removeMarkers = function () { |
|
|
|
|
|
|
|
for (var k in this.markers) { |
|
|
|
|
|
|
|
this.removeMarker(k) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* unhighlight the current highlighted statement |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
Debugger.prototype.removeMarker = function (key) { |
|
|
|
|
|
|
|
if (this.markers[key]) { |
|
|
|
|
|
|
|
this.editor.removeMarker(this.markers[key]) |
|
|
|
|
|
|
|
this.markers[key] = null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = Debugger |
|
|
|
module.exports = Debugger |
|
|
|