[commit] selected_frame and flush_cached_frames cleanups

Daniel Jacobowitz drow@false.org
Wed Feb 28 17:37:00 GMT 2007


Two small cleanups:

Now that there are no accesses to selected_frame except through
get_selected_frame, it's never necessary to call select_frame
(get_current_frame ()) if you reinitialize the frame cache.  It will
happen automatically when it's needed.

And given that, reinit_frame_cache and flush_cached_frames were
exactly the same, so I eliminated flush_cached_frames (fewer call
sites).

Tested on x86_64-pc-linux-gnu and checked in.

-- 
Daniel Jacobowitz
CodeSourcery

2007-02-28  Daniel Jacobowitz  <dan@codesourcery.com>

	* frame.c (frame_pop, frame_observer_target_changed): Call
	reinit_frame_cache.
	(flush_cached_frames): Rename to reinit_frame_cache and delete
	old implementation.
	* frame.h (flush_cached_frames): Delete prototype and update comment.

	* bsd-kvm.c (bsd_kvm_open, bsd_kvm_proc_cmd, bsd_kvm_pcb_cmd): Call
	reinit_frame_cache instead of flush_cached_frames.  Do not call
	select_frame after reinit_frame_cache.
	* corelow.c (core_open): Likewise.
	* gdbarch.sh (deprecated_current_gdbarch_select_hack): Likewise.
	* infrun.c (prepare_to_proceed, context_switch)
	(handle_inferior_event): Likewise.
	* linux-fork.c (fork_load_infrun_state): Likewise.
	* ocd.c (ocd_start_remote): Likewise.
	* remote-e7000.c (e7000_start_remote): Likewise.
	* remote-mips.c (device): Likewise.
	* thread.c (switch_to_thread): Likewise.
	* tracepoint.c (finish_tfind_command): Likewise.
	* gdbarch.c: Regenerated.

Index: bsd-kvm.c
===================================================================
RCS file: /cvs/src/src/gdb/bsd-kvm.c,v
retrieving revision 1.18
diff -u -p -r1.18 bsd-kvm.c
--- bsd-kvm.c	9 Jan 2007 17:58:50 -0000	1.18
+++ bsd-kvm.c	28 Feb 2007 17:16:35 -0000
@@ -93,8 +93,7 @@ bsd_kvm_open (char *filename, int from_t
 
   target_fetch_registers (-1);
 
-  flush_cached_frames ();
-  select_frame (get_current_frame ());
+  reinit_frame_cache ();
   print_stack_frame (get_selected_frame (NULL), -1, 1);
 }
 
@@ -276,8 +275,7 @@ bsd_kvm_proc_cmd (char *arg, int fromtty
 
   target_fetch_registers (-1);
 
-  flush_cached_frames ();
-  select_frame (get_current_frame ());
+  reinit_frame_cache ();
   print_stack_frame (get_selected_frame (NULL), -1, 1);
 }
 
@@ -297,8 +295,7 @@ bsd_kvm_pcb_cmd (char *arg, int fromtty)
 
   target_fetch_registers (-1);
 
-  flush_cached_frames ();
-  select_frame (get_current_frame ());
+  reinit_frame_cache ();
   print_stack_frame (get_selected_frame (NULL), -1, 1);
 }
 
Index: corelow.c
===================================================================
RCS file: /cvs/src/src/gdb/corelow.c,v
retrieving revision 1.57
diff -u -p -r1.57 corelow.c
--- corelow.c	9 Jan 2007 17:58:50 -0000	1.57
+++ corelow.c	28 Feb 2007 17:16:35 -0000
@@ -378,8 +378,7 @@ core_open (char *filename, int from_tty)
       target_fetch_registers (-1);
 
       /* Now, set up the frame cache, and print the top of stack.  */
-      flush_cached_frames ();
-      select_frame (get_current_frame ());
+      reinit_frame_cache ();
       print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC);
     }
   else
Index: frame.c
===================================================================
RCS file: /cvs/src/src/gdb/frame.c,v
retrieving revision 1.222
diff -u -p -r1.222 frame.c
--- frame.c	27 Feb 2007 20:17:18 -0000	1.222
+++ frame.c	28 Feb 2007 17:16:35 -0000
@@ -537,7 +537,7 @@ frame_pop (struct frame_info *this_frame
 
   /* We've made right mess of GDB's local state, just discard
      everything.  */
-  flush_cached_frames ();
+  reinit_frame_cache ();
 }
 
 void
