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

VDBAbstractApplication subclass:#VDBMemoryApplication
	instanceVariableNames:'addressHolder sizeIndexHolder formatHolder memoryHolder
		numRowsHolder numColsHolder'
	classVariableNames:'Sizes LastSizeIndex LastFormat'
	poolDictionaries:''
	category:'VDB-UI-Others'
!

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

!VDBMemoryApplication class methodsFor:'initialization'!

initialize
    "Invoked at system start or when the class is dynamically loaded."

    "/ please change as required (and remove this comment)

    Sizes := #(
        'Bytes'
        'Words (2 bytes)'
        'Doublewords (4 bytes)'
        'Quadwords (8 bytes)'
        'Octawords (16 bytes)'
    ).
    LastSizeIndex := ExternalAddress pointerSize == 4 ifTrue:[ 3 ] ifFalse:[ 4 ].
    LastFormat := FormatPaddedHexadecimal.

    "Modified: / 26-01-2018 / 00:48:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBMemoryApplication class methodsFor:'interface specs'!

windowSpec
    "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."

    "
     UIPainter new openOnClass:VDBMemoryApplication andSelector:#windowSpec
     VDBMemoryApplication new openInterface:#windowSpec
     VDBMemoryApplication open
    "

    <resource: #canvas>

    ^ 
    #(FullSpec
       name: windowSpec
       uuid: 'b9ab7340-296c-11eb-9b5e-606720e43e2c'
       window: 
      (WindowSpec
         label: 'Memory Dump'
         name: 'Memory Dump'
         uuid: '9ba699c1-0231-11e8-b0df-606720e43e2c'
         bounds: (Rectangle 0 0 854 502)
      ) component: 
      (SpecCollection
         collection: (
          (HorizontalPanelViewSpec
             name: 'HeaderBar'
             layout: (LayoutFrame 30 0 0 0 0 1 30 0) uuid: '9ba6c0d0-0231-11e8-b0df-606720e43e2c'
             horizontalLayout: rightSpaceFit
             verticalLayout: center
             horizontalSpace: 3
             verticalSpace: 3
             component: 
            (SpecCollection
               collection: (
                (InputFieldSpec
                   name: 'Address'
                   uuid: '9ba6c0d1-0231-11e8-b0df-606720e43e2c'
                   model: addressHolder
                   acceptOnReturn: true
                   acceptOnTab: true
                   acceptOnPointerLeave: true
                   emptyFieldReplacementText: 'Address'
                   extent: (Point 249 22)
                )
                (LabelSpec
                   label: 'Size:'
                   name: 'SizeLabel'
                   uuid: '9ba6c0d2-0231-11e8-b0df-606720e43e2c'
                   translateLabel: true
                   useDefaultExtent: true
                )
                (PopUpListSpec
                   label: 'Size'
                   name: 'Size'
                   uuid: '9ba6c0d3-0231-11e8-b0df-606720e43e2c'
                   translateLabel: true
                   tabable: true
                   model: sizeIndexHolder
                   menu: sizeList
                   useIndex: true
                   extent: (Point 200 27)
                )
                (LabelSpec
                   label: 'Format:'
                   name: 'FormatLabel'
                   uuid: '9ba6c0d4-0231-11e8-b0df-606720e43e2c'
                   translateLabel: true
                   useDefaultExtent: true
                )
                (PopUpListSpec
                   label: 'Format'
                   name: 'Format'
                   uuid: '9ba6c0d5-0231-11e8-b0df-606720e43e2c'
                   translateLabel: true
                   tabable: true
                   model: formatHolder
                   menu: formatList
                   extent: (Point 170 27)
                )
                (InputFieldSpec
                   name: 'EntryField1'
                   uuid: '9ba6c0d1-0231-11e8-b0df-606720e43e2c'
                   model: numRowsHolder
                   type: string
                   acceptOnReturn: true
                   acceptOnTab: true
                   converter: integerOrNilConverter
                   acceptOnPointerLeave: true
                   emptyFieldReplacementText: 'Rows'
                   extent: (Point 40 22)
                )
                (InputFieldSpec
                   name: 'EntryField2'
                   uuid: '9ba6c0d1-0231-11e8-b0df-606720e43e2c'
                   model: numColsHolder
                   type: integer
                   acceptOnReturn: true
                   acceptOnTab: true
                   converter: integerOrNilConverter
                   acceptOnPointerLeave: true
                   emptyFieldReplacementText: 'Cols'
                   extent: (Point 40 22)
                )
              )
            )
          )
          (MenuPanelSpec
             name: 'ToolBar'
             layout: (LayoutFrame 0 0 0 0 30 0 30 0) uuid: '9ba6c0d6-0231-11e8-b0df-606720e43e2c'
             menu: toolbarMenu
             textDefault: true
          )
          (TextEditorSpec
             name: 'MemoryView'
             layout: (LayoutFrame 0 0 30 0 0 1 -30 1) uuid: '9ba6c0d7-0231-11e8-b0df-606720e43e2c'
             model: memoryHolder
             hasHorizontalScrollBar: true
             hasVerticalScrollBar: true
             isReadOnly: true
             hasKeyboardFocusInitially: false
             postBuildCallback: postBuildMemoryView:
          )
          (TransparentBoxSpec
             name: 'FooterBar'
             layout: (LayoutFrame 0 0 -30 1 0 1 0 1) uuid: '9ba6c0d8-0231-11e8-b0df-606720e43e2c'
          )
        )
      )
    )
! !

