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]

[rfc] [2/7] infrun cleanup: miscellaneous cleanups


Hello,

this patch performs a number of cleanups that the follwoing patches
depend upon.  While I think that this patch should have no effect on
GDB behaviour, this is less obviously the case that for the follow-on
patches (which are clearly mechanical changes).  Therefore, I'd 
definitely appreciate feedback in particular on this patch.

The changes are in detail:

* handle_inferior_event is made static.

* prepare_to_wait performs some cleanup in preparation for another
  target_wait call, most notably calling registers_changed.  It does
  this only in infwait_normal_state -- but in those places where
  another infwait_state is chosen, handle_inferior_event actually
  calls registers_changed itself.

  This patch changes wait_for_inferior to *always* invalidate
  registers (and overlay cache state) before every call to target_wait,
  and removes this from prepare_to_wait and handle_inferior_event.

* prepare_to_wait also resets waiton_ptid.  This is moved into
  handle_inferior_event at the place where infwait_state is reset
  (those two globals really should always be set at the same time).

* fetch_inferior_event uses the contents of ecs->ptid and
  ecs->event_thread after handle_inferior_event returns.  As later
  patches will remove those fields, I've replaced them with accessing
  the current inferior -- just like normal_stop, which is called
  by fetch_inferior_event anyway, does as well.

* Finally, some dead code is removed: infrun_thread_stop_requested_callback
  sets ecs->event_thread before calling handle_inferior_event -- which is
  always ignored and re-computed by that routine.  fetch_inferior_event
  performs a check for !ecs->wait_some_more -- immediately after memsetting
  the ecs structure to zero.  And finally handle_step_into_function_backward
  computes the function end-of-prologue address  -- without ever using it.

Bye,
Ulrich


ChangeLog:

	* infrun.c (infrun_thread_stop_requested_callback): Do not set
	ecs->event_thread before calling handle_inferior_event.

	(fetch_inferior_event): Remove check for always-true condition.
	Do not rely on contents of ecs->ptid or ecs->event_thread
	after calling handle_inferior_event.

	(handle_step_into_function_backward): Do not modify (unused)
	ecs->stop_func_start.

	(wait_for_inferior): Invalidate registers and overlay cache
	every time before calling target_wait.
	(handle_inferior_event): Make static. Always reset waiton_ptid.
	Never call registers_changed.
	(prepare_to_wait): Do not invaliate registers or overlay cache
	(moved to wait_for_inferior).  Do not reset waiton_ptid (moved
	to handle_inferior_event).


Index: gdb-head/gdb/infrun.c
===================================================================
--- gdb-head.orig/gdb/infrun.c
+++ gdb-head/gdb/infrun.c
@@ -1581,7 +1581,7 @@ struct execution_control_state
 
 void init_execution_control_state (struct execution_control_state *ecs);
 
-void handle_inferior_event (struct execution_control_state *ecs);
+static void handle_inferior_event (struct execution_control_state *ecs);
 
 static void handle_step_into_function (struct execution_control_state *ecs);
 static void handle_step_into_function_backward (struct execution_control_state *ecs);
