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 09/12] Delete varobj's children on traceframe is changed.


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  <yao@codesourcery.com>

	* 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 <string.h>
@@ -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


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