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

VDBAbstractTreeApplication subclass:#VDBStackApplication
	instanceVariableNames:'selectedThreadGroupHolder selectedThreadHolder
		selectedFrameHolder'
	classVariableNames:''
	poolDictionaries:''
	category:'VDB-UI-Others'
!

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

!VDBStackApplication class methodsFor:'accessing'!

defaultWindowTitle
    ^ self resources string: 'Callstack'

    "Created: / 11-07-2017 / 16:37:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 03-10-2018 / 15:39:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBStackApplication class methodsFor:'plugIn spec'!

aspectSelectors
    "This resource specification was automatically generated
     by the UIPainter of ST/X."

    "Do not manually edit this. If it is corrupted,
     the UIPainter may not be able to read the specification."

    "Return a description of exported aspects;
     these can be connected to aspects of an embedding application
     (if this app is embedded in a subCanvas)."

    ^ #(
        #debuggerHolder
        #selectedFrameHolder
        #selectedThreadGroupHolder
        #selectedThreadHolder
      ).

! !

!VDBStackApplication methodsFor:'aspects'!

foregroundColorFor: aVDBAbstractPresenter
    ^ (aVDBAbstractPresenter isFramePresenter and:[ aVDBAbstractPresenter frame thread isStopped not])
        ifTrue:[  Color gray ]
        ifFalse:[ nil ]

    "Created: / 26-06-2018 / 13:06:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 04-07-2018 / 13:13:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

selectedFrameHolder
    "return/create the 'selectionHolder' value holder (automatically generated)"

    selectedFrameHolder isNil ifTrue:[
        selectedFrameHolder := ValueHolder new.
        selectedFrameHolder addDependent:self.
    ].
    ^ selectedFrameHolder

    "Created: / 21-09-2014 / 23:51:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

selectedFrameHolder:aValueModel
    "set the 'selectionHolder' value holder (automatically generated)"

    |oldValue newValue|

    selectedFrameHolder notNil ifTrue:[
        oldValue := selectedFrameHolder value.
        selectedFrameHolder removeDependent:self.
    ].
    selectedFrameHolder := aValueModel.
    selectedFrameHolder notNil ifTrue:[
        selectedFrameHolder addDependent:self.
    ].
    newValue := selectedFrameHolder value.
    oldValue ~~ newValue ifTrue:[
        self update:#value with:newValue from:selectedFrameHolder.
    ].

    "Created: / 21-09-2014 / 23:50:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

selectedThreadGroupHolder
    "return/create the 'selectedThreadGroupHolder' value holder (automatically generated)"

    selectedThreadGroupHolder isNil ifTrue:[
        selectedThreadGroupHolder := ValueHolder new.
        selectedThreadGroupHolder addDependent:self.
    ].
    ^ selectedThreadGroupHolder
!

selectedThreadGroupHolder:something
    "set the 'selectedThreadGroupHolder' value holder (automatically generated)"

    |oldValue newValue|

    selectedThreadGroupHolder notNil ifTrue:[
        oldValue := selectedThreadGroupHolder value.
        selectedThreadGroupHolder removeDependent:self.
    ].
    selectedThreadGroupHolder := something.
    selectedThreadGroupHolder notNil ifTrue:[
        selectedThreadGroupHolder addDependent:self.
    ].
    newValue := selectedThreadGroupHolder value.
    oldValue ~~ newValue ifTrue:[
        self update:#value with:newValue from:selectedThreadGroupHolder.
    ].
!

selectedThreadHolder
    "return/create the 'selectedThreadHolder' value holder (automatically generated)"

    selectedThreadHolder isNil ifTrue:[
        selectedThreadHolder := ValueHolder new.
        selectedThreadHolder addDependent:self.
    ].
    ^ selectedThreadHolder
!

