VDBBreakpointPresenter.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 20 Jun 2019 16:11:12 +0100
changeset 174 3f6f51330641
parent 158 9915317c3a62
child 249 1a76ea72b44b
permissions -rw-r--r--
UI: add "Edit" button to settings application to edit GDB and VDB init scripts

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

VDBAbstractPresenter subclass:#VDBBreakpointPresenter
	instanceVariableNames:'breakpoint'
	classVariableNames:''
	poolDictionaries:''
	category:'VDB-Presentation'
!

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

!VDBBreakpointPresenter 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:VDBBreakpointPresenter andSelector:#contextMenu
     (Menu new fromLiteralArrayEncoding:(VDBBreakpointPresenter contextMenu)) startUp
    "

    <resource: #menu>

    ^ 
     #(Menu
        (
         (MenuItem
            enabled: canEnable
            label: 'Enable'
            itemValue: doEnable
            isVisible: isDisabled
          )
         (MenuItem
            enabled: canDisable
            label: 'Disable'
            itemValue: doDisable
            isVisible: isEnabled
          )
         )
        nil
        nil
      )
! !

!VDBBreakpointPresenter methodsFor:'accessing'!

breakpoint
    ^ breakpoint
!

label
    ^ String streamContents:[ :aStream |
        aStream nextPutAll:(breakpoint enabled ifTrue:[ 'e ' ] ifFalse:[ 'd ' ]).

        (breakpoint type = 'watchpoint' or:[ breakpoint type = 'hw watchpoint' ]) ifTrue:[ 
            | location |

            aStream nextPutAll: 'W '.
            breakpoint number printOn:aStream.
            aStream nextPutAll:', '.

            aStream nextPutAll:'at '.
            location := breakpoint propertyAt: 'what'.
            aStream nextPutAll: location ? '??'.
        ] ifFalse:[
            | func |
            aStream nextPutAll: 'B '.
            breakpoint number printOn:aStream.
            aStream nextPutAll:', '.

            func := breakpoint func.
            func isNil and:[  
                func := breakpoint propertyAt:'original-location'
            ].
    
            func notNil ifTrue:[ 
                aStream nextPutAll:'in '.
                func printOn:aStream.   
                "/ I (JV) prefer to have () after plain C function names. GDB seems to
                "/ to add them for C functions but does add them for C++ functions / methods
                "/ (well. perhaps this is compile who does that, does not matter).
                "/ 
                "/ So, if there's no $(, assume it's a C function and add () at the end.
                "/ We'll see how this works...
                (func includes: $() ifFalse:[
                    aStream nextPutAll:'()'. 
                ].
                aStream nextPutAll:', '
            ].
            breakpoint hasMultipleLocations ifTrue:[ 
                breakpoint locations size printOn: aStream.
                aStream nextPutAll: ' locations'.
            ] ifFalse:[
                breakpoint file notNil ifTrue:[
                    breakpoint file printOn:aStream.
                    aStream nextPut:$:.
                    breakpoint line printOn:aStream.
                ] ifFalse:[ 
                    | addr |

                    addr := breakpoint addr.
                    addr isNil ifTrue:[ 
                        aStream nextPutAll:'at ??'.
                    ] ifFalse:[addr isInteger ifTrue:[
                        aStream nextPutAll:'at 0x'.
                        addr printOn: aStream radix: 16
                    ] ifFalse:[ 
                        addr printOn: aStream
                    ]].
                ].      
            ].
        ]
    ].

    "Created: / 10-07-2017 / 13:30:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 26-03-2019 / 10:58:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

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

    ^ breakpoint

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

!VDBBreakpointPresenter methodsFor:'initialization'!

setBreakpoint: aGDBBreakpoint
    breakpoint := aGDBBreakpoint

    "Created: / 10-07-2017 / 13:29:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBBreakpointPresenter methodsFor:'menu-actions'!

doDisable
    breakpoint enabled: false

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

doEnable
    breakpoint enabled: true

    "Created: / 05-02-2018 / 12:25:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBBreakpointPresenter methodsFor:'menu-queries'!

canDisable
    ^ breakpoint enabled and: [breakpoint debugger selectedInferior isStopped]

    "Created: / 05-02-2018 / 12:27:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 13-05-2019 / 10:38:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

canEnable
    ^ breakpoint enabled not and: [breakpoint debugger selectedInferior isStopped]

    "Created: / 05-02-2018 / 12:26:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 13-05-2019 / 10:38:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

isDisabled
    ^ breakpoint enabled not

    "Created: / 13-05-2019 / 10:39:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

isEnabled
    ^ breakpoint enabled

    "Created: / 13-05-2019 / 10:39:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBBreakpointPresenter methodsFor:'private'!

fetchChildren
    breakpoint hasMultipleLocations ifTrue:[
        ^ breakpoint locations collect:[ :l | VDBBreakpointPresenter new setBreakpoint: l; parent: self ]
    ] ifFalse:[ 
        ^ #()
    ].

    "Created: / 26-03-2019 / 10:10:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBBreakpointPresenter methodsFor:'testing'!

isBreakpointPresenter
    ^ true

    "Created: / 11-07-2017 / 11:50:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBBreakpointPresenter class methodsFor:'documentation'!

version_HG

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