Compatiblity: refactor `GDBPTY` to allow separate stream objects for reading and writing
authorJan Vrany <jan.vrany@labware.com>
Wed, 02 Aug 2023 13:21:16 +0100
changeset 294 7c84fcc868e2
parent 293 d1422e1ee1bd
child 295 4e7365cece13
Compatiblity: refactor `GDBPTY` to allow separate stream objects for reading and writing This commit changes `GDBPTY` to keep read- and write- streams of both PTY's master and slave as separate objects. This enhances portability as some dialects do not support (character) read-write streams, e.g., Pharo.
GDBDebugger.st
GDBPTY.st
GDBPortlib.st
GDBUnixProcess.st
--- a/GDBDebugger.st	Mon Jul 24 23:15:14 2023 +0100
+++ b/GDBDebugger.st	Wed Aug 02 13:21:16 2023 +0100
@@ -200,24 +200,27 @@
 !
 
 inferiorStderr
-    ^ connection inferiorPTY master
+    ^ connection inferiorPTY masterReadStream
 
     "Created: / 09-06-2014 / 10:01:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 09-06-2014 / 18:26:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 02-08-2023 / 12:51:17 / Jan Vrany <jan.vrany@labware.com>"
 !
 
 inferiorStdin
-    ^ connection inferiorPTY master
+    ^ connection inferiorPTY masterWriteStream
 
     "Created: / 09-06-2014 / 10:00:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 09-06-2014 / 18:27:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 02-08-2023 / 12:51:26 / Jan Vrany <jan.vrany@labware.com>"
 !
 
 inferiorStdout
-    ^ connection inferiorPTY master
+    ^ connection inferiorPTY masterReadStream
 
     "Created: / 09-06-2014 / 10:01:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 09-06-2014 / 18:27:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 02-08-2023 / 12:51:05 / Jan Vrany <jan.vrany@labware.com>"
 !
 
 inferiors
--- a/GDBPTY.st	Mon Jul 24 23:15:14 2023 +0100
+++ b/GDBPTY.st	Wed Aug 02 13:21:16 2023 +0100
@@ -26,7 +26,8 @@
 "{ NameSpace: Smalltalk }"
 
 Object subclass:#GDBPTY
-	instanceVariableNames:'name master slave'
+	instanceVariableNames:'name masterReadStream masterWriteStream slaveReadStream
+		slaveWriteStream'
 	classVariableNames:''
 	poolDictionaries:'TTYConstants'
 	category:'GDB-Internal'
@@ -62,10 +63,10 @@
 
 !GDBPTY class methodsFor:'instance creation'!
 
-name: name master: master slave: slave
-    ^ self basicNew initializeWithName: name master: master slave: slave
+name: name masterReadStream: masterRS masterWriteStream: masterWS slaveReadStream: slaveRS slaveWriteStream: slaveWS
+    ^ self basicNew initializeWithName: name masterReadStream: masterRS masterWriteStream: masterWS slaveReadStream: slaveRS slaveWriteStream: slaveWS
 
-    "Created: / 24-07-2023 / 22:43:32 / Jan Vrany <jan.vrany@labware.com>"
+    "Created: / 02-08-2023 / 13:10:57 / Jan Vrany <jan.vrany@labware.com>"
 !
 
 new
@@ -77,40 +78,66 @@
 
 !GDBPTY methodsFor:'accessing'!
 
-master
-    ^ master
+masterReadStream
+    "Return stream to read from PTY's master"
+
+    ^ masterReadStream
+!
+
+masterWriteStream
+    "Return stream to write to PTY's master"
+
+    ^ masterWriteStream
 !
 
 name
     ^ name
 !
 
-slave
-    ^ slave
+slaveReadStream
+    "Return stream to read from PTY's slave"
+
+    ^ slaveReadStream
+!
+
+slaveWriteStream
+    "Return stream to write to PTY's slave"
+
+    ^ slaveWriteStream
 ! !
 
 !GDBPTY methodsFor:'initialization & release'!
 
-initializeWithName: nameArg master: masterStream slave: slaveStream
+initializeWithName: nameArg masterReadStream: masterRS masterWriteStream: masterWS slaveReadStream: slaveRS slaveWriteStream: slaveWS
+    self assert: masterRS fileDescriptor = masterWS fileDescriptor.
+    self assert: slaveRS fileDescriptor = slaveWS fileDescriptor.
+
     name := nameArg.
-    master := masterStream.
-    slave := slaveStream.
+
+    masterReadStream := masterRS.
+    masterWriteStream := masterWS.
 
-    "Created: / 24-07-2023 / 22:41:41 / Jan Vrany <jan.vrany@labware.com>"
+    slaveReadStream := slaveRS.
+    slaveWriteStream := slaveWS.
+
+    "Created: / 02-08-2023 / 13:10:23 / Jan Vrany <jan.vrany@labware.com>"
 !
 
 release
     name := nil.