!VDBMemoryApplication class methodsFor:'menu specs'!

toolbarMenu
    "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:VDBMemoryApplication andSelector:#toolbarMenu
     (Menu new fromLiteralArrayEncoding:(VDBMemoryApplication toolbarMenu)) startUp
    "

    <resource: #menu>

    ^ 
     #(Menu
        (
         (MenuItem
            label: 'Refresh'
            itemValue: doRefresh
            labelImage: (ResourceRetriever VDBIconLibrary #'refresh_tab')
          )
         )
        nil
        nil
      )
! !

!VDBMemoryApplication 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
      ).

! !

!VDBMemoryApplication methodsFor:'accessing'!

memory: aGDBMemoryDump
    | string |
    aGDBMemoryDump isNil ifTrue: [
        string := ''
    ] ifFalse: [
        string := aGDBMemoryDump displayString.
    ].
    self memoryHolder value: string

    "Created: / 26-01-2018 / 22:51:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 17-11-2020 / 20:23:00 / Jan Vrany <jan.vrany@labware.com>"
! !

!VDBMemoryApplication methodsFor:'actions'!

postBuildMemoryView: aView
    aView scrolledView font: self textFont.

    "Modified: / 28-11-2018 / 13:03:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBMemoryApplication methodsFor:'aspects'!

addressHolder
    <resource: #uiAspect>
    addressHolder isNil ifTrue:[
        addressHolder := ValueHolder new.
        addressHolder addDependent:self.
    ].
    ^ addressHolder.

    "Modified: / 26-01-2018 / 00:47:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

formatHolder
    formatHolder isNil ifTrue:[
        formatHolder := ValueHolder with: LastFormat ? GDBOutputFormat paddedHexadecimal.
        formatHolder addDependent:self.
    ].
    ^ formatHolder.

    "Modified: / 28-11-2018 / 13:09:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

formatList
    ^ GDBOutputFormat all

    "Created: / 26-01-2018 / 00:49:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

integerOrNilConverter
    ^ TypeConverter new integerOrNil

    "Created: / 18-11-2020 / 07:07:13 / Jan Vrany <jan.vrany@labware.com>"
!

memoryHolder
    <resource: #uiAspect>

    "automatically generated by UIPainter ..."

    "*** the code below creates a default model when invoked."
    "*** (which may not be the one you wanted)"
    "*** Please change as required and accept it in the browser."
    "*** (and replace this comment by something more useful ;-)"

    memoryHolder isNil ifTrue:[
        memoryHolder := '' asValue.
"/ if your app needs to be notified of changes, uncomment one of the lines below:
"/       memoryHolder addDependent:self.
"/       memoryHolder onChangeSend:#memoryHolderChanged to:self.
    ].
    ^ memoryHolder.
!

numColsHolder
    <resource: #uiAspect>

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

    "Modified: / 05-07-2018 / 14:37:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

numRowsHolder
    <resource: #uiAspect>

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

    "Modified (format): / 05-07-2018 / 14:37:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

sizeIndexHolder
    <resource: #uiAspect>
    sizeIndexHolder isNil ifTrue:[
        sizeIndexHolder := ValueHolder with: LastSizeIndex.
        sizeIndexHolder addDependent:self.
    ].
    ^ sizeIndexHolder.

    "Modified: / 26-01-2018 / 00:48:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

sizeList
    ^ Sizes

    "Created: / 26-01-2018 / 00:40:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBMemoryApplication methodsFor:'change & update'!

update
    | address size format ncols nrows |

    address := self addressHolder value.
    address isEmptyOrNil ifTrue:[ ^ self memory: nil ].
    size := 1 << (self sizeIndexHolder value - 1).
    format := self formatHolder value format.
    ncols := self numColsHolder value ? 4.
    nrows := self numRowsHolder value ? 10.

    debugger 
        send: (GDBMI_data_read_memory arguments: (Array with: address with: format with: size with: nrows with: ncols))
        andWithResultDo:[ :result | self window sensor pushUserEvent: #memory: for: self withArgument: result value ]

    "Created: / 26-01-2018 / 12:41:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 30-01-2019 / 11:42:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

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

    "stub code automatically generated - please change as required"

    sender == addressHolder ifTrue:[ 
        self update.
        ^ self.
    ].
    (sender == sizeIndexHolder or:[ sender == formatHolder ]) ifTrue:[ 
        self update.
        ^ self.
    ].
    (sender == numRowsHolder or:[ sender == numColsHolder ]) ifTrue:[
         self update.
         ^ self.
    ].
    super update:aspect with:parameter from:sender

    "Modified: / 29-01-2019 / 10:02:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBMemoryApplication methodsFor:'event handling'!

onStoppedEvent: aGDBStoppedEvent
    self update

    "Created: / 25-01-2019 / 23:21:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBMemoryApplication methodsFor:'initialization & release'!

subscribe
    super subscribe.
    
    debugger announcer 
        when:GDBStoppedEvent        send:#onStoppedEvent:       to:self.

    "Created: / 25-01-2019 / 23:20:03 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 17-11-2021 / 16:39:28 / Jan Vrany <jan.vrany@labware.com>"
    "Modified (comment): / 18-11-2021 / 16:24:40 / Jan Vrany <jan.vrany@labware.com>"
! !

!VDBMemoryApplication methodsFor:'menu actions'!

doRefresh
    self update

    "Modified: / 17-01-2019 / 10:36:04 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!VDBMemoryApplication class methodsFor:'documentation'!

version_HG

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


VDBMemoryApplication initialize!