GDBUnixProcess.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Tue, 27 Mar 2018 08:55:29 +0100
changeset 116 ffd185f7a357
parent 93 b1715ebf8df1
child 134 3abcf54431c1
permissions -rw-r--r--
Fix: initialize debugger features early during initialization The frontend or `stx:libgdbs` may need to query features to conditionally perform some logic, however, if the target does not support async mode (such as Windows), it would block. The GDB documentation says: Whenever a target can change, due to commands such as -target-select, -target-attach or -exec-run, the list of target features may change, and the frontend should obtain it again. The problem is, however, that on a target that does not support, once `-exec-run` is issued, the inferior runs so GDB does not accept any commands until inferior stops. To workaround this until a better solution is found, initialize target features on first stopped event and until initialized, use "default natives features", a hard-coded set. Ugly, but we should move on.

"
jv:libgdbs - GNU Debugger Interface Library
Copyright (C) 2015-now Jan Vrany

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License. 

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
"
"{ Package: 'jv:libgdbs' }"

"{ NameSpace: Smalltalk }"

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

!GDBUnixProcess class methodsFor:'documentation'!

copyright
"
jv:libgdbs - GNU Debugger Interface Library
Copyright (C) 2015-now Jan Vrany

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License. 

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
"
! !

!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>"
!

nativeTargetFeatures
    ^ #('async')

    "Created: / 09-04-2018 / 15:40:32 / 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.
            debuggerInput := debuggerOutput := debuggerPTY master.
            pid.
        ]
        action:[:stat | self exited:stat ].
    pid isNil ifTrue:[
        conpty close.
        dbgpty close.
        self error:'Failed to launch gdb'.
    ].

    "Modified: / 16-12-2017 / 22:27:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

release
    debuggerPTY notNil ifTrue:[
        debuggerPTY release.
        debuggerInput := debuggerOutput := nil
    ].
    consolePTY notNil ifTrue:[
        consolePTY release.
    ].
    super release

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

!GDBUnixProcess class methodsFor:'documentation'!

version_HG

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