This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] [4/5] Types reference counting [varobj-validation]


Hi,

currently GDB was sometimes keeping varobjs with stale references to objfiles.
With the changes GDB started crashing on this problem.

+/* Invalidate the varobjs that are tied to the specified OBJFILE.  Call this
+   function before you start removing OBJFILE.
+
+   Call varobj_revalidate after the OBJFILEs updates get finished.

As varobj_invalidate was unconditionally invalidating any local varobjs more
often calls to varobj_invalidate could become more intrusive to the user so
I also fixed varobj_invalidate to care only about varobjs bound to the
specific objfile.


Thanks,
Jan


gdb/
2009-04-11  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Split varobj_invalidate into a two-phased operation.
	* objfiles.c: Include varobj.h
	(free_objfile): Call varobj_invalidate.
	* symfile.c (new_symfile_objfile): Call varobj_revalidate.
	(reread_symbols): Call varobj_invalidate and varobj_revalidate.
	(clear_symtab_users): No longer call varobj_invalidate.
	* varobj.c (varobj_invalidate): New parameter `objfile', comment it.
	New variable `var'.  Invalidate any varobj related to `objfile'.
	Remove unconditional invalidation of local varobjs.  Move global
	varobjs revalidation to ...
	(varobj_revalidate): ... a new function.
	* varobj.h (varobj_invalidate): Update the prototype.
	(varobj_revalidate): New prototype.

diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 795d53b..8e794e0 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -50,6 +50,7 @@
 #include "addrmap.h"
 #include "arch-utils.h"
 #include "exec.h"
+#include "varobj.h"
 
 /* Prototypes for local functions */
 
@@ -409,6 +410,7 @@ free_objfile (struct objfile *objfile)
   /* Remove any references to this objfile in the global value
      lists.  */
   preserve_values (objfile);
+  varobj_invalidate (objfile);
 
   /* First do any symbol file specific actions required when we are
      finished with a particular symbol file.  Note that if the objfile
diff --git a/gdb/symfile.c b/gdb/symfile.c
index af1ab74..54d2bad 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -927,6 +927,8 @@ new_symfile_objfile (struct objfile *objfile, int mainline, int verbo)
 
   /* We're done reading the symbol file; finish off complaints.  */
   clear_complaints (&symfile_complaints, 0, verbo);
+
+  varobj_revalidate ();
 }
 
 /* Process a symbol file, as either the main file or as a dynamically
@@ -2341,6 +2343,7 @@ reread_symbols (void)
 	      /* Remove any references to this objfile in the global
 		 value lists.  */
 	      preserve_values (objfile);
+	      varobj_invalidate (objfile);
 
 	      /* Nuke all the state that we will re-read.  Much of the following
 	         code which sets things to NULL really is necessary to tell
@@ -2437,6 +2440,7 @@ reread_symbols (void)
 	         frameless.  */
 
 	      reinit_frame_cache ();
+	      varobj_revalidate ();
 
 	      /* Discard cleanups as symbol reading was successful.  */
 	      discard_cleanups (old_cleanups);
@@ -2817,10 +2821,6 @@ clear_symtab_users (void)
      between expressions and which ought to be reset each time.  */
   expression_context_block = NULL;
   innermost_block = NULL;
-
-  /* Varobj may refer to old symbols, perform a cleanup.  */
-  varobj_invalidate ();
-
 }
 
 static void
diff --git a/gdb/varobj.c b/gdb/varobj.c
index a7957f6..b60b0a8 100644
--- a/gdb/varobj.c
+++ b/gdb/varobj.c
@@ -2748,12 +2748,74 @@ When non-zero, varobj debugging is enabled."),
 			    &setlist, &showlist);
 }
 
-/* Invalidate the varobjs that are tied to locals and re-create the ones that
-   are defined on globals.
+/* Invalidate the varobjs that are tied to the specified OBJFILE.  Call this
+   function before you start removing OBJFILE.
+
+   Call varobj_revalidate after the OBJFILEs updates get finished.
+
    Invalidated varobjs will be always printed in_scope="invalid".  */
 
 void 
