Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preventing "Run to" debugger command from raising update events, in order to prevent unnecessary (and broken) updates #642

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -405,6 +405,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 @@ -266,6 +266,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 @@ -413,7 +413,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