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

!VDBBreakpointPresenter class methodsFor:'documentation'!

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

!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 or: [breakpoint debugger selectedInferior isRunning not ] ]

    "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>"
    "Modified: / 08-01-2022 / 13:29:45 / Jan Vrany <jan.vrany@labware.com>"
!

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

    "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>"
    "Modified: / 08-01-2022 / 13:29:05 / Jan Vrany <jan.vrany@labware.com>"
!

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> $'
! !