-    master notNil ifTrue:[ 
-        master close.
-        master := nil.
+    masterReadStream notNil ifTrue:[ 
+        masterReadStream close.
+        masterReadStream := nil.
+        masterWriteStream := nil.
     ].
-    slave notNil ifTrue:[ 
-        slave close.
-        slave := nil.
+    slaveReadStream notNil ifTrue:[ 
+        slaveReadStream close.
+        slaveReadStream := nil.
+        slaveWriteStream := nil.
     ].
 
     "Created: / 09-06-2014 / 18:25:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 02-08-2023 / 13:29:06 / Jan Vrany <jan.vrany@labware.com>"
 ! !
 
 !GDBPTY methodsFor:'printing & storing'!
@@ -129,31 +156,17 @@
 !GDBPTY methodsFor:'setup'!
 
 setLocalEcho: aBoolean
-    | attrs |
-
-    attrs := master getTTYAttributes.
-    aBoolean ifTrue:[ 
-        attrs c_lflag: (attrs c_lflag bitOr: ECHO).
-    ] ifFalse:[ 
-        attrs c_lflag: (attrs c_lflag bitClear: ECHO).
-    ].
-    master setTTYAttributes: attrs.
+     self masterReadStream setLocalEcho: aBoolean
 
     "Created: / 31-05-2017 / 20:19:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 02-08-2023 / 13:05:45 / Jan Vrany <jan.vrany@labware.com>"
 !
 
 setOutputCRLF: aBoolean
-    | attrs |
-
-    attrs := master getTTYAttributes.
-    aBoolean ifTrue:[ 
-        attrs c_oflag: (attrs c_oflag bitOr: ONLCR).
-    ] ifFalse:[ 
-        attrs c_oflag: (attrs c_oflag bitClear: ONLCR).
-    ].
-    master setTTYAttributes: attrs.
+    self masterReadStream setOutputCRLF: aBoolean
 
     "Created: / 31-05-2017 / 20:20:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 02-08-2023 / 13:05:30 / Jan Vrany <jan.vrany@labware.com>"
 ! !
 
 !GDBPTY class methodsFor:'documentation'!
--- a/GDBPortlib.st	Mon Jul 24 23:15:14 2023 +0100
+++ b/GDBPortlib.st	Wed Aug 02 13:21:16 2023 +0100
@@ -127,7 +127,7 @@
         slave := NonPositionableExternalStream forReadWriteToFileDescriptor:(triplet at:2).
         slave buffered:false.
 
-        ^ GDBPTY name: name master: master slave: slave.
+        ^ GDBPTY name: name masterReadStream: master masterWriteStream: master slaveReadStream: slave slaveWriteStream: slave.
     ].
 
     OperatingSystem isMSWINDOWSlike ifTrue:[ 
@@ -135,6 +135,8 @@
     ].
 
     self error: 'Operating system not supported'
+
+    "Modified: / 02-08-2023 / 13:11:19 / Jan Vrany <jan.vrany@labware.com>"
 !
 
 newPipe
--- a/GDBUnixProcess.st	Mon Jul 24 23:15:14 2023 +0100
+++ b/GDBUnixProcess.st	Wed Aug 02 13:21:16 2023 +0100
@@ -89,15 +89,17 @@
 !GDBUnixProcess methodsFor:'accessing'!
 
 consoleInput
-    ^ consolePTY master
+    ^ consolePTY masterWriteStream
 
     "Created: / 02-06-2017 / 23:36:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 02-08-2023 / 12:50:52 / Jan Vrany <jan.vrany@labware.com>"
 !
 
 consoleOutput
-    ^ consolePTY master
+    ^ consolePTY masterReadStream
 
     "Created: / 02-06-2017 / 23:36:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 02-08-2023 / 12:50:41 / Jan Vrany <jan.vrany@labware.com>"
 !
 
 nativeTargetFeatures
@@ -128,9 +130,9 @@
 
     pid := GDBPortlib current 
                  spawn: argv
-                 stdin: conpty slave
-                 stdout: conpty slave
-                 stderr: conpty slave
+                 stdin: conpty slaveReadStream
+                 stdout: conpty slaveWriteStream
+                 stderr: conpty slaveWriteStream
                  exit: [:stat | self exited: stat ].             
     pid isNil ifTrue:[
         conpty close.
@@ -140,11 +142,12 @@
 
     consolePTY := conpty.
     debuggerPTY := dbgpty.
-    debuggerInput := debuggerOutput := debuggerPTY master.
+    debuggerInput := dbgpty masterWriteStream. 
+    debuggerOutput := dbgpty masterReadStream.
 
     "Created: / 12-12-2018 / 20:13:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 11-06-2019 / 11:44:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 24-07-2023 / 23:00:19 / Jan Vrany <jan.vrany@labware.com>"
+    "Modified: / 02-08-2023 / 13:07:17 / Jan Vrany <jan.vrany@labware.com>"
 !
 
 release