From d2f1e6a8515582cd0ed810e28a60eff6df929f9c Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 17 Jan 2019 11:06:18 -0500 Subject: [PATCH] create rdb bin --- remix-debug/bin/rdb | 112 ++++++++++++++++++++++++++++++++ remix-debug/package.json | 1 + remix-debug/{rdb.js => test.js} | 1 + 3 files changed, 114 insertions(+) create mode 100755 remix-debug/bin/rdb rename remix-debug/{rdb.js => test.js} (98%) diff --git a/remix-debug/bin/rdb b/remix-debug/bin/rdb new file mode 100755 index 0000000000..6e0945952a --- /dev/null +++ b/remix-debug/bin/rdb @@ -0,0 +1,112 @@ +#!/usr/bin/env node + +const program = require('commander') +const version = require('../package.json').version + +program + .command('version') + .description("outputs version number") + .action(() => { + console.log(version) + process.exit(0) + }) + +program + .command('help') + .description("outputs usage information") + .action(() => { + program.help() + process.exit(0) + }) + +program + .option('-f, --file [filename]', 'solidity filename to debug') + .option('--tx [txHash]', 'transaction hash to debug') + .option('--node [url]', 'node to connect to') + .parse(process.argv) + +var CmdLine = require('../src/cmdline/index.js') + +var solc = require('solc') +var fs = require('fs') + +var filename = 'test/sol/simple_storage.sol' +var shortFilename = 'simple_storage.sol' + +var inputJson = { + language: 'Solidity', + sources: { + }, + settings: { + optimizer: { + enabled: true, + runs: 200 + }, + outputSelection: { + '*': { + '': [ 'legacyAST' ], + '*': [ 'abi', 'metadata', 'devdoc', 'userdoc', 'evm.legacyAssembly', 'evm.bytecode', 'evm.deployedBytecode', 'evm.methodIdentifiers', 'evm.gasEstimates' ] + } + } + } +} + +inputJson.sources[shortFilename] = {content: fs.readFileSync(filename).toString()} + +console.log('compiling...') + +let compilationData = JSON.parse(solc.compileStandardWrapper(JSON.stringify(inputJson))) +var compilation = {} +compilation.data = compilationData +compilation.source = { sources: inputJson.sources } + +var cmdLine = new CmdLine() +cmdLine.connect('http', 'http://localhost:8545') +cmdLine.loadCompilationResult(compilation) +cmdLine.initDebugger() + +var tx = '0xf510c4f0b1d9ee262d7b9e9e87b4262f275fe029c2c733feef7dfa1e2b1e32aa' + +cmdLine.startDebug(tx, shortFilename) + +cmdLine.events.on('source', () => { + cmdLine.getSource().forEach(console.dir) +}) + +const repl = require('repl') + +repl.start({ + prompt: '> ', + eval: (cmd, context, filename, cb) => { + let command = cmd.trim() + if (command === 'next' || command === 'n') { + cmdLine.stepOverForward(true) + } + if (command === 'previous' || command === 'p' || command === 'prev') { + cmdLine.stepOverBack(true) + } + if (command === 'step' || command === 's') { + cmdLine.stepIntoForward(true) + } + if (command === 'stepback' || command === 'sb') { + cmdLine.stepIntoBack(true) + } + if (command === 'exit' || command === 'quit') { + process.exit(0) + } + if (command === 'var local' || command === 'v l' || command === 'vl') { + cmdLine.displayLocals() + } + if (command === 'var global' || command === 'v g' || command === 'vg') { + cmdLine.displayGlobals() + } + if (command.split(' ')[0] === 'jump') { + let stepIndex = parseInt(command.split(' ')[1], 10) + cmdLine.jumpTo(stepIndex) + } + cb(null, '') + } +}) + +module.exports = cmdLine + diff --git a/remix-debug/package.json b/remix-debug/package.json index 7db0079bfd..ecd72c8f04 100644 --- a/remix-debug/package.json +++ b/remix-debug/package.json @@ -18,6 +18,7 @@ ], "main": "./index.js", "dependencies": { + "commander": "^2.19.0", "ethereumjs-util": "^4.5.0", "ethereumjs-vm": "2.4.0", "fast-async": "^6.1.2", diff --git a/remix-debug/rdb.js b/remix-debug/test.js similarity index 98% rename from remix-debug/rdb.js rename to remix-debug/test.js index 7a81771c64..abfa0da629 100644 --- a/remix-debug/rdb.js +++ b/remix-debug/test.js @@ -1,3 +1,4 @@ +// TODO: this file shoudl be removed at some point var CmdLine = require('./src/cmdline/index.js') // var compilation = require('./compilation.json')