Variable objects: delete var. objects that are no longer needed
authorJan Vrany <jan.vrany@fit.cvut.cz>
Mon, 29 Jan 2018 10:21:03 +0000
changeset 102 d573a3b2abe2
parent 101 d8fee2af20b2
child 103 56bf65352505
Variable objects: delete var. objects that are no longer needed ...to save resources. This is done by implementing finalization schema for top-level objects. `GDBDebugger` instance holds the finalization registry.
GDBDebugger.st
GDBVariable.st
GDBVariableObject.st
GDBVariableObjectExecutor.st
Make.proto
Make.spec
abbrev.stc
bc.mak
jv_libgdbs.st
libInit.cc
--- a/GDBDebugger.st	Sun Jan 28 22:19:27 2018 +0000
+++ b/GDBDebugger.st	Mon Jan 29 10:21:03 2018 +0000
@@ -23,7 +23,8 @@
 Object subclass:#GDBDebugger
 	instanceVariableNames:'connection commandSequenceNumber inferiorStateSequenceNumber
 		inferiors breakpoints selectedInferior selectedThread
-		selectedFrame prettyPrintingEnabled frameFiltersEnabled'
+		selectedFrame prettyPrintingEnabled frameFiltersEnabled
+		finalizationRegistry'
 	classVariableNames:''
 	poolDictionaries:'GDBCommandStatus'
 	category:'GDB-Core'
@@ -151,6 +152,10 @@
     "Created: / 19-06-2014 / 22:22:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+finalizationRegistry
+    ^ finalizationRegistry
+!
+
 nextCommandSequnceNumber
     commandSequenceNumber := commandSequenceNumber + 1.
     commandSequenceNumber == SmallInteger maxVal ifTrue:[ 
@@ -687,6 +692,8 @@
 
 initializeWithProcess: aGDBProcess
     self registerForFinalization.
+
+    finalizationRegistry := Registry new.
     connection := GDBConnection newWithProcess: aGDBProcess.
 
     commandSequenceNumber := 0.
@@ -707,8 +714,8 @@
     frameFiltersEnabled := false.
 
     "Created: / 20-06-2014 / 21:45:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 17-11-2017 / 20:14:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 12-01-2018 / 00:13:09 / jv"
+    "Modified: / 28-01-2018 / 23:19:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 release
--- a/GDBVariable.st	Sun Jan 28 22:19:27 2018 +0000
+++ b/GDBVariable.st	Mon Jan 29 10:21:03 2018 +0000
@@ -107,12 +107,13 @@
 
         varobj := result value.
         varobj setDebugger: debugger; setExpression: name.    
+        varobj registerForFinalization.
     ].
     ^ varobj
 
     "Created: / 27-02-2015 / 17:18:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 15-01-2018 / 23:10:31 / jv"
-    "Modified: / 28-01-2018 / 21:52:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 28-01-2018 / 23:29:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !GDBVariable methodsFor:'initialization'!
--- a/GDBVariableObject.st	Sun Jan 28 22:19:27 2018 +0000
+++ b/GDBVariableObject.st	Mon Jan 29 10:21:03 2018 +0000
@@ -24,7 +24,7 @@
 	instanceVariableNames:'parent name exp thread_id value type numchild has_more children'
 	classVariableNames:''
 	poolDictionaries:''
-	category:'GDB-Private-Model'
+	category:'GDB-Core'
 !
 
 !GDBVariableObject class methodsFor:'documentation'!
@@ -139,6 +139,24 @@
     "Created: / 28-01-2018 / 21:42:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
