From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 53562 invoked by alias); 22 Oct 2019 06:46:26 -0000 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 Received: (qmail 53553 invoked by uid 89); 22 Oct 2019 06:46:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-12.3 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.1 spammy=Destroy, boards, 3236, re-create X-HELO: esa4.mentor.iphmx.com Received: from esa4.mentor.iphmx.com (HELO esa4.mentor.iphmx.com) (68.232.137.252) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 22 Oct 2019 06:46:24 +0000 IronPort-SDR: ZQFr3fOK0fZ79tvPbUEcDUZmur8x65Q5LUxJ/jQRz2ZAhVaRJ7eSTEpvCoNOtBodvYZeH17YCC SPaGfz/dDEywUrwZ4AzPTkyIycPAo3ypykdgn/mTT5OCBG00hvyODAy/T9i7ZOUeqeVJsMbB7q ieCEwnzR8Z8wwojmYzdBvQS9c+ENvv+WUZjBkqVo0dRkMOvrxpPB/ey8HAkrLYPK04A4g5uqdb 0Q3VfJwY7lr7e7rIaeMNboY95t7/JiWMQiFGsvY/MDS8tnYOzrJTcDlBrGnI6YciA0NbonujcK JmU= Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa4.mentor.iphmx.com with ESMTP; 21 Oct 2019 22:46:23 -0800 IronPort-SDR: lr37FsA4/LND++qCM3hV4q2Sbr+3/oGXXHxUtaFupvGUDLmB7xrOp8EWVVlcJ7HxZqm1T/4M+z vFJnSxegJds0UBAx5saln1LUoqUOedf7J4Nv21nQ98hiA9Ve9/WOJGZY0mbz6TEuRAXOTainJY FZz07c2fghQLHg0LpAlB+WsfU0RfB4YXwrDKnbWqn1xT056fI6i/oBmzgL5n1l/ZKjm9hA/7Qf o3KAA/qSdG/1jWnBu8PCoM+6YUvdcGCOJ4UDwH+BWxxAWPhjv8pAlT0Ttsw9Q2MFCJBmCFkD8c Htk= Subject: Re: [PING][PATCH 1/2] Fix varobj updation after symbol removal To: CC: , References: <1571306592-24472-1-git-send-email-Saqlain_Raza@mentor.com> <1571306592-24472-2-git-send-email-Saqlain_Raza@mentor.com> From: Saqlain Raza Message-ID: Date: Tue, 22 Oct 2019 06:46:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <1571306592-24472-2-git-send-email-Saqlain_Raza@mentor.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 7bit Return-Path: saqlain_raza@mentor.com X-SW-Source: 2019-10/txt/msg00780.txt.bz2 Ping ! Thanks, Saqlain On 10/17/19 3:03 PM, Raza, Saqlain wrote: > This problem was observed while loading and unloading symbols using > add-symbol-file and remove-symbol-file. When remove-symbol-file > command is invoked, it calls clear_symtab_users that calls varobj_invalidate > to invalidate variable objects. This function invalidates the varobjs > that are tied to locals and re-create the ones that are defined on > globals. During this re-creation of globals, variable objects are > re-evaluated that can result in new value. But this change is not recorded > and because of this, -var-update for such modified variable objects > gives empty change list. > > Proposed Fix: > ============= > GDB has mechanism of marking varobj's updated if they are set via > varobj_set_value operation. This allows any next -var-update to report > this change. Same approach should be used during varobj invalidation. > If value of newly created varobj is different from previous one, mark it > updated so that -var-update can get this change. > > Variable object invalidation code is cleaned up to avoid using pointers > whose target has been already freed. > > Fix Testing: > =========== > This fix has been regression tested on both simulator and real boards > for x86_64 and arm-none-linux-gnueabi targets. > > 2019-10-17 Saqlain Raza > Taimoor Mirza > Maciej W. Rozycki > > gdb/ > * objfiles.c: Include varobj.h. > (invalidate_objfile_varobj_type_iter): New function. > (free_objfile): Call it. > * varobj.c (varobj_is_valid_p, varobj_set_invalid): New functions. > (varobj_invalidate_iter): Mark re-created global object updated > if its value is different from previous value. > * varobj.h (varobj_is_valid_p, varobj_set_invalid): New > prototypes. > > Signed-off-by: Raza, Saqlain > --- > gdb/ChangeLog | 13 +++++++++++++ > gdb/objfiles.c | 19 +++++++++++++++++++ > gdb/varobj.c | 35 +++++++++++++++++++++++++++++++++++ > gdb/varobj.h | 4 ++++ > 4 files changed, 71 insertions(+) > > diff --git a/gdb/ChangeLog b/gdb/ChangeLog > index ced508f..b92da1b 100644 > --- a/gdb/ChangeLog > +++ b/gdb/ChangeLog > @@ -1,3 +1,16 @@ > +2019-10-17 Saqlain Raza > + Taimoor Mirza > + Maciej W. Rozycki > + > + * objfiles.c: Include varobj.h. > + (invalidate_objfile_varobj_type_iter): New function. > + (free_objfile): Call it. > + * varobj.c (varobj_is_valid_p, varobj_set_invalid): New functions. > + (varobj_invalidate_iter): Mark re-created global object updated > + if its value is different from previous value. > + * varobj.h (varobj_is_valid_p, varobj_set_invalid): New > + prototypes. > + > 2019-10-16 Tom Tromey > > * objfiles.h (struct objfile) : Now const. > diff --git a/gdb/objfiles.c b/gdb/objfiles.c > index f9e7d20..8704814 100644 > --- a/gdb/objfiles.c > +++ b/gdb/objfiles.c > @@ -32,6 +32,7 @@ > #include "bcache.h" > #include "expression.h" > #include "parser-defs.h" > +#include "varobj.h" > > #include > #include > @@ -568,6 +569,21 @@ free_objfile_separate_debug (struct objfile *objfile) > } > } > > +/* Mark the variable object VAR invalid if built upon a type coming from > + the objfile requested, passed as DATA. Also clear the type reference. */ > + > +static void > +invalidate_objfile_varobj_type_iter (struct varobj *var, void *data) > +{ > + struct objfile *objfile = (struct objfile*)data; > + > + if (varobj_is_valid_p (var) && TYPE_OBJFILE (var->type) == objfile) > + { > + varobj_set_invalid (var); > + var->type = NULL; > + } > +} > + > /* Destroy an objfile and all the symtabs and psymtabs under it. */ > > objfile::~objfile () > @@ -613,6 +629,9 @@ objfile::~objfile () > lists. */ > preserve_values (this); > > + /* Varobj may refer to types stored in objfile's obstack. */ > + all_root_varobjs (invalidate_objfile_varobj_type_iter, this); > + > /* It still may reference data modules have associated with the objfile and > the symbol file data. */ > forget_cached_source_info_for_objfile (this); > diff --git a/gdb/varobj.c b/gdb/varobj.c > index 37a522b..f7696e7 100644 > --- a/gdb/varobj.c > +++ b/gdb/varobj.c > @@ -2431,6 +2431,22 @@ varobj_floating_p (const struct varobj *var) > return var->root->floating; > } > > +/* Get the valid flag of varobj VAR. */ > + > +int > +varobj_is_valid_p (struct varobj *var) > +{ > + return var->root->is_valid; > +} > + > +/* Clear the valid flag on varobj VAR. */ > + > +void > +varobj_set_invalid (struct varobj *var) > +{ > + var->root->is_valid = 0; > +} > + > /* Implement the "value_is_changeable_p" varobj callback for most > languages. */ > > @@ -2492,6 +2508,7 @@ varobj_invalidate_iter (struct varobj *var, void *unused) > if (var->root->floating || var->root->valid_block == NULL) > { > struct varobj *tmp_var; > + std::string tmp_var_value, var_value; > > /* Try to create a varobj with same expression. If we succeed > replace the old varobj, otherwise invalidate it. */ > @@ -2500,6 +2517,24 @@ varobj_invalidate_iter (struct varobj *var, void *unused) > if (tmp_var != NULL) > { > tmp_var->obj_name = var->obj_name; > + tmp_var_value = varobj_get_value (tmp_var); > + var_value = varobj_get_value (var); > + > + /* Since varobjs are re-evaluated during creation, there is a > + chance the new value is different from old one. Compare > + old varobj and the newly created varobj and mark varobj > + updated ff new value is different. */ > + if (var_value.empty() && tmp_var_value.empty()) > + ; /* Equal. */ > + else if (var_value.empty() || tmp_var_value.empty()) > + tmp_var->updated = 1; > + else > + { > + /* Mark tmp_var updated if the new value is different. */ > + if (tmp_var_value != var_value) > + tmp_var->updated = 1; > + } > + > varobj_delete (var, 0); > install_variable (tmp_var); > } > diff --git a/gdb/varobj.h b/gdb/varobj.h > index 66db780..0885f70 100644 > --- a/gdb/varobj.h > +++ b/gdb/varobj.h > @@ -323,6 +323,10 @@ extern bool varobj_editable_p (const struct varobj *var); > > extern bool varobj_floating_p (const struct varobj *var); > > +extern int varobj_is_valid_p (struct varobj *var); > + > +extern void varobj_set_invalid (struct varobj *var); > + > extern void varobj_set_visualizer (struct varobj *var, > const char *visualizer); >