pull/7/head
Iuri Matias 6 years ago
parent 56b1067f73
commit 8432618b3d
  1. 6415
      remix-debug/compilation.json
  2. 59
      remix-debug/contextManager.js
  3. 0
      remix-debug/lib_test.js
  4. 44
      remix-debug/src/debugger/debugger.js
  5. 87
      remix-debug/test.js

File diff suppressed because one or more lines are too long

@ -0,0 +1,59 @@
var remixLib = require('remix-lib')
var EventManager = remixLib.EventManager
var executionContext = remixLib.execution.executionContext
var Web3Providers = remixLib.vm.Web3Providers
var DummyProvider = remixLib.vm.DummyProvider
var init = remixLib.init
class ContextManager {
constructor () {
this.executionContext = executionContext
this.web3 = this.executionContext.web3()
this.event = new EventManager()
}
initProviders () {
this.web3Providers = new Web3Providers()
this.addProvider('DUMMYWEB3', new DummyProvider())
this.switchProvider('DUMMYWEB3')
this.addProvider('vm', this.executionContext.vm())
this.addProvider('injected', this.executionContext.internalWeb3())
this.addProvider('web3', this.executionContext.internalWeb3())
this.switchProvider(this.executionContext.getProvider())
}
getWeb3 () {
return this.web3
}
addProvider (type, obj) {
this.web3Providers.addProvider(type, obj)
this.event.trigger('providerAdded', [type])
}
switchProvider (type) {
var self = this
this.web3Providers.get(type, function (error, obj) {
if (error) {
console.log('provider ' + type + ' not defined')
} else {
self.web3 = obj
self.executionContext.detectNetwork((error, network) => {
if (error || !network) {
self.web3 = obj
} else {
var webDebugNode = init.web3DebugNode(network.name)
self.web3 = (!webDebugNode ? obj : webDebugNode)
}
self.event.trigger('providerChanged', [type, self.web3])
})
self.event.trigger('providerChanged', [type, self.web3])
}
})
}
}
module.exports = ContextManager

@ -11,7 +11,8 @@ function Debugger (options) {
var self = this
this.event = new EventManager()
this.offsetToLineColumnConverter = options.offsetToLineColumnConverter
// TODO: temporarily commented out
// this.offsetToLineColumnConverter = options.offsetToLineColumnConverter
this.compiler = options.compiler
this.debugger = new Ethdebugger({
@ -25,11 +26,12 @@ function Debugger (options) {
}
})
this.breakPointManager = new remixLib.code.BreakpointManager(this.debugger, (sourceLocation) => {
return self.offsetToLineColumnConverter.offsetToLineColumn(sourceLocation, sourceLocation.file, this.compiler.lastCompilationResult.source.sources, this.compiler.lastCompilationResult.data.sources)
}, (step) => {
self.event.trigger('breakpointStep', [step])
})
// TODO: temporarily commented out
// this.breakPointManager = new remixLib.code.BreakpointManager(this.debugger, (sourceLocation) => {
// return self.offsetToLineColumnConverter.offsetToLineColumn(sourceLocation, sourceLocation.file, this.compiler.lastCompilationResult.source.sources, this.compiler.lastCompilationResult.data.sources)
// }, (step) => {
// self.event.trigger('breakpointStep', [step])
// })
this.debugger.setBreakpointManager(this.breakPointManager)
@ -47,20 +49,22 @@ function Debugger (options) {
}
Debugger.prototype.registerAndHighlightCodeItem = function (index) {
const self = this
// register selected code item, highlight the corresponding source location
if (!self.compiler.lastCompilationResult) return
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) {
if (!error && self.compiler.lastCompilationResult && self.compiler.lastCompilationResult.data) {
var lineColumnPos = self.offsetToLineColumnConverter.offsetToLineColumn(rawLocation, rawLocation.file, self.compiler.lastCompilationResult.source.sources, self.compiler.lastCompilationResult.data.sources)
self.event.trigger('newSourceLocation', [lineColumnPos, rawLocation])
} else {
self.event.trigger('newSourceLocation', [null])
}
})
})
return
// TODO: temporarily commented out
// const self = this
// // register selected code item, highlight the corresponding source location
// if (!self.compiler.lastCompilationResult) return
// 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) {
// if (!error && self.compiler.lastCompilationResult && self.compiler.lastCompilationResult.data) {
// var lineColumnPos = self.offsetToLineColumnConverter.offsetToLineColumn(rawLocation, rawLocation.file, self.compiler.lastCompilationResult.source.sources, self.compiler.lastCompilationResult.data.sources)
// self.event.trigger('newSourceLocation', [lineColumnPos, rawLocation])
// } else {
// self.event.trigger('newSourceLocation', [null])
// }
// })
// })
}
Debugger.prototype.updateWeb3 = function (web3) {

@ -0,0 +1,87 @@
// options
// * executionContext
// * offsetToLineColumnConverter
// *** disable for now
// * compiler
// ** lastCompilationResult
var remixLib = require('remix-lib')
//var executionContext = remixLib.execution.executionContext
var Debugger = require('./src/debugger/debugger.js')
var compilation = {
}
compilation.lastCompilationResult = require('./compilation.json')
// connecting to a node
// var Web3 = require('web3')
// web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"))
// global.my_web3 = web3
// with vm
var ContextManager = require('./contextManager.js')
var contextManager = new ContextManager()
_debugger = new Debugger({
//web3: web3,
web3: contextManager.getWeb3(),
//executionContext: executionContext,
//offsetToLineColumnConverter: this.registry.get('offsettolinecolumnconverter').api,
compiler: compilation
})
// with vm
contextManager.initProviders()
contextManager.event.register('providerChanged', () => {
_debugger.updateWeb3(contextManager.getWeb3())
})
contextManager.switchProvider('vm')
_debugger.event.register('debuggerStatus', function (isActive) {
console.dir("debugger status")
console.dir(isActive)
});
_debugger.event.register('newSourceLocation', function (lineColumnPos, rawLocation) {
console.dir("newSourceLocation")
});
_debugger.event.register('debuggerUnloaded', function() {
console.dir("debugger unloaded")
});
let _web3 = _debugger.debugger.web3
// let web3 = _debugger.debugger.executionContext.web3()
let blockNumber = null
let txNumber = null
let tx = null
// let code = compilation.lastCompilationResult.data.contracts['browser/ballot.sol'].Ballot.evm.bytecode.object
// _web3.eth.sendTransaction({data: "0x" + code, from: _web3.eth.accounts[0], gas: 800000}, (err, txHash) => {
// console.dir(err)
// console.dir(txHash)
//
// txNumber = txHash
//
// _debugger.debug(blockNumber, txNumber, tx, () => {
// console.dir('debugger started')
// })
//
// })
//_debugger.debug(blockNumber, txNumber, tx, () => {
// console.dir('debugger started')
//})
//_debugger.debugger.web3.eth.accounts()
console.dir("done!")
module.exports = _debugger
Loading…
Cancel
Save