VDBVariableObjectPresenter.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) 2020-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:#VDBVariableObjectPresenter
	instanceVariableNames:'varobj'
	classVariableNames:''
	poolDictionaries:''
	category:'VDB-Presentation'
!

!VDBVariableObjectPresenter class methodsFor:'documentation'!

copyright
"
jv:libgdbs - GNU Debugger Interface Library
Copyright (C) 2015-now Jan Vrany
Copyright (C) 2020-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.
"
! !

!VDBVariableObjectPresenter class methodsFor:'menu specs'!

contextMenu
    "This resource specification was automatically generated
     by the MenuEditor of ST/X."

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


    "
     MenuEditor new openOnClass:VDBVariableObjectPresenter andSelector:#contextMenu
     (Menu new fromLiteralArrayEncoding:(VDBVariableObjectPresenter contextMenu)) startUp
    "

    <resource: #menu>

    ^ 
     #(Menu (
         (MenuItem
            label: 'Inspect'
            itemValue: doInspect
            isVisible: true
         )
         (MenuItem
            label: '-'
            isVisible: true
         )
         (MenuItem
            label: 'Copy Value'
            itemValue: doCopyValue
            isVisible: true
         )
         (MenuItem
            label: 'Copy Expression'
            itemValue: doCopyPath
            isVisible: true
         )
       ) nil
        nil
     )
! !

!VDBVariableObjectPresenter methodsFor:'accessing'!

label
    ^ varobj expression
"/    ^ (varobj parent notNil or:[varobj parentIsDynamic])
"/        ifTrue:[ varobj expression ] 
"/        ifFalse:[ varobj path ]

    "Created: / 27-02-2015 / 15:57:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 08-07-2019 / 23:10:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

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

    ^ varobj

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

tooltip
    ^ self valueString

    "Created: / 29-07-2018 / 21:35:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

value
    ^ varobj value

    "Created: / 02-06-2017 / 07:32:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 28-01-2018 / 22:49:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

valueString
    ^ varobj value

    "Created: / 11-06-2017 / 23:25:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 01-09-2018 / 00:55:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

varobj
    ^ varobj varobj

    "Created: / 28-01-2018 / 22:45:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 21-09-2019 / 01:30:15 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 17-03-2022 / 21:38:52 / Jan Vrany <jan.vrany@labware.com>"
! !

!VDBVariableObjectPresenter methodsFor:'initialization'!

setVarobj:aGDBVariable 
    varobj := aGDBVariable.

    "Created: / 27-02-2015 / 16:00:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 18-03-2022 / 11:21:54 / Jan Vrany <jan.vrany@labware.com>"
! !

!VDBVariableObjectPresenter methodsFor:'menu'!

contextMenuBAST:aMenu 
    "Adds a Smalltalk/X debugging menu items to the context menu."

    <menuextension: #contextMenu>

    ((varobj type startsWith:'BAST::OOP') 
        or:[ varobj type includesSubString:'BAST::VM' ]) 
            ifTrue:[
                aMenu 
                    addItem:((MenuItem 
                            label:(self class classResources string:'Inspect Object')
                            itemValue:#doInspectBeeObject) receiver:self).
                aMenu addSeparator.
            ].

    "Created: / 21-09-2019 / 01:33:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 08-11-2019 / 23:30:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (format): / 11-11-2019 / 13:44:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

contextMenuBee: aMenu
    "Adds a Smalltalk/X debugging menu items to the context menu."

    <menuextension: #contextMenu>

    (varobj type endsWith: 'Bee::oop_t *') ifTrue:[ 
        aMenu addItem: (
            (MenuItem label: (self class classResources string: 'Inspect Object')
                 itemValue: #doInspectBeeObject)
                 receiver: self
        ).
        aMenu addSeparator.
    ].

    "Created: / 08-07-2019 / 21:54:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

contextMenuStX: aMenu
    "Adds a Smalltalk/X debugging menu items to the context menu."

    <menuextension: #contextMenu>

    (varobj type endsWith: 'OBJ') ifTrue:[ 
        aMenu addItem: (
            (MenuItem label: (self class classResources string: 'Inspect Object')
                 itemValue: #doInspectStXObject)
                 receiver: self
        ).
        aMenu addSeparator.
    ].

    "Created: / 10-02-2018 / 23:06:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 08-07-2019 / 22:52:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBVariableObjectPresenter methodsFor:'menu actions'!

doCopyPath
    self doCopy: varobj path.

    "Created: / 05-02-2018 / 22:32:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

doCopyValue
    self doCopy: varobj value.

    "Created: / 16-01-2018 / 23:28:56 / jv"
    "Modified: / 28-01-2018 / 22:55:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

doInspect
    self doInspectUsingVisualizer: 'vdb.contents_visualizer'

    "Modified: / 17-11-2021 / 13:17:01 / Jan Vrany <jan.vrany@labware.com>"
!

doInspectUsingVisualizer:visualizerExpr 
    "
     Open an inspector of a copy of varobj. If `visualizerExpr`
     is not nil then the visualizer of a *copy* is set to
     `visualizerExpr`
"
    
    | dup |

    dup := varobj duplicate.
    dup == varobj ifTrue:[
        dup := VDBVariableObject 
                evaluate:varobj path
                in:varobj frame
                using:varobj debugger.
    ].
    visualizerExpr notNil ifTrue:[
        dup visualizer:visualizerExpr
    ].
    self doInspect: dup

    "Created: / 17-11-2021 / 13:16:42 / Jan Vrany <jan.vrany@labware.com>"
! !

!VDBVariableObjectPresenter methodsFor:'private'!

fetchChildren
    ^ varobj children collect:[ :each | self class new setVarobj:each; parent:self;yourself ]

    "Created: / 28-01-2018 / 22:46:28 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBVariableObjectPresenter methodsFor:'protocol-queries'!

hasChanged
    ^ varobj hasChanged

    "Created: / 18-03-2022 / 11:23:13 / Jan Vrany <jan.vrany@labware.com>"
!

hasChildren
    ^ varobj hasChildren

    "Created: / 28-01-2018 / 22:49:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBVariableObjectPresenter methodsFor:'testing'!

isVariablePresenter
    ^ true

    "Created: / 02-06-2017 / 00:05:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBVariableObjectPresenter class methodsFor:'documentation'!

version_HG

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