selectedThreadHolder:something
    "set the 'selectedThreadHolder' value holder (automatically generated)"

    |oldValue newValue|

    selectedThreadHolder notNil ifTrue:[
        oldValue := selectedThreadHolder value.
        selectedThreadHolder removeDependent:self.
    ].
    selectedThreadHolder := something.
    selectedThreadHolder notNil ifTrue:[
        selectedThreadHolder addDependent:self.
    ].
    newValue := selectedThreadHolder value.
    oldValue ~~ newValue ifTrue:[
        self update:#value with:newValue from:selectedThreadHolder.
    ].
! !

!VDBStackApplication methodsFor:'change & update'!

update:aspect with:param from:sender
    "Invoked when an object that I depend upon sends a change notification."

    "stub code automatically generated - please change as required"

    sender == selectedFrameHolder ifTrue:[
         self updateInternalSelection.
         ^ self.
    ].
    super update:aspect with:param from:sender

    "Modified: / 27-02-2015 / 15:44:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

updateInternalSelection
    | frame frameP |

    frame := self selectedFrameHolder value.

    frame notNil ifTrue:[
"/        presenter := self internalSelectionHolder value.
"/        "/ Short-circuit if already selected.
"/        (presenter notNil and: [ presenter isFramePresenter and:[presenter frame = frame ] ]) ifTrue:[ 
"/            (self internalListHolder value root recursiveDetect: [ :e | presenter == e ]) notNil ifTrue: [ 
"/                ^ self 
"/            ].
"/        ].

        "/ Find presenter for given frame. Here we do it in two
        "/ steps:
        "/   1. find presenter for frame's thread and then
        "/   2. find presenter for frame starting in thread presenter.
        "/ 
        "/ In multi-threaded programs this helps to avoid fetching frames
        "/ for other threads and thus save some time

        | rootP threadGroupP threadP |

        "/ 1.
        rootP := self internalListHolder value root.
        threadGroupP := rootP children detect: [:each | each threadGroup = frame thread group ] ifNone: [ ^ self ].
        threadP := threadGroupP children detect: [:each | each thread = frame thread ] ifNone: [ ^ self ].
        "/ 2.
        frameP := threadP children detect: [:each | each frame level = frame level ].
    ].
    frameP notNil ifTrue: [ 
        frameP parent expand. "/ expand thread item
        frameP parent parent expand. "/ expand thread group item
        frameP parent parent parent expand "/ expand (hidden) root item
    ].
    self internalSelectionHolder
        value: frameP
        withoutNotifying: self.

    "Created: / 20-09-2014 / 23:05:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (format): / 30-07-2018 / 07:40:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 17-05-2021 / 19:48:36 / Jan Vrany <jan.vrany@labware.com>"
!

updateSelection
    | internalSelection frame thread group |

    internalSelection := self internalSelectionHolder value.
    internalSelection notNil ifTrue:[ 
        internalSelection isFramePresenter ifTrue:[
            frame := internalSelection frame.
            thread := frame thread.
            group := thread group.
        ] ifFalse:[ 
            internalSelection isThreadPresenter ifTrue:[ 
                thread := internalSelection thread.
                group := thread group.
            ] ifFalse:[  
                group := internalSelection threadGroup.
            ]
        ].
    ].

    self selectedThreadGroupHolder value: group withoutNotifying: self.
    self selectedThreadHolder value: thread withoutNotifying: self.
    self selectedFrameHolder value: frame withoutNotifying: self.

    "Created: / 20-09-2014 / 23:10:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 22-09-2014 / 00:17:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBStackApplication methodsFor:'change & update-delayed'!

