GDBConnection.st
changeset 23 a7eb888c81b5
parent 22 57025871aed4
child 24 98ff50f8a25d
--- a/GDBConnection.st	Fri Jun 20 21:25:03 2014 +0100
+++ b/GDBConnection.st	Fri Jun 20 22:14:51 2014 +0100
@@ -1,10 +1,9 @@
 "{ Package: 'jv:libgdbs' }"
 
 Object subclass:#GDBConnection
-	instanceVariableNames:'pid debuggerInput debuggerOutput inferiorPTY eventAnnouncer
-		eventAnnouncerInternal eventQueue eventQueueLock
-		eventQueueNotifier eventDispatchProcess eventPumpProcess
-		outstandingCommands'
+	instanceVariableNames:'process inferiorPTY eventAnnouncer eventAnnouncerInternal
+		eventQueue eventQueueLock eventQueueNotifier eventDispatchProcess
+		eventPumpProcess outstandingCommands'
 	classVariableNames:''
 	poolDictionaries:'GDBDebugFlags'
 	category:'GDB-Private'
@@ -13,13 +12,16 @@
 
 !GDBConnection class methodsFor:'instance creation'!
 
-pid:pidArg input:inputArg output:outputArg
-    ^ self new 
-        initializeWithPid:pidArg
-        input:inputArg
-        output:outputArg
+new
+    ^ self shouldNotImplement.
 
-    "Created: / 09-06-2014 / 18:20:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 20-06-2014 / 21:45:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+newWithProcess: aGDBProcess
+    ^ self basicNew initializeWithProcess: aGDBProcess
+
+    "Created: / 20-06-2014 / 21:45:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !GDBConnection methodsFor:'accessing'!
@@ -38,6 +40,18 @@
     ^ inferiorPTY
 ! !
 
+!GDBConnection methodsFor:'commands'!
+
+send: command
+    command token notNil ifTrue:[ 
+        process debuggerInput nextPutAll: command token printString.
+    ].
+    outstandingCommands add: command.
+    process debuggerInput nextPutLine: command asString.
+
+    "Created: / 20-06-2014 / 22:09:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !GDBConnection methodsFor:'event dispatching'!
 
 eventDispatchLoop
@@ -65,12 +79,12 @@
                 ].
             ].
         ].
-        pid isNil ifTrue:[ ^ self ]. "/ gdb process terninated
+        process pid isNil ifTrue:[ ^ self ]. "/ gdb process terninated
         eventQueueNotifier wait.
     ] loop.
 
     "Created: / 02-06-2014 / 22:51:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified (comment): / 04-06-2014 / 09:16:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 20-06-2014 / 21:38:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 eventDispatchSingle: aGDBEvent
@@ -92,7 +106,7 @@
                 ].
                 self eventDispatchLoop.
             ] newProcess.
-        eventDispatchProcess name:('GDB Event dispatcher (%1)' bindWith:pid).
+        eventDispatchProcess name:('GDB Event dispatcher (%1)' bindWith:process pid).
         eventDispatchProcess priority:Processor userBackgroundPriority.
         eventDispatchProcess addExitAction:[ 
             eventDispatchProcess := nil. 
@@ -104,7 +118,7 @@
     ].
 
     "Created: / 02-06-2014 / 22:51:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 04-06-2014 / 09:27:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 20-06-2014 / 21:38:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 eventDispatchStop
@@ -121,28 +135,12 @@
     "Created: / 02-06-2014 / 22:52:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
-!GDBConnection methodsFor:'event handling'!
-
-onCommand: aGDBCommandEvent
-    | command |
-
-    command := aGDBCommandEvent command.
-    command token notNil ifTrue:[ 
-        debuggerInput nextPutAll: command token printString.
-    ].
-    outstandingCommands add: command.
-    debuggerInput nextPutLine: command asString.
-
-    "Created: / 02-06-2014 / 23:38:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 19-06-2014 / 22:08:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-! !
-
 !GDBConnection methodsFor:'event pump'!
 
 eventPumpLoop
     | parser |
 
-    parser := GDBParser on: debuggerOutput.
+    parser := GDBParser on: process debuggerOutput.
     parser token2CommandMappingBlock:[ :token | 
         | command |
 
@@ -150,7 +148,7 @@
         command notNil ifTrue:[ outstandingCommands remove: command ].
         command
     ].
