VDBSimpleDebuggerConsoleApplication.st
author Jan Vrany <jan.vrany@labware.com>
Tue, 26 Jul 2022 15:01:33 +0100
changeset 265 f2470f0dd9cd
parent 264 23960fcb9dac
permissions -rw-r--r--
Do not show address for (pseudo) instructions with no code While such instructions do not appear in GDB-produced disassembly, they may appear in some manually-generated instruction lists. One example of such (pseudo) instruction is label.

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

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"
"{ Package: 'jv:vdb' }"

"{ NameSpace: Smalltalk }"

VDBAbstractConsoleApplication subclass:#VDBSimpleDebuggerConsoleApplication
	instanceVariableNames:'prompt promptPrinted running ignoreNextLogEvent'
	classVariableNames:''
	poolDictionaries:'GDBCommandStatus'
	category:'VDB-UI-Console'
!

!VDBSimpleDebuggerConsoleApplication class methodsFor:'documentation'!

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

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the 'Software'), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"
!

documentation
""
! !

!VDBSimpleDebuggerConsoleApplication class methodsFor:'accessing'!

defaultWindowTitle
    ^ self resources string: 'Debugger Console'

    "Created: / 08-01-2018 / 18:59:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 03-10-2018 / 15:39:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBSimpleDebuggerConsoleApplication class methodsFor:'startup-web applications'!

initialPageSpec
    "this is only required for web-applications"

    ^ self shouldImplement
!

pageSpecs
    "this is only required for web-applications"

    ^ self shouldImplement
! !

!VDBSimpleDebuggerConsoleApplication methodsFor:'actions'!

