Skip to content

Commit

Permalink
Merge pull request #667 from StevenCostiou/15454-removing-ui-manager-…
Browse files Browse the repository at this point in the history
…dependencies

The debugger now delegate UI decisions to the backend provided by its application
  • Loading branch information
jecisc committed Jun 20, 2024
2 parents dd3e7cc + c02a7ab commit 2306aa8
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 17 deletions.
8 changes: 6 additions & 2 deletions src/BaselineOfNewTools/BaselineOfNewTools.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ BaselineOfNewTools >> baseline: spec [
package: 'NewTools-Debugger' with: [ spec requires: #( 'NewTools-Inspector' 'NewTools-Debugger-Commands' 'NewTools-Debugger-Extensions' 'NewTools-SpTextPresenterDecorators' ) ];
package: 'NewTools-Debugger-Commands';
package: 'NewTools-Debugger-Extensions';
package: 'NewTools-Debugger-Morphic';
package: 'NewTools-Debugger-Tests' with: [ spec requires: #( 'NewTools-Debugger' ) ];
"playground"
package: 'NewTools-Playground' with: [ spec requires: #( 'NewTools-Inspector' ) ];
Expand Down Expand Up @@ -116,8 +117,11 @@ BaselineOfNewTools >> baseline: spec [
'NewTools-Debugger-Commands'
'NewTools-Debugger-Extensions'
'NewTools-Debugger'
'NewTools-ObjectCentricBreakpoints'
'NewTools-Sindarin-Tools'
'NewTools-Debugger-Morphic'
'NewTools-ObjectCentricBreakpoints'
'NewTools-Sindarin-Tools'
'NewTools-Sindarin-Commands'
'NewTools-Sindarin-Commands-Tests'
'NewTools-Debugger-Breakpoints-Tools'
Expand Down
9 changes: 9 additions & 0 deletions src/NewTools-Debugger-Morphic/SpMorphicBackend.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Extension { #name : 'SpMorphicBackend' }

{ #category : '*NewTools-Debugger-Morphic' }
SpMorphicBackend >> spawnNewDebugSessionForSpecBackend: aDebugSession [

^ (StMorphicDebugSession newFromSession: aDebugSession)
backend: self;
yourself
]
88 changes: 88 additions & 0 deletions src/NewTools-Debugger-Morphic/StMorphicDebugSession.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
"
I specialize a debug session for Morphic backends used by spec tools
"
Class {
#name : 'StMorphicDebugSession',
#superclass : 'DebugSession',
#instVars : [
'errorWasInUIProcess',
'backend'
],
#category : 'NewTools-Debugger-Morphic',
#package : 'NewTools-Debugger-Morphic'
}

{ #category : 'instance creation' }
StMorphicDebugSession class >> newFromSession: aDebugSession [

^ (self
named: aDebugSession name
on: aDebugSession interruptedProcess
startedAt: aDebugSession interruptedContext)
exception: aDebugSession exception;
detectUIProcess;
spawnNewUIProcessIfNecessary;
yourself
]

{ #category : 'accessing' }
StMorphicDebugSession >> backend: aSpMorphicBackend [

backend := aSpMorphicBackend
]

{ #category : 'debugging actions' }
StMorphicDebugSession >> deferDebuggerOpeningToBackend: aStDebugger [

backend defer: [ aStDebugger openWithFullView ]
]

{ #category : 'process' }
StMorphicDebugSession >> detectUIProcess [

errorWasInUIProcess := MorphicUIManager uiProcess
== interruptedProcess
]

{ #category : 'accessing' }
StMorphicDebugSession >> errorWasInUIProcess [

^ errorWasInUIProcess
]

{ #category : 'accessing' }
StMorphicDebugSession >> errorWasInUIProcess: aBoolean [

errorWasInUIProcess := aBoolean
]

{ #category : 'private' }
StMorphicDebugSession >> resumeInterruptedProcess [

errorWasInUIProcess ifFalse: [ ^ super resumeInterruptedProcess ].
MorphicUIManager default resumeUIProcess: interruptedProcess
]

{ #category : 'process' }
StMorphicDebugSession >> spawnNewUIProcess [

DefaultExecutionEnvironment beActiveDuring: [
MorphicUIManager default spawnNewProcess ]
]

{ #category : 'process' }
StMorphicDebugSession >> spawnNewUIProcessIfNecessary [
"If we're about to debug the UI process, we must create a new UI process to take its place. Because the debugged process will be suspended at some point, and suspending the UI process means freezing the UI of the image"

errorWasInUIProcess ifTrue: [ self spawnNewUIProcess ]
]

{ #category : 'debugging actions' }
StMorphicDebugSession >> terminate [

self interruptedProcess ifNotNil: [ ^ super terminate ].

"Assume the interrupted process was resumed."
"Kill the active process if the error was in the UI as there should be only one UI process."
self errorWasInUIProcess ifTrue: [ Processor terminateActive ]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"
This morphic debug session just redefines methods to be used in tests to avoid spawning new ui processes for real
"
Class {
#name : 'StMorphicDebugSessionForTests',
#superclass : 'StMorphicDebugSession',
#instVars : [
'newUIProcessSpawned'
],
#category : 'NewTools-Debugger-Morphic',
#package : 'NewTools-Debugger-Morphic'
}

{ #category : 'process' }
StMorphicDebugSessionForTests >> newUIProcessSpawned [

newUIProcessSpawned ifNil: [ newUIProcessSpawned := false ].
^ newUIProcessSpawned
]

{ #category : 'process' }
StMorphicDebugSessionForTests >> spawnNewUIProcessIfNecessary [
"we just want to avoid spawning UI processes, while ensuring that we actually called the ui process spawning logic "

newUIProcessSpawned := errorWasInUIProcess
]
53 changes: 53 additions & 0 deletions src/NewTools-Debugger-Morphic/StMorphicDebugSessionTest.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
Class {
#name : 'StMorphicDebugSessionTest',
#superclass : 'TestCase',
#category : 'NewTools-Debugger-Morphic',
#package : 'NewTools-Debugger-Morphic'
}

{ #category : 'utilities' }
StMorphicDebugSessionTest >> createDebugSessionForNotUIProcess [

| exception nonUIProcess request |
nonUIProcess := [ 1 + 1 ] newProcess.
[ Exception signal ]
on: Exception
do: [ :e | exception := e ].
request := (OupsDummyDebugRequest newForException: exception)
process: nonUIProcess;
yourself.
^ StMorphicDebugSessionForTests newFromSession: request debugSession
]

{ #category : 'utilities' }
StMorphicDebugSessionTest >> createDebugSessionForUIProcess [

| exception request |
[ Exception signal ]
on: Exception
do: [ :e | exception := e ].
request := (OupsDummyDebugRequest newForException: exception)
process: MorphicUIManager uiProcess;
yourself.
^ StMorphicDebugSessionForTests newFromSession: request debugSession
]

{ #category : 'utilities' }
StMorphicDebugSessionTest >> testNonUIProcessIsRecognised [
"Tests that a DebuggerSystem opening a DebugRequest that is NOT on the ui process does NOT spawn a new UI process"

| morphicDebugSession |
morphicDebugSession := self createDebugSessionForNotUIProcess.
self deny: morphicDebugSession errorWasInUIProcess.
self deny: morphicDebugSession newUIProcessSpawned
]

{ #category : 'tests' }
StMorphicDebugSessionTest >> testUIProcessIsRecognised [
"Test that a DebuggerSystem opening a DebugRequest on the ui process will spawn a new UI process"

| morphicDebugSession |
morphicDebugSession := self createDebugSessionForUIProcess.
self assert: morphicDebugSession errorWasInUIProcess.
self assert: morphicDebugSession newUIProcessSpawned
]
1 change: 1 addition & 0 deletions src/NewTools-Debugger-Morphic/package.st
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Package { #name : 'NewTools-Debugger-Morphic' }
10 changes: 0 additions & 10 deletions src/NewTools-Debugger/DebugSession.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,5 @@ DebugSession >> application [

{ #category : '*NewTools-Debugger' }
DebugSession >> application: anApplication [
]

{ #category : '*NewTools-Debugger' }
DebugSession >> spanNewSession [

^ (self class
named: self name
on: self interruptedProcess
startedAt: self interruptedContext)
errorWasInUIProcess: self errorWasInUIProcess;
yourself
]
7 changes: 7 additions & 0 deletions src/NewTools-Debugger/SpApplicationBackend.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Extension { #name : 'SpApplicationBackend' }

{ #category : '*NewTools-Debugger' }
SpApplicationBackend >> spawnNewDebugSessionForSpecBackend: aDebugSession [

^ aDebugSession
]
15 changes: 10 additions & 5 deletions src/NewTools-Debugger/StDebugger.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,18 @@ StDebugger class >> configureLayout: aSymbol [
{ #category : 'instance creation' }
StDebugger class >> debugSession: aDebugSession [

| debugger debugActionModel |
debugActionModel := StDebuggerActionModel on: aDebugSession.
debugger := self on: aDebugSession.
aDebugSession application ifNotNil: [ :app |
| applicationDebugSession debugger debugActionModel |

applicationDebugSession := self currentApplication backend
spawnNewDebugSessionForSpecBackend: aDebugSession.

debugActionModel := StDebuggerActionModel on: applicationDebugSession.
debugger := self on: applicationDebugSession.
aDebugSession application ifNotNil: [ :app |
debugger application: app ].
debugger openWithFullView.

applicationDebugSession deferDebuggerOpeningToBackend: debugger.

^ debugger
]

Expand Down

0 comments on commit 2306aa8

Please sign in to comment.