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]

value_of_root cleanup


This patch, checked in, makes value_of_root handle saving and
restoring selected frame, and frees varobj_update of that burden --
clearly, the function who messes up selected frame should be 
restoring it itself, and not pass that responsibility onto callers.

Note that the code uses deprecated_safe_get_selected_frame, because
some of MI tests try to use -var-update when the target is not running.
Not sure it's a good idea, as MI commands accessing the target generally
don't work if there's no target.

[The gdbthread.h/thread.c part of this patch is checked in as obvious].

- Volodya



Index: gdb/ChangeLog
===================================================================
RCS file: /cvs/src/src/gdb/ChangeLog,v
retrieving revision 1.9245
diff -u -p -r1.9245 ChangeLog
--- gdb/ChangeLog	23 Mar 2008 08:59:19 -0000	1.9245
+++ gdb/ChangeLog	23 Mar 2008 09:52:26 -0000
@@ -1,5 +1,15 @@
 2008-03-23  Vladimir Prus  <vladimir@codesourcery.com>
 
+	* thread.c (make_cleanup_restore_current_thread): Make it
+	globally visible.
+	* gdbthread.h (make_cleanup_restore_current_thread): Declare.
+	* varobj.c (varobj_update): Don't save/restore frame.
+	(c_value_of_root): Save/restore thread and frame here,
+	using make_cleanup_restore_current_thread.
+	* Makefile.in: Update dependecies.
+
+2008-03-23  Vladimir Prus  <vladimir@codesourcery.com>
+
         * varobj.c (struct varobj_root): Clarify
         comment on the frame field.
         (varobj_create): Don't set frame if we have no
Index: gdb/Makefile.in
===================================================================
RCS file: /cvs/src/src/gdb/Makefile.in,v
retrieving revision 1.994
diff -u -p -r1.994 Makefile.in
--- gdb/Makefile.in	21 Mar 2008 17:09:35 -0000	1.994
+++ gdb/Makefile.in	23 Mar 2008 09:52:27 -0000
@@ -2940,7 +2940,8 @@ value.o: value.c $(defs_h) $(gdb_string_
 	$(gdb_assert_h) $(regcache_h) $(block_h) $(dfp_h)
 varobj.o: varobj.c $(defs_h) $(exceptions_h) $(value_h) $(expression_h) \
 	$(frame_h) $(language_h) $(wrapper_h) $(gdbcmd_h) $(block_h) \
-	$(gdb_assert_h) $(gdb_string_h) $(varobj_h) $(vec_h)
+	$(gdb_assert_h) $(gdb_string_h) $(varobj_h) $(vec_h) $(gdbthread_h) \
+	$(inferior_h)
 vaxbsd-nat.o: vaxbsd-nat.c $(defs_h) $(inferior_h) $(regcache_h) $(target_h) \
 	$(vax_tdep_h) $(inf_ptrace_h) $(bsd_kvm_h)
 vax-nat.o: vax-nat.c $(defs_h) $(inferior_h) $(gdb_assert_h) $(vax_tdep_h) \
Index: gdb/gdbthread.h
===================================================================
RCS file: /cvs/src/src/gdb/gdbthread.h,v
retrieving revision 1.21
diff -u -p -r1.21 gdbthread.h
--- gdb/gdbthread.h	21 Mar 2008 15:44:53 -0000	1.21
+++ gdb/gdbthread.h	23 Mar 2008 09:52:27 -0000
@@ -158,4 +158,8 @@ extern int print_thread_events;
 
 extern void print_thread_info (struct ui_out *uiout, int thread);
 
+extern struct cleanup *make_cleanup_restore_current_thread (ptid_t,
+                                                            struct frame_id);
+
+
 #endif /* GDBTHREAD_H */
Index: gdb/thread.c
===================================================================
RCS file: /cvs/src/src/gdb/thread.c,v
retrieving revision 1.64
diff -u -p -r1.64 thread.c
--- gdb/thread.c	21 Mar 2008 15:44:53 -0000	1.64
+++ gdb/thread.c	23 Mar 2008 09:52:27 -0000
@@ -61,8 +61,6 @@ static void info_threads_command (char *
 static void thread_apply_command (char *, int);
 static void restore_current_thread (ptid_t);
 static void prune_threads (void);
-static struct cleanup *make_cleanup_restore_current_thread (ptid_t,
-                                                            struct frame_id);
 
 void
 delete_step_resume_breakpoint (void *arg)
@@ -570,7 +568,7 @@ do_restore_current_thread_cleanup (void 
   xfree (old);
 }
 
-static struct cleanup *
+struct cleanup *
 make_cleanup_restore_current_thread (ptid_t inferior_ptid, 
                                      struct frame_id a_frame_id)
 {
Index: gdb/varobj.c
===================================================================
RCS file: /cvs/src/src/gdb/varobj.c,v
retrieving revision 1.104
diff -u -p -r1.104 varobj.c
--- gdb/varobj.c	23 Mar 2008 08:59:19 -0000	1.104
+++ gdb/varobj.c	23 Mar 2008 09:52:27 -0000
@@ -31,6 +31,8 @@
 
 #include "varobj.h"
 #include "vec.h"
+#include "gdbthread.h"
+#include "inferior.h"
 
 /* Non-zero if we want to see trace of varobj level stuff.  */
 
@@ -1111,7 +1113,6 @@ varobj_update (struct varobj **varp, str
   struct value *new;
   VEC (varobj_p) *stack = NULL;
   VEC (varobj_p) *result = NULL;
-  struct frame_id old_fid;
   struct frame_info *fi;
 
   /* sanity check: have we been passed a pointer?  */
@@ -1130,10 +1131,6 @@ varobj_update (struct varobj **varp, str
 
   if ((*varp)->root->rootvar == *varp)
     {
-      /* Save the selected stack frame, since we will need to change it
-	 in order to evaluate expressions.  */
-      old_fid = get_frame_id (deprecated_safe_get_selected_frame ());
-      
       /* Update the root variable. value_of_root can return NULL
 	 if the variable is no longer around, i.e. we stepped out of
 	 the frame in which a local existed. We are letting the 
@@ -1141,11 +1138,6 @@ varobj_update (struct varobj **varp, str
 	 has changed.  */
       type_changed = 1;
       new = value_of_root (varp, &type_changed);
-
-      /* Restore selected frame.  */
-      fi = frame_find_by_id (old_fid);
-      if (fi)
-	select_frame (fi);
       
       /* If this is a "use_selected_frame" varobj, and its type has changed,
 	 them note that it's changed.  */
@@ -2153,12 +2145,15 @@ c_value_of_root (struct varobj **var_han
   struct varobj *var = *var_handle;
   struct frame_info *fi;
   int within_scope;
-
+  struct cleanup *back_to;
+								 
   /*  Only root variables can be updated... */
   if (!is_root_p (var))
     /* Not a root var */
     return NULL;
 
+  back_to = make_cleanup_restore_current_thread (
+    inferior_ptid, get_frame_id (deprecated_safe_get_selected_frame ()));
 
   /* Determine whether the variable is still around. */
   if (var->root->valid_block == NULL || var->root->use_selected_frame)
@@ -2187,6 +2182,8 @@ c_value_of_root (struct varobj **var_han
       return new_val;
     }
 
+  do_cleanups (back_to);
+
   return NULL;
 }
 

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