-varobj_invalidate (void)
+varobj_invalidate (struct objfile *objfile)
+{
+  struct varobj **all_rootvarobj;
+  struct varobj **varp;
+
+  if (varobj_list (&all_rootvarobj) > 0)
+    {
+      varp = all_rootvarobj;
+      while (*varp != NULL)
+	{
+	  struct varobj *var = *varp;
+
+	  /* Floating varobjs are reparsed on each stop, so we don't care if
+	     the presently parsed expression refers to something that's gone.
+	     */
+	  if (var->root->floating)
+	    continue;
+
+	  if (var->root->valid_block != NULL && var->root->is_valid)
+	    {
+	      struct block *block = var->root->valid_block;
+	      struct symbol *func = block_linkage_function (block);
+	      struct objfile *func_objfile = SYMBOL_SYMTAB (func)->objfile;
+
+	      if (func_objfile == objfile)
+		var->root->is_valid = 0;
+	    }
+	  
+	  if (var->type && TYPE_OBJFILE (var->type) == objfile)
+	    {
+	      if (!var->root->valid_block)
+		var->root->is_valid = 0;
+	      else
+		gdb_assert (!var->root->is_valid);
+
+	      var->type = NULL;
+	    }
+	  if (var->value
+	      && TYPE_OBJFILE (value_type (var->value)) == objfile)
+	    {
+	      if (!var->root->valid_block)
+		var->root->is_valid = 0;
+	      else
+		gdb_assert (!var->root->is_valid);
+
+	      value_free (var->value);
+	      var->value = NULL;
+	    }
+
+	  varp++;
+	}
+    }
+  xfree (all_rootvarobj);
+}
+
+/* Recreate any global varobjs possibly previously invalidated.  If the
+   expressions are no longer evaluatable set/keep the varobj invalid.  */
+
+void 
+varobj_revalidate (void)
 {
   struct varobj **all_rootvarobj;
   struct varobj **varp;
@@ -2763,36 +2825,34 @@ varobj_invalidate (void)
       varp = all_rootvarobj;
       while (*varp != NULL)
 	{
+	  struct varobj *var = *varp;
+
 	  /* Floating varobjs are reparsed on each stop, so we don't care if
 	     the presently parsed expression refers to something that's gone.
 	     */
-	  if ((*varp)->root->floating)
+	  if (var->root->floating)
 	    continue;
 
 	  /* global var must be re-evaluated.  */     
-	  if ((*varp)->root->valid_block == NULL)
+	  if (var->root->valid_block == NULL)
 	    {
 	      struct varobj *tmp_var;
 
 	      /* Try to create a varobj with same expression.  If we succeed
 		 replace the old varobj, otherwise invalidate it.  */
-	      tmp_var = varobj_create (NULL, (*varp)->name, (CORE_ADDR) 0,
-				       USE_CURRENT_FRAME);
+	      tmp_var = varobj_create (NULL, var->name, 0, USE_CURRENT_FRAME);
 	      if (tmp_var != NULL) 
 		{ 
-		  tmp_var->obj_name = xstrdup ((*varp)->obj_name);
-		  varobj_delete (*varp, NULL, 0);
+		  tmp_var->obj_name = xstrdup (var->obj_name);
+		  varobj_delete (var, NULL, 0);
 		  install_variable (tmp_var);
 		}
 	      else
-		(*varp)->root->is_valid = 0;
+		var->root->is_valid = 0;
 	    }
-	  else /* locals must be invalidated.  */
-	    (*varp)->root->is_valid = 0;
 
 	  varp++;
 	}
     }
   xfree (all_rootvarobj);
-  return;
 }
diff --git a/gdb/varobj.h b/gdb/varobj.h
index f2cdcf8..85f2890 100644
--- a/gdb/varobj.h
+++ b/gdb/varobj.h
@@ -135,7 +135,9 @@ extern int varobj_list (struct varobj ***rootlist);
 extern VEC(varobj_update_result) *varobj_update (struct varobj **varp, 
 						 int explicit);
 
-extern void varobj_invalidate (void);
+extern void varobj_invalidate (struct objfile *objfile);
+
+extern void varobj_revalidate (void);
 
 extern int varobj_editable_p (struct varobj *var);
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]