GDBVariable.st
author Jan Vrany <jan.vrany@labware.com>
Fri, 08 Sep 2023 12:40:22 +0100
changeset 317 7f63737e0374
parent 272 cdd1c9ad00de
permissions -rw-r--r--
Fix `GDBMIDebugger` after rename of `GDBStXUnixProcess` to `GDBUnixProcess` ...in commit d1422e1ee.

"
jv:libgdbs - GNU Debugger Interface Library
Copyright (C) 2015-now Jan Vrany
Copyright (C) 2022-2023 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:libgdbs' }"

"{ NameSpace: Smalltalk }"

GDBDebuggerObject subclass:#GDBVariable
	instanceVariableNames:'frame name value type arg varobj'
	classVariableNames:'VarobjUnavailable'
	poolDictionaries:''
	category:'GDB'
!

!GDBVariable class methodsFor:'documentation'!

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

!GDBVariable class methodsFor:'initialization'!

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

    VarobjUnavailable := Object new.

    "Modified (comment): / 05-07-2018 / 11:05:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBVariable class methodsFor:'accessing - GDB value descriptors'!

description
    ^ (super description)
        define:#name as:String;
        define:#arg as:Boolean;       
        yourself

    "Created: / 16-09-2014 / 23:59:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 05-07-2018 / 11:07:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBVariable methodsFor:'accessing'!

children
    | vobj |

    vobj := self varobj.
    ^ vobj notNil ifTrue:[ vobj children ] ifFalse: [ #() ].

    "Created: / 05-07-2018 / 11:59:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

expression
    ^ self name

    "Created: / 05-07-2018 / 11:58:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

frame
    ^ frame

    "Created: / 08-07-2019 / 20:56:00 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

name
    ^ name
!

parent
    ^ nil

    "Created: / 10-09-2018 / 16:45:06 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

path
    ^ self expression

    "Created: / 05-07-2018 / 11:58:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

type
    ^ type
!

value
    "Retun an up-to-date pretty-printed string representation of this variable's value."

    | vobj |

    "/ The code below tries to avoid creating an varobj if 
    "/ possible since creation of varobj might be costly.
    "/ 
    "/ THerefore we check whether `value` instvar (cached
    "/ string representation) is not nil and varobj is nil
    "/ (i.e., has not yet been created). If so, return
    "/ cached `value` without creating varobj. Otherwise,
    "/ create varobj and ask it for a value.

    varobj == VarobjUnavailable ifTrue:[ ^ value ].
    (varobj isNil and: [value notNil])  ifTrue:[ ^ value ].

    vobj := self varobj.
    vobj notNil ifTrue:[ ^ vobj value ].

    ^ self class classResources string:'<could not read value>'

    "Created: / 27-02-2015 / 23:37:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 27-02-2019 / 16:58:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

visualizer: aString   
    "Ignored, to make it polymorphic with GDBVariableObject"

    "Created: / 01-09-2018 / 00:57:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBVariable methodsFor:'accessing-private'!

varobj
    varobj isNil ifTrue:[ 
        varobj := [ debugger evaluate: name in: frame ] on: GDBCommandFailedError do: [ VarobjUnavailable ].
    ].
    varobj == VarobjUnavailable ifTrue:[ ^ nil ].
    ^ varobj

    "Created: / 27-02-2015 / 17:18:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 15-01-2018 / 23:10:31 / jv"
    "Modified: / 05-07-2018 / 11:06:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBVariable methodsFor:'copying'!

duplicate
    "Create and returns a duplicate of the receiver, representing
     the same value. Other than that the returned duplicate is completely 
     independent" 

    | vobj |

    vobj := self varobj.
    vobj isNil ifTrue:[ 
        ^ self
    ].
    ^ vobj duplicate

    "Created: / 01-09-2018 / 00:27:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 08-07-2019 / 20:53:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBVariable methodsFor:'initialization'!

setFrame: aGDBFrame
    self assert: frame isNil.
    self assert: (debugger isNil or:[ debugger == aGDBFrame debugger ]).
    frame := aGDBFrame.
    self setDebugger: frame debugger.

    "Created: / 27-02-2015 / 17:08:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 04-02-2018 / 21:41:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

setValue: aString
    value := aString

    "Created: / 01-02-2018 / 21:34:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBVariable methodsFor:'inspecting'!

inspectorExtraAttributes
    ^ super inspectorExtraAttributes
        add:('-varobj' -> [ self varobj ]);
        yourself

    "Created: / 13-06-2017 / 14:51:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBVariable methodsFor:'printing & storing'!

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

    super printOn:aStream.
    aStream nextPutAll:'('.
    name printOn: aStream.
    aStream nextPutAll:': '.
    aStream nextPutAll: self valueString.
    aStream nextPutAll:')'.

    "Modified: / 13-06-2017 / 17:01:41 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

valueString
    "Return value as string to be presented to user. The difference
     to sending `value displayString` is that #valueString returns a
     pretty-printed value (if pretty printing was enabled for GDB)

     @see GDBMI_enable_pretty_printing
     @see GDBDebugger >> enablePrettyPrinting
    "

    ^ value notNil ifTrue:[ value ] ifFalse:[ self value displayString ]

    "Created: / 11-06-2017 / 23:24:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified (comment): / 12-06-2017 / 09:26:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBVariable methodsFor:'private'!

updateFromIgnoredInstvarNames
    ^ super updateFromIgnoredInstvarNames , #(varobj)

    "Created: / 25-02-2019 / 17:43:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBVariable methodsFor:'testing'!

hasChanged
    | vobj |

    vobj := self varobj.
    ^ vobj notNil ifTrue:[ vobj hasChanged ] ifFalse: [ false ].

    "Created: / 05-07-2018 / 11:59:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

hasChildren
    | vobj |

    vobj := self varobj.
    ^ vobj notNil ifTrue:[ vobj hasChildren ] ifFalse: [ false ].

    "Created: / 05-07-2018 / 12:00:34 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

isArgument
    ^ arg == true

    "Created: / 05-07-2018 / 11:08:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

isValid
    ^ frame isValid

    "Created: / 04-02-2018 / 21:32:26 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

parentIsDynamic
    ^ false

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

!GDBVariable class methodsFor:'documentation'!

version_HG

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


GDBVariable initialize!