GDBThreadGroup.st
changeset 81 5e07808d349f
parent 60 ab92b3e4aecf
child 86 7f53d51a0a65
--- a/GDBThreadGroup.st	Mon Jun 05 17:56:05 2017 +0100
+++ b/GDBThreadGroup.st	Tue Jun 06 09:37:04 2017 +0100
@@ -5,15 +5,21 @@
 "{ NameSpace: Smalltalk }"
 
 GDBDebuggerObject subclass:#GDBThreadGroup
-	instanceVariableNames:'id type executable pid exit_code threads'
+	instanceVariableNames:'id type executable running pid exit_code threads'
 	classVariableNames:''
-	poolDictionaries:''
+	poolDictionaries:'GDBCommandStatus'
 	category:'GDB-Core'
 !
 
 
 !GDBThreadGroup class methodsFor:'instance creation'!
 
+new
+    "return an initialized instance"
+
+    ^ self basicNew initialize.
+!
+
 newWithDebugger: debugger id: aString
     ^ self new setDebugger: debugger; setId: aString; yourself
 
@@ -43,14 +49,30 @@
         };
         accessor: (GDBMAPropertyAccessor forPropertyNamed: 'type');
         label: 'type';
-        description: 'The type of the thread group. At present, only ‘process’ is a valid type.';
+        comment: 'The type of the thread group. At present, only ‘process’ is a valid type.';
         yourself.
 
     "Created: / 01-10-2014 / 01:29:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 05-06-2017 / 23:49:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !GDBThreadGroup methodsFor:'accessing'!
 
+executable
+    (executable isNil and:[ pid notNil ]) ifTrue:[
+        | result tg |
+        result := debugger send: GDBMI_list_thread_groups new.
+        result status ~~ CommandStatusDone ifTrue:[ 
+            self error: 'Failed to send command.'
+        ].
+        tg := (result propertyAt: 'groups') detect: [: each | each id = id ].
+        executable := tg executable.
+    ].
+    ^ executable
+
+    "Created: / 06-06-2017 / 00:04:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 exitCode
     ^ exit_code
 
@@ -119,12 +141,21 @@
 
 !GDBThreadGroup methodsFor:'initialization'!
 
+initialize
+    "Invoked when a new instance is created."
+
+    running := false.
+
+    "Modified: / 06-06-2017 / 00:25:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 setExitCode: anInteger
     exit_code := anInteger.
-    threads removeAll
+    running := false.
+    threads removeAll.
 
     "Created: / 06-09-2014 / 02:33:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 22-09-2014 / 01:23:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 06-06-2017 / 00:24:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 setId: aString
@@ -136,9 +167,11 @@
 setPid: anInteger
     pid := anInteger.
     exit_code := nil.
+    executable := nil.
+    running := true.
 
     "Created: / 06-09-2014 / 02:32:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 07-09-2014 / 12:34:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 06-06-2017 / 00:24:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !GDBThreadGroup methodsFor:'printing & storing'!
@@ -173,22 +206,57 @@
 !GDBThreadGroup methodsFor:'testing'!
 
 isDead
-    ^ exit_code notNil
+    "Return true if program finished, either normally or abruptly (usng `kill` command).
+     To tell whether is has finished normally or it has been terminated see
+     #isFinished and / or #isTerminated"
+
+    ^ self isRunning not and:[ pid notNil ]
 
     "Created: / 06-09-2014 / 02:38:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 06-06-2017 / 09:22:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+isFinished
+    "Return true if program finished its execution normally (as opposed to be
+     terminated by the debugger), false otherwise. 
+
+     @see also #isTerminated
+     @see also #isDead
+    "
+
+    ^ self isDead  and:[ exit_code notNil ]
+
+    "Created: / 06-06-2017 / 09:23:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 isRunning
-    ^ pid notNil and: [ exit_code isNil ] and:[ self isStopped not ]
+    "Return true, if program is currently running, false otherwise.
+     Note, that program is running even of it's stopped byt the debugger.
+     See #isStopped"
+
+    ^ running
 
     "Created: / 06-09-2014 / 02:38:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 30-09-2014 / 00:49:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 06-06-2017 / 00:25:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 isStopped
     ^ threads notEmptyOrNil and:[ threads anySatisfy: [:t | t isStopped ] ].
 
     "Created: / 30-09-2014 / 00:49:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+isTerminated
+    "Return true if program has been terminated (as opposed to finishing normally),
+     false otherwise.
+
+     @see also #isFinished
+     @see also #isDead
+    "
+
+    ^ self isDead and:[ exit_code isNil ]
+
+    "Created: / 06-06-2017 / 09:26:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !GDBThreadGroup class methodsFor:'documentation'!