+!GDBVariableObject methodsFor:'finalization'!
+
+executor
+    ^ GDBVariableObjectExecutor new 
+            setDebugger: debugger;
+            setId: name;
+            yourself
+
+    "Created: / 28-01-2018 / 23:27:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+finalizationLobby
+    self assert: debugger notNil.
+    ^ debugger finalizationRegistry.
+
+    "Created: / 28-01-2018 / 23:21:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !GDBVariableObject methodsFor:'initialization'!
 
 setExpression: aString
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/GDBVariableObjectExecutor.st	Mon Jan 29 10:21:03 2018 +0000
@@ -0,0 +1,68 @@
+"
+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 }"
+
+GDBDebuggerObject subclass:#GDBVariableObjectExecutor
+	instanceVariableNames:'name'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'GDB-Private'
+!
+
+!GDBVariableObjectExecutor 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
+"
+! !
+
+!GDBVariableObjectExecutor methodsFor:'finalization'!
+
+finalize
+    debugger send: (GDBMI_var_delete arguments: (Array with: '-c' with: name))
+
+    "Created: / 28-01-2018 / 23:26:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
+!GDBVariableObjectExecutor methodsFor:'initialization'!
+
+setId: aString
+    name := aString
+
+    "Created: / 28-01-2018 / 23:25:13 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
--- a/Make.proto	Sun Jan 28 22:19:27 2018 +0000
+++ b/Make.proto	Mon Jan 29 10:21:03 2018 +0000
@@ -34,7 +34,7 @@
 # add the path(es) here:,
 # ********** OPTIONAL: MODIFY the next lines ***
 # LOCALINCLUDES=-Ifoo -Ibar
-LOCALINCLUDES= -I$(INCLUDE_TOP)/stx/goodies/announcements -I$(INCLUDE_TOP)/stx/goodies/magritte -I$(INCLUDE_TOP)/stx/libbasic -I$(INCLUDE_TOP)/stx/libbasic2 -I$(INCLUDE_TOP)/stx/libtool -I$(INCLUDE_TOP)/stx/libview2 -I$(INCLUDE_TOP)/stx/libwidg
+LOCALINCLUDES= -I$(INCLUDE_TOP)/stx/goodies/announcements -I$(INCLUDE_TOP)/stx/goodies/magritte -I$(INCLUDE_TOP)/stx/goodies/sunit -I$(INCLUDE_TOP)/stx/libbasic -I$(INCLUDE_TOP)/stx/libbasic2 -I$(INCLUDE_TOP)/stx/libtool -I$(INCLUDE_TOP)/stx/libview2 -I$(INCLUDE_TOP)/stx/libwidg
 
 
 # if you need any additional defines for embedded C code,
@@ -296,6 +296,7 @@
 $(OUTDIR)GDBThreadGroup.$(O) GDBThreadGroup.$(C) GDBThreadGroup.$(H): GDBThreadGroup.st $(INCLUDE_TOP)/jv/libgdbs/GDBCommandStatus.$(H) $(INCLUDE_TOP)/jv/libgdbs/GDBDebuggerObject.$(H) $(INCLUDE_TOP)/jv/libgdbs/GDBObject.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR)
 $(OUTDIR)GDBTransientObject.$(O) GDBTransientObject.$(C) GDBTransientObject.$(H): GDBTransientObject.st $(INCLUDE_TOP)/jv/libgdbs/GDBDebuggerObject.$(H) $(INCLUDE_TOP)/jv/libgdbs/GDBObject.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR)
 $(OUTDIR)GDBVariableObject.$(O) GDBVariableObject.$(C) GDBVariableObject.$(H): GDBVariableObject.st $(INCLUDE_TOP)/jv/libgdbs/GDBDebuggerObject.$(H) $(INCLUDE_TOP)/jv/libgdbs/GDBObject.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR)
