GDBVariable.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 23 Nov 2017 22:51:20 +0000
changeset 91 472a4841a8b6
parent 90 6046abc9ddf4
child 95 f417138e9c48
permissions -rw-r--r--
License this package under 'GNU Lesser General Public License'

"
jv:libgdbs - GNU Debugger Interface Library
Copyright (C) 2015-now Jan Vrany

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License. 

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
"
"{ Package: 'jv:libgdbs' }"

"{ NameSpace: Smalltalk }"

GDBTransientObject subclass:#GDBVariable
	instanceVariableNames:'frame name value varobj'
	classVariableNames:''
	poolDictionaries:''
	category:'GDB-Core'
!

!GDBVariable class methodsFor:'documentation'!

copyright
"
jv:libgdbs - GNU Debugger Interface Library
Copyright (C) 2015-now Jan Vrany

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License. 

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
"
! !

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

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

    "Created: / 16-09-2014 / 23:59:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 27-02-2015 / 15:00:49 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBVariable methodsFor:'accessing'!

name
    ^ name
!

value
    ^ self varobj value

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

!GDBVariable methodsFor:'accessing-private'!

varobj
    varobj isNil ifTrue:[ 
        | result currentThreadId currentFrameId |

        result := debugger send: (GDBMI_thread_list_ids new).
        currentThreadId := result propertyAt: 'current-thread-id'.
        result := debugger send: (GDBMI_stack_info_frame new).
        currentFrameId := (result propertyAt: 'frame') level.
        
        frame thread id ~= currentThreadId ifTrue:[ 
            debugger send: (GDBMI_thread_select new arguments:(Array with:frame thread id)).       
            debugger send: (GDBMI_stack_select_frame new arguments:(Array with:frame level)).       
        ] ifFalse:[ 
            frame level ~= currentFrameId ifTrue:[ 
                debugger send: (GDBMI_stack_select_frame new arguments:(Array with:frame level)).       
            ].
        ].

        result := debugger send: (GDBMI_var_create new arguments: (Array with: '-' with: '*' with: name)).

        frame thread id ~= currentThreadId ifTrue:[ 
            debugger send: (GDBMI_thread_select new arguments:currentThreadId).       
            debugger send: (GDBMI_stack_select_frame new arguments:currentFrameId).       
        ] ifFalse:[ 
            frame level ~= currentFrameId ifTrue:[ 
                debugger send: (GDBMI_stack_select_frame new arguments:currentFrameId).       
            ].
        ].

        varobj := result value.
    ].
    ^ varobj

    "Created: / 27-02-2015 / 17:18:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 17-11-2017 / 20:19:45 / 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 debugger: frame debugger.

    "Created: / 27-02-2015 / 17:08:02 / 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 class methodsFor:'documentation'!

version_HG

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