GDBThreadGroup.st
changeset 124 74c24ce40251
parent 117 17e5e955c3c1
child 129 661e16236c67
--- a/GDBThreadGroup.st	Mon Jun 04 15:12:54 2018 +0100
+++ b/GDBThreadGroup.st	Thu Jun 07 10:11:07 2018 +0100
@@ -24,7 +24,7 @@
 
 GDBDebuggerObject subclass:#GDBThreadGroup
 	instanceVariableNames:'id type executable running pid exit_code threads'
-	classVariableNames:''
+	classVariableNames:'ExecutableSentinel'
 	poolDictionaries:'GDBCommandStatus'
 	category:'GDB-Core'
 !
@@ -52,6 +52,16 @@
 "
 ! !
 
+!GDBThreadGroup class methodsFor:'initialization'!
+
+initialize
+    "Invoked at system start or when the class is dynamically loaded."
+
+    ExecutableSentinel := Object new.
+
+    "Modified: / 07-06-2018 / 10:05:35 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !GDBThreadGroup class methodsFor:'instance creation'!
 
 new
@@ -99,6 +109,8 @@
 !GDBThreadGroup methodsFor:'accessing'!
 
 executable
+    "Return name path of the executable (if known) or nil (if unknown)"
+
     (executable isNil and:[ pid notNil and:[self isStopped or:[debugger hasFeature:'async']]]) ifTrue:[
         | result tg |
 
@@ -107,12 +119,27 @@
             self error: 'Failed to send command.'
         ].
         tg := (result propertyAt: 'groups') detect: [: each | each id = id ].
-        executable := tg executable.
+        "/ In some cases the executable is not known - it may not exist (such as
+        "/ when debugging bare-metal code) or the target does not report it
+        "/ (may happen, for example wine's winedbg GDB proxy does not report
+        "/ executable names).
+        "/ 
+        "/ In this case, we store a sentinel object in `executable` instvar
+        "/ to prevent repeated queries which are bound to fail (see the nil-check
+        "/ above.
+        executable := tg executableOrNil ? ExecutableSentinel.
     ].
-    ^ executable
+    ^ executable == ExecutableSentinel ifTrue:[ nil ] ifFalse:[ executable ]
 
     "Created: / 06-06-2017 / 00:04:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 26-03-2018 / 21:44:53 / jv"
+    "Modified (comment): / 07-06-2018 / 10:09:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+executableOrNil
+    ^ executable
+
+    "Created: / 06-06-2018 / 15:43:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 exitCode
@@ -316,3 +343,5 @@
     ^ '$Changeset: <not expanded> $'
 ! !
 
+
+GDBThreadGroup initialize!