From 5d5fcae465b94be51b13d7a4f84dbbeb469ae8b2 Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 16 Oct 2018 13:18:34 -0400 Subject: [PATCH] don't print source automatically; has to be required instead --- remix-debug/src/cmdline/index.js | 69 +++++++++++++++-------- remix-debug/src/debugger/solidityState.js | 7 ++- 2 files changed, 51 insertions(+), 25 deletions(-) diff --git a/remix-debug/src/cmdline/index.js b/remix-debug/src/cmdline/index.js index 56d5044e77..a1ae0cfade 100644 --- a/remix-debug/src/cmdline/index.js +++ b/remix-debug/src/cmdline/index.js @@ -1,10 +1,13 @@ var Web3 = require('web3') var Debugger = require('../debugger/debugger.js') var ContextManager = require('./contextManager.js') +var EventManager = require('events') class CmdLine { constructor () { + this.events = new EventManager() + this.lineColumnPos = null } connect (providerType, url) { @@ -36,35 +39,53 @@ class CmdLine { this.contextManager.switchProvider('debugger_web3') } + getSource() { + const self = this + + console.dir("getSource") + console.dir(this.lineColumnPos) + console.dir(this.filename) + + let lineColumnPos = this.lineColumnPos + + if (!lineColumnPos || !lineColumnPos.start) return; + + let content = self.compilation.lastCompilationResult.source.sources[this.filename].content.split("\n") + + let source = [] + + let line + line = content[lineColumnPos.start.line - 2] + if ( line !== undefined) { + source.push(" " + (lineColumnPos.start.line - 1) + ": " + line) + } + line = content[lineColumnPos.start.line - 1] + if ( line !== undefined) { + source.push(" " + lineColumnPos.start.line + ": " + line) + } + + let currentLineNumber = lineColumnPos.start.line + let currentLine = content[currentLineNumber] + source.push("=> " + (currentLineNumber + 1) + ": " + currentLine) + + let startLine = lineColumnPos.start.line + for (var i=1; i < 4; i++) { + let line = content[startLine + i] + source.push(" " + (startLine + i + 1) + ": " + line) + } + + return source + } + // TODO: is filename really necessary? startDebug(txNumber, filename) { const self = this + this.filename = filename this.debugger.debug(null, txNumber, null, () => { - self.debugger.event.register('newSourceLocation', function (lineColumnPos, rawLocation) { - if (!lineColumnPos || !lineColumnPos.start) return; - - let content = self.compilation.lastCompilationResult.source.sources[filename].content.split("\n") - - let line - line = content[lineColumnPos.start.line - 2] - if ( line !== undefined) { - console.dir(" " + (lineColumnPos.start.line - 1) + ": " + line) - } - line = content[lineColumnPos.start.line - 1] - if ( line !== undefined) { - console.dir(" " + lineColumnPos.start.line + ": " + line) - } - - let currentLineNumber = lineColumnPos.start.line - let currentLine = content[currentLineNumber] - console.dir("=> " + (currentLineNumber + 1) + ": " + currentLine) - - let startLine = lineColumnPos.start.line - for (var i=1; i < 4; i++) { - let line = content[startLine + i] - console.dir(" " + (startLine + i + 1) + ": " + line) - } + self.debugger.event.register('newSourceLocation', function (lineColumnPos, _rawLocation) { + self.lineColumnPos = lineColumnPos + self.events.emit("source") }); self.debugger.vmDebuggerLogic.event.register('solidityState', (data) => { diff --git a/remix-debug/src/debugger/solidityState.js b/remix-debug/src/debugger/solidityState.js index 8f2896c71c..d95894beca 100644 --- a/remix-debug/src/debugger/solidityState.js +++ b/remix-debug/src/debugger/solidityState.js @@ -36,7 +36,12 @@ class DebuggerSolidityState { } self.event.trigger('solidityStateUpdating') decodeTimeout = setTimeout(function () { - self.decode(index) + // necessary due to some states that can crash the debugger + try { + self.decode(index) + } catch(err) { + } + }, 500) }