[rfc] [7/7] infrun cleanup: the rest

Ulrich Weigand uweigand@de.ibm.com
Sun Dec 7 00:21:00 GMT 2008


Hello,

the only remaining members of struct execution_control_state are now
ptid and ws -- the two "input arguments" to handle_inferior_event.

This patch changes the interface of handle_inferior_event to explicitly
take those two values as arguments instead of ECS, and updates the
callers accordingly.

Bye,
Ulrich


ChangeLog:

	* infrun.c (struct execution_control_state): Remove.
	(handle_inferior_event): Replace ECS argument by PTID and WS
	arguments.  Use PTID instead of ECS->PTID and WS instead of
	&ECS->WS.
	(infrun_thread_stop_requested_callback): Update call.
	(wait_for_inferior): Likewise.
	(fetch_inferior_event): Likewise.


Index: gdb-head/gdb/infrun.c
===================================================================
--- gdb-head.orig/gdb/infrun.c
+++ gdb-head/gdb/infrun.c
@@ -1561,15 +1561,7 @@ ptid_t waiton_ptid;
 /* Current inferior wait state.  */
 enum infwait_states infwait_state;
 
-/* Data to be passed around while handling an event.  This data is
-   discarded between events.  */
-struct execution_control_state
-{
-  ptid_t ptid;
-  struct target_waitstatus ws;
-};
-
-static int handle_inferior_event (struct execution_control_state *ecs);
+static int handle_inferior_event (ptid_t ptid, struct target_waitstatus *ws);
 
 static int handle_step_into_function (struct thread_info *tp,
 				      CORE_ADDR, CORE_ADDR);
