add basic cmd line debugger

pull/5370/head
Iuri Matias 6 years ago
parent afe0e596ee
commit 1f0e23b565
  1. 59
      remix-debug/rdb.js
  2. 0
      remix-debug/src/cmdline/contextManager.js
  3. 103
      remix-debug/src/cmdline/index.js
  4. 139
      remix-debug/test.js

@ -0,0 +1,59 @@
var CmdLine = require('./src/cmdline/index.js')
var compilation = require('./compilation.json')
var cmd_line = new CmdLine()
cmd_line.connect("http", "http://localhost:8545")
cmd_line.loadCompilationResult(compilation)
cmd_line.initDebugger()
var deployContract = function (cb) {
let _web3 = cmd_line.debugger.debugger.web3
let blockNumber = null
let txNumber = null
let tx = null
let code = compilation.data.contracts['browser/ballot.sol'].Ballot.evm.bytecode.object
_web3.eth.sendTransaction({data: "0x" + code, from: _web3.eth.accounts[0], gas: 800000}, cb)
}
deployContract((err, tx) => {
cmd_line.startDebug(tx, "browser/ballot.sol")
})
const repl = require('repl')
const r = repl.start({
prompt: '> ',
eval: (cmd, context, filename, cb) => {
let command = cmd.trim()
if (command === 'next' || command === 'n') {
cmd_line.debugger.step_manager.stepOverForward()
}
if (command === 'previous' || command === 'p' || command === 'prev') {
cmd_line.debugger.step_manager.stepOverBack()
}
if (command === 'step' || command === 's') {
cmd_line.debugger.step_manager.stepIntoForward()
}
if (command === 'stepback' || command === 'sb') {
cmd_line.debugger.step_manager.stepIntoBack()
}
if (command === 'exit' || command === 'quit') {
process.exit(0)
}
if (command === 'var local' || command === 'v l' || command === 'vl') {
cmd_line.displayLocals()
}
if (command === 'var global' || command === 'v g' || command === 'vg') {
cmd_line.displayGlobals()
}
if (command.split(' ')[0] === 'jump') {
let stepIndex = parseInt(command.split(' ')[1], 10)
cmd_line.debugger.step_manager.jumpTo(stepIndex)
}
cb(null, '');
}
});

@ -0,0 +1,103 @@
var Web3 = require('web3')
var Debugger = require('../debugger/debugger.js')
var ContextManager = require('./contextManager.js')
class CmdLine {
constructor () {
}
connect (providerType, url) {
if (providerType !== 'http') throw new Error("unsupported provider type")
this.web3 = new Web3(new Web3.providers.HttpProvider(url))
}
loadCompilationResult (compilationResult) {
this.compilation = {}
this.compilation.lastCompilationResult = compilationResult
}
initDebugger () {
const self = this
this.contextManager = new ContextManager()
this.debugger = new Debugger({
web3: this.contextManager.getWeb3(),
compiler: this.compilation
})
this.contextManager.event.register('providerChanged', () => {
self.debugger.updateWeb3(self.contextManager.getWeb3())
})
this.contextManager.initProviders()
this.contextManager.addProvider('debugger_web3', this.web3)
this.contextManager.switchProvider('debugger_web3')
}
// TODO: is filename really necessary?
startDebug(txNumber, filename) {
const self = this
this.debugger.debug(null, txNumber, null, () => {
self.debugger.event.register('newSourceLocation', function (lineColumnPos, rawLocation) {
console.dir("newSourceLocation")
if (!lineColumnPos || !lineColumnPos.start) return;
let line
line = self.compilation.lastCompilationResult.source.sources['browser/ballot.sol'].content.split("\n")[lineColumnPos.start.line - 1]
console.dir(line)
line = self.compilation.lastCompilationResult.source.sources['browser/ballot.sol'].content.split("\n")[lineColumnPos.start.line]
console.dir(line)
console.dir("^^^^^^^^^^^^^^^ ")
line = self.compilation.lastCompilationResult.source.sources['browser/ballot.sol'].content.split("\n")[lineColumnPos.start.line + 1]
console.dir(line)
});
self.debugger.step_manager.event.register('stepChanged', (stepIndex) => {
// console.dir("---------")
// console.dir("stepChanged: " + stepIndex)
// console.dir("---------")
})
self.debugger.step_manager.event.register('traceLengthChanged', (traceLength) => {
// console.dir("---------")
// console.dir("traceLengthChanged: " + traceLength)
// console.dir("---------")
});
self.debugger.vmDebuggerLogic.event.register('solidityState', (data) => {
self.solidityState = data
});
self.debugger.vmDebuggerLogic.event.register('solidityLocals', (data) => {
self.solidityLocals = data
});
self.debugger.vmDebuggerLogic.event.register('traceManagerMemoryUpdate', (data) => {
// console.dir("---------")
// console.dir("traceManagerMemoryUpdate")
// console.dir(data)
// console.dir("---------")
});
})
}
displayLocals () {
console.dir(this.solidityLocals)
}
displayGlobals () {
console.dir(this.solidityState)
if (this.solidityState && this.solidityState.voters) {
console.dir(this.solidityState.voters)
console.dir(this.solidityState.voters.value)
}
}
}
module.exports = CmdLine

@ -1,139 +0,0 @@
// 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.event.register('providerChanged', () => {
_debugger.updateWeb3(contextManager.getWeb3())
})
contextManager.initProviders()
contextManager.addProvider('myweb3', web3)
contextManager.switchProvider('myweb3')
//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")
if (!lineColumnPos || !lineColumnPos.start) return;
let line
//let line = compilation.lastCompilationResult.source.sources['browser/ballot.sol'].content.split("\n")[lineColumnPos.start.line].slice(lineColumnPos.start.column, lineColumnPos.start.column + lineColumnPos.end.column)
line = compilation.lastCompilationResult.source.sources['browser/ballot.sol'].content.split("\n")[lineColumnPos.start.line - 1]
console.dir(line)
line = compilation.lastCompilationResult.source.sources['browser/ballot.sol'].content.split("\n")[lineColumnPos.start.line]
console.dir(line)
console.dir("^^^^^^^^^^^^^^^ ")
line = compilation.lastCompilationResult.source.sources['browser/ballot.sol'].content.split("\n")[lineColumnPos.start.line + 1]
console.dir(line)
});
_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
global.mytx = txHash
_debugger.event.register('newSourceLocation', (lineColumnPos, rawLocation) => {
console.dir("************ new source location *********")
console.dir(lineColumnPos)
console.dir(rawLocation)
})
_debugger.debug(blockNumber, txNumber, tx, () => {
_debugger.step_manager.event.register('stepChanged', (stepIndex) => {
console.dir("---------")
console.dir("stepChanged: " + stepIndex)
console.dir("---------")
})
_debugger.step_manager.event.register('traceLengthChanged', (traceLength) => {
console.dir("---------")
console.dir("traceLengthChanged: " + traceLength)
console.dir("---------")
});
_debugger.vmDebuggerLogic.event.register('codeManagerChanged', (code, address, index) => {
console.dir("---------")
console.dir("codeManagerChanged")
console.dir("address: " + address)
console.dir("asm code: " + code[index])
console.dir("---------")
});
_debugger.vmDebuggerLogic.event.register('traceManagerMemoryUpdate', (data) => {
console.dir("---------")
console.dir("traceManagerMemoryUpdate")
console.dir(data)
console.dir("---------")
});
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