GDBDriver.st
changeset 10 f04a22c9b16c
parent 9 5cc8797f6523
child 11 474fbb650afe
equal deleted inserted replaced
9:5cc8797f6523 10:f04a22c9b16c
     1 "{ Package: 'jv:libgdbs' }"
     1 "{ Package: 'jv:libgdbs' }"
     2 
     2 
     3 Object subclass:#GDBDriver
     3 Object subclass:#GDBDriver
     4 	instanceVariableNames:'pid input output eventAnnouncer eventQueue eventQueueLock
     4 	instanceVariableNames:'pid debuggerInput debuggerOutput inferiorInput inferiorOutput
     5 		eventQueueNotifier eventDispatchProcess eventPumpProcess'
     5 		eventAnnouncer eventQueue eventQueueLock eventQueueNotifier
       
     6 		eventDispatchProcess eventPumpProcess'
     6 	classVariableNames:''
     7 	classVariableNames:''
     7 	poolDictionaries:'GDBDebugFlags'
     8 	poolDictionaries:'GDBDebugFlags'
     8 	category:'GDB-Private'
     9 	category:'GDB-Private'
     9 !
    10 !
    10 
    11 
    11 
    12 
    12 !GDBDriver class methodsFor:'instance creation'!
    13 !GDBDriver class methodsFor:'instance creation'!
    13 
    14 
    14 pid:pidArg input:inputArg output:outputArg
    15 debuggerPid:pidArg debuggerInput:inputArg debuggerOutput:outputArg inferiorInput:inferiorInputArg inferiorOutput:inferiorOutputArg 
    15     ^ self new 
    16     ^ self new 
    16             initializeWithPid:pidArg
    17         initializeWithDebuggerPid:pidArg
    17             input:inputArg
    18         debuggerInput:inputArg
    18             output:outputArg
    19         debuggerOutput:outputArg
       
    20         inferiorInput:inferiorInputArg
       
    21         inferiorOutput:inferiorOutputArg
    19 
    22 
    20     "Created: / 26-05-2014 / 13:35:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    23     "Created: / 26-05-2014 / 13:35:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    24     "Modified: / 09-06-2014 / 09:20:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    21 ! !
    25 ! !
    22 
    26 
    23 !GDBDriver methodsFor:'accessing'!
    27 !GDBDriver methodsFor:'accessing'!
    24 
    28 
    25 eventAnnouncer
    29 eventAnnouncer
    26     ^ eventAnnouncer
    30     ^ eventAnnouncer
       
    31 !
       
    32 
       
    33 inferiorInput
       
    34     ^ inferiorInput
       
    35 !
       
    36 
       
    37 inferiorOutput
       
    38     ^ inferiorOutput
    27 ! !
    39 ! !
    28 
    40 
    29 !GDBDriver methodsFor:'event dispatching'!
    41 !GDBDriver methodsFor:'event dispatching'!
    30 
    42 
    31 eventDispatchLoop
    43 eventDispatchLoop
   113 onCommand: aGDBCommandEvent
   125 onCommand: aGDBCommandEvent
   114     | command |
   126     | command |
   115 
   127 
   116     command := aGDBCommandEvent command.
   128     command := aGDBCommandEvent command.
   117     command token notNil ifTrue:[ 
   129     command token notNil ifTrue:[ 
   118         input nextPutAll: command token printString.
   130         debuggerInput nextPutAll: command token printString.
   119     ].
   131     ].
   120     input nextPutLine: command asString.
   132     debuggerInput nextPutLine: command asString.
   121 
   133 
   122     "Created: / 02-06-2014 / 23:38:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   134     "Created: / 02-06-2014 / 23:38:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   123 ! !
   135 ! !
   124 
   136 
   125 !GDBDriver methodsFor:'event pump'!
   137 !GDBDriver methodsFor:'event pump'!
   126 
   138 
   127 eventPumpLoop
   139 eventPumpLoop
   128     | parser |
   140     | parser |
   129 
   141 
   130     parser := GDBParser on: output.
   142     parser := GDBParser on: debuggerOutput.
   131     [ output atEnd ] whileFalse:[ 
   143     [ debuggerOutput atEnd ] whileFalse:[ 
   132         | eventset |
   144         | eventset |
   133 
   145 
   134         [
   146         [
   135             [ 
   147             [ 
   136                 eventset := parser parseOutput.
   148                 eventset := parser parseOutput.
   141         ] on: AbortOperationRequest do:[
   153         ] on: AbortOperationRequest do:[
   142             | terminator i c |
   154             | terminator i c |
   143 
   155 
   144             terminator := '(gdb)'.
   156             terminator := '(gdb)'.
   145             i := 1.
   157             i := 1.
   146             output notNil ifTrue:[
   158             debuggerOutput notNil ifTrue:[
   147                 [ output atEnd not and: [i <= terminator size ] ] whileTrue:[ 
   159                 [ debuggerOutput atEnd not and: [i <= terminator size ] ] whileTrue:[ 
   148                     c := output next.
   160                     c := debuggerOutput next.
   149                     c == (terminator at: i) ifTrue:[ 
   161                     c == (terminator at: i) ifTrue:[ 
   150                         i := i + 1.
   162                         i := i + 1.
   151                     ] ifFalse:[ 
   163                     ] ifFalse:[ 
   152                         i := 1.
   164                         i := 1.
   153                     ].
   165                     ].
   154                 ].
   166                 ].
   155                 output next. "/ read nl.
   167                 debuggerOutput next. "/ read nl.
   156             ] ifFalse:[ 
   168             ] ifFalse:[ 
   157                 ^ self.
   169                 ^ self.
   158             ].
   170             ].
   159         ]
   171         ]
   160     ]
   172     ]
   220     "Created: / 02-06-2014 / 22:42:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   232     "Created: / 02-06-2014 / 22:42:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   221 ! !
   233 ! !
   222 
   234 
   223 !GDBDriver methodsFor:'initialize & release'!
   235 !GDBDriver methodsFor:'initialize & release'!
   224 
   236 
   225 initializeWithPid:pidArg input:inputArg output:outputArg 
   237 initializeWithDebuggerPid:pidArg debuggerInput:inputArg debuggerOutput:outputArg inferiorInput:inferiorInputArg inferiorOutput:inferiorOutputArg 
   226     pid := pidArg.
   238     pid := pidArg.
   227     input := inputArg.
   239     debuggerInput := inputArg.
   228 
   240     debuggerOutput := outputArg.
   229     output := outputArg.
   241     inferiorInput := inferiorInputArg.
       
   242     inferiorOutput := inferiorOutputArg.
   230     eventQueue := OrderedCollection new.
   243     eventQueue := OrderedCollection new.
   231     eventQueueLock := RecursionLock new.
   244     eventQueueLock := RecursionLock new.
   232     eventQueueNotifier := Semaphore new.
   245     eventQueueNotifier := Semaphore new.
   233     eventAnnouncer := Announcer new.
   246     eventAnnouncer := Announcer new.
   234 
   247     eventAnnouncer 
   235     eventAnnouncer when: GDBCommandEvent send: #onCommand: to: self.
   248         when:GDBCommandEvent
       
   249         send:#onCommand:
       
   250         to:self.
   236 
   251 
   237     "Created: / 26-05-2014 / 13:35:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   252     "Created: / 26-05-2014 / 13:35:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   238     "Modified: / 02-06-2014 / 23:39:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   253     "Modified: / 09-06-2014 / 09:14:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   239 !
   254 !
   240 
   255 
   241 release
   256 release
   242     pid notNil ifTrue:[
   257     pid notNil ifTrue:[
   243         OperatingSystem sendSignal:(OperatingSystem sigKILL) to:pid.       
   258         OperatingSystem sendSignal:(OperatingSystem sigKILL) to:pid.       
   260     TraceProcesses ifTrue:[ 
   275     TraceProcesses ifTrue:[ 
   261         Logger log: ('gdb process: event pump finished' bindWith: status code)  severity: #trace facility: 'GDB'.
   276         Logger log: ('gdb process: event pump finished' bindWith: status code)  severity: #trace facility: 'GDB'.
   262     ].
   277     ].
   263     pid := nil.       
   278     pid := nil.       
   264     eventQueueNotifier signalForAll.           
   279     eventQueueNotifier signalForAll.           
   265     input notNil ifTrue:[ 
   280     debuggerInput notNil ifTrue:[ 
   266         input close.
   281         debuggerInput close.
   267         input := nil.
   282         debuggerInput := nil.
   268     ].
   283     ].
   269     output notNil ifTrue:[ 
   284     debuggerOutput notNil ifTrue:[ 
   270         output close.
   285         debuggerOutput close.
   271         output := nil.
   286         debuggerOutput := nil.
   272     ].
   287     ].
   273 
   288 
   274     "Created: / 26-05-2014 / 21:31:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   289     "Created: / 26-05-2014 / 21:31:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   275     "Modified: / 04-06-2014 / 09:20:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   290     "Modified: / 04-06-2014 / 09:20:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   276 ! !
   291 ! !