@@ -1070,13 +1070,13 @@ get_next_frame (struct frame_info *this_
 void
 frame_observer_target_changed (struct target_ops *target)
 {
-  flush_cached_frames ();
+  reinit_frame_cache ();
 }
 
 /* Flush the entire frame cache.  */
 
 void
-flush_cached_frames (void)
+reinit_frame_cache (void)
 {
   /* Since we can't really be sure what the first object allocated was */
   obstack_free (&frame_cache_obstack, 0);
@@ -1086,21 +1086,7 @@ flush_cached_frames (void)
   select_frame (NULL);
   annotate_frames_invalid ();
   if (frame_debug)
-    fprintf_unfiltered (gdb_stdlog, "{ flush_cached_frames () }\n");
-}
-
-/* Flush the frame cache, and start a new one if necessary.  */
-
-void
-reinit_frame_cache (void)
-{
-  flush_cached_frames ();
-
-  /* FIXME: The inferior_ptid test is wrong if there is a corefile.  */
-  if (PIDGET (inferior_ptid) != 0)
-    {
-      select_frame (get_current_frame ());
-    }
+    fprintf_unfiltered (gdb_stdlog, "{ reinit_frame_cache () }\n");
 }
 
 /* Find where a register is saved (in memory or another register).
Index: frame.h
===================================================================
RCS file: /cvs/src/src/gdb/frame.h,v
retrieving revision 1.154
diff -u -p -r1.154 frame.h
--- frame.h	27 Feb 2007 20:17:18 -0000	1.154
+++ frame.h	28 Feb 2007 17:16:35 -0000
@@ -225,17 +225,10 @@ extern struct frame_info *get_current_fr
 /* Invalidates the frame cache (this function should have been called
    invalidate_cached_frames).
 
-   FIXME: cagney/2002-11-28: The only difference between
-   flush_cached_frames() and reinit_frame_cache() is that the latter
-   explicitly sets the selected frame back to the current frame -- there
-   isn't any real difference (except that one delays the selection of
-   a new frame).  Code can instead simply rely on get_selected_frame()
-   to reinit the selected frame as needed.  As for invalidating the
-   cache, there should be two methods: one that reverts the thread's
-   selected frame back to current frame (for when the inferior
-   resumes) and one that does not (for when the user modifies the
-   target invalidating the frame cache).  */
-extern void flush_cached_frames (void);
+   FIXME: cagney/2002-11-28: There should be two methods: one that
+   reverts the thread's selected frame back to current frame (for when
+   the inferior resumes) and one that does not (for when the user
+   modifies the target invalidating the frame cache).  */
 extern void reinit_frame_cache (void);
 
 /* On demand, create the selected frame and then return it.  If the
Index: gdbarch.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.c,v
retrieving revision 1.337
diff -u -p -r1.337 gdbarch.c
--- gdbarch.c	8 Feb 2007 21:00:29 -0000	1.337
+++ gdbarch.c	28 Feb 2007 17:16:35 -0000
@@ -4202,7 +4202,7 @@ deprecated_current_gdbarch_select_hack (
   current_gdbarch_swap_out_hack ();
   current_gdbarch_swap_in_hack (new_gdbarch);
   architecture_changed_event ();
-  flush_cached_frames ();
+  reinit_frame_cache ();
 }
 
 extern void _initialize_gdbarch (void);
Index: gdbarch.sh
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.sh,v
retrieving revision 1.375
diff -u -p -r1.375 gdbarch.sh
--- gdbarch.sh	8 Feb 2007 21:00:29 -0000	1.375
+++ gdbarch.sh	28 Feb 2007 17:16:36 -0000
@@ -2241,7 +2241,7 @@ deprecated_current_gdbarch_select_hack (
   current_gdbarch_swap_out_hack ();
   current_gdbarch_swap_in_hack (new_gdbarch);
   architecture_changed_event ();
-  flush_cached_frames ();
+  reinit_frame_cache ();
 }
 
 extern void _initialize_gdbarch (void);
Index: infrun.c
===================================================================
RCS file: /cvs/src/src/gdb/infrun.c,v
retrieving revision 1.221
diff -u -p -r1.221 infrun.c
--- infrun.c	27 Feb 2007 19:46:04 -0000	1.221
+++ infrun.c	28 Feb 2007 17:16:36 -0000
@@ -686,10 +686,9 @@ prepare_to_proceed (void)
 
 	  /* FIXME: This stuff came from switch_to_thread() in
 	     thread.c (which should probably be a public function).  */
-	  flush_cached_frames ();
+	  reinit_frame_cache ();
 	  registers_changed ();
 	  stop_pc = wait_pc;
-	  select_frame (get_current_frame ());
 	}
 
       /* We return 1 to indicate that there is a breakpoint here,
@@ -1157,7 +1156,7 @@ context_switch (struct execution_control
 			 &ecs->current_line, &ecs->current_symtab);
     }
   inferior_ptid = ecs->ptid;
-  flush_cached_frames ();
+  reinit_frame_cache ();
 }
 
 static void
@@ -1304,7 +1303,7 @@ handle_inferior_event (struct execution_
     }
   ecs->infwait_state = infwait_normal_state;
 
-  flush_cached_frames ();
+  reinit_frame_cache ();
 
   /* If it's a new process, add it to the thread database */
 
