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

VDBAbstractPresenter subclass:#VDBThreadGroupPresenter
	instanceVariableNames:'threadGroup'
	classVariableNames:''
	poolDictionaries:''
	category:'VDB-Presentation'
!

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

!VDBThreadGroupPresenter methodsFor:'accessing'!

icon
    threadGroup isRunning ifTrue:[ ^ VDBIconLibrary threadGroupRunning16x16 ].
    threadGroup isStopped ifTrue:[ ^ VDBIconLibrary threadGroupStopped16x16 ].
    threadGroup isDead    ifTrue:[ ^ VDBIconLibrary threadGroupTerminated16x16 ].
    ^ nil

    "Created: / 22-09-2014 / 22:13:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 30-09-2014 / 00:55:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

label
    | executableOrThreadGrouppId pidOrEmpty state |

    threadGroup executable notNil ifTrue:[ 
        executableOrThreadGrouppId := threadGroup executable contractTo: 30 
    ] ifFalse:[ 
        executableOrThreadGrouppId := 'thread group ', threadGroup id.
    ].

    (threadGroup type = 'process' and:[ threadGroup pid notNil ]) ifTrue:[
        pidOrEmpty := 'pid ', threadGroup pid printString , ', '.
    ].
    threadGroup isStopped ifTrue:[ 
        state := 'stopped'
    ] ifFalse:[ 
    threadGroup isRunning ifTrue:[ 
        state := 'running'
    ] ifFalse:[ 
    threadGroup isFinished ifTrue:[ 
        state := 'finished'
    ] ifFalse:[ 
    threadGroup isTerminated ifTrue:[ 
        state := 'terminated'
    ] ifFalse:[ 
        state := 'not run'
    ]]]].

    ^ '%1 [%2%3]' bindWith: executableOrThreadGrouppId 
                      with: pidOrEmpty ? ''
                      with: state

    "Created: / 22-09-2014 / 00:14:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 07-06-2017 / 07:47:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

subject
    "Return an instance of GDB object that this presenter displays."

    ^ threadGroup

    "Modified: / 05-02-2018 / 13:08:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

threadGroup
    ^ threadGroup
! !

!VDBThreadGroupPresenter methodsFor:'change & update'!

updateChildren
    | childrenToRemove childrenToAdd |

    children isNil ifTrue: [ ^ self ].
    childrenToRemove := children copy.
    childrenToAdd := #().

    threadGroup threads do: [:thread |  
        | child |

        child := children detect: [:each | each thread == thread ] ifNone: nil.
        child notNil ifTrue: [ 
            childrenToRemove remove: child.
            child updateChildren.
        ] ifFalse: [ 
            child := VDBThreadPresenter new
                        setThread: thread;
                        parent: self;
                        yourself.
            childrenToAdd := childrenToAdd copyWith: child.
        ].
    ].
    childrenToRemove notEmpty ifTrue: [ 
        self removeAll: childrenToRemove.
    ].
    childrenToAdd notEmpty ifTrue: [ 
        self addAll: childrenToAdd.
    ].

    "Modified: / 17-05-2021 / 16:24:15 / Jan Vrany <jan.vrany@labware.com>"
! !

!VDBThreadGroupPresenter methodsFor:'initialization'!

setThreadGroup: aGDBThreadGroup
    threadGroup := aGDBThreadGroup

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

!VDBThreadGroupPresenter methodsFor:'printing & storing'!

printOn:aStream
    "append a printed representation of the receiver to the argument, aStream"

    super printOn:aStream.
    aStream nextPut:$(.
    threadGroup printOn:aStream.
    aStream nextPut:$).

    "Created: / 14-05-2021 / 14:34:06 / Jan Vrany <jan.vrany@labware.com>"
! !

!VDBThreadGroupPresenter methodsFor:'protocol-accessing'!

fetchChildren
    "should compute the list of children via the model.
     Be aware, that the somewhat stupid 'optimization' of how the model is fetched may lead to
     a O(n*log n) or even O(n^2) behavior here.
     *** to optimize: redefine by subClass"

    ^ threadGroup threads collect:[ :t | VDBThreadPresenter new setThread: t; parent: self ]

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

!VDBThreadGroupPresenter methodsFor:'protocol-displaying'!

heightOn:aGC

    "/ Following is a performance optimization. We know
    "/ that label will be a string, so passing any string
    "/ would do (this in the end asks a font metrics).
    "/ 
    "/ This saves us a lot of time when system generates
    "/ a lot of events since #label sends ask GDB dof details
    height isNil ifTrue:[
        height := self heightOf:'%1 [%2%3]' on:aGC
    ].
    ^ height

    "Created: / 15-01-2018 / 09:54:22 / jv"
! !

!VDBThreadGroupPresenter methodsFor:'testing'!

isThreadGroupPresenter
    ^ true

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

!VDBThreadGroupPresenter class methodsFor:'documentation'!

version_HG

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