+$(OUTDIR)GDBVariableObjectExecutor.$(O) GDBVariableObjectExecutor.$(C) GDBVariableObjectExecutor.$(H): GDBVariableObjectExecutor.st $(INCLUDE_TOP)/jv/libgdbs/GDBDebuggerObject.$(H) $(INCLUDE_TOP)/jv/libgdbs/GDBObject.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR)
 $(OUTDIR)GDBBreakpointDeletedEvent.$(O) GDBBreakpointDeletedEvent.$(C) GDBBreakpointDeletedEvent.$(H): GDBBreakpointDeletedEvent.st $(INCLUDE_TOP)/jv/libgdbs/GDBAsyncEvent.$(H) $(INCLUDE_TOP)/jv/libgdbs/GDBEvent.$(H) $(INCLUDE_TOP)/jv/libgdbs/GDBNotificationEvent.$(H) $(INCLUDE_TOP)/stx/goodies/announcements/Announcement.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR)
 $(OUTDIR)GDBBreakpointEvent.$(O) GDBBreakpointEvent.$(C) GDBBreakpointEvent.$(H): GDBBreakpointEvent.st $(INCLUDE_TOP)/jv/libgdbs/GDBAsyncEvent.$(H) $(INCLUDE_TOP)/jv/libgdbs/GDBEvent.$(H) $(INCLUDE_TOP)/jv/libgdbs/GDBNotificationEvent.$(H) $(INCLUDE_TOP)/stx/goodies/announcements/Announcement.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR)
 $(OUTDIR)GDBCmdParamChangedEvent.$(O) GDBCmdParamChangedEvent.$(C) GDBCmdParamChangedEvent.$(H): GDBCmdParamChangedEvent.st $(INCLUDE_TOP)/jv/libgdbs/GDBAsyncEvent.$(H) $(INCLUDE_TOP)/jv/libgdbs/GDBEvent.$(H) $(INCLUDE_TOP)/jv/libgdbs/GDBNotificationEvent.$(H) $(INCLUDE_TOP)/stx/goodies/announcements/Announcement.$(H) $(INCLUDE_TOP)/stx/libbasic/Object.$(H) $(STCHDR)
--- a/Make.spec	Sun Jan 28 22:19:27 2018 +0000
+++ b/Make.spec	Mon Jan 29 10:21:03 2018 +0000
@@ -220,6 +220,7 @@
 	GDBThreadGroup \
 	GDBTransientObject \
 	GDBVariableObject \
+	GDBVariableObjectExecutor \
 	GDBBreakpointDeletedEvent \
 	GDBBreakpointEvent \
 	GDBCmdParamChangedEvent \
@@ -415,6 +416,7 @@
     $(OUTDIR)GDBThreadGroup.$(O) \
     $(OUTDIR)GDBTransientObject.$(O) \
     $(OUTDIR)GDBVariableObject.$(O) \
+    $(OUTDIR)GDBVariableObjectExecutor.$(O) \
     $(OUTDIR)GDBBreakpointDeletedEvent.$(O) \
     $(OUTDIR)GDBBreakpointEvent.$(O) \
     $(OUTDIR)GDBCmdParamChangedEvent.$(O) \
--- a/abbrev.stc	Sun Jan 28 22:19:27 2018 +0000
+++ b/abbrev.stc	Mon Jan 29 10:21:03 2018 +0000
@@ -46,7 +46,6 @@
 GDBThreadStateTerminated GDBThreadStateTerminated jv:libgdbs 'GDB-Core' 1
 GDBThreadStateUnknown GDBThreadStateUnknown jv:libgdbs 'GDB-Core' 1
 GDBUnixProcess GDBUnixProcess jv:libgdbs 'GDB-Private' 0
-GDBVariableObject GDBVariableObject jv:libgdbs 'GDB-Private-Model' 0
 GDBWindowsProcess GDBWindowsProcess jv:libgdbs 'GDB-Private' 0
 GDBBreakpoint GDBBreakpoint jv:libgdbs 'GDB-Core' 0
 GDBConsoleOutputEvent GDBConsoleOutputEvent jv:libgdbs 'GDB-Core-Events' 0
@@ -171,6 +170,8 @@
 GDBThread GDBThread jv:libgdbs 'GDB-Core' 0
 GDBThreadGroup GDBThreadGroup jv:libgdbs 'GDB-Core' 0
 GDBTransientObject GDBTransientObject jv:libgdbs 'GDB-Core' 0
