GDBSimulatorProcess.st
changeset 27 e7e01078d9c4
parent 26 dbcc28b503c0
child 31 1d8d532f27fd
child 32 d9c96b33afd6
equal deleted inserted replaced
26:dbcc28b503c0 27:e7e01078d9c4
     1 "{ Package: 'jv:libgdbs' }"
     1 "{ Package: 'jv:libgdbs' }"
     2 
     2 
     3 GDBProcess subclass:#GDBSimulatorProcess
     3 GDBProcess subclass:#GDBSimulatorProcess
     4 	instanceVariableNames:'record thread'
     4 	instanceVariableNames:'record thread steppingSemaphore'
     5 	classVariableNames:''
     5 	classVariableNames:''
     6 	poolDictionaries:''
     6 	poolDictionaries:''
     7 	category:'GDB-Private'
     7 	category:'GDB-Private-Simulator'
     8 !
     8 !
       
     9 
       
    10 !GDBSimulatorProcess methodsFor:'execution'!
       
    11 
       
    12 pause
       
    13     steppingSemaphore isNil ifTrue:[ 
       
    14         steppingSemaphore := Semaphore new.
       
    15     ] ifFalse:[
       
    16         steppingSemaphore clear.        
       
    17     ].
       
    18 
       
    19     "Created: / 24-06-2014 / 13:05:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    20 !
       
    21 
       
    22 resume
       
    23     | sema |
       
    24 
       
    25     steppingSemaphore notNil ifTrue:[ 
       
    26         sema :=  steppingSemaphore.
       
    27         steppingSemaphore := nil.
       
    28         sema signalForAll.
       
    29     ].
       
    30     thread isNil ifTrue:[ self start ].
       
    31 
       
    32     "Created: / 24-06-2014 / 13:05:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    33 !
       
    34 
       
    35 step
       
    36     steppingSemaphore isNil ifTrue:[ 
       
    37         steppingSemaphore := Semaphore new.
       
    38     ].
       
    39     thread isNil ifTrue:[ self start ].
       
    40     steppingSemaphore signal.
       
    41 
       
    42     "Created: / 24-06-2014 / 13:02:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
    43 ! !
     9 
    44 
    10 !GDBSimulatorProcess methodsFor:'initialization'!
    45 !GDBSimulatorProcess methodsFor:'initialization'!
    11 
    46 
    12 initialize
    47 initialize
    13     pid := -1.
    48     pid := -1.
    17     "Modified: / 20-06-2014 / 22:18:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    52     "Modified: / 20-06-2014 / 22:18:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    18 ! !
    53 ! !
    19 
    54 
    20 !GDBSimulatorProcess methodsFor:'processing'!
    55 !GDBSimulatorProcess methodsFor:'processing'!
    21 
    56 
    22 process: commandOrResponse
    57 processCommand: actual expecting: expected
    23     | commandLine |
       
    24 
    58 
    25     "Process response..."
    59     actual class == GDBMI_gdb_exit ifTrue:[ 
    26     commandOrResponse isResponse ifTrue:[ 
    60         actual token notNil ifTrue:[ 
    27         debuggerOutput nextPutAll: commandOrResponse string.
    61             debuggerOutput nextPutAll: actual token printString.
       
    62         ].
       
    63         debuggerOutput nextPutLine: '^exit'.
       
    64         ^ true.
       
    65     ].
       
    66     (actual class == GDBMI_inferior_tty_set and:[expected class == GDBMI_inferior_tty_set]) ifTrue:[ 
    28         ^ false.
    67         ^ false.
    29     ].
    68     ].
    30     "Process command"
       
    31     commandLine := debuggerInput nextLine.
       
    32     commandLine ~= commandOrResponse string ifTrue:[ 
       
    33         | commandLineStream token command |
       
    34 
    69 
    35         commandLineStream := commandLine readStream.
    70     actual token notNil ifTrue:[ 
    36         commandLineStream peek isDigit ifTrue:[ 
    71         debuggerOutput nextPutAll: actual token printString.
    37             token := 0.
    72     ].    
    38             [ commandLineStream peek isDigit ] whileTrue:[
    73     debuggerOutput nextPutLine: '^error,msg="Unexpected command"'.
    39                 token := (token * 10) + (commandLineStream next codePoint - $0 codePoint)
    74     ^ false
    40             ]
       
    41         ].
       
    42         command := commandLineStream upToEnd.
       
    43         token notNil ifTrue:[ 
       
    44             debuggerOutput nextPutAll: token printString.
       
    45         ].
       
    46 
    75 
    47         command = '-gdb-exit' ifTrue:[ 
    76     "Created: / 24-06-2014 / 23:37:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    48             debuggerOutput nextPutLine: '^exit'.
    77 !
    49             ^ true "/ We're done
    78 
    50         ] ifFalse:[ 
    79 processCommandLineExpecting: lineExpected
    51             debuggerOutput nextPutLine:'^error,msg="Unexpected command for this simulation"'
    80     | lineActual |
    52         ].
    81 
    53             
    82     lineActual := debuggerInput nextLine.
       
    83     lineActual ~= lineExpected ifTrue:[ 
       
    84         | cmdActual cmdExpected |
       
    85 
       
    86         cmdActual := (GDBParser on: lineActual ) parseCommand.  
       
    87         cmdExpected := (GDBParser on: lineExpected ) parseCommand.  
       
    88 
       
    89         ^ self processCommand: cmdActual expecting: cmdExpected.  
    54     ].
    90     ].
    55     ^ false
    91     ^ false
    56 
    92 
    57     "Created: / 24-06-2014 / 08:50:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    93     "Created: / 24-06-2014 / 23:37:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    58 !
    94 !
    59 
    95 
    60 processLoop
    96 processLoop
    61     | done events |
    97     | done events |
    62 
    98 
    63     done := false.
    99     done := false.
    64     events := record readStream.
   100     events := record readStream.
    65     [ done or:[ events atEnd ] ] whileFalse:[ 
   101     [ done or:[ events atEnd ] ] whileFalse:[
    66         done := self process: events next.
   102         | event |
       
   103 
       
   104         event := events next.
       
   105         event isCommand ifTrue:[ 
       
   106             done := self processCommandLineExpecting: event string.
       
   107         ] ifFalse:[
       
   108             self processResponse: event.
       
   109         ]
    67 
   110 
    68     ].
   111     ].
    69 
   112 
    70     "Created: / 24-06-2014 / 08:48:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   113     "Created: / 24-06-2014 / 08:48:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   114     "Modified: / 24-06-2014 / 23:37:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
       
   115 !
       
   116 
       
   117 processResponse: response
       
   118     debuggerOutput nextPutAll: response string
       
   119 
       
   120     "Created: / 24-06-2014 / 22:57:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    71 ! !
   121 ! !
    72 
   122 
    73 !GDBSimulatorProcess methodsFor:'start & stop'!
   123 !GDBSimulatorProcess methodsFor:'start & stop'!
    74 
   124 
    75 record
   125 record
    76     ^ record
   126     ^ record
    77 !
   127 !
    78 
   128 
    79 record:aGDBSessionRecord
   129 record:aGDBSessionRecord
    80     record := aGDBSessionRecord.
   130     record := aGDBSessionRecord.
    81     self start.
       
    82 
   131 
    83     "Modified: / 24-06-2014 / 00:58:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
   132     "Modified: / 24-06-2014 / 13:06:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    84 !
   133 !
    85 
   134 
    86 start
   135 start
    87     self stop.
   136     self stop.
    88 
   137