From b8c7e30dff2a7de206941a5a2ae64fc7ac833dee Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Thu, 11 Oct 2018 13:02:02 -0400 Subject: [PATCH] add resolveToReducedTrace; clean up; improve output --- remix-debug/rdb.js | 8 +-- remix-debug/src/Ethdebugger.js | 1 - remix-debug/src/cmdline/index.js | 51 ++++++++----------- remix-debug/src/debugger/debugger.js | 1 - remix-debug/src/debugger/stepManager.js | 40 +++++++++++++-- .../src/solidity-decoder/internalCallTree.js | 4 +- .../src/solidity-decoder/solidityProxy.js | 2 +- 7 files changed, 64 insertions(+), 43 deletions(-) diff --git a/remix-debug/rdb.js b/remix-debug/rdb.js index 19b589b424..3eb2bf55af 100644 --- a/remix-debug/rdb.js +++ b/remix-debug/rdb.js @@ -29,16 +29,16 @@ const r = repl.start({ eval: (cmd, context, filename, cb) => { let command = cmd.trim() if (command === 'next' || command === 'n') { - cmd_line.debugger.step_manager.stepOverForward() + cmd_line.debugger.step_manager.stepOverForward(true) } if (command === 'previous' || command === 'p' || command === 'prev') { - cmd_line.debugger.step_manager.stepOverBack() + cmd_line.debugger.step_manager.stepOverBack(true) } if (command === 'step' || command === 's') { - cmd_line.debugger.step_manager.stepIntoForward() + cmd_line.debugger.step_manager.stepIntoForward(true) } if (command === 'stepback' || command === 'sb') { - cmd_line.debugger.step_manager.stepIntoBack() + cmd_line.debugger.step_manager.stepIntoBack(true) } if (command === 'exit' || command === 'quit') { process.exit(0) diff --git a/remix-debug/src/Ethdebugger.js b/remix-debug/src/Ethdebugger.js index 8f325280d7..7545bebebb 100644 --- a/remix-debug/src/Ethdebugger.js +++ b/remix-debug/src/Ethdebugger.js @@ -183,7 +183,6 @@ Ethdebugger.prototype.debug = function (tx) { tx.to = traceHelper.contractCreationToken('0') } this.setCompilationResult(this.opts.compilationResult()) - console.log('loading trace...') this.tx = tx var self = this this.traceManager.resolveTrace(tx, function (error, result) { diff --git a/remix-debug/src/cmdline/index.js b/remix-debug/src/cmdline/index.js index 6cacf83974..bb27b6fdab 100644 --- a/remix-debug/src/cmdline/index.js +++ b/remix-debug/src/cmdline/index.js @@ -42,48 +42,41 @@ class CmdLine { 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(" " + (lineColumnPos.start.line - 1) + " " + line) - line = self.compilation.lastCompilationResult.source.sources['browser/ballot.sol'].content.split("\n")[lineColumnPos.start.line] - console.dir("=> " + lineColumnPos.start.line + " " + line) - line = self.compilation.lastCompilationResult.source.sources['browser/ballot.sol'].content.split("\n")[lineColumnPos.start.line + 1] - console.dir(" " + (lineColumnPos.start.line + 1) + " " + line) - line = self.compilation.lastCompilationResult.source.sources['browser/ballot.sol'].content.split("\n")[lineColumnPos.start.line + 2] - console.dir(" " + (lineColumnPos.start.line + 2) + " " + line) - }); - - self.debugger.step_manager.event.register('stepChanged', (stepIndex) => { - // console.dir("---------") - // console.dir("stepChanged: " + stepIndex) - // console.dir("---------") - }) + let content = self.compilation.lastCompilationResult.source.sources['browser/ballot.sol'].content.split("\n") - self.debugger.step_manager.event.register('traceLengthChanged', (traceLength) => { - // console.dir("---------") - // console.dir("traceLengthChanged: " + traceLength) - // console.dir("---------") + 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.vmDebuggerLogic.event.register('solidityState', (data) => { self.solidityState = data }); + // TODO: this doesnt work too well, it should request the data instead... self.debugger.vmDebuggerLogic.event.register('solidityLocals', (data) => { + if (JSON.stringify(data) === '{}') return self.solidityLocals = data }); - self.debugger.vmDebuggerLogic.event.register('traceManagerMemoryUpdate', (data) => { - // console.dir("---------") - // console.dir("traceManagerMemoryUpdate") - // console.dir(data) - // console.dir("---------") - }); - }) } diff --git a/remix-debug/src/debugger/debugger.js b/remix-debug/src/debugger/debugger.js index b6bb8ee616..de0ba0d386 100644 --- a/remix-debug/src/debugger/debugger.js +++ b/remix-debug/src/debugger/debugger.js @@ -115,7 +115,6 @@ Debugger.prototype.debugTx = function (tx, loadingCb) { this.vmDebuggerLogic.start() this.step_manager.event.register('stepChanged', this, function (stepIndex) { - console.dir("stepChanged, going to trigger the other components.. " + stepIndex); self.debugger.codeManager.resolveStep(stepIndex, tx) self.step_manager.event.trigger('indexChanged', [stepIndex]) self.vmDebuggerLogic.event.trigger('indexChanged', [stepIndex]) diff --git a/remix-debug/src/debugger/stepManager.js b/remix-debug/src/debugger/stepManager.js index 26e48ecd4b..eb64ffe401 100644 --- a/remix-debug/src/debugger/stepManager.js +++ b/remix-debug/src/debugger/stepManager.js @@ -1,5 +1,6 @@ var remixLib = require('remix-lib') var EventManager = remixLib.EventManager +var util = remixLib.util class DebuggerStepManager { @@ -81,43 +82,58 @@ class DebuggerStepManager { }) } - stepIntoBack () { + stepIntoBack (solidityMode) { if (!this.traceManager.isLoaded()) return var step = this.currentStepIndex - 1 this.currentStepIndex = step + if (solidityMode) { + step = this.resolveToReducedTrace(step, -1) + } if (!this.traceManager.inRange(step)) { return } this.event.trigger('stepChanged', [step]) } - stepIntoForward () { + stepIntoForward (solidityMode) { if (!this.traceManager.isLoaded()) return var step = this.currentStepIndex + 1 this.currentStepIndex = step + if (solidityMode) { + step = this.resolveToReducedTrace(step, 1) + } if (!this.traceManager.inRange(step)) { return } this.event.trigger('stepChanged', [step]) } - stepOverBack () { + stepOverBack (solidityMode) { if (!this.traceManager.isLoaded()) return var step = this.traceManager.findStepOverBack(this.currentStepIndex) + if (solidityMode) { + step = this.resolveToReducedTrace(step, -1) + } this.currentStepIndex = step this.event.trigger('stepChanged', [step]) } - stepOverForward () { + stepOverForward (solidityMode) { if (!this.traceManager.isLoaded()) return var step = this.traceManager.findStepOverForward(this.currentStepIndex) + if (solidityMode) { + step = this.resolveToReducedTrace(step, 1) + } this.currentStepIndex = step this.event.trigger('stepChanged', [step]) } - jumpOut () { + jumpOut (solidityMode) { if (!this.traceManager.isLoaded()) return var step = this.traceManager.findStepOut(this.currentStepIndex) + if (solidityMode) { + step = this.resolveToReducedTrace(step, 0) + } this.currentStepIndex = step this.event.trigger('stepChanged', [step]) } @@ -140,6 +156,20 @@ class DebuggerStepManager { this.debugger.breakpointManager.jumpPreviousBreakpoint(this.currentStepIndex, true) } + resolveToReducedTrace (value, incr) { + if (this.debugger.callTree.reducedTrace.length) { + var nextSource = util.findClosestIndex(value, this.debugger.callTree.reducedTrace) + nextSource = nextSource + incr + if (nextSource <= 0) { + nextSource = 0 + } else if (nextSource > this.debugger.callTree.reducedTrace.length) { + nextSource = this.debugger.callTree.reducedTrace.length - 1 + } + return this.debugger.callTree.reducedTrace[nextSource] + } + return value + } + } module.exports = DebuggerStepManager diff --git a/remix-debug/src/solidity-decoder/internalCallTree.js b/remix-debug/src/solidity-decoder/internalCallTree.js index 1f2559c0d8..974241de97 100644 --- a/remix-debug/src/solidity-decoder/internalCallTree.js +++ b/remix-debug/src/solidity-decoder/internalCallTree.js @@ -230,7 +230,7 @@ function resolveVariableDeclaration (tree, step, sourceLocation) { if (ast) { tree.variableDeclarationByFile[sourceLocation.file] = extractVariableDeclarations(ast, tree.astWalker) } else { - console.log('Ast not found for step ' + step + '. file ' + sourceLocation.file) + // console.log('Ast not found for step ' + step + '. file ' + sourceLocation.file) return null } } @@ -243,7 +243,7 @@ function resolveFunctionDefinition (tree, step, sourceLocation) { if (ast) { tree.functionDefinitionByFile[sourceLocation.file] = extractFunctionDefinitions(ast, tree.astWalker) } else { - console.log('Ast not found for step ' + step + '. file ' + sourceLocation.file) + // console.log('Ast not found for step ' + step + '. file ' + sourceLocation.file) return null } } diff --git a/remix-debug/src/solidity-decoder/solidityProxy.js b/remix-debug/src/solidity-decoder/solidityProxy.js index 63a42670e3..1fdb293315 100644 --- a/remix-debug/src/solidity-decoder/solidityProxy.js +++ b/remix-debug/src/solidity-decoder/solidityProxy.js @@ -117,7 +117,7 @@ class SolidityProxy { if (this.sources[file]) { return this.sources[file].legacyAST } else { - console.log('AST not found for file id ' + sourceLocation.file) + // console.log('AST not found for file id ' + sourceLocation.file) return null } }