GDBProcess.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sat, 20 Oct 2018 07:48:11 +0100
changeset 152 fab425b52c21
parent 149 0db2ccc6da7b
child 153 dd55019f1d86
permissions -rw-r--r--
Refactor `GDBProcess` hierarchy to improve portability Spawning and managing an OS process is tightly bound to the underlaying platform (both, smalltalk-wise and OS-wise). To improve portability and clarity of the code, rename `GDBUnixProcess` and `GDBWindowsProcess` to `GDBStXUnixProcess` and `GDBStxWindowsProcess`. This commit also includes a new abstract superclass (a `GDBLocalProcess`) for all specialisation spawning and managing a GDB process running on the same host as `jv:libgdbs` code.

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

Object subclass:#GDBProcess
	instanceVariableNames:'connection debuggerInput debuggerOutput'
	classVariableNames:''
	poolDictionaries:''
	category:'GDB-Private'
!

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

documentation
"
    GDBProcess is represents a running GDB and provides access
    to MI and CLI channels (see #debuggerIput / #debuggerOutput).

    [author:]
        Jan Vrany <jan.vrany@fit.cvut.cz>

    [instance variables:]

    [class variables:]

    [see also:]
        GDBStXUnixProcess
        GDBStXWindowsProcess

"
! !

!GDBProcess class methodsFor:'instance creation'!

new
    self == GDBProcess ifTrue:[
        Smalltalk isSmalltalkX ifTrue:[
            OperatingSystem isUNIXlike ifTrue:[
                ^ GDBStXUnixProcess basicNew initialize
            ].
            OperatingSystem isMSWINDOWSlike ifTrue:[
                ^ GDBStXWindowsProcess basicNew initialize
            ]
        ].
        GDBError raiseErrorString:'Unsuported platform'.
    ] ifFalse:[ 
        ^ super new.
    ].

    "
     GDBProcess new release."

    "Modified (comment): / 11-01-2018 / 23:02:11 / jv"
    "Modified: / 19-10-2018 / 10:03:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBProcess class methodsFor:'accessing'!

gdbExecutable
    | exe |

    exe := UserPreferences current gdbExecutable.
    exe notNil ifTrue:[ ^ exe ].

    "/ On Windows, look for MSYS2 installation and
    "/ try to pick GDB matching current arch (i686
    "/ or x86_64) since on Windows, there's no GDB
    "/ supporting both targets :-(
    OperatingSystem isMSWINDOWSlike ifTrue:[ 
        ExternalAddress pointerSize == 8 ifTrue:[
            exe := 'C:\msys64\mingw64\bin\gdb.exe'.
            exe asFilename exists ifTrue:[ ^ exe ].
            exe := 'C:\msys64\usr\bin\gdb.exe'.
            exe asFilename exists ifTrue:[ ^ exe ].
        ] ifFalse:[
            exe := 'C:\msys64\mingw32\bin\gdb.exe'.
            exe asFilename exists ifTrue:[ ^ exe ].
        ]
    ].

    "/ Search for `gdb` along the PATH...
    exe := OperatingSystem pathOfCommand: 'gdb'.
    exe notNil ifTrue:[ ^ exe ].   

    "/ Nothing found :-(
    ^ nil

    "
    GDBProcess gdbExecutable
    UserPreferences current gdbExecutable: nil.
    UserPreferences current gdbExecutable: '/home/jv/Projects/gdb/users_jv_vdb/gdb/gdb'.

      

    "

    "Created: / 01-03-2015 / 08:07:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (format): / 03-10-2018 / 22:18:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (comment): / 07-10-2018 / 07:59:57 / jv"
!

gdbExecutable: aString
    UserPreferences current gdbExecutable: aString

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

!GDBProcess class methodsFor:'queries'!

isAbstract
    "Return if this class is an abstract class.
     True is returned here for myself only; false for subclasses.
     Abstract subclasses must redefine again."

    ^ self == GDBProcess.
! !

!GDBProcess methodsFor:'accessing'!

connection:aGDBConnection
    connection := aGDBConnection.
!

consoleInput
    "Return a write stream on debugger's CLI channel. CLI commands
     should be written here. If this process does not have a CLI
     channel opened, `nil` is returned. In this case, CLI must be
     emulated - if required. See `-interpreter-exec` MI command.

     CLI channel is generally available only on Smalltalk/X and only
     on UNIX platform where this stream points to TTY."

    ^ nil

    "Created: / 02-06-2017 / 23:35:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 15-12-2017 / 23:58:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (comment): / 17-10-2018 / 22:20:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

consoleOutput
    "Return a read stream on debugger's CLI channel. CLI output
     should be read from. If this process does not have a CLI
     channel opened, `nil` is returned. In this case, CLI must be
     emulated - if required.

     CLI channel is generally available only on Smalltalk/X and only
     on UNIX platform where this stream points to TTY."

    ^ nil

    "Created: / 02-06-2017 / 23:35:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 15-12-2017 / 23:58:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (comment): / 17-10-2018 / 22:21:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

debuggerInput
    "Return a write stream on debugger's MI channel. (MI) commands
     should be written there."

    ^ debuggerInput

    "Modified: / 15-12-2017 / 23:58:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (comment): / 17-10-2018 / 22:14:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

debuggerOutput
    "Return read stream on debuugger's MI channel. Command responses
     and events should be read from here"

    ^ debuggerOutput

    "Modified: / 15-12-2017 / 23:58:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (comment): / 17-10-2018 / 22:15:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

id
    "Return a string identification of this GDBProcess. 
     Used for debugging purposes only."

    ^ self subclassResponsibility

    "Created: / 19-10-2018 / 10:08:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

nativeTargetFeatures    
    "Return default native target features. This is used when
     used GDB does not support =target-connected and =target-disconnected
     events."

    "/ Be conservative and  report no features at all...
    ^ #()

    "Created: / 09-04-2018 / 15:40:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (comment): / 17-10-2018 / 22:12:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBProcess methodsFor:'initialization & release'!

initialize
    "raise an error: must be redefined in concrete subclass(es)"

    ^ self subclassResponsibility
! !

!GDBProcess class methodsFor:'documentation'!

version_HG

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