diff --git a/src/code/breakpointManager.js b/src/code/breakpointManager.js index 5cb46ccf81..f3bfceeb39 100644 --- a/src/code/breakpointManager.js +++ b/src/code/breakpointManager.js @@ -1,5 +1,6 @@ 'use strict' var EventManager = require('../lib/eventManager') +var helper = require('../helpers/traceHelper') /** * allow to manage breakpoint @@ -50,10 +51,26 @@ class BreakpointManager { console.log('row converter not provided') return } + + function hitLine (currentStep, sourceLocation, self) { + if (helper.isJumpDestInstruction(self.debugger.traceManager.trace[currentStep]) || + helper.isReturnInstruction(self.debugger.traceManager.trace[currentStep - 1]) || + helper.isStopInstruction(self.debugger.traceManager.trace[currentStep - 1])) { + return false + } else { + self.debugger.stepManager.jumpTo(currentStep) + self.event.trigger('breakpointHit', [sourceLocation]) + return true + } + } + var sourceLocation + var previousSourceLocation var currentStep = this.debugger.currentStepIndex + direction + var lineHadBreakpoint = false while (currentStep > 0 && currentStep < this.debugger.traceManager.trace.length) { try { + previousSourceLocation = sourceLocation sourceLocation = await this.debugger.callTree.extractSourceLocation(currentStep) } catch (e) { console.log('cannot jump to breakpoint ' + e) @@ -61,11 +78,23 @@ class BreakpointManager { } var lineColumn = this.locationToRowConverter(sourceLocation) if (this.previousLine !== lineColumn.start.line) { + if (direction === -1 && lineHadBreakpoint) { // TODO : improve this when we will build the correct structure before hand + if (hitLine(currentStep + 1, previousSourceLocation, this)) { + break + } else { + lineHadBreakpoint = false + } + } this.previousLine = lineColumn.start.line if (this.hasBreakpointAtLine(sourceLocation.file, lineColumn.start.line)) { - this.debugger.stepManager.jumpTo(currentStep) - this.event.trigger('breakpointHit', [sourceLocation]) - break + lineHadBreakpoint = true + if (direction === 1) { + if (hitLine(currentStep, sourceLocation, this)) { + break + } else { + lineHadBreakpoint = false + } + } } } currentStep += direction diff --git a/src/helpers/traceHelper.js b/src/helpers/traceHelper.js index dee13c88e9..8d2a560d30 100644 --- a/src/helpers/traceHelper.js +++ b/src/helpers/traceHelper.js @@ -25,6 +25,10 @@ module.exports = { return step.op === 'RETURN' }, + isJumpDestInstruction: function (step) { + return step.op === 'JUMPDEST' + }, + isStopInstruction: function (step) { return step.op === 'STOP' },