Skip to content

Commit

Permalink
Merge pull request #642 from adri09070/607-Debugger-var-duplication-a…
Browse files Browse the repository at this point in the history
…nd-big-slowdown-when-executing-a-loop-with-run-to-action

Preventing "Run to" debugger command from raising update events, in order to prevent unnecessary (and broken) updates
  • Loading branch information
StevenCostiou authored Dec 8, 2023
2 parents 41835e3 + 085682f commit cc9aaff
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 19 deletions.
56 changes: 38 additions & 18 deletions src/NewTools-Debugger-Tests/StDebuggerActionModelTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -1151,40 +1151,60 @@ StDebuggerActionModelTest >> testUpdateTopContext [

{ #category : 'tests - contexts' }
StDebuggerActionModelTest >> testUpdateTopContextAfterSessionOperation [
|mockDebugActionModel context|

| mockDebugActionModel context |
context := [ ] asContext.
mockDebugActionModel := StMockDebuggerActionModel new.
mockDebugActionModel stepInto: context.
self assert: mockDebugActionModel tag equals: #updateTopContext.
mockDebugActionModel clear; clearDebugSession.

self assert: mockDebugActionModel tag equals: #updateTopContext.
mockDebugActionModel
clear;
clearDebugSession.

mockDebugActionModel := StMockDebuggerActionModel new.
mockDebugActionModel stepOver: context.
self assert: mockDebugActionModel tag equals: #updateTopContext.
mockDebugActionModel clear; clearDebugSession.

mockDebugActionModel
clear;
clearDebugSession.

mockDebugActionModel := StMockDebuggerActionModel new.
mockDebugActionModel stepThrough: context.
self assert: mockDebugActionModel tag equals: #updateTopContext.
mockDebugActionModel clear; clearDebugSession.

mockDebugActionModel
clear;
clearDebugSession.

mockDebugActionModel := StMockDebuggerActionModel new.
mockDebugActionModel restartContext: context.
self assert: mockDebugActionModel tag equals: #updateTopContext.
mockDebugActionModel clear; clearDebugSession.

mockDebugActionModel
clear;
clearDebugSession.

mockDebugActionModel := StMockDebuggerActionModel new.
mockDebugActionModel returnValueFromExpression: 'nil' fromContext: [] asContext.
mockDebugActionModel
returnValueFromExpression: 'nil'
fromContext: [ ] asContext.
self assert: mockDebugActionModel tag equals: #updateTopContext.
mockDebugActionModel clear; clearDebugSession.

mockDebugActionModel
clear;
clearDebugSession.

mockDebugActionModel := StMockDebuggerActionModel new.
mockDebugActionModel runToSelection: nil inContext: nil.
mockDebugActionModel runToSelection: nil inContext: StMockContext new.
self assert: mockDebugActionModel tag equals: #updateTopContext.
mockDebugActionModel clear; clearDebugSession.

mockDebugActionModel
clear;
clearDebugSession.

mockDebugActionModel := StMockDebuggerActionModel new.
mockDebugActionModel implement: nil inClass: nil forContext: nil.
mockDebugActionModel
implement: nil
inClass: nil
forContext: StMockContext new.
self assert: mockDebugActionModel tag equals: #updateTopContext.
mockDebugActionModel clear; clearDebugSession
mockDebugActionModel
clear;
clearDebugSession
]
53 changes: 53 additions & 0 deletions src/NewTools-Debugger-Tests/StDebuggerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,59 @@ StDebuggerTest >> testContextTempVarListUpdatesTempsWhenEnteringOrLeavingInlined
identicalTo: (contextItems at: i) ]
]

{ #category : 'tests - context inspector' }
StDebuggerTest >> testContextTempVarListUpdatesTempsWhenEnteringOrLeavingInlinedBlocksWithRunTo [

| contextItems inspectorTable newContextItems sourceCode targetCode beginIndex |
dbg := self debuggerOn:
StTestDebuggerProvider new sessionWithInlinedLoop.
inspectorTable := dbg inspector getRawInspectorPresenterOrNil
attributeTable.

"We stop on the node `b := 0` node"
4 timesRepeat: [ dbg stepOver ].

contextItems := inspectorTable roots copy.
sourceCode := dbg context compiledCode sourceCode.

"We enter inlined block"
targetCode := 'nbMonth := nbMonth + 1'.
beginIndex := sourceCode indexOfSubCollection: targetCode.
dbg code selectionInterval:
(Interval from: beginIndex to: beginIndex + targetCode size).
dbg runToSelection.

newContextItems := inspectorTable roots.

self assert: newContextItems size equals: contextItems size + 1.

1 to: contextItems size do: [ :i |
self
assert: (newContextItems at: i)
identicalTo: (contextItems at: i) ].

self assert:
(newContextItems at: contextItems size + 1) tempVariable
isTempVariable.
self
assert:
(newContextItems at: contextItems size + 1) tempVariable name
equals: 'list'.

"We leave inlined block"
targetCode := 'a := b * 42'.
beginIndex := sourceCode indexOfSubCollection: targetCode.
dbg code selectionInterval:
(Interval from: beginIndex to: beginIndex + targetCode size).
dbg runToSelection.

self assert: newContextItems size equals: contextItems size.
1 to: contextItems size do: [ :i |
self
assert: (newContextItems at: i)
identicalTo: (contextItems at: i) ]
]

{ #category : 'tests - context inspector' }
StDebuggerTest >> testContextUnchangedAfterStepOver [
| currentContext |
Expand Down
29 changes: 29 additions & 0 deletions src/NewTools-Debugger-Tests/StTestDebuggerProvider.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,35 @@ StTestDebuggerProvider >> sessionWithDNUAfterStep [
^ sessionForTests
]

{ #category : 'helpers' }
StTestDebuggerProvider >> sessionWithInlinedLoop [

| context process sessionForTests |
context := [
| a b nbMonth |
a := 20.
b := 0.
nbMonth := 0.
[ a > b ] whileTrue: [
| list |
nbMonth := nbMonth + 1.
list := #( 1 2 3 ) asOrderedCollection collect: [ :e |
e + nbMonth ].
b := b + 1 ].
a := b * 42.
^ a ] asContext.
process := Process
forContext: context
priority: Processor userInterruptPriority.
sessionForTests := DebugSession
named: 'test sessionProviderForDebuggerTestsWithInlinedLoop'
on: process
startedAt: context.
sessionForTests exception:
(OupsNullException fromSignallerContext: context).
^ sessionForTests
]

{ #category : 'helpers' }
StTestDebuggerProvider >> terminate [
session ifNotNil:[session clear].
Expand Down
5 changes: 4 additions & 1 deletion src/NewTools-Debugger/StDebuggerActionModel.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,10 @@ StDebuggerActionModel >> returnValueFromExpression: aString fromContext: aContex

{ #category : 'debug - execution' }
StDebuggerActionModel >> runToSelection: aSelectionInterval inContext: aContext [
self session runToSelection: aSelectionInterval inContext: aContext.

previousASTScope := aContext sourceNodeExecuted scope.
self preventUpdatesDuring: [
self session runToSelection: aSelectionInterval inContext: aContext ].
self updateTopContext
]

Expand Down

0 comments on commit cc9aaff

Please sign in to comment.