From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22944 invoked by alias); 11 Apr 2009 10:22:27 -0000 Received: (qmail 22936 invoked by uid 22791); 11 Apr 2009 10:22:26 -0000 X-SWARE-Spam-Status: No, hits=-1.6 required=5.0 tests=AWL,BAYES_00,KAM_STOCKGEN,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mx2.redhat.com (HELO mx2.redhat.com) (66.187.237.31) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 11 Apr 2009 10:22:21 +0000 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n3BAMJPc002279 for ; Sat, 11 Apr 2009 06:22:19 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n3BAMLdU014077 for ; Sat, 11 Apr 2009 06:22:21 -0400 Received: from host0.dyn.jankratochvil.net (sebastian-int.corp.redhat.com [172.16.52.221]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n3BAMI57011790 for ; Sat, 11 Apr 2009 06:22:19 -0400 Received: from host0.dyn.jankratochvil.net (localhost [127.0.0.1]) by host0.dyn.jankratochvil.net (8.14.3/8.14.3) with ESMTP id n3BAMFLp000558 for ; Sat, 11 Apr 2009 12:22:16 +0200 Received: (from jkratoch@localhost) by host0.dyn.jankratochvil.net (8.14.3/8.14.2/Submit) id n3BAMF32000557 for gdb-patches@sourceware.org; Sat, 11 Apr 2009 12:22:15 +0200 Date: Sat, 11 Apr 2009 10:22:00 -0000 From: Jan Kratochvil To: gdb-patches@sourceware.org Subject: [patch] [4/5] Types reference counting [varobj-validation] Message-ID: <20090411102215.GE32624@host0.dyn.jankratochvil.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-04/txt/msg00203.txt.bz2 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 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);