GDBThread.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 18 Sep 2014 09:32:30 +0100
changeset 41 fb48207b6104
parent 40 0ce76b671515
child 43 22236b6d1d9a
permissions -rw-r--r--
Fixes in thread's stack mangement. Dispatch events to applications using their UI event loop.

"{ Package: 'jv:libgdbs' }"

GDBDebuggerObject subclass:#GDBThread
	instanceVariableNames:'id group status stack'
	classVariableNames:''
	poolDictionaries:''
	category:'GDB-Core'
!

!GDBThread class methodsFor:'instance creation'!

newWithDebugger: debugger id: id group: group
    ^ self new
        setDebugger: debugger;
        setId: id;
        setGroup: group;
        yourself.

    "Created: / 07-09-2014 / 21:33:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

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

gdbValueDescriptor
    ^ (super gdbValueDescriptor)
        define: #id as: Integer;
        yourself

    "Created: / 06-09-2014 / 02:21:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBThread methodsFor:'accessing'!

id
    ^ id

    "Created: / 07-09-2014 / 22:41:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

stack
    self ensureIsStopped.
    stack isNil ifTrue:[
        stack := GDBTransientDataHolder debugger: debugger factory:[ 
            | result depth |
            result := debugger send: (GDBMI_stack_info_depth new arguments: { '--thread' . id . 100 }).
            depth := result propertyAt: #depth.
            result := debugger send: (GDBMI_stack_list_frames new arguments: { '--thread' . id . 0 . depth - 1 }).
            result propertyAt: #stack.
        ].
    ].
    ^ stack value

    "Created: / 09-09-2014 / 00:02:45 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 17-09-2014 / 22:12:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

status
    ^ status
! !

!GDBThread methodsFor:'initialization'!

setGroup: aGDBThreadGroup
    self assert: group isNil.
    group := aGDBThreadGroup.

    "Created: / 07-09-2014 / 21:32:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

setId: tid
    self assert: id isNil.
    id := tid.
    status := GDBThreadStatusRunning theOneAndOnlyInstance

    "Created: / 07-09-2014 / 21:31:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 07-09-2014 / 23:27:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

setStatus: aGDBThreadStatus
    status := aGDBThreadStatus.
    status isStopped ifFalse:[
        stack := nil.
    ].

    "Created: / 07-09-2014 / 23:25:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 09-09-2014 / 00:04:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

setTerminated
    status := GDBThreadStatusTerminated theOneAndOnlyInstance

    "Created: / 07-09-2014 / 21:37:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 07-09-2014 / 23:21:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBThread methodsFor:'private'!

ensureIsStopped
    self isStopped ifFalse:[
        (GDBInvalidObject newException)
            parameter:self;
            messageText:'Invalid state (thread is running or already dead)';
            raise.
    ].

    "Created: / 09-09-2014 / 00:04:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 16-09-2014 / 23:51:09 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBThread methodsFor:'testing'!

isRunning
    ^ status isRunning

    "Created: / 07-09-2014 / 23:23:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

isStopped
    ^ status isStopped

    "Created: / 07-09-2014 / 23:23:36 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

isTerminated
    ^ status isTerminated

    "Created: / 07-09-2014 / 23:23:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !