20 "{ Package: 'jv:libgdbs' }" |
20 "{ Package: 'jv:libgdbs' }" |
21 |
21 |
22 "{ NameSpace: Smalltalk }" |
22 "{ NameSpace: Smalltalk }" |
23 |
23 |
24 Object subclass:#GDBEventDispatcher |
24 Object subclass:#GDBEventDispatcher |
25 instanceVariableNames:'debugger queue lock notifier process stopping announcer1 |
25 instanceVariableNames:'debugger queue lock thread announcer1 announcer2' |
26 announcer2' |
|
27 classVariableNames:'' |
26 classVariableNames:'' |
28 poolDictionaries:'GDBDebugFlags' |
27 poolDictionaries:'GDBDebugFlags' |
29 category:'GDB-Private' |
28 category:'GDB-Private' |
30 ! |
29 ! |
31 |
30 |
62 ! ! |
61 ! ! |
63 |
62 |
64 !GDBEventDispatcher methodsFor:'accessing'! |
63 !GDBEventDispatcher methodsFor:'accessing'! |
65 |
64 |
66 process |
65 process |
67 ^ process |
66 ^ thread |
|
67 |
|
68 "Modified: / 26-03-2021 / 13:43:40 / Jan Vrany <jan.vrany@labware.com>" |
68 ! ! |
69 ! ! |
69 |
70 |
70 !GDBEventDispatcher methodsFor:'adding'! |
71 !GDBEventDispatcher methodsFor:'adding'! |
71 |
72 |
72 pushEvent: aGDBEvent |
73 pushEvent: aGDBEvent |
73 lock critical:[ |
74 lock critical:[ |
|
75 Logger |
|
76 log:('event loop: pushing %1 (%2)' bindWith:aGDBEvent class name |
|
77 with:aGDBEvent token) |
|
78 severity:#trace |
|
79 facility:'GDB' |
|
80 originator:self |
|
81 attachment:aGDBEvent. |
74 queue add: aGDBEvent. |
82 queue add: aGDBEvent. |
75 notifier signal. |
83 ]. |
76 ]. |
84 self start |
77 |
85 |
78 "Created: / 02-06-2014 / 22:49:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
86 "Created: / 02-06-2014 / 22:49:49 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
79 "Modified: / 02-10-2018 / 14:30:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
87 "Modified: / 02-10-2018 / 14:30:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
80 "Modified (format): / 17-03-2021 / 12:33:05 / Jan Vrany <jan.vrany@labware.com>" |
88 "Modified: / 17-03-2021 / 13:26:57 / Jan Vrany <jan.vrany@labware.com>" |
81 ! |
89 ! |
82 |
90 |
83 pushEventSet: aGDBEventSet |
91 pushEventSet: aGDBEventSet |
84 lock critical:[ |
92 lock critical:[ |
85 queue add: (GDBEventSetProcessingStarted new setEventSet: aGDBEventSet). |
93 queue add: (GDBEventSetProcessingStarted new setEventSet: aGDBEventSet). |
86 queue addAll: aGDBEventSet. |
94 queue addAll: aGDBEventSet. |
87 queue add: (GDBEventSetProcessingFinished new setEventSet: aGDBEventSet). |
95 queue add: (GDBEventSetProcessingFinished new setEventSet: aGDBEventSet). |
88 notifier signal. |
96 ]. |
89 ]. |
97 self start. |
90 |
98 |
91 "Created: / 02-06-2014 / 22:42:54 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
99 "Created: / 02-06-2014 / 22:42:54 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
92 "Modified: / 02-10-2018 / 14:30:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
100 "Modified: / 02-10-2018 / 14:30:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
93 "Modified (format): / 17-03-2021 / 12:33:01 / Jan Vrany <jan.vrany@labware.com>" |
101 "Modified (format): / 17-03-2021 / 12:33:01 / Jan Vrany <jan.vrany@labware.com>" |
94 ! ! |
102 ! ! |
95 |
103 |
96 !GDBEventDispatcher methodsFor:'dispatching'! |
|
97 |
|
98 start |
|
99 self assert: queue notNil. |
|
100 self assert: lock notNil. |
|
101 |
|
102 process isNil ifTrue:[ |
|
103 stopping := false. |
|
104 process := [ |
|
105 TraceEvents ifTrue:[ |
|
106 Logger log: 'event loop: starting' severity: #trace facility: 'GDB' |
|
107 ]. |
|
108 self dispatch. |
|
109 ] newProcess. |
|
110 process name:('GDB Event dispatcher'). |
|
111 process priority:Processor userBackgroundPriority. |
|
112 process addExitAction:[ |
|
113 process := nil. |
|
114 stopping := nil. |
|
115 TraceEvents ifTrue:[ |
|
116 Logger log: 'event loop: terminated' severity: #trace facility: 'GDB' |
|
117 ]. |
|
118 ]. |
|
119 process resume. |
|
120 ]. |
|
121 |
|
122 "Created: / 02-10-2018 / 14:25:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
123 "Modified (format): / 02-10-2018 / 16:34:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
124 ! |
|
125 |
|
126 stop |
|
127 stopping := true. |
|
128 notifier signal. |
|
129 |
|
130 "Created: / 02-10-2018 / 14:25:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
131 ! ! |
|
132 |
|
133 !GDBEventDispatcher methodsFor:'initialization'! |
104 !GDBEventDispatcher methodsFor:'initialization'! |
134 |
105 |
135 initialize |
106 initialize |
136 "Invoked when a new instance is created." |
107 "Invoked when a new instance is created." |
137 |
108 |
138 super initialize. |
109 super initialize. |
139 queue := OrderedCollection new. |
110 queue := OrderedCollection new. |
140 lock := RecursionLock new. |
111 lock := RecursionLock new. |
141 notifier := Semaphore new. |
|
142 |
112 |
143 "Modified: / 02-10-2018 / 14:13:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
113 "Modified: / 02-10-2018 / 14:13:27 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
144 "Modified: / 17-03-2021 / 12:40:41 / Jan Vrany <jan.vrany@labware.com>" |
114 "Modified: / 17-03-2021 / 12:40:41 / Jan Vrany <jan.vrany@labware.com>" |
145 ! |
115 ! |
146 |
116 |
158 |
128 |
159 setDebugger: aGDBDebugger |
129 setDebugger: aGDBDebugger |
160 debugger := aGDBDebugger |
130 debugger := aGDBDebugger |
161 |
131 |
162 "Created: / 09-03-2021 / 21:02:59 / Jan Vrany <jan.vrany@labware.com>" |
132 "Created: / 09-03-2021 / 21:02:59 / Jan Vrany <jan.vrany@labware.com>" |
163 ! |
|
164 |
|
165 setLock: aRecursionLock |
|
166 lock := aRecursionLock |
|
167 |
|
168 "Created: / 02-10-2018 / 14:20:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
169 ! |
|
170 |
|
171 setQueue: anOrderedCollection |
|
172 queue := anOrderedCollection. |
|
173 |
|
174 "Created: / 02-10-2018 / 14:20:09 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
175 ! ! |
133 ! ! |
176 |
134 |
177 !GDBEventDispatcher methodsFor:'private'! |
135 !GDBEventDispatcher methodsFor:'private'! |
178 |
|
179 dispatch |
|
180 "raise an error: this method should be implemented (TODO)" |
|
181 |
|
182 [ |
|
183 | eventQueueEmpty | |
|
184 |
|
185 eventQueueEmpty := false. |
|
186 [ eventQueueEmpty ] whileFalse:[ |
|
187 | event | |
|
188 |
|
189 event := nil. |
|
190 lock |
|
191 critical:[ |
|
192 eventQueueEmpty := queue isEmpty. |
|
193 eventQueueEmpty ifFalse:[ |
|
194 event := queue removeFirst. |
|
195 ] |
|
196 ]. |
|
197 eventQueueEmpty ifFalse:[ |
|
198 (AbortOperationRequest , AbortAllOperationRequest) |
|
199 ignoreIn:[ self dispatchEvent:event. ] |
|
200 ]. |
|
201 ]. |
|
202 stopping == true ifTrue:[ |
|
203 ^ self. |
|
204 ]. |
|
205 notifier wait. |
|
206 ] loop. |
|
207 |
|
208 "Created: / 02-06-2014 / 22:51:48 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
209 "Modified: / 14-01-2018 / 21:54:32 / jv" |
|
210 "Modified: / 02-10-2018 / 13:35:35 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
211 ! |
|
212 |
136 |
213 dispatchEvent:aGDBEvent |
137 dispatchEvent:aGDBEvent |
214 aGDBEvent debugger: debugger. |
138 aGDBEvent debugger: debugger. |
215 TraceEvents ifTrue:[ |
139 TraceEvents ifTrue:[ |
216 Logger |
140 Logger |
229 ]. |
153 ]. |
230 |
154 |
231 "Created: / 02-06-2014 / 22:58:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
155 "Created: / 02-06-2014 / 22:58:20 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
232 "Modified: / 02-10-2018 / 14:36:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
156 "Modified: / 02-10-2018 / 14:36:04 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
233 "Modified: / 09-03-2021 / 21:03:21 / Jan Vrany <jan.vrany@labware.com>" |
157 "Modified: / 09-03-2021 / 21:03:21 / Jan Vrany <jan.vrany@labware.com>" |
|
158 ! |
|
159 |
|
160 dispatchEvents |
|
161 "Dispatch all events the queue." |
|
162 |
|
163 | event | |
|
164 |
|
165 [ |
|
166 event := nil. |
|
167 lock critical:[ |
|
168 queue notEmpty ifTrue:[event := queue removeFirst] |
|
169 ]. |
|
170 event notNil ifTrue:[ |
|
171 self dispatchEvent: event |
|
172 ]. |
|
173 event notNil. |
|
174 ] whileTrue. |
|
175 |
|
176 "Created: / 26-03-2021 / 21:10:49 / Jan Vrany <jan.vrany@labware.com>" |
234 ! ! |
177 ! ! |
235 |
178 |
236 !GDBEventDispatcher methodsFor:'queries'! |
179 !GDBEventDispatcher methodsFor:'queries'! |
237 |
180 |
238 hasPendingEvents |
181 hasPendingEvents |
256 ^ anyCommandEventPending |
199 ^ anyCommandEventPending |
257 |
200 |
258 "Created: / 17-03-2021 / 12:37:58 / Jan Vrany <jan.vrany@labware.com>" |
201 "Created: / 17-03-2021 / 12:37:58 / Jan Vrany <jan.vrany@labware.com>" |
259 ! ! |
202 ! ! |
260 |
203 |
|
204 !GDBEventDispatcher methodsFor:'start & stop'! |
|
205 |
|
206 start |
|
207 | t | |
|
208 |
|
209 self assert: queue notNil. |
|
210 self assert: lock notNil. |
|
211 |
|
212 ((t := thread) isNil or:[t isDead]) ifTrue:[ |
|
213 thread := [ |
|
214 self dispatchEvents. |
|
215 thread := nil. |
|
216 ] newProcess. |
|
217 thread name:('GDB Event dispatcher'). |
|
218 "/thread priority:Processor userBackgroundPriority. |
|
219 thread addExitAction:[ |
|
220 thread := nil. |
|
221 ]. |
|
222 thread resume. |
|
223 ]. |
|
224 |
|
225 "Created: / 02-10-2018 / 14:25:28 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
226 "Modified (format): / 02-10-2018 / 16:34:55 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
227 "Modified: / 26-03-2021 / 21:10:59 / Jan Vrany <jan.vrany@labware.com>" |
|
228 ! |
|
229 |
|
230 wait |
|
231 "Wait until all events are processed" |
|
232 |
|
233 | t | |
|
234 |
|
235 (t := thread) isNil ifTrue:[^self]. |
|
236 thread := nil. |
|
237 t isDead ifTrue: [ ^ self ]. |
|
238 t priority:(Processor userSchedulingPriority + 1). |
|
239 |
|
240 "Created: / 02-10-2018 / 14:25:36 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
241 "Modified: / 26-03-2021 / 14:17:11 / Jan Vrany <jan.vrany@labware.com>" |
|
242 "Modified (comment): / 26-03-2021 / 21:01:30 / Jan Vrany <jan.vrany@labware.com>" |
|
243 ! ! |
|
244 |
261 !GDBEventDispatcher class methodsFor:'documentation'! |
245 !GDBEventDispatcher class methodsFor:'documentation'! |
262 |
246 |
263 version_HG |
247 version_HG |
264 |
248 |
265 ^ '$Changeset: <not expanded> $' |
249 ^ '$Changeset: <not expanded> $' |