-    [ debuggerOutput atEnd ] whileFalse:[ 
+    [ process debuggerOutput atEnd ] whileFalse:[ 
         | eventset |
 
         [
@@ -165,16 +163,16 @@
 
             terminator := '(gdb)'.
             i := 1.
-            debuggerOutput notNil ifTrue:[
-                [ debuggerOutput atEnd not and: [i <= terminator size ] ] whileTrue:[ 
-                    c := debuggerOutput next.
+            process debuggerOutput notNil ifTrue:[
+                [ process debuggerOutput atEnd not and: [i <= terminator size ] ] whileTrue:[ 
+                    c := process debuggerOutput next.
                     c == (terminator at: i) ifTrue:[ 
                         i := i + 1.
                     ] ifFalse:[ 
                         i := 1.
                     ].
                 ].
-                debuggerOutput next. "/ read nl.
+                process debuggerOutput next. "/ read nl.
             ] ifFalse:[ 
                 ^ self.
             ].
@@ -182,7 +180,7 @@
     ]
 
     "Created: / 02-06-2014 / 22:38:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 19-06-2014 / 22:10:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 20-06-2014 / 21:39:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 eventPumpStart
@@ -193,7 +191,7 @@
                 ].
                 self eventPumpLoop
             ] newProcess.
-        eventPumpProcess name:('GDB Event pump (%1)' bindWith:pid).
+        eventPumpProcess name:('GDB Event pump (%1)' bindWith:process pid).
         eventPumpProcess priority:Processor userBackgroundPriority.
         eventPumpProcess addExitAction:[ 
             TraceEvents ifTrue:[
@@ -205,7 +203,7 @@
     ].
 
     "Created: / 02-06-2014 / 22:38:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 04-06-2014 / 09:27:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 20-06-2014 / 21:37:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 eventPumpStop
@@ -244,10 +242,8 @@
 
 !GDBConnection methodsFor:'initialize & release'!
 
-initializeWithPid:pidArg input:inputArg output:outputArg
-    pid := pidArg.
-    debuggerInput := inputArg.
-    debuggerOutput := outputArg.
+initializeWithProcess: aGDBProcess
+    process := aGDBProcess.
     inferiorPTY := GDBPTY new.
     eventQueue := OrderedCollection new.
     eventQueueLock := RecursionLock new.
@@ -255,27 +251,22 @@
     eventAnnouncer := Announcer new.
     eventAnnouncerInternal := Announcer new.    
     outstandingCommands := Set new.
-    eventAnnouncerInternal 
-        when:GDBCommandEvent
-        send:#onCommand:
-        to:self.
 
-    "Created: / 09-06-2014 / 18:21:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 19-06-2014 / 22:18:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 20-06-2014 / 21:40:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 release
-    pid notNil ifTrue:[
-        OperatingSystem sendSignal:(OperatingSystem sigKILL) to:pid.       
+    process pid notNil ifTrue:[
+        OperatingSystem sendSignal:(OperatingSystem sigKILL) to:process pid.       
     ]
 
     "Created: / 26-05-2014 / 21:30:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 03-06-2014 / 00:55:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 20-06-2014 / 21:41:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 released: status
     TraceProcesses ifTrue:[ 
-        Logger log: ('gdb process: terminated with status %1' bindWith: status code)  severity: #trace facility: 'GDB'.
+        Logger log: ('gdb process: exited with status %1' bindWith: status code)  severity: #trace facility: 'GDB'.
     ].
     TraceProcesses ifTrue:[ 
         Logger log: ('gdb process: waiting for event pump to finish' bindWith: status code)  severity: #trace facility: 'GDB'.
@@ -286,20 +277,12 @@
     TraceProcesses ifTrue:[ 
         Logger log: ('gdb process: event pump finished' bindWith: status code)  severity: #trace facility: 'GDB'.
     ].
-    pid := nil.       
     eventQueueNotifier signalForAll.           
-    debuggerInput notNil ifTrue:[ 
-        debuggerInput close.
-        debuggerInput := nil.
-    ].
-    debuggerOutput notNil ifTrue:[ 
-        debuggerOutput close.
-        debuggerOutput := nil.
-    ].
+    process release.
     inferiorPTY release.
 
     "Created: / 26-05-2014 / 21:31:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 09-06-2014 / 18:26:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 20-06-2014 / 21:37:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !GDBConnection class methodsFor:'documentation'!