Skip to content

Commit

Permalink
Merge pull request #552 from jecisc/restart-dead-home
Browse files Browse the repository at this point in the history
[P12] Fix DNU when recompiling block with dead home
  • Loading branch information
MarcusDenker authored Jun 20, 2023
2 parents a1e35a3 + 5c944b5 commit c10a1df
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/NewTools-Debugger-Tests/StDebugContextForTests.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,21 @@ Class {
#category : #'NewTools-Debugger-Tests-Utils'
}

{ #category : #private }
StDebugContextForTests >> browseMethod: aMethod [

"Do not open a browser, we are in a test"
]

{ #category : #'ui requests' }
StDebugContextForTests >> confirm: aString [
"Voluntarily returns true to simulate popup validation"

^ true
]

{ #category : #'ui requests' }
StDebugContextForTests >> confirm: message trueChoice: trueChoice falseChoice: falseChoice [
"Yes?"
^ true
]
75 changes: 75 additions & 0 deletions src/NewTools-Debugger-Tests/StDebuggerActionModelTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ StDebuggerActionModelTest >> emptyContextForMethod: aCompiledMethod [
yourself
]

{ #category : #helper }
StDebuggerActionModelTest >> evaluateMethodWithDeadHomeBlockContext [

self methodWithDeadBlockContext value
]

{ #category : #helper }
StDebuggerActionModelTest >> fileOutMethod: anObject [
result := anObject
Expand Down Expand Up @@ -101,6 +107,12 @@ StDebuggerActionModelTest >> methodWithBlockContext [
block value
]

{ #category : #helper }
StDebuggerActionModelTest >> methodWithDeadBlockContext [

^ [ (1+1 ) printString ]
]

{ #category : #helper }
StDebuggerActionModelTest >> methodWithPragma [
<debuggerCompleteToSender>
Expand All @@ -122,6 +134,24 @@ StDebuggerActionModelTest >> newSessionWithBlockContext [
debugActionModel stepInto: debugActionModel topContext ]
]

{ #category : #helper }
StDebuggerActionModelTest >> newSessionWithDeadHomeBlockContext [

| process method |
method := self class >> #evaluateMethodWithDeadHomeBlockContext.
methodWithBlockContextOriginalSource := method sourceCode.
process := [ method valueWithReceiver: self arguments: #( ) ]
newProcess.
self
setSessionAndDebuggerModelForMethod: method
inContext: process suspendedContext.

"Step until we are inside the closure"
[ debugActionModel topContext isBlockContext ] whileFalse: [
debugActionModel stepInto: debugActionModel topContext.
]
]

{ #category : #helper }
StDebuggerActionModelTest >> resetModifiedSourceCode [

Expand Down Expand Up @@ -571,6 +601,51 @@ StDebuggerActionModelTest >> testRecompileMethodToInBlockContext [
identicalTo: (self class >> #methodWithBlockContext) ast statements first value scope
]

{ #category : #'tests - actions' }
StDebuggerActionModelTest >> testRecompileMethodToInBlockContextWithDeadHome [

| contextChanged |

DebugSession contextModelClass: StDebugContextForTests.
self newSessionWithDeadHomeBlockContext.
methodWithBlockContextOriginalSource := (self class >> #methodWithDeadBlockContext) sourceCode.

contextChanged := debugActionModel topContext.

debugActionModel
recompileMethodTo: contextChanged method sourceCode , ' yourself'
inContext: contextChanged
notifying: nil.
debugActionModel updateTopContext.

"The new ast scope is the one of the AST of the first interesting bytecode of the method,
that is the block declaration:"
self assert: (self class >> #methodWithDeadBlockContext) ast formattedCode equals: 'methodWithDeadBlockContext
^ [ (1 + 1) printString ] yourself'
]

{ #category : #'tests - actions' }
StDebuggerActionModelTest >> testRecompileMethodToInBlockContextWithDeadHomeRemainsInOldBlock [

| contextChanged |

DebugSession contextModelClass: StDebugContextForTests.
self newSessionWithDeadHomeBlockContext.
methodWithBlockContextOriginalSource := (self class >> #methodWithDeadBlockContext) sourceCode.

contextChanged := debugActionModel topContext.

debugActionModel
recompileMethodTo: contextChanged method sourceCode , ' yourself'
inContext: contextChanged
notifying: nil.
debugActionModel updateTopContext.

"We should be in the same context as before if the home was dead"
self assert: debugActionModel topContext equals: contextChanged
]

{ #category : #'tests - actions' }
StDebuggerActionModelTest >> testRecompileMethodToInContextNotifyingUpdatesSourceCodeAndContext [

Expand Down
7 changes: 5 additions & 2 deletions src/NewTools-Debugger/StDebuggerActionModel.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -285,16 +285,19 @@ StDebuggerActionModel >> proceedDebugSession [
{ #category : #actions }
StDebuggerActionModel >> recompileMethodTo: aString inContext: aContext notifying: aNotifyer [

| methodContext |
| methodContext homePC |
aContext ifNil: [ ^ self ].
self session
recompileMethodTo: aString
inContext: aContext
notifying: aNotifyer.

methodContext := aContext home.
homePC := methodContext isDead
ifTrue: [ methodContext endPC ]
ifFalse: [ methodContext pc ].
previousASTScope := (methodContext compiledCode sourceNodeForPC:
methodContext pc) scope
homePC) scope
]

{ #category : #context }
Expand Down

0 comments on commit c10a1df

Please sign in to comment.