@@ -1429,7 +1428,7 @@ handle_inferior_event (struct execution_
       if (!ptid_equal (ecs->ptid, inferior_ptid))
 	{
 	  context_switch (ecs);
-	  flush_cached_frames ();
+	  reinit_frame_cache ();
 	}
 
       stop_pc = read_pc ();
@@ -1490,7 +1489,7 @@ handle_inferior_event (struct execution_
       if (!ptid_equal (ecs->ptid, inferior_ptid))
 	{
 	  context_switch (ecs);
-	  flush_cached_frames ();
+	  reinit_frame_cache ();
 	}
 
       /* If no catchpoint triggered for this, then keep going.  */
Index: linux-fork.c
===================================================================
RCS file: /cvs/src/src/gdb/linux-fork.c,v
retrieving revision 1.9
diff -u -p -r1.9 linux-fork.c
--- linux-fork.c	9 Jan 2007 17:58:51 -0000	1.9
+++ linux-fork.c	28 Feb 2007 17:16:36 -0000
@@ -250,10 +250,6 @@ fork_load_infrun_state (struct fork_info
   registers_changed ();
   reinit_frame_cache ();
 
-  /* We must select a new frame before making any inferior calls to
-     avoid warnings.  */
-  select_frame (get_current_frame ());
-
   stop_pc = read_pc ();
   nullify_last_target_wait_ptid ();
 
Index: ocd.c
===================================================================
RCS file: /cvs/src/src/gdb/ocd.c,v
retrieving revision 1.45
diff -u -p -r1.45 ocd.c
--- ocd.c	9 Jan 2007 17:58:55 -0000	1.45
+++ ocd.c	28 Feb 2007 17:16:36 -0000
@@ -223,7 +223,7 @@ ocd_start_remote (void *dummy)
    doesn't happen here (in fact, it may not be possible to get the monitor to
    send the appropriate packet).  */
 
-  flush_cached_frames ();
+  reinit_frame_cache ();
   registers_changed ();
   stop_pc = read_pc ();
   print_stack_frame (get_selected_frame (NULL), 0, SRC_AND_LOC);
Index: remote-e7000.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-e7000.c,v
retrieving revision 1.59
diff -u -p -r1.59 remote-e7000.c
--- remote-e7000.c	9 Jan 2007 17:58:56 -0000	1.59
+++ remote-e7000.c	28 Feb 2007 17:16:36 -0000
@@ -628,7 +628,7 @@ e7000_start_remote (void *dummy)
    that the target is about to print out a status message of some sort.  That
    doesn't happen here. */
 
-  flush_cached_frames ();
+  reinit_frame_cache ();
   registers_changed ();
   stop_pc = read_pc ();
   print_stack_frame (get_selected_frame (NULL), 0, SRC_AND_LOC);
Index: remote-mips.c
===================================================================
RCS file: /cvs/src/src/gdb/remote-mips.c,v
retrieving revision 1.70
diff -u -p -r1.70 remote-mips.c
--- remote-mips.c	9 Jan 2007 17:58:56 -0000	1.70
+++ remote-mips.c	28 Feb 2007 17:16:37 -0000
@@ -1584,7 +1584,7 @@ device is attached to the target board (
      of some sort.  That doesn't happen here (in fact, it may not be
      possible to get the monitor to send the appropriate packet).  */
 
-  flush_cached_frames ();
+  reinit_frame_cache ();
   registers_changed ();
   stop_pc = read_pc ();
   print_stack_frame (get_selected_frame (NULL), 0, SRC_AND_LOC);
Index: thread.c
===================================================================
RCS file: /cvs/src/src/gdb/thread.c,v
retrieving revision 1.50
diff -u -p -r1.50 thread.c
--- thread.c	2 Feb 2007 12:18:37 -0000	1.50
+++ thread.c	28 Feb 2007 17:16:37 -0000
@@ -461,10 +461,9 @@ switch_to_thread (ptid_t ptid)
     return;
 
   inferior_ptid = ptid;
-  flush_cached_frames ();
+  reinit_frame_cache ();
   registers_changed ();
   stop_pc = read_pc ();
-  select_frame (get_current_frame ());
 }
 
 static void
Index: tracepoint.c
===================================================================
RCS file: /cvs/src/src/gdb/tracepoint.c,v
retrieving revision 1.88
diff -u -p -r1.88 tracepoint.c
--- tracepoint.c	9 Jan 2007 17:58:59 -0000	1.88
+++ tracepoint.c	28 Feb 2007 17:16:37 -0000
@@ -1969,9 +1969,8 @@ finish_tfind_command (char **msg,
 	error (_("Bogus reply from target: %s"), reply);
       }
 
-  flush_cached_frames ();
+  reinit_frame_cache ();
   registers_changed ();
-  select_frame (get_current_frame ());
   set_traceframe_num (target_frameno);
   set_tracepoint_num (target_tracept);
   if (target_frameno == -1)



More information about the Gdb-patches mailing list