+GDBVariableObject GDBVariableObject jv:libgdbs 'GDB-Core' 0
+GDBVariableObjectExecutor GDBVariableObjectExecutor jv:libgdbs 'GDB-Private' 0
 GDBBreakpointDeletedEvent GDBBreakpointDeletedEvent jv:libgdbs 'GDB-Core-Events' 0
 GDBBreakpointEvent GDBBreakpointEvent jv:libgdbs 'GDB-Core-Events' 0
 GDBCmdParamChangedEvent GDBCmdParamChangedEvent jv:libgdbs 'GDB-Core-Events' 0
--- a/bc.mak	Sun Jan 28 22:19:27 2018 +0000
+++ b/bc.mak	Mon Jan 29 10:21:03 2018 +0000
@@ -35,7 +35,7 @@
 
 
 
-LOCALINCLUDES= -I$(INCLUDE_TOP)\stx\goodies\announcements -I$(INCLUDE_TOP)\stx\goodies\magritte -I$(INCLUDE_TOP)\stx\libbasic -I$(INCLUDE_TOP)\stx\libbasic2 -I$(INCLUDE_TOP)\stx\libtool -I$(INCLUDE_TOP)\stx\libview2 -I$(INCLUDE_TOP)\stx\libwidg
+LOCALINCLUDES= -I$(INCLUDE_TOP)\stx\goodies\announcements -I$(INCLUDE_TOP)\stx\goodies\magritte -I$(INCLUDE_TOP)\stx\goodies\sunit -I$(INCLUDE_TOP)\stx\libbasic -I$(INCLUDE_TOP)\stx\libbasic2 -I$(INCLUDE_TOP)\stx\libtool -I$(INCLUDE_TOP)\stx\libview2 -I$(INCLUDE_TOP)\stx\libwidg
 LOCALDEFINES=
 
 STCLOCALOPT=-package=$(PACKAGE) -I. $(LOCALINCLUDES) -headerDir=. $(STCLOCALOPTIMIZATIONS) $(STCWARNINGS) $(LOCALDEFINES)  -varPrefix=$(LIBNAME)
@@ -243,6 +243,7 @@
 $(OUTDIR)GDBThreadGroup.$(O) GDBThreadGroup.$(C) GDBThreadGroup.$(H): GDBThreadGroup.st $(INCLUDE_TOP)\jv\libgdbs\GDBCommandStatus.$(H) $(INCLUDE_TOP)\jv\libgdbs\GDBDebuggerObject.$(H) $(INCLUDE_TOP)\jv\libgdbs\GDBObject.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR)
 $(OUTDIR)GDBTransientObject.$(O) GDBTransientObject.$(C) GDBTransientObject.$(H): GDBTransientObject.st $(INCLUDE_TOP)\jv\libgdbs\GDBDebuggerObject.$(H) $(INCLUDE_TOP)\jv\libgdbs\GDBObject.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR)
 $(OUTDIR)GDBVariableObject.$(O) GDBVariableObject.$(C) GDBVariableObject.$(H): GDBVariableObject.st $(INCLUDE_TOP)\jv\libgdbs\GDBDebuggerObject.$(H) $(INCLUDE_TOP)\jv\libgdbs\GDBObject.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR)