@@ -1605,10 +1597,7 @@ infrun_thread_stop_requested_callback (s
       && !is_executing (info->ptid))
     {
       struct cleanup *old_chain;
-      struct execution_control_state ecss;
-      struct execution_control_state *ecs = &ecss;
-
-      memset (ecs, 0, sizeof (*ecs));
+      struct target_waitstatus ws;
 
       old_chain = make_cleanup_restore_current_thread ();
 
@@ -1617,11 +1606,11 @@ infrun_thread_stop_requested_callback (s
       /* Go through handle_inferior_event/normal_stop, so we always
 	 have consistent output as if the stop event had been
 	 reported.  */
-      ecs->ptid = info->ptid;
-      ecs->ws.kind = TARGET_WAITKIND_STOPPED;
-      ecs->ws.value.sig = TARGET_SIGNAL_0;
+      memset (&ws, 0, sizeof (ws));
+      ws.kind = TARGET_WAITKIND_STOPPED;
+      ws.value.sig = TARGET_SIGNAL_0;
 
-      if (!handle_inferior_event (ecs))
+      if (!handle_inferior_event (info->ptid, &ws))
 	{
 	  struct thread_info *tp;
 
@@ -1733,8 +1722,6 @@ void
 wait_for_inferior (void)
 {
   struct cleanup *old_cleanups;
-  struct execution_control_state ecss;
-  struct execution_control_state *ecs;
 
   if (debug_infrun)
     fprintf_unfiltered (gdb_stdlog, "infrun: wait_for_inferior\n");
@@ -1742,14 +1729,14 @@ wait_for_inferior (void)
   old_cleanups =
     make_cleanup (delete_step_thread_step_resume_breakpoint_cleanup, NULL);
 
-  ecs = &ecss;
-  memset (ecs, 0, sizeof (*ecs));
-
   /* We'll update this if & when we switch to a new thread.  */
   previous_inferior_ptid = inferior_ptid;
 
   while (1)
     {
+      ptid_t ptid;
+      struct target_waitstatus ws;
+
       /* 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
@@ -1759,13 +1746,15 @@ wait_for_inferior (void)
       overlay_cache_invalid = 1;
       registers_changed ();
 
+      memset (&ws, 0, sizeof (ws));
+
       if (deprecated_target_wait_hook)
-	ecs->ptid = deprecated_target_wait_hook (waiton_ptid, &ecs->ws);
+	ptid = deprecated_target_wait_hook (waiton_ptid, &ws);
       else
-	ecs->ptid = target_wait (waiton_ptid, &ecs->ws);
+	ptid = target_wait (waiton_ptid, &ws);
 
       /* Now figure out what to do with the result of the result.  */
-      if (!handle_inferior_event (ecs))
+      if (!handle_inferior_event (ptid, &ws))
 	break;
     }
 
@@ -1784,13 +1773,11 @@ wait_for_inferior (void)
 void
 fetch_inferior_event (void *client_data)
 {
-  struct execution_control_state ecss;
-  struct execution_control_state *ecs = &ecss;
+  ptid_t ptid;
+  struct target_waitstatus ws;
   struct cleanup *old_chain = make_cleanup (null_cleanup, NULL);
   int was_sync = sync_execution;
 
-  memset (ecs, 0, sizeof (*ecs));
-
   /* We'll update this if & when we switch to a new thread.  */
   previous_inferior_ptid = inferior_ptid;
 
@@ -1810,23 +1797,24 @@ fetch_inferior_event (void *client_data)
   overlay_cache_invalid = 1;
   registers_changed ();
 
+  memset (&ws, 0, sizeof (ws));
+
   if (deprecated_target_wait_hook)
-    ecs->ptid =
-      deprecated_target_wait_hook (waiton_ptid, &ecs->ws);
+    ptid = deprecated_target_wait_hook (waiton_ptid, &ws);
   else
-    ecs->ptid = target_wait (waiton_ptid, &ecs->ws);
+    ptid = target_wait (waiton_ptid, &ws);
 
   if (non_stop
-      && ecs->ws.kind != TARGET_WAITKIND_IGNORE
-      && ecs->ws.kind != TARGET_WAITKIND_EXITED
-      && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED)
+      && ws.kind != TARGET_WAITKIND_IGNORE
+      && ws.kind != TARGET_WAITKIND_EXITED
+      && ws.kind != TARGET_WAITKIND_SIGNALLED)
     /* In non-stop mode, each thread is handled individually.  Switch
        early, so the global state is set correctly for this
        thread.  */
-    context_switch (ecs->ptid);
+    context_switch (ptid);
 
   /* Now figure out what to do with the result of the result.  */
-  if (!handle_inferior_event (ecs))
+  if (!handle_inferior_event (ptid, &ws))
     {
       struct inferior *inf = current_inferior ();
 
@@ -1837,8 +1825,8 @@ fetch_inferior_event (void *client_data)
 	normal_stop ();
 
       if (target_has_execution
-	  && ecs->ws.kind != TARGET_WAITKIND_EXITED
-	  && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
+	  && ws.kind != TARGET_WAITKIND_EXITED
+	  && ws.kind != TARGET_WAITKIND_SIGNALLED
 	  && inferior_thread ()->step_multi
 	  && inferior_thread ()->stop_step)
 	inferior_event_handler (INF_EXEC_CONTINUE, NULL);
@@ -2044,7 +2032,7 @@ ensure_not_running (void)
    appropriate action.  */
 
 static int
-handle_inferior_event (struct execution_control_state *ecs)
+handle_inferior_event (ptid_t ptid, struct target_waitstatus *ws)
 {
   int stopped_by_watchpoint;
   int stepped_after_stopped_by_watchpoint = 0;
@@ -2056,11 +2044,11 @@ handle_inferior_event (struct execution_
   int new_thread_event;
   struct thread_info *tp;
 
-  if (ecs->ws.kind != TARGET_WAITKIND_EXITED
-      && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
-      && ecs->ws.kind != TARGET_WAITKIND_IGNORE)
+  if (ws->kind != TARGET_WAITKIND_EXITED
+      && ws->kind != TARGET_WAITKIND_SIGNALLED
+      && ws->kind != TARGET_WAITKIND_IGNORE)
     {
-      struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
+      struct inferior *inf = find_inferior_pid (ptid_get_pid (ptid));
       gdb_assert (inf);
       stop_soon = inf->stop_soon;
     }
@@ -2068,8 +2056,8 @@ handle_inferior_event (struct execution_
     stop_soon = NO_STOP_QUIETLY;
 
   /* Cache the last pid/waitstatus. */
-  target_last_wait_ptid = ecs->ptid;
-  target_last_waitstatus = ecs->ws;
+  target_last_wait_ptid = ptid;
+  target_last_waitstatus = *ws;
 
   /* Always clear state belonging to the previous time we stopped.  */
   stop_stack_dummy = 0;
@@ -2077,33 +2065,33 @@ handle_inferior_event (struct execution_
 
   /* If it's a new process, add it to the thread database */
 
-  new_thread_event = (!ptid_equal (ecs->ptid, inferior_ptid)
-		      && !ptid_equal (ecs->ptid, minus_one_ptid)
-		      && !in_thread_list (ecs->ptid));
-
-  if (ecs->ws.kind != TARGET_WAITKIND_EXITED
-      && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED && new_thread_event)
-    add_thread (ecs->ptid);
+  new_thread_event = (!ptid_equal (ptid, inferior_ptid)
+		      && !ptid_equal (ptid, minus_one_ptid)
+		      && !in_thread_list (ptid));
+
+  if (ws->kind != TARGET_WAITKIND_EXITED
+      && ws->kind != TARGET_WAITKIND_SIGNALLED && new_thread_event)
+    add_thread (ptid);
 
-  tp = find_thread_pid (ecs->ptid);
+  tp = find_thread_pid (ptid);
 
   /* Dependent on valid TP.  */
-  adjust_pc_after_break (tp, &ecs->ws);
+  adjust_pc_after_break (tp, ws);
 
   /* Dependent on the current PC value modified by adjust_pc_after_break.  */
   reinit_frame_cache ();
 
-  if (ecs->ws.kind != TARGET_WAITKIND_IGNORE)
+  if (ws->kind != TARGET_WAITKIND_IGNORE)
     {
       breakpoint_retire_moribund ();
 
       /* Mark the non-executing threads accordingly.  */
       if (!non_stop
- 	  || ecs->ws.kind == TARGET_WAITKIND_EXITED
- 	  || ecs->ws.kind == TARGET_WAITKIND_SIGNALLED)
+ 	  || ws->kind == TARGET_WAITKIND_EXITED
+ 	  || ws->kind == TARGET_WAITKIND_SIGNALLED)
  	set_executing (pid_to_ptid (-1), 0);
       else
- 	set_executing (ecs->ptid, 0);
+ 	set_executing (ptid, 0);
     }
 
   switch (infwait_state)
@@ -2145,7 +2133,7 @@ handle_inferior_event (struct execution_
   infwait_state = infwait_normal_state;
   waiton_ptid = pid_to_ptid (-1);
 
-  switch (ecs->ws.kind)
+  switch (ws->kind)
     {
     case TARGET_WAITKIND_LOADED:
       if (debug_infrun)
@@ -2223,13 +2211,13 @@ handle_inferior_event (struct execution_
       if (debug_infrun)
         fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXITED\n");
       target_terminal_ours ();	/* Must do this before mourn anyway */
-      print_stop_reason (EXITED, ecs->ws.value.integer);
+      print_stop_reason (EXITED, ws->value.integer);
 
       /* Record the exit code in the convenience variable $_exitcode, so
          that the user can inspect this again later.  */
       set_internalvar (lookup_internalvar ("_exitcode"),
 		       value_from_longest (builtin_type_int32,
-					   (LONGEST) ecs->ws.value.integer));
+					   (LONGEST) ws->value.integer));
       gdb_flush (gdb_stdout);
       target_mourn_inferior ();
       singlestep_breakpoints_inserted_p = 0;
@@ -2249,7 +2237,7 @@ handle_inferior_event (struct execution_
          may be needed. */
       target_mourn_inferior ();
 
-      print_stop_reason (SIGNAL_EXITED, ecs->ws.value.sig);
+      print_stop_reason (SIGNAL_EXITED, ws->value.sig);
       singlestep_breakpoints_inserted_p = 0;
       return 0;
 
@@ -2259,20 +2247,20 @@ handle_inferior_event (struct execution_
     case TARGET_WAITKIND_VFORKED:
       if (debug_infrun)
         fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_FORKED\n");
-      pending_follow.kind = ecs->ws.kind;
+      pending_follow.kind = ws->kind;
 
-      pending_follow.fork_event.parent_pid = ecs->ptid;
-      pending_follow.fork_event.child_pid = ecs->ws.value.related_pid;
+      pending_follow.fork_event.parent_pid = ptid;
+      pending_follow.fork_event.child_pid = ws->value.related_pid;
 
-      if (!ptid_equal (ecs->ptid, inferior_ptid))
+      if (!ptid_equal (ptid, inferior_ptid))
 	{
-	  context_switch (ecs->ptid);
+	  context_switch (ptid);
 	  reinit_frame_cache ();
 	}
 
       stop_pc = read_pc ();
 
-      tp->stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid);
+      tp->stop_bpstat = bpstat_stop_status (stop_pc, ptid);
 
       /* If no catchpoint triggered for this, then keep going.  */
       if (!bpstat_explains_signal (tp->stop_bpstat))
@@ -2287,12 +2275,12 @@ handle_inferior_event (struct execution_
       if (debug_infrun)
         fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_EXECD\n");
       pending_follow.execd_pathname =
-	savestring (ecs->ws.value.execd_pathname,
-		    strlen (ecs->ws.value.execd_pathname));
+	savestring (ws->value.execd_pathname,
+		    strlen (ws->value.execd_pathname));
 
-      if (!ptid_equal (ecs->ptid, inferior_ptid))
+      if (!ptid_equal (ptid, inferior_ptid))
 	{
-	  context_switch (ecs->ptid);
+	  context_switch (ptid);
 	  reinit_frame_cache ();
 	}
 
@@ -2304,7 +2292,7 @@ handle_inferior_event (struct execution_
       follow_exec (inferior_ptid, pending_follow.execd_pathname);
       xfree (pending_follow.execd_pathname);
 
-      tp->stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid);
+      tp->stop_bpstat = bpstat_stop_status (stop_pc, ptid);
 
       /* If no catchpoint triggered for this, then keep going.  */
       if (!bpstat_explains_signal (tp->stop_bpstat))
@@ -2331,13 +2319,13 @@ handle_inferior_event (struct execution_
     case TARGET_WAITKIND_SYSCALL_RETURN:
       if (debug_infrun)
         fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_SYSCALL_RETURN\n");
-      target_resume (ecs->ptid, 1, TARGET_SIGNAL_0);
+      target_resume (ptid, 1, TARGET_SIGNAL_0);
       return 1;
 
     case TARGET_WAITKIND_STOPPED:
       if (debug_infrun)
         fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_STOPPED\n");
-      tp->stop_signal = ecs->ws.value.sig;
+      tp->stop_signal = ws->value.sig;
       break;
 
     case TARGET_WAITKIND_NO_HISTORY:
@@ -2381,12 +2369,12 @@ targets should add new threads to the th
       return 1;
     }
 
-  if (ecs->ws.kind == TARGET_WAITKIND_STOPPED)
+  if (ws->kind == TARGET_WAITKIND_STOPPED)
     {
       /* Do we need to clean up the state of a thread that has
 	 completed a displaced single-step?  (Doing so usually affects
 	 the PC, so do it here, before we set stop_pc.)  */
-      displaced_step_fixup (ecs->ptid, tp->stop_signal);
+      displaced_step_fixup (ptid, tp->stop_signal);
 
       /* If we either finished a single-step or hit a breakpoint, but
 	 the user wanted this thread to be stopped, pretend we got a
@@ -2397,13 +2385,13 @@ targets should add new threads to the th
 	tp->stop_signal = TARGET_SIGNAL_0;
     }
 
-  stop_pc = regcache_read_pc (get_thread_regcache (ecs->ptid));
+  stop_pc = regcache_read_pc (get_thread_regcache (ptid));
 
   if (debug_infrun)
     {
       fprintf_unfiltered (gdb_stdlog, "infrun: stop_pc = 0x%s\n",
                           paddr_nz (stop_pc));
-      if (STOPPED_BY_WATCHPOINT (&ecs->ws))
+      if (STOPPED_BY_WATCHPOINT (ws))
 	{
           CORE_ADDR addr;
 	  fprintf_unfiltered (gdb_stdlog, "infrun: stopped by watchpoint\n");
@@ -2421,7 +2409,7 @@ targets should add new threads to the th
   if (stepping_past_singlestep_breakpoint)
     {
       gdb_assert (singlestep_breakpoints_inserted_p);
-      gdb_assert (ptid_equal (singlestep_ptid, ecs->ptid));
+      gdb_assert (ptid_equal (singlestep_ptid, ptid));
       gdb_assert (!ptid_equal (singlestep_ptid, saved_singlestep_ptid));
 
       stepping_past_singlestep_breakpoint = 0;
@@ -2439,7 +2427,7 @@ targets should add new threads to the th
 
 	  context_switch (saved_singlestep_ptid);
 	  if (deprecated_context_hook)
-	    deprecated_context_hook (pid_to_thread_id (ecs->ptid));
+	    deprecated_context_hook (pid_to_thread_id (ptid));
 
 	  resume (1, TARGET_SIGNAL_0);
 	  return 1;
@@ -2493,7 +2481,7 @@ targets should add new threads to the th
          not see this breakpoint hit when stepping onto breakpoints.  */
       if (regular_breakpoint_inserted_here_p (stop_pc))
 	{
-	  if (!breakpoint_thread_match (stop_pc, ecs->ptid))
+	  if (!breakpoint_thread_match (stop_pc, ptid))
 	    thread_hop_needed = 1;
 	}
       else if (singlestep_breakpoints_inserted_p)
@@ -2503,14 +2491,13 @@ targets should add new threads to the th
 	  gdb_assert (ptid_equal (inferior_ptid, singlestep_ptid));
 	  if (debug_infrun)
 	    fprintf_unfiltered (gdb_stdlog, "infrun: software single step "
-				"trap for %s\n",
-				target_pid_to_str (ecs->ptid));
+				"trap for %s\n", target_pid_to_str (ptid));
 
 	  /* The call to in_thread_list is necessary because PTIDs sometimes
 	     change when we go from single-threaded to multi-threaded.  If
 	     the singlestep_ptid is still in the list, assume that it is
-	     really different from ecs->ptid.  */
-	  if (!ptid_equal (singlestep_ptid, ecs->ptid)
+	     really different from ptid.  */
+	  if (!ptid_equal (singlestep_ptid, ptid)
 	      && in_thread_list (singlestep_ptid))
 	    {
 	      /* If the PC of the thread we were trying to single-step
@@ -2548,8 +2535,8 @@ targets should add new threads to the th
 		    state and continue.  */
                  stop_signal = tp->stop_signal;
                  tp->stop_signal = TARGET_SIGNAL_0;
-                 ecs->ptid = singlestep_ptid;
-                 tp = find_thread_pid (ecs->ptid);
+                 ptid = singlestep_ptid;
+                 tp = find_thread_pid (ptid);
                  tp->stop_signal = stop_signal;
                  stop_pc = new_singlestep_pc;
                }
@@ -2599,14 +2586,14 @@ targets should add new threads to the th
 	    error (_("Cannot step over breakpoint hit in wrong thread"));
 	  else
 	    {			/* Single step */
-	      if (!ptid_equal (inferior_ptid, ecs->ptid))
-		context_switch (ecs->ptid);
+	      if (!ptid_equal (inferior_ptid, ptid))
+		context_switch (ptid);
 
 	      if (!non_stop)
 		{
 		  /* Only need to require the next event from this
 		     thread in all-stop mode.  */
-		  waiton_ptid = ecs->ptid;
+		  waiton_ptid = ptid;
 		  infwait_state = infwait_thread_hop_state;
 		}
 
@@ -2618,15 +2605,15 @@ targets should add new threads to the th
 
   /* See if something interesting happened to the non-current thread.  If
      so, then switch to that thread.  */
-  if (!ptid_equal (ecs->ptid, inferior_ptid))
+  if (!ptid_equal (ptid, inferior_ptid))
     {
       if (debug_infrun)
 	fprintf_unfiltered (gdb_stdlog, "infrun: context switch\n");
 
-      context_switch (ecs->ptid);
+      context_switch (ptid);
 
       if (deprecated_context_hook)
-	deprecated_context_hook (pid_to_thread_id (ecs->ptid));
+	deprecated_context_hook (pid_to_thread_id (ptid));
     }
 
   if (singlestep_breakpoints_inserted_p)
@@ -2639,7 +2626,7 @@ targets should add new threads to the th
   if (stepped_after_stopped_by_watchpoint)
     stopped_by_watchpoint = 0;
   else
-    stopped_by_watchpoint = watchpoints_triggered (&ecs->ws);
+    stopped_by_watchpoint = watchpoints_triggered (ws);
 
   /* If necessary, step over this watchpoint.  We'll be back to display
      it in a moment.  */
@@ -2670,8 +2657,8 @@ targets should add new threads to the th
 	 
       if (!HAVE_STEPPABLE_WATCHPOINT)
 	remove_breakpoints ();
-      target_resume (ecs->ptid, 1, TARGET_SIGNAL_0);	/* Single step */
-      waiton_ptid = ecs->ptid;
+      target_resume (ptid, 1, TARGET_SIGNAL_0);	/* Single step */
+      waiton_ptid = ptid;
       if (HAVE_STEPPABLE_WATCHPOINT)
 	infwait_state = infwait_step_watch_state;
       else
@@ -2805,7 +2792,7 @@ targets should add new threads to the th
 	}
 
       /* See if there is a breakpoint at the current PC.  */
-      tp->stop_bpstat = bpstat_stop_status (stop_pc, ecs->ptid);
+      tp->stop_bpstat = bpstat_stop_status (stop_pc, ptid);
       
       /* Following in case break condition called a
 	 function.  */
@@ -3140,8 +3127,7 @@ infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (
 	    fprintf_unfiltered (gdb_stdlog,
 				"infrun: switching back to stepped thread\n");
 
-	  ecs->ptid = step_tp->ptid;
-	  context_switch (ecs->ptid);
+	  context_switch (step_tp->ptid);
 	  return keep_going (step_tp);
 	}
     }
@@ -3153,7 +3139,7 @@ infrun: BPSTAT_WHAT_SET_LONGJMP_RESUME (
     {
 #if defined(SOLIB_ADD)
       /* Have we reached our destination?  If not, keep going. */
-      if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ecs->ptid), stop_pc))
+      if (SOLIB_IN_DYNAMIC_LINKER (PIDGET (ptid), stop_pc))
 	{
           if (debug_infrun)
 	    fprintf_unfiltered (gdb_stdlog, "infrun: stepping in dynamic linker\n");
-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com



More information about the Gdb-patches mailing list