doComplete: line
    "Called when a user triggers a command completion (usually by pressing
     tab)"

    | command |

    command := GDBMI_complete arguments: (Array with: line).
    debugger send: command andWithResultDo: [ :result |
        result isDone ifTrue:[ 
            consoleView completion: (result propertyAt: #completion) matches: (result propertyAt: #matches)
        ].
    ].

    "Created: / 30-12-2018 / 22:01:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 25-01-2019 / 22:03:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 12-06-2019 / 18:27:04 / jv"
!

doFire: aString
    "Executes entered command"

    | cmd |

    promptPrinted := false.
    consoleView cr.
    aString isEmptyOrNil ifTrue:[ 
        self showPrompt.
        ^ self.
    ].
    cmd := GDBCommand parse: aString.
    cmd isCLICommand ifTrue:[ 
        "/ If CLI command is one of the execution commands, run 
        "/ the command in background. This allows user to interrupt 
        "/ it, among other things.
        "/
        "/ See GDB manual, Section 5.5.3 Background Execution

        (#('run' 'attach') includes: cmd operation) ifTrue:[ 
            "/ Sigh, background command execution is not supported by some
            "/ targets, most notably by Windows native target. However, at this
            "/ point we don't know which target we will use therefore we cannot
            "/ check target features. 
            "/ 
            "/ Therefore make a guess and assime we gonna use native target.
            "/ This is so bad, this *absolutely* has to be fixed somehow.
            cmd runOnBackground: debugger nativeTargetHasFeatureAsync.
        ] ifFalse:[ (#('step' 'stepi' 'next' 'nexti' 'continue' 'until' 'finish' 'rn' 'rns' 'rs' 'rsi' 'rc') includes: cmd operation) ifTrue:[ 
            debugger hasFeatureAsync ifTrue:[
                cmd runOnBackground: true.      
            ].
        ]].
    ].
    consoleView readOnly:true. 
    ignoreNextLogEvent := true.
    debugger send:cmd andWithResultDo:[:result| 
        result isError ifTrue:[ 
            consoleView showCR: 'ERROR: ', (result propertyAt: #msg).
        ].
        consoleView readOnly:false.
        ignoreNextLogEvent := false.
        self showPrompt.
    ].

    "Created: / 25-01-2019 / 12:12:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 13-03-2019 / 14:02:22 / jv"
    "Modified: / 01-12-2019 / 21:52:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBSimpleDebuggerConsoleApplication methodsFor:'aspects'!

consoleViewClass
    ^ VDBSimpleConsoleView

    "Modified: / 21-01-2019 / 14:22:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBSimpleDebuggerConsoleApplication methodsFor:'event handling'!

onCmdParamChanged: event
    event name = 'prompt' ifTrue:[
        prompt := event value
    ].

    "Created: / 19-01-2019 / 22:13:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

onEventSetProcessingFinished: event
    consoleView readOnly: running.
    running ifFalse:[self showPrompt].

    "Created: / 01-12-2019 / 20:24:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

onLogOutputEvent: event
    ignoreNextLogEvent ifTrue:[
        ignoreNextLogEvent := false.
    ] ifFalse:[
        self onStreamOutputEvent: event
    ].

    "Created: / 13-03-2019 / 13:59:39 / jv"
!

onRunningEvent: event
    running := true.
    consoleView readOnly: true.

    "Created: / 19-01-2019 / 23:46:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

onStoppedEvent: event
    running := false.

    "Created: / 19-01-2019 / 23:46:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 01-12-2019 / 20:24:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

onStreamOutputEvent: event
    promptPrinted ifTrue:[ consoleView cr ].
    promptPrinted := false.
    consoleView show: event value

    "Created: / 11-06-2014 / 12:00:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 25-01-2019 / 13:36:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBSimpleDebuggerConsoleApplication methodsFor:'hooks'!

postBuildConsoleView: aTextCollector
    consoleView := aTextCollector scrolledView.
    consoleView readOnly: true;       
                font: CodeView defaultFont;
                foregroundColor: Color white
                backgroundColor: Color black;
                cursorForegroundColor: Color white
                      backgroundColor: Color white.

    "Modified: / 08-01-2018 / 19:16:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBSimpleDebuggerConsoleApplication methodsFor:'initialization & release'!

initialize
    super initialize.
    prompt := '(gdb) '.
    promptPrinted := false.
    running := false.
    ignoreNextLogEvent := false

    "Created: / 10-06-2014 / 01:23:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 25-01-2019 / 22:01:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 13-03-2019 / 14:01:53 / jv"
!

initializeConsoleView: view
    super initializeConsoleView: view.
    consoleView acceptAction: [ :command | self doFire: command ].

    "Created: / 25-01-2019 / 12:13:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 25-01-2019 / 22:34:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

initializeConsoleView: aTerminalView forDebugger: aGDBDebugger
    super initializeConsoleView: aTerminalView forDebugger: aGDBDebugger.
    consoleView clear.       
    consoleView completeAction: nil.  
    (aGDBDebugger notNil) ifTrue:[ 
        prompt := debugger getParameter: 'prompt'.
        self showPrompt.
        (aGDBDebugger hasCommand:'-complete') ifTrue:[ 
            consoleView completeAction: [ :command | self doComplete: command ]
        ].
    ] ifFalse:[ 
        prompt := '(gdb) '
    ].

    "Created: / 21-01-2019 / 15:33:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 25-01-2019 / 22:35:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

subscribe   
    super subscribe.

    debugger announcer 
"/        when: GDBCommandEvent           send: #onCommandEvent:          to: self;
"/        when: GDBCommandResultEvent     send: #onCommandResultEvent:    to: self;

        when: GDBRunningEvent           send: #onRunningEvent:          to: self;
        when: GDBStoppedEvent           send: #onStoppedEvent:          to: self;
        when: GDBEventSequenceProcessingFinished
                                        send: #onEventSetProcessingFinished:
                                                                        to: self;

        when: GDBConsoleOutputEvent     send: #onStreamOutputEvent:     to: self;
        when: GDBLogOutputEvent         send: #onLogOutputEvent:        to: self;
        when: GDBTargetOutputEvent      send: #onStreamOutputEvent:     to: self;

        when: GDBCmdParamChangedEvent   send: #onCmdParamChanged:       to: self.

    running := debugger inferiors anySatisfy:[ :tg | tg isRunning and:[ tg isStopped not ] ].

    "Created: / 06-06-2014 / 21:26:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 13-03-2019 / 13:59:19 / jv"
    "Modified: / 01-12-2019 / 20:24:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 17-11-2021 / 16:39:05 / Jan Vrany <jan.vrany@labware.com>"
    "Modified (comment): / 18-11-2021 / 16:24:47 / Jan Vrany <jan.vrany@labware.com>"
! !

!VDBSimpleDebuggerConsoleApplication methodsFor:'private'!

showCR: aString
    consoleView show: aString; cr.

    "Created: / 01-12-2019 / 21:52:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

showPrompt
    (running not and: [promptPrinted not]) ifTrue:[
        consoleView nextPutAll: prompt.
        promptPrinted := true.
    ].

    "Created: / 18-09-2014 / 23:18:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 04-04-2018 / 23:01:24 / jv"
    "Modified: / 01-12-2019 / 11:57:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBSimpleDebuggerConsoleApplication class methodsFor:'documentation'!

version_HG

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