forked from pharo-project/pharo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
StDebuggerActionModel.class.st
203 lines (175 loc) · 5.92 KB
/
StDebuggerActionModel.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
"
I implement debug actions exposed by debuggers, and performed on the current debug session.
"
Class {
#name : #StDebuggerActionModel,
#superclass : #Object,
#instVars : [
'debugger',
'session'
],
#category : #'NewTools-Debugger-Model'
}
{ #category : #'instance creation' }
StDebuggerActionModel class >> on: aDebugSession [
^ self new session: aDebugSession
]
{ #category : #accessing }
StDebuggerActionModel >> assertEqualsSelectors [
^ #(#assert:equals: #assert:closeTo:precision: #assert:closeTo: #assert:identicalTo: #assertCollection:equals: #assertCollection:hasSameElements:)
]
{ #category : #'debug - execution' }
StDebuggerActionModel >> clearDebugSession [
self session terminate
]
{ #category : #'debug - stack' }
StDebuggerActionModel >> copyStackToClipboard [
Clipboard
clipboardText:
(String
streamContents: [ :s | self interruptedContext shortDebugStackOn: s ])
]
{ #category : #'debug - stack' }
StDebuggerActionModel >> exceptionInContextOrNil: aContext [
| ex |
ex := aContext temporaries at: #exception ifAbsent: [ nil ].
ex isClass
ifTrue: [ ^ nil ].
^ ex
]
{ #category : #'debug - stack' }
StDebuggerActionModel >> fileOutMethod: aMethod [
aMethod methodClass fileOutMethod: aMethod selector
]
{ #category : #'debug - stack' }
StDebuggerActionModel >> filterStack: aStack [
| context contextsToReject |
context := aStack first.
contextsToReject := 0.
[
context notNil and: [
context method hasPragmaNamed: #debuggerCompleteToSender ] ]
whileTrue: [
contextsToReject := contextsToReject + 1.
context := context sender ].
contextsToReject timesRepeat: [ aStack removeFirst ].
^ aStack
]
{ #category : #'debug - session' }
StDebuggerActionModel >> implement: aMessage classified: messageCategory inClass: aClass forContext: aContext [
self session
implement: aMessage
classified: messageCategory
inClass: aClass
forContext: aContext
]
{ #category : #accessing }
StDebuggerActionModel >> interruptedContext [
^self session interruptedContext
]
{ #category : #'debug - predicates' }
StDebuggerActionModel >> isContextSteppable [
self flag: 'Too complex: could we reify debugging predicates for more clarity and simplicity?'.
^ (self isInterruptedContextError
or: [ self isInterruptedContextATestFailure
or: [ self isInterruptedContextPostMortem
or: [ self isInterruptedContextDoesNotUnderstand
or: [ self isInterruptedContextMissingClassException
or: [ self isInterruptedContextSubclassResponsibilityException ] ] ] ] ])
not
]
{ #category : #'debug - predicates' }
StDebuggerActionModel >> isInterruptedContextATestFailure [
^ self session isInterruptedContextAnAssertionFailure
]
{ #category : #'debug - predicates' }
StDebuggerActionModel >> isInterruptedContextAnAssertEqualsFailure [
self flag: 'Way too much complex: could we reify debugging predicates for more clarity and simplicity?'.
^ self isInterruptedContextATestFailure
and: [ | failure |
failure := self interruptedContext temporaries
at: #aStringOrBlock
ifAbsent: [ nil ].
failure notNil
and: [ failure isString not
and: [ self assertEqualsSelectors includes: failure outerContext selector ] ] ]
]
{ #category : #'debug - predicates' }
StDebuggerActionModel >> isInterruptedContextDoesNotUnderstand [
^self session isInterruptedContextDoesNotUnderstand
]
{ #category : #'debug - predicates' }
StDebuggerActionModel >> isInterruptedContextError [
self flag:
'Does not pass yet: we need a secure way of knowing the session was opened from **any** kind of exception'.
^ (self session interruptedContext temporaryVariableNamed: #exception)
notNil
]
{ #category : #'debug - predicates' }
StDebuggerActionModel >> isInterruptedContextMissingClassException [
^ self isInterruptedContextDoesNotUnderstand
and: [ self interruptedContext size >= 2
and: [ (self interruptedContext tempAt: 2) class == VariableNotDeclared ]]
]
{ #category : #'debug - predicates' }
StDebuggerActionModel >> isInterruptedContextPostMortem [
^ self session isContextPostMortem: self session interruptedContext
]
{ #category : #'debug - predicates' }
StDebuggerActionModel >> isInterruptedContextSubclassResponsibilityException [
^ self interruptedContext selector == #subclassResponsibility
"### Comments says it should not happen, so why keeping the code? Let's experiment
and:
[" "If we work with an instance of the abstract class (shouldn't normally happen) do not add this action,
as the abstract class alredy contains the the method."
" interruptedContext sender receiver class
~~ interruptedContext sender methodClass ]"
]
{ #category : #'debug - stack' }
StDebuggerActionModel >> peelToFirstLike: aContext [
self session peelToFirstLike: aContext
]
{ #category : #'debug - execution' }
StDebuggerActionModel >> proceedDebugSession [
self session
resume;
clear
]
{ #category : #'debug - execution' }
StDebuggerActionModel >> restartContext: aContext [
self session restart: aContext
]
{ #category : #'debug - execution' }
StDebuggerActionModel >> returnValueFromExpression: aString fromContext: aContext [
| value |
value := session class compiler
source: aString;
context: aContext;
receiver: aContext receiver;
evaluate.
self session returnValue: value from: aContext
]
{ #category : #'debug - execution' }
StDebuggerActionModel >> runToSelection: aSelectionInterval inContext: aContext [
self session runToSelection: aSelectionInterval inContext: aContext
]
{ #category : #accessing }
StDebuggerActionModel >> session [
^session
]
{ #category : #accessing }
StDebuggerActionModel >> session: aDebugSession [
session := aDebugSession
]
{ #category : #'debug - stepping' }
StDebuggerActionModel >> stepInto: aContext [
self session stepInto: aContext
]
{ #category : #'debug - stepping' }
StDebuggerActionModel >> stepOver: aContext [
self session stepOver: aContext
]
{ #category : #'debug - stepping' }
StDebuggerActionModel >> stepThrough: aContext [
self session stepThrough: aContext
]