+$(OUTDIR)GDBVariableObjectExecutor.$(O) GDBVariableObjectExecutor.$(C) GDBVariableObjectExecutor.$(H): GDBVariableObjectExecutor.st $(INCLUDE_TOP)\jv\libgdbs\GDBDebuggerObject.$(H) $(INCLUDE_TOP)\jv\libgdbs\GDBObject.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR)
 $(OUTDIR)GDBBreakpointDeletedEvent.$(O) GDBBreakpointDeletedEvent.$(C) GDBBreakpointDeletedEvent.$(H): GDBBreakpointDeletedEvent.st $(INCLUDE_TOP)\jv\libgdbs\GDBAsyncEvent.$(H) $(INCLUDE_TOP)\jv\libgdbs\GDBEvent.$(H) $(INCLUDE_TOP)\jv\libgdbs\GDBNotificationEvent.$(H) $(INCLUDE_TOP)\stx\goodies\announcements\Announcement.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR)
 $(OUTDIR)GDBBreakpointEvent.$(O) GDBBreakpointEvent.$(C) GDBBreakpointEvent.$(H): GDBBreakpointEvent.st $(INCLUDE_TOP)\jv\libgdbs\GDBAsyncEvent.$(H) $(INCLUDE_TOP)\jv\libgdbs\GDBEvent.$(H) $(INCLUDE_TOP)\jv\libgdbs\GDBNotificationEvent.$(H) $(INCLUDE_TOP)\stx\goodies\announcements\Announcement.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR)
 $(OUTDIR)GDBCmdParamChangedEvent.$(O) GDBCmdParamChangedEvent.$(C) GDBCmdParamChangedEvent.$(H): GDBCmdParamChangedEvent.st $(INCLUDE_TOP)\jv\libgdbs\GDBAsyncEvent.$(H) $(INCLUDE_TOP)\jv\libgdbs\GDBEvent.$(H) $(INCLUDE_TOP)\jv\libgdbs\GDBNotificationEvent.$(H) $(INCLUDE_TOP)\stx\goodies\announcements\Announcement.$(H) $(INCLUDE_TOP)\stx\libbasic\Object.$(H) $(STCHDR)
--- a/jv_libgdbs.st	Sun Jan 28 22:19:27 2018 +0000
+++ b/jv_libgdbs.st	Mon Jan 29 10:21:03 2018 +0000
@@ -89,6 +89,7 @@
      Please also take a look at the #mandatoryPreRequisites method"
 
     ^ #(
+        #'stx:goodies/sunit'    "TestAsserter - superclass of GDBSimulatorResource"
         #'stx:libbasic2'    "List - referenced by GDBDebugger>>breakpoints"
         #'stx:libtool'    "Tools::Inspector2Tab - referenced by GDBBreakpoint>>inspector2TabCondition"
         #'stx:libview2'    "ApplicationModel - referenced by GDBEventSubscription class>>blockFor:withSelector:"
@@ -161,7 +162,6 @@
         GDBThreadStateTerminated
         GDBThreadStateUnknown
         GDBUnixProcess
-        GDBVariableObject
         GDBWindowsProcess
         GDBBreakpoint
         GDBConsoleOutputEvent
@@ -286,6 +286,8 @@
         GDBThread
         GDBThreadGroup
         GDBTransientObject
+        GDBVariableObject
+        GDBVariableObjectExecutor
         GDBBreakpointDeletedEvent
         GDBBreakpointEvent
         GDBCmdParamChangedEvent
--- a/libInit.cc	Sun Jan 28 22:19:27 2018 +0000
+++ b/libInit.cc	Mon Jan 29 10:21:03 2018 +0000
@@ -185,6 +185,7 @@
 extern void _GDBThreadGroup_Init(int pass, struct __vmData__ *__pRT__, OBJ snd);
 extern void _GDBTransientObject_Init(int pass, struct __vmData__ *__pRT__, OBJ snd);
 extern void _GDBVariableObject_Init(int pass, struct __vmData__ *__pRT__, OBJ snd);
+extern void _GDBVariableObjectExecutor_Init(int pass, struct __vmData__ *__pRT__, OBJ snd);
 extern void _GDBBreakpointDeletedEvent_Init(int pass, struct __vmData__ *__pRT__, OBJ snd);
 extern void _GDBBreakpointEvent_Init(int pass, struct __vmData__ *__pRT__, OBJ snd);
 extern void _GDBCmdParamChangedEvent_Init(int pass, struct __vmData__ *__pRT__, OBJ snd);
@@ -389,6 +390,7 @@
     _GDBThreadGroup_Init(pass,__pRT__,snd);
     _GDBTransientObject_Init(pass,__pRT__,snd);
     _GDBVariableObject_Init(pass,__pRT__,snd);
+    _GDBVariableObjectExecutor_Init(pass,__pRT__,snd);
     _GDBBreakpointDeletedEvent_Init(pass,__pRT__,snd);
     _GDBBreakpointEvent_Init(pass,__pRT__,snd);
     _GDBCmdParamChangedEvent_Init(pass,__pRT__,snd);