From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30252 invoked by alias); 14 Feb 2014 08:46:50 -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 30194 invoked by uid 89); 14 Feb 2014 08:46:50 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.3.2 X-HELO: relay1.mentorg.com Received: from relay1.mentorg.com (HELO relay1.mentorg.com) (192.94.38.131) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 14 Feb 2014 08:46:48 +0000 Received: from svr-orw-exc-10.mgc.mentorg.com ([147.34.98.58]) by relay1.mentorg.com with esmtp id 1WEEQ0-0006l1-Rc from Yao_Qi@mentor.com for gdb-patches@sourceware.org; Fri, 14 Feb 2014 00:46:44 -0800 Received: from SVR-ORW-FEM-04.mgc.mentorg.com ([147.34.97.41]) by SVR-ORW-EXC-10.mgc.mentorg.com with Microsoft SMTPSVC(6.0.3790.4675); Fri, 14 Feb 2014 00:46:44 -0800 Received: from qiyao.dyndns.org.dyndns.org (147.34.91.1) by svr-orw-fem-04.mgc.mentorg.com (147.34.97.41) with Microsoft SMTP Server id 14.2.247.3; Fri, 14 Feb 2014 00:46:44 -0800 From: Yao Qi To: Subject: [PATCH 09/12] Delete varobj's children on traceframe is changed. Date: Fri, 14 Feb 2014 08:46:00 -0000 Message-ID: <1392367471-13527-10-git-send-email-yao@codesourcery.com> In-Reply-To: <1392367471-13527-1-git-send-email-yao@codesourcery.com> References: <1392367471-13527-1-git-send-email-yao@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain X-IsSubscribed: yes X-SW-Source: 2014-02/txt/msg00499.txt.bz2 Hi, The memory availability varies on trace frames. When --available-children-only is used, the varobj tree structure changes when trace frame is changed. GDB has to remove varobj's children if it is marked as 'available_children_only'. For example, in traceframe 1, foo.a and foo.c is collected, and in traceframe 2, foo.b is collected, struct foo { int a; /* Collected in traceframe 1 */ int b; /* Collected in traceframe 2 */ int c; /* Collected in traceframe 1 */ }; When available-children-only is used, the expected result is that in traceframe 1, foo has two children (a and c), and foo has one child (b) in traceframe 2. Without this patch, foo has a, b, and c in traceframe 2, which is wrong. In this patch, we install a traceframe_changed observer to clear varobjs marked as 'available_children_only'. V2: - Move common code to varobj_clear_children. - Update comments. gdb: 2014-02-14 Yao Qi * varobj.c: Include "observer.h". (varobj_clear_children): New functiuon. (varobj_set_available_children_only): Move some code to varobj_clear_children. Call varobj_clear_children. (varobj_delete_if_available_children_only): New function. (varobj_traceframe_changed): New function. (_initialize_varobj): Install varobj_traceframe_changed to traceframe_changed observer. --- gdb/varobj.c | 47 +++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 39 insertions(+), 8 deletions(-) diff --git a/gdb/varobj.c b/gdb/varobj.c index bfa6b1d..f0ea383 100644 --- a/gdb/varobj.c +++ b/gdb/varobj.c @@ -24,6 +24,7 @@ #include "gdbcmd.h" #include "block.h" #include "valprint.h" +#include "observer.h" #include "gdb_assert.h" #include @@ -919,6 +920,21 @@ varobj_get_num_children (struct varobj *var) return var->num_children >= 0 ? var->num_children : 0; } +/* Clear children of VAR and stuff needed for iteration over + children. */ + +static void +varobj_clear_children (struct varobj *var) +{ + /* If there are any children now, wipe them. */ + varobj_delete (var, NULL, /* children only */ 1); + var->num_children = -1; + + varobj_iter_delete (var->dynamic->child_iter); + var->dynamic->child_iter = NULL; + varobj_clear_saved_item (var->dynamic); +} + /* Update the field available_children_only of variable object VAR with AVAILABLE_ONLY. */ @@ -927,15 +943,9 @@ varobj_set_available_children_only (struct varobj *var, int available_only) { if (var->dynamic->available_children_only != available_only) { - /* If there are any children now, wipe them. */ - varobj_delete (var, NULL, /* children only */ 1); - var->num_children = -1; - var->dynamic->available_children_only = available_only; + varobj_clear_children (var); - /* We're starting over, so get rid of any iterator. */ - varobj_iter_delete (var->dynamic->child_iter); - var->dynamic->child_iter = NULL; - varobj_clear_saved_item (var->dynamic); + var->dynamic->available_children_only = available_only; } } @@ -2753,6 +2763,25 @@ all_root_varobjs (void (*func) (struct varobj *var, void *data), void *data) (*func) (var_root->rootvar, data); } } + +/* Delete VAR's children if it is marked as 'available_children_only'. */ + +static void +varobj_delete_if_available_children_only (struct varobj *var, void *data) +{ + if (var->dynamic->available_children_only) + varobj_clear_children (var); + +} + +/* The callback installed for traceframe_changed events. */ + +static void +varobj_traceframe_changed (int tfnum, int tpnum) +{ + all_root_varobjs (varobj_delete_if_available_children_only , NULL); +} + extern void _initialize_varobj (void); void @@ -2770,6 +2799,8 @@ _initialize_varobj (void) _("When non-zero, varobj debugging is enabled."), NULL, show_varobjdebug, &setlist, &showlist); + + observer_attach_traceframe_changed (varobj_traceframe_changed); } /* Invalidate varobj VAR if it is tied to locals and re-create it if it is -- 1.7.7.6