delayedUpdateInternalList
    | root inferiorPs inferiorPsToRemove inferiorPsToAdd |

    root := self internalListHolder value root.
    debugger isNil ifTrue: [ 
        root removeAll. 
        ^ self.
    ].

    inferiorPs := root getChildren ? #().
    inferiorPsToRemove := inferiorPs copy.
    inferiorPsToAdd := #().
    debugger inferiors do: [:inferior |  
        | inferiorP |

        inferiorP := inferiorPs detect: [:each | each threadGroup == inferior ] ifNone: nil.
        inferiorP notNil ifTrue: [ 
            inferiorPsToRemove remove: inferiorP.
            inferiorP updateChildren.
        ] ifFalse: [ 
            inferiorP := VDBThreadGroupPresenter new
                        setThreadGroup: inferior;
                        parent: self;
                        yourself.
            inferiorPsToAdd := inferiorPsToAdd copyWith: inferiorP.
        ].
    ].
    inferiorPsToRemove notEmpty ifTrue: [ 
        root removeAll: inferiorPsToRemove.
    ].
    inferiorPsToAdd notEmpty ifTrue: [ 
        root addAll: inferiorPsToAdd.
        root expand.
    ].

    self updateInternalSelection.
    self delayedInvalidateInternalList

    "Created: / 20-09-2014 / 23:05:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 09-04-2018 / 19:52:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (format): / 06-09-2019 / 01:51:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 18-05-2021 / 11:20:43 / Jan Vrany <jan.vrany@labware.com>"
!

delayedUpdateSelection
    | internalSelection frame thread |

    internalSelection := self internalSelectionHolder value.
    internalSelection notNil ifTrue:[ 
        internalSelection isFramePresenter ifTrue:[
            frame := internalSelection frame.
            thread := frame thread.
        ] ifFalse:[ 
            internalSelection isThreadPresenter ifTrue:[ 
                frame := internalSelection children first frame.
                thread := internalSelection thread.
            ].
        ].
    ].

    thread notNil ifTrue: [
        self selectedThreadHolder value: thread withoutNotifying: self.
        self selectedFrameHolder value: frame withoutNotifying: self.
    ].

    "Created: / 27-02-2015 / 15:33:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 12-03-2021 / 15:03:18 / Jan Vrany <jan.vrany@labware.com>"
! !

!VDBStackApplication methodsFor:'event handling'!

onRunningEvent: event
    self enqueueDelayedInvalidateInternalList

    "Created: / 30-09-2014 / 00:02:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 17-01-2018 / 06:59:11 / jv"
    "Modified: / 01-10-2018 / 12:59:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 17-05-2021 / 19:59:21 / Jan Vrany <jan.vrany@labware.com>"
    "Modified (comment): / 18-05-2021 / 11:19:59 / Jan Vrany <jan.vrany@labware.com>"
!

onStoppedEvent: event
    self enqueueDelayedUpdateContents.

    "Created: / 17-09-2014 / 23:04:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 15-01-2018 / 11:51:51 / jv"
    "Modified: / 14-02-2019 / 16:31:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 12-03-2021 / 15:04:38 / Jan Vrany <jan.vrany@labware.com>"
!

onThreadGroupExitedEvent: event
    self enqueueDelayedUpdateContents.

    "Created: / 18-09-2014 / 23:30:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 14-02-2019 / 16:31:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

onThreadGroupStartedEvent: event
    self enqueueDelayedUpdateContents.

    "Created: / 02-03-2015 / 06:42:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 14-02-2019 / 16:31:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBStackApplication methodsFor:'initialization & release'!

subscribe   
    super subscribe.

    debugger announcer
        when: GDBRunningEvent               send: #onRunningEvent: to: self;
        when: GDBStoppedEvent               send: #onStoppedEvent: to: self;
        when: GDBThreadGroupStartedEvent    send: #onThreadGroupStartedEvent: to: self;
        when: GDBThreadGroupExitedEvent     send: #onThreadGroupExitedEvent: to: self

    "Created: / 07-06-2014 / 14:33:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 02-03-2015 / 06:42:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 17-01-2018 / 06:56:46 / jv"
    "Modified: / 17-11-2021 / 16:37:55 / Jan Vrany <jan.vrany@labware.com>"
    "Modified (comment): / 18-11-2021 / 16:24:54 / Jan Vrany <jan.vrany@labware.com>"
! !

!VDBStackApplication methodsFor:'queries'!

canSelect: anItem
    ^ anItem isFramePresenter not or:[ anItem frame thread isStopped ]

    "Created: / 09-04-2018 / 20:52:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBStackApplication class methodsFor:'documentation'!

version_HG

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