GDBThread.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Tue, 10 Mar 2015 09:57:21 +0000
changeset 70 6d7285bb1703
parent 67 c4ac76afe03d
child 72 eb4eea3ebf4c
permissions -rw-r--r--
GDBThread: use native name in thread's displayString

"{ Encoding: utf8 }"

"{ Package: 'jv:libgdbs' }"

"{ NameSpace: Smalltalk }"

GDBDebuggerObject subclass:#GDBThread
	instanceVariableNames:'id group info 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'!

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

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

!GDBThread methodsFor:'accessing'!

group
    ^ group
!

id
    ^ id

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

name
    ^ self targetId

    "Created: / 10-03-2015 / 00:32:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

stack
    self ensureIsStopped.
    stack isNil ifTrue:[
        stack := GDBTransientDataHolder debugger: debugger factory:[ 
            | result depth frames |
            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 }).
            frames := result propertyAt: #stack.
            frames do:[:each | 
                each debugger: debugger.
                each propertyAt: #thread put: self 
            ].
            frames
        ].
    ].
    ^ stack value

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

status
    ^ self info state

    "Modified: / 08-03-2015 / 09:10:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

targetId
    ^ self info targetId

    "Created: / 10-03-2015 / 00:32:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBThread methodsFor:'accessing-private'!

info
    info isNil ifTrue:[
        info := GDBTransientDataHolder debugger: debugger factory:[ 
            | result infos |

            result := debugger send: (GDBMI_thread_info new arguments: { id }).
            infos := result propertyAt: #threads.
            self assert: (infos isEmptyOrNil or:[ infos size == 1 and:[ infos first id = id ] ]).
            infos isEmptyOrNil ifTrue:[ GDBThreadInfo new setId: id state: GDBThreadStateTerminated theOneAndOnlyInstance ] ifFalse:[ infos first ]
        ].
    ].
    ^ info value

    "Created: / 08-03-2015 / 09:07:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 08-03-2015 / 12:35:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBThread methodsFor:'displaying'!

displayString
    ^ '%1 [%2]' bindWith: self name with: self status

    "Created: / 10-03-2015 / 00:32:47 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

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

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

setTerminated

    "Created: / 07-09-2014 / 21:37:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 08-03-2015 / 09:08:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!GDBThread methodsFor:'printing & storing'!

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

    aStream nextPutAll:'thread  '.
    id printOn:aStream.
"/    aStream nextPutAll:'in group '.
"/    group id printOn:aStream.
    aStream nextPutAll:' ['.
    self status printOn:aStream.
    aStream nextPutAll:']'.

    "Modified: / 08-03-2015 / 09:07:55 / 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'!

isDead
    ^ self status isTerminated

    "Created: / 22-09-2014 / 00:54:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 08-03-2015 / 12:35:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

isRunning
    ^ self status isRunning

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

isStopped
    ^ self status isStopped

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

isTerminated
    ^ self status isTerminated

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

!GDBThread class methodsFor:'documentation'!

version_HG

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