@@ -1631,7 +1631,6 @@ infrun_thread_stop_requested_callback (s
 	 have consistent output as if the stop event had been
 	 reported.  */
       ecs->ptid = info->ptid;
-      ecs->event_thread = find_thread_pid (info->ptid);
       ecs->ws.kind = TARGET_WAITKIND_STOPPED;
       ecs->ws.value.sig = TARGET_SIGNAL_0;
 
@@ -1761,21 +1760,20 @@ wait_for_inferior (void)
   ecs = &ecss;
   memset (ecs, 0, sizeof (*ecs));
 
-  overlay_cache_invalid = 1;
-
   /* We'll update this if & when we switch to a new thread.  */
   previous_inferior_ptid = inferior_ptid;
 
-  /* We have to invalidate the registers BEFORE calling target_wait
-     because they can be loaded from the target while in target_wait.
-     This makes remote debugging a bit more efficient for those
-     targets that provide critical registers as part of their normal
-     status mechanism. */
-
-  registers_changed ();
-
   while (1)
     {
+      /* We have to invalidate the registers BEFORE calling target_wait
+	 because they can be loaded from the target while in target_wait.
+	 This makes remote debugging a bit more efficient for those
+	 targets that provide critical registers as part of their normal
+	 status mechanism. */
+
+      overlay_cache_invalid = 1;
+      registers_changed ();
+
       if (deprecated_target_wait_hook)
 	ecs->ptid = deprecated_target_wait_hook (waiton_ptid, &ecs->ws);
       else
@@ -1810,14 +1808,8 @@ fetch_inferior_event (void *client_data)
 
   memset (ecs, 0, sizeof (*ecs));
 
-  overlay_cache_invalid = 1;
-
-  /* We can only rely on wait_for_more being correct before handling
-     the event in all-stop, but previous_inferior_ptid isn't used in
-     non-stop.  */
-  if (!ecs->wait_some_more)
-    /* We'll update this if & when we switch to a new thread.  */
-    previous_inferior_ptid = inferior_ptid;
+  /* We'll update this if & when we switch to a new thread.  */
+  previous_inferior_ptid = inferior_ptid;
 
   if (non_stop)
     /* In non-stop mode, the user/frontend should not notice a thread
@@ -1832,6 +1824,7 @@ fetch_inferior_event (void *client_data)
      targets that provide critical registers as part of their normal
      status mechanism. */
 
+  overlay_cache_invalid = 1;
   registers_changed ();
 
   if (deprecated_target_wait_hook)
@@ -1854,7 +1847,7 @@ fetch_inferior_event (void *client_data)
 
   if (!ecs->wait_some_more)
     {
-      struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
+      struct inferior *inf = current_inferior ();
 
       delete_step_thread_step_resume_breakpoint ();
 
@@ -1865,8 +1858,8 @@ fetch_inferior_event (void *client_data)
       if (target_has_execution
 	  && ecs->ws.kind != TARGET_WAITKIND_EXITED
 	  && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
-	  && ecs->event_thread->step_multi
-	  && ecs->event_thread->stop_step)
+	  && inferior_thread ()->step_multi
+	  && inferior_thread ()->stop_step)
 	inferior_event_handler (INF_EXEC_CONTINUE, NULL);
       else
 	inferior_event_handler (INF_EXEC_COMPLETE, NULL);
@@ -2078,7 +2071,7 @@ ensure_not_running (void)
    by an event from the inferior, figure out what it means and take
    appropriate action.  */
 
-void
+static void
 handle_inferior_event (struct execution_control_state *ecs)
 {
   int sw_single_step_trap_p = 0;
@@ -2141,8 +2134,6 @@ handle_inferior_event (struct execution_
     case infwait_thread_hop_state:
       if (debug_infrun)
         fprintf_unfiltered (gdb_stdlog, "infrun: infwait_thread_hop_state\n");
-      /* Cancel the waiton_ptid. */
-      waiton_ptid = pid_to_ptid (-1);
       break;
 
     case infwait_normal_state:
@@ -2173,7 +2164,9 @@ handle_inferior_event (struct execution_
     default:
       internal_error (__FILE__, __LINE__, _("bad switch"));
     }
+
   infwait_state = infwait_normal_state;
+  waiton_ptid = pid_to_ptid (-1);
 
   switch (ecs->ws.kind)
     {
@@ -2665,7 +2658,6 @@ targets should add new threads to the th
 
 	      ecs->event_thread->stepping_over_breakpoint = 1;
 	      keep_going (ecs);
-	      registers_changed ();
 	      return;
 	    }
 	}
@@ -2732,7 +2724,6 @@ targets should add new threads to the th
 	 
       if (!HAVE_STEPPABLE_WATCHPOINT)
 	remove_breakpoints ();
-      registers_changed ();
       target_resume (ecs->ptid, 1, TARGET_SIGNAL_0);	/* Single step */
       waiton_ptid = ecs->ptid;
       if (HAVE_STEPPABLE_WATCHPOINT)
@@ -3765,14 +3756,7 @@ handle_step_into_function (struct execut
 static void
 handle_step_into_function_backward (struct execution_control_state *ecs)
 {
-  struct symtab *s;
-  struct symtab_and_line stop_func_sal, sr_sal;
-
-  s = find_pc_symtab (stop_pc);
-  if (s && s->language != language_asm)
-    ecs->stop_func_start = gdbarch_skip_prologue (current_gdbarch, 
-						  ecs->stop_func_start);
-
+  struct symtab_and_line stop_func_sal;
   stop_func_sal = find_pc_line (stop_pc, 0);
 
   /* OK, we're just going to keep stepping here.  */
@@ -3998,19 +3982,7 @@ prepare_to_wait (struct execution_contro
 {
   if (debug_infrun)
     fprintf_unfiltered (gdb_stdlog, "infrun: prepare_to_wait\n");
-  if (infwait_state == infwait_normal_state)
-    {
-      overlay_cache_invalid = 1;
-
-      /* We have to invalidate the registers BEFORE calling
-         target_wait because they can be loaded from the target while
-         in target_wait.  This makes remote debugging a bit more
-         efficient for those targets that provide critical registers
-         as part of their normal status mechanism. */
 
-      registers_changed ();
-      waiton_ptid = pid_to_ptid (-1);
-    }
   /* This is the old end of the while loop.  Let everybody know we
      want to wait for the inferior some more and get called again
      soon.  */
-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


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