Commit 3284337f authored by Iuri Matias's avatar Iuri Matias

add resolveToReducedTrace; clean up; improve output

parent b40e09e3
......@@ -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)
......
......@@ -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) {
......
......@@ -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 content = self.compilation.lastCompilationResult.source.sources['browser/ballot.sol'].content.split("\n")
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)
});
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)
}
self.debugger.step_manager.event.register('stepChanged', (stepIndex) => {
// console.dir("---------")
// console.dir("stepChanged: " + stepIndex)
// console.dir("---------")
})
let currentLineNumber = lineColumnPos.start.line
let currentLine = content[currentLineNumber]
console.dir("=> " + (currentLineNumber + 1) + ": " + currentLine)
self.debugger.step_manager.event.register('traceLengthChanged', (traceLength) => {
// console.dir("---------")
// console.dir("traceLengthChanged: " + traceLength)
// console.dir("---------")
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("---------")
});
})
}
......
......@@ -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])
......
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
......@@ -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
}
}
......
......@@ -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
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment