GDBConnection.st
changeset 219 f5c899ac62ec
parent 185 4e1be69b39ce
parent 218 42d5a8a5e14e
child 221 e7a1196c0c41
equal deleted inserted replaced
217:011d65a54cc5 219:f5c899ac62ec
     1 "
     1 "
     2 jv:libgdbs - GNU Debugger Interface Library
     2 jv:libgdbs - GNU Debugger Interface Library
     3 Copyright (C) 2015-now Jan Vrany
     3 Copyright (C) 2015-now Jan Vrany
       
     4 Copyright (C) 2021 LabWare
     4 
     5 
     5 This library is free software; you can redistribute it and/or
     6 This library is free software; you can redistribute it and/or
     6 modify it under the terms of the GNU Lesser General Public
     7 modify it under the terms of the GNU Lesser General Public
     7 License as published by the Free Software Foundation; either
     8 License as published by the Free Software Foundation; either
     8 version 2.1 of the License. 
     9 version 2.1 of the License. 
    20 
    21 
    21 "{ NameSpace: Smalltalk }"
    22 "{ NameSpace: Smalltalk }"
    22 
    23 
    23 Object subclass:#GDBConnection
    24 Object subclass:#GDBConnection
    24 	instanceVariableNames:'process inferiorPTY eventAnnouncer eventAnnouncerInternal
    25 	instanceVariableNames:'process inferiorPTY eventAnnouncer eventAnnouncerInternal
    25 		eventQueue eventQueueLock eventDispatchNotifier
    26 		eventQueue eventQueueLock eventDispatcher eventPumpProcess
    26 		eventDispatchProcess eventDispatchProcessStopping
    27 		outstandingCommands recorder'
    27 		eventPumpProcess outstandingCommands recorder'
       
    28 	classVariableNames:''
    28 	classVariableNames:''
    29 	poolDictionaries:'GDBDebugFlags'
    29 	poolDictionaries:'GDBDebugFlags'
    30 	category:'GDB-Private'
    30 	category:'GDB-Private'
    31 !
    31 !
    32 
    32 
    34 
    34 
    35 copyright
    35 copyright
    36 "
    36 "
    37 jv:libgdbs - GNU Debugger Interface Library
    37 jv:libgdbs - GNU Debugger Interface Library
    38 Copyright (C) 2015-now Jan Vrany
    38 Copyright (C) 2015-now Jan Vrany
       
    39 Copyright (C) 2021 LabWare
    39 
    40 
    40 This library is free software; you can redistribute it and/or
    41 This library is free software; you can redistribute it and/or
    41 modify it under the terms of the GNU Lesser General Public
    42 modify it under the terms of the GNU Lesser General Public
    42 License as published by the Free Software Foundation; either
    43 License as published by the Free Software Foundation; either
    43 version 2.1 of the License. 
    44 version 2.1 of the License. 
    87 
    88 
    88 eventAnnouncerInternal
    89 eventAnnouncerInternal
    89     ^ eventAnnouncerInternal
    90     ^ eventAnnouncerInternal
    90 
    91 
    91     "Created: / 19-06-2014 / 22:18:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    92     "Created: / 19-06-2014 / 22:18:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    93 !
       
    94 
       
    95 eventDispatchProcess
       
    96     ^ eventDispatcher process
       
    97 
       
    98     "Created: / 09-03-2021 / 20:51:54 / Jan Vrany <jan.vrany@labware.com>"
    92 !
    99 !
    93 
   100 
    94 inferiorPTY
   101 inferiorPTY
    95     ^ inferiorPTY
   102     ^ inferiorPTY
    96 !
   103 !
   140     "Modified: / 11-07-2017 / 22:39:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   147     "Modified: / 11-07-2017 / 22:39:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   141 ! !
   148 ! !
   142 
   149 
   143 !GDBConnection methodsFor:'event dispatching'!
   150 !GDBConnection methodsFor:'event dispatching'!
   144 
   151 
   145 eventDispatchLoop
   152 eventDispatchStart
   146     "raise an error: this method should be implemented (TODO)"
   153     eventDispatcher start
   147 
       
   148     [  
       
   149         | eventQueueEmpty |
       
   150 
       
   151         eventQueueEmpty := false.
       
   152         [ eventQueueEmpty ] whileFalse:[
       
   153             | event |
       
   154 
       
   155             event := nil.
       
   156             eventQueueLock critical:[ 
       
   157                 eventQueueEmpty := eventQueue isEmpty.
       
   158                 eventQueueEmpty ifFalse:[ 
       
   159                     event := eventQueue removeFirst.
       
   160                 ]
       
   161             ].
       
   162             eventQueueEmpty ifFalse:[
       
   163                 (AbortOperationRequest , AbortAllOperationRequest) ignoreIn:[
       
   164                     self eventDispatchSingle: event.
       
   165                 ]
       
   166             ].
       
   167         ].
       
   168         eventDispatchProcessStopping == true ifTrue:[ 
       
   169             ^ self.
       
   170         ].
       
   171         eventDispatchNotifier wait.
       
   172     ] loop.
       
   173 
   154 
   174     "Created: / 02-06-2014 / 22:51:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   155     "Created: / 02-06-2014 / 22:51:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   175     "Modified: / 14-01-2018 / 21:54:32 / jv"
   156     "Modified: / 02-10-2018 / 14:28:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   176     "Modified: / 02-10-2018 / 13:35:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   177 !
       
   178 
       
   179 eventDispatchProcess
       
   180     ^ eventDispatchProcess
       
   181 !
       
   182 
       
   183 eventDispatchSingle: aGDBEvent
       
   184     TraceEvents ifTrue:[ 
       
   185         Logger log: ('event loop: broadcasting %1 (%2)' bindWith: aGDBEvent class name with: aGDBEvent token) severity: #trace facility: 'GDB' originator: self attachment: aGDBEvent
       
   186     ].
       
   187     eventAnnouncerInternal announce: aGDBEvent.
       
   188     eventAnnouncer announce: aGDBEvent
       
   189 
       
   190     "Created: / 02-06-2014 / 22:58:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   191     "Modified: / 27-02-2015 / 09:49:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   192 !
       
   193 
       
   194 eventDispatchStart
       
   195     eventDispatchProcess isNil ifTrue:[
       
   196         eventDispatchProcessStopping := false.
       
   197         eventDispatchProcess := [
       
   198                 TraceEvents ifTrue:[
       
   199                     Logger log: 'event loop: starting' severity: #trace facility: 'GDB'
       
   200                 ].
       
   201                 self eventDispatchLoop.
       
   202             ] newProcess.
       
   203         eventDispatchProcess name:('GDB Event dispatcher (%1)' bindWith:process id).
       
   204         eventDispatchProcess priority:Processor userBackgroundPriority.
       
   205         eventDispatchProcess addExitAction:[ 
       
   206             eventDispatchProcess := nil. 
       
   207             eventDispatchProcessStopping := nil.
       
   208             TraceEvents ifTrue:[
       
   209                 Logger log: 'event loop: terminated' severity: #trace facility: 'GDB'
       
   210             ].
       
   211         ].
       
   212         eventDispatchProcess resume.
       
   213     ].
       
   214 
       
   215     "Created: / 02-06-2014 / 22:51:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   216     "Modified: / 19-10-2018 / 10:11:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   217 !
   157 !
   218 
   158 
   219 eventDispatchStop            
   159 eventDispatchStop            
   220     eventDispatchProcessStopping := true.
   160     eventDispatcher stop
   221     eventDispatchNotifier signal.
       
   222 
   161 
   223     "Created: / 02-06-2014 / 22:52:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   162     "Created: / 02-06-2014 / 22:52:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   224     "Modified: / 02-10-2018 / 14:00:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   163     "Modified: / 02-10-2018 / 14:28:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   225 ! !
   164 ! !
   226 
   165 
   227 !GDBConnection methodsFor:'event pump'!
   166 !GDBConnection methodsFor:'event pump'!
   228 
   167 
   229 eventPumpLoop
   168 eventPumpLoop
   326 !GDBConnection methodsFor:'events'!
   265 !GDBConnection methodsFor:'events'!
   327 
   266 
   328 pushEvent: aGDBEvent
   267 pushEvent: aGDBEvent
   329     eventQueueLock critical:[
   268     eventQueueLock critical:[
   330         eventQueue add: aGDBEvent.
   269         eventQueue add: aGDBEvent.
   331         eventDispatchNotifier signal.
   270         eventDispatcher notify.
   332     ].
   271     ].
   333 
   272 
   334     "Created: / 02-06-2014 / 22:49:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   273     "Created: / 02-06-2014 / 22:49:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   335     "Modified: / 02-10-2018 / 14:00:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   274     "Modified: / 02-10-2018 / 14:30:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   336 !
   275 !
   337 
   276 
   338 pushEventSet: aGDBEventSet
   277 pushEventSet: aGDBEventSet
   339     eventQueueLock critical:[
   278     eventQueueLock critical:[
   340         eventQueue add: (GDBEventSetProcessingStarted new setEventSet: aGDBEventSet).  
   279         eventQueue add: (GDBEventSetProcessingStarted new setEventSet: aGDBEventSet).  
   341         eventQueue addAll: aGDBEventSet.
   280         eventQueue addAll: aGDBEventSet.
   342         eventQueue add: (GDBEventSetProcessingFinished new setEventSet: aGDBEventSet).
   281         eventQueue add: (GDBEventSetProcessingFinished new setEventSet: aGDBEventSet).
   343         eventDispatchNotifier signal.
   282         eventDispatcher notify.
   344     ].
   283     ].
   345 
   284 
   346     "Created: / 02-06-2014 / 22:42:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   285     "Created: / 02-06-2014 / 22:42:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   347     "Modified: / 02-10-2018 / 14:00:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   286     "Modified: / 02-10-2018 / 14:30:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   348 ! !
   287 ! !
   349 
   288 
   350 !GDBConnection methodsFor:'initialize & release'!
   289 !GDBConnection methodsFor:'initialize & release'!
   351 
   290 
   352 initializeWithProcess:aGDBProcess 
   291 initializeWithProcess:aGDBProcess 
   354     (OperatingSystem isUNIXlike and:[aGDBProcess canUsePTY]) ifTrue:[
   293     (OperatingSystem isUNIXlike and:[aGDBProcess canUsePTY]) ifTrue:[
   355         inferiorPTY := GDBPTY new.
   294         inferiorPTY := GDBPTY new.
   356     ].
   295     ].
   357     eventQueue := OrderedCollection new.
   296     eventQueue := OrderedCollection new.
   358     eventQueueLock := RecursionLock new.
   297     eventQueueLock := RecursionLock new.
   359     eventDispatchNotifier := Semaphore new.
   298     eventAnnouncerInternal := Announcer new.
   360     eventAnnouncer := Announcer new.
   299     eventAnnouncer := Announcer new.
   361     eventAnnouncer subscriptionRegistry 
   300     eventAnnouncer subscriptionRegistry 
   362         subscriptionClass:GDBEventSubscription.
   301         subscriptionClass:GDBEventSubscription.
   363     eventAnnouncerInternal := Announcer new.
   302     eventDispatcher := GDBEventDispatcher new
       
   303                         setQueue: eventQueue;
       
   304                         setLock: eventQueueLock;
       
   305                         setAnnouncer1: eventAnnouncerInternal;
       
   306                         setAnnouncer2: eventAnnouncer;
       
   307                         yourself.
   364     outstandingCommands := Set new.
   308     outstandingCommands := Set new.
   365     recorder := GDBMITracer new.
   309     recorder := GDBMITracer new.
   366     aGDBProcess connection:self.
   310     aGDBProcess connection:self.
   367 
   311 
   368     "Created: / 20-06-2014 / 21:40:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   312     "Created: / 20-06-2014 / 21:40:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   369     "Modified: / 12-01-2018 / 00:12:25 / jv"
   313     "Modified: / 12-01-2018 / 00:12:25 / jv"
       
   314     "Modified: / 02-10-2018 / 14:29:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   370     "Modified: / 16-01-2019 / 23:02:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   315     "Modified: / 16-01-2019 / 23:02:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   371 !
   316 !
   372 
   317 
   373 release
   318 release
   374     process release
   319     process release