GDBProcess.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sat, 19 Jan 2019 23:25:55 +0000
changeset 169 a3d1f59e3bfd
parent 167 6da3d808c7cc
child 193 2aa0074479d9
permissions -rw-r--r--
API: add `GDBDebugger >> getParameter:` and `setParameter:to:` ...to get / set GDB internal parameters such as prompt. The only complication here is that when a parameter is set by MI `-gdb-set` command, the `=cmd-param-changed' notification is not sent. This may or may not be a GDB bug. To make this transparent to `libgdbs` clients, intercept all `-gdb-set` commands and when sucessful, emit the event manually. This way, client may rely on value change notification (`GDBCmdParamChangedEvent`) to detect changes.

"
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:[
        ^ GDBLocalProcess newWithCommand: nil  
    ] ifFalse:[
        ^ super new.
    ].

    "
     GDBProcess new release."

    "Modified (comment): / 11-01-2018 / 23:02:11 / jv"
    "Modified: / 12-12-2018 / 22:22:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBProcess class methodsFor:'accessing'!

gdbCommand
    | exe |

    exe := UserPreferences current gdbCommand.
    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  gdbCommand
    UserPreferences current gdbCommand: nil.
    UserPreferences current gdbCommand: '/home/jv/Projects/gdb/users_jv_vdb/gdb/gdb'.

      

    "

    "Created: / 13-12-2018 / 11:29:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

gdbCommand: aString
    UserPreferences current gdbCommand: aString

    "Created: / 13-12-2018 / 11:29:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

gdbExecutable
    <resource: #obsolete>

    self obsoleteFeatureWarning: 'Renamed to #gdbCommand'.
    ^ self gdbCommand

    "Created: / 01-03-2015 / 08:07:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (comment): / 07-10-2018 / 07:59:57 / jv"
    "Modified: / 13-12-2018 / 11:33:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

gdbExecutable: aString
     <resource: #obsolete>

    self obsoleteFeatureWarning: 'Renamed to #gdbCommand'.   
    self gdbCommand: aString

    "Created: / 01-03-2015 / 08:07:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 13-12-2018 / 11:33:56 / 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:'queries'!

canUsePTY
    "Return true if PTYs can be used with this process, false otherwise"

    ^ false

    "Created: / 16-01-2019 / 23:02:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBProcess class methodsFor:'documentation'!

version_HG

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