GDBUnixProcess.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 17 Nov 2017 20:36:08 -0300
changeset 90 6046abc9ddf4
parent 79 303c4edc75ad
child 91 472a4841a8b6
permissions -rw-r--r--
Replaced Squek computed arrays by more verbose `Array with:...` ...to workaround a buggy stx, sigh.

"{ Package: 'jv:libgdbs' }"

"{ NameSpace: Smalltalk }"

GDBProcess subclass:#GDBUnixProcess
	instanceVariableNames:'debuggerPTY consolePTY'
	classVariableNames:'GDBExecutable'
	poolDictionaries:''
	category:'GDB-Private'
!


!GDBUnixProcess class methodsFor:'accessing'!

gdbExecutable
    ^ GDBExecutable

    "Created: / 01-03-2015 / 08:07:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

gdbExecutable: aString
    GDBExecutable := aString

    "Created: / 01-03-2015 / 08:07:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBUnixProcess methodsFor:'accessing'!

consoleInput
    ^ consolePTY master

    "Created: / 02-06-2017 / 23:36:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

consoleOutput
    ^ consolePTY master

    "Created: / 02-06-2017 / 23:36:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

debuggerInput
    ^ debuggerPTY master

    "Modified: / 26-05-2017 / 11:33:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

debuggerOutput
    ^ debuggerPTY master

    "Modified: / 26-05-2017 / 11:34:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBUnixProcess methodsFor:'initialization & release'!

initialize
    | conpty dbgpty args |

    conpty := GDBPTY new.

    dbgpty := GDBPTY new.
    dbgpty setLocalEcho: false.
    dbgpty setOutputCRLF: false.

    args := (Array new: 8)
                at: 1 put: GDBExecutable ? '/usr/bin/gdb';
                at: 2 put: '-q';
                at: 3 put: '-ex';
                at: 4 put: 'new-ui mi ', dbgpty name;
                at: 5 put: '-ex';
                at: 6 put: 'set pagination off';
                at: 7 put: '-ex';
                at: 8 put: 'show version';
                yourself.
    Processor
        monitor:[
            pid := OperatingSystem
                    exec:args first
                    withArguments:args
                    environment:OperatingSystem getEnvironment
                    fileDescriptors:{
                            conpty slave fileDescriptor.
                            conpty slave fileDescriptor.
                            conpty slave fileDescriptor
                        }
                    fork:true
                    newPgrp:false
                    inDirectory:Filename currentDirectory
                    showWindow: false.
            consolePTY := conpty.
            debuggerPTY := dbgpty.
            pid.
        ]
        action:[:stat | self exited:stat ].
    pid isNil ifTrue:[
        conpty close.
        dbgpty close.
        self error:'Failed to launch gdb'.
    ].

    "Modified: / 17-11-2017 / 20:18:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

release
    debuggerPTY notNil ifTrue:[
        debuggerPTY release.
    ].
    consolePTY notNil ifTrue:[
        consolePTY release.
    ].
    super release

    "Created: / 02-06-2017 / 23:33:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBUnixProcess class methodsFor:'documentation'!

version_HG

    ^ '$Changeset: <not expanded> $'
! !