VDBSimpleDebuggerConsoleApplication.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 21 Jun 2019 22:54:50 +0100
changeset 175 a304c250e889
parent 170 cd9615ebe6a9
child 190 f37694040277
permissions -rw-r--r--
UI: add "Scratch Pad" tool which can be used by user to keep notes during debug session, to edit (configuration) files and so on.

"
jv:vdb - Visual / VM Debugger
Copyright (C) 2015-now Jan Vrany

This software is licensed under 'Creative Commons Attribution-NonCommercial 4.0 International License'

You may find a full license text in LICENSE.txt or at http://creativecommons.org/licenses/by-nc/4.0/
"
"{ 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:vdb - Visual / VM Debugger
Copyright (C) 2015-now Jan Vrany

This software is licensed under 'Creative Commons Attribution-NonCommercial 4.0 International License'

You may find a full license text in LICENSE.txt or at http://creativecommons.org/licenses/by-nc/4.0/
"
!

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.

    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| 
        consoleView readOnly:false.
        ignoreNextLogEvent := false.
        self showPrompt.
    ].

    "Created: / 25-01-2019 / 12:12:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (format): / 29-01-2019 / 09:37:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 13-03-2019 / 14:02:22 / jv"
! !

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

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.
    consoleView readOnly: false.
    self showPrompt.

    "Created: / 19-01-2019 / 23:46: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   
    "Register for debugger events. To be overrided by subclasses"

    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: 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: / 25-01-2019 / 12:33:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 13-03-2019 / 13:59:19 / jv"
! !

!VDBSimpleDebuggerConsoleApplication methodsFor:'private'!

showPrompt
    (running not and: [promptPrinted not]) ifTrue:[
        consoleView show: 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: / 25-01-2019 / 12:02:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBSimpleDebuggerConsoleApplication class methodsFor:'documentation'!

version_HG

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