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]

[RFA 04/08] multi-process support: Make stop_soon a per-inferior property


This patch makes stop_soon be a per-inferior property, and adjusts
all references to it.

There was one wrinkle to solve --- infrun.c:signal_stop_state referenced the
stop_soon global, because in some cases, like when attaching to a stopped
process in native linux, we always want the core to be notified of signals.

There are two alternatives I can see to adjust this to a multi-process
environment:

  - Either make sure that process of interest is the one selected, and
make signal_stop_state reference stop_soon of the current inferior, or,
  - Move the stop_soon check to the signal_stop_state callers.

I've chosen the latter approach, as I believe such implicit, hidden
references are more surprising.  I think it actually makes the code
clearer to its intent.

-- 
Pedro Alves
2008-09-12  Pedro Alves  <pedro@codesourcery.com>

	Make the stop_soon global be per-inferior instead.

	* infcmd.c (attach_command_post_wait): Adjust.
	(attach_command): Likewise.

	* inferior.h (stop_soon): Delete.
	(struct inferior): Add stop_soon member.

	* infrun.c (stop_soon): Delete.
	(clear_proceed_status, start_remote)
	(fetch_inferior_event, handle_inferior_event): Adjust.
	(signal_stop_state): Don't check stop_soon here.  Check in callers
	instead.
	(save_inferior_status, restore_inferior_status): Adjust.

	* linux-nat.c (linux_nat_resume, linux_nat_wait): Always pass
	signals to common code if starting up the inferior.
	
	* inferior.h (struct inferior_info): Added stop_soon member.
	* inferior.c (add_inferior) Clear stop_soon.

	* mips-tdep.c (heuristic_proc_start): Adjust.
	* nto-procfs.c (procfs_create_inferior): Adjust.
	* solib-irix.c (irix_solib_create_inferior_hook): Adjust.
	* solib-osf.c (osf_solib_create_inferior_hook): Adjust.
	* solib-sunos.c (sunos_solib_create_inferior_hook): Adjust.
	* solib-svr4.c (svr4_solib_create_inferior_hook): Adjust.

	* win32-nat.c (do_initial_win32_stuff): Adjust.

	* alpha-tdep.c (alpha_heuristic_proc_start): Adjust.

---
 gdb/alpha-tdep.c  |    5 ++++-
 gdb/infcmd.c      |    8 ++++++--
 gdb/inferior.c    |    2 ++
 gdb/inferior.h    |    5 +++--
 gdb/infrun.c      |   53 ++++++++++++++++++++++++++++++++++++-----------------
 gdb/linux-nat.c   |   23 +++++++++++++++++++----
 gdb/mips-tdep.c   |    5 ++++-
 gdb/nto-procfs.c  |    1 -
 gdb/solib-irix.c  |    9 +++++++--
 gdb/solib-osf.c   |    6 ++++--
 gdb/solib-sunos.c |    8 ++++++--
 gdb/solib-svr4.c  |    6 ++++--
 gdb/win32-nat.c   |    7 ++++---
 13 files changed, 99 insertions(+), 39 deletions(-)

Index: src/gdb/infcmd.c
===================================================================
--- src.orig/gdb/infcmd.c	2008-09-12 12:27:24.000000000 +0100
+++ src/gdb/infcmd.c	2008-09-12 13:36:49.000000000 +0100
@@ -1956,8 +1956,10 @@ attach_command_post_wait (char *args, in
 {
   char *exec_file;
   char *full_exec_path = NULL;
+  struct inferior *inferior;
 
-  stop_soon = NO_STOP_QUIETLY;
+  inferior = current_inferior ();
+  inferior->stop_soon = NO_STOP_QUIETLY;
 
   /* If no exec file is yet known, try to determine it from the
      process itself.  */
@@ -2087,12 +2089,14 @@ attach_command (char *args, int from_tty
      E.g. Mach 3 or GNU hurd.  */
   if (!target_attach_no_wait)
     {
+      struct inferior *inferior = current_inferior ();
+
       /* Careful here. See comments in inferior.h.  Basically some
 	 OSes don't ignore SIGSTOPs on continue requests anymore.  We
 	 need a way for handle_inferior_event to reset the stop_signal
 	 variable after an attach, and this is what
 	 STOP_QUIETLY_NO_SIGSTOP is for.  */
-      stop_soon = STOP_QUIETLY_NO_SIGSTOP;
+      inferior->stop_soon = STOP_QUIETLY_NO_SIGSTOP;
 
       if (target_can_async_p ())
 	{
Index: src/gdb/inferior.h
===================================================================
--- src.orig/gdb/inferior.h	2008-09-12 12:44:38.000000000 +0100
+++ src/gdb/inferior.h	2008-09-12 13:36:49.000000000 +0100
@@ -339,8 +339,6 @@ enum stop_kind
     STOP_QUIETLY_NO_SIGSTOP
   };
 
-extern enum stop_kind stop_soon;
-
 /* Nonzero if proceed is being used for a "finish" command or a similar
    situation when stop_registers should be saved.  */
 
@@ -410,6 +408,9 @@ struct inferior
   int num;			/* Convenient handle (GDB inferior
 				   id) */
 
+  /* See the definition of stop_kind above.  */
+  enum stop_kind stop_soon;
+
   /* Private data used by the target vector implementation.  */
   struct private_inferior *private;
 };
Index: src/gdb/infrun.c
===================================================================
--- src.orig/gdb/infrun.c	2008-09-12 12:27:24.000000000 +0100
+++ src/gdb/infrun.c	2008-09-12 13:36:49.000000000 +0100
@@ -230,13 +230,6 @@ show_stop_on_solib_events (struct ui_fil
 
 int stop_after_trap;
 
-/* Nonzero means expecting a trap and caller will handle it themselves.
-   It is used after attach, due to attaching to a process;
-   when running in the shell before the child program has been exec'd;
-   and when running some kinds of remote stuff (FIXME?).  */
-
-enum stop_kind stop_soon;
-
 /* Save register contents here when about to pop a stack dummy frame,
    if-and-only-if proceed_to_finish is set.
    Thus this contains the return value from the called function (assuming
@@ -1097,7 +1090,10 @@ clear_proceed_status (void)
 {
   if (!ptid_equal (inferior_ptid, null_ptid))
     {
-      struct thread_info *tp = inferior_thread ();
+      struct thread_info *tp;
+      struct inferior *inferior;
+
+      tp = inferior_thread ();
 
       tp->trap_expected = 0;
       tp->step_range_start = 0;
@@ -1112,10 +1108,12 @@ clear_proceed_status (void)
       /* Discard any remaining commands or status from previous
 	 stop.  */
       bpstat_clear (&tp->stop_bpstat);
+
+      inferior = current_inferior ();
+      inferior->stop_soon = NO_STOP_QUIETLY;
     }
 
   stop_after_trap = 0;
-  stop_soon = NO_STOP_QUIETLY;
   breakpoint_proceeded = 1;	/* We're about to proceed... */
 
   if (stop_registers)
@@ -1351,8 +1349,11 @@ proceed (CORE_ADDR addr, enum target_sig
 void
 start_remote (int from_tty)
 {
+  struct inferior *inferior;
   init_wait_for_inferior ();
-  stop_soon = STOP_QUIETLY_REMOTE;
+
+  inferior = current_inferior ();
+  inferior->stop_soon = STOP_QUIETLY_REMOTE;
 
   /* Always go on waiting for the target, regardless of the mode. */
   /* FIXME: cagney/1999-09-23: At present it isn't possible to
@@ -1652,9 +1653,12 @@ fetch_inferior_event (void *client_data)
 
   if (!ecs->wait_some_more)
     {
+      struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
+
       delete_step_thread_step_resume_breakpoint ();
 
-      if (stop_soon == NO_STOP_QUIETLY)
+      /* We may not find an inferior if this was a process exit.  */
+      if (inf == NULL || inf->stop_soon == NO_STOP_QUIETLY)
 	normal_stop ();
 
       if (target_has_execution
@@ -1844,6 +1848,18 @@ handle_inferior_event (struct execution_
   int stopped_by_watchpoint;
   int stepped_after_stopped_by_watchpoint = 0;
   struct symtab_and_line stop_pc_sal;
+  enum stop_kind stop_soon;
+
+  if (ecs->ws.kind != TARGET_WAITKIND_EXITED
+      && ecs->ws.kind != TARGET_WAITKIND_SIGNALLED
+      && ecs->ws.kind != TARGET_WAITKIND_IGNORE)
+    {
+      struct inferior *inf = find_inferior_pid (ptid_get_pid (ecs->ptid));
+      gdb_assert (inf);
+      stop_soon = inf->stop_soon;
+    }
+  else
+    stop_soon = NO_STOP_QUIETLY;
 
   breakpoint_retire_moribund ();
 
@@ -2673,7 +2689,10 @@ process_event_stop_test:
 	  target_terminal_ours_for_output ();
 	  print_stop_reason (SIGNAL_RECEIVED, ecs->event_thread->stop_signal);
 	}
-      if (signal_stop_state (ecs->event_thread->stop_signal))
+      /* Always stop on signals if we're just gaining control of the
+	 program.  */
+      if (stop_soon != NO_STOP_QUIETLY
+	  || signal_stop_state (ecs->event_thread->stop_signal))
 	{
 	  stop_stepping (ecs);
 	  return;
@@ -3972,9 +3991,7 @@ hook_stop_stub (void *cmd)
 int
 signal_stop_state (int signo)
 {
-  /* Always stop on signals if we're just gaining control of the
-     program.  */
-  return signal_stop[signo] || stop_soon != NO_STOP_QUIETLY;
+  return signal_stop[signo];
 }
 
 int
@@ -4376,6 +4393,7 @@ save_inferior_status (int restore_stack_
 {
   struct inferior_status *inf_status = XMALLOC (struct inferior_status);
   struct thread_info *tp = inferior_thread ();
+  struct inferior *inf = current_inferior ();
 
   inf_status->stop_signal = tp->stop_signal;
   inf_status->stop_pc = stop_pc;
@@ -4388,7 +4406,7 @@ save_inferior_status (int restore_stack_
   inf_status->step_frame_id = tp->step_frame_id;
   inf_status->step_over_calls = tp->step_over_calls;
   inf_status->stop_after_trap = stop_after_trap;
-  inf_status->stop_soon = stop_soon;
+  inf_status->stop_soon = inf->stop_soon;
   /* Save original bpstat chain here; replace it with copy of chain.
      If caller's caller is walking the chain, they'll be happier if we
      hand them back the original chain when restore_inferior_status is
@@ -4430,6 +4448,7 @@ void
 restore_inferior_status (struct inferior_status *inf_status)
 {
   struct thread_info *tp = inferior_thread ();
+  struct inferior *inf = current_inferior ();
 
   tp->stop_signal = inf_status->stop_signal;
   stop_pc = inf_status->stop_pc;
@@ -4442,7 +4461,7 @@ restore_inferior_status (struct inferior
   tp->step_frame_id = inf_status->step_frame_id;
   tp->step_over_calls = inf_status->step_over_calls;
   stop_after_trap = inf_status->stop_after_trap;
-  stop_soon = inf_status->stop_soon;
+  inf->stop_soon = inf_status->stop_soon;
   bpstat_clear (&tp->stop_bpstat);
   tp->stop_bpstat = inf_status->stop_bpstat;
   breakpoint_proceeded = inf_status->breakpoint_proceeded;
Index: src/gdb/linux-nat.c
===================================================================
--- src.orig/gdb/linux-nat.c	2008-09-12 12:45:09.000000000 +0100
+++ src/gdb/linux-nat.c	2008-09-12 13:36:49.000000000 +0100
@@ -1708,9 +1708,17 @@ linux_nat_resume (ptid_t ptid, int step,
 
   if (lp->status && WIFSTOPPED (lp->status))
     {
-      int saved_signo = target_signal_from_host (WSTOPSIG (lp->status));
+      int saved_signo;
+      struct inferior *inf;
 
-      if (signal_stop_state (saved_signo) == 0
+      inf = find_inferior_pid (ptid_get_pid (ptid));
+      gdb_assert (inf);
+      saved_signo = target_signal_from_host (WSTOPSIG (lp->status));
+
+      /* Defer to common code if we're gaining control of the
+	 inferior.  */
+      if (inf->stop_soon == NO_STOP_QUIETLY
+	  && signal_stop_state (saved_signo) == 0
 	  && signal_print_state (saved_signo) == 0
 	  && signal_pass_state (saved_signo) == 1)
 	{
@@ -2926,10 +2934,17 @@ retry:
   if (WIFSTOPPED (status))
     {
       int signo = target_signal_from_host (WSTOPSIG (status));
+      struct inferior *inf;
 
-      /* If we get a signal while single-stepping, we may need special
-	 care, e.g. to skip the signal handler.  Defer to common code.  */
+      inf = find_inferior_pid (ptid_get_pid (lp->ptid));
+      gdb_assert (inf);
+
+      /* Defer to common code if we get a signal while
+	 single-stepping, since that may need special care, e.g. to
+	 skip the signal handler, or, if we're gaining control of the
+	 inferior.  */
       if (!lp->step
+	  && inf->stop_soon == NO_STOP_QUIETLY
 	  && signal_stop_state (signo) == 0
 	  && signal_print_state (signo) == 0
 	  && signal_pass_state (signo) == 1)
Index: src/gdb/inferior.c
===================================================================
--- src.orig/gdb/inferior.c	2008-09-12 12:39:51.000000000 +0100
+++ src/gdb/inferior.c	2008-09-12 13:36:49.000000000 +0100
@@ -76,6 +76,8 @@ add_inferior_silent (int pid)
   memset (inf, 0, sizeof (*inf));
   inf->pid = pid;
 
+  inf->stop_soon = NO_STOP_QUIETLY;
+
   inf->num = ++highest_inferior_num;
   inf->next = inferior_list;
   inferior_list = inf;
Index: src/gdb/mips-tdep.c
===================================================================
--- src.orig/gdb/mips-tdep.c	2008-09-12 12:27:24.000000000 +0100
+++ src/gdb/mips-tdep.c	2008-09-12 13:36:49.000000000 +0100
@@ -2493,6 +2493,7 @@ heuristic_proc_start (struct gdbarch *gd
   CORE_ADDR fence;
   int instlen;
   int seen_adjsp = 0;
+  struct inferior *inf;
 
   pc = gdbarch_addr_bits_remove (gdbarch, pc);
   start_pc = pc;
@@ -2505,6 +2506,8 @@ heuristic_proc_start (struct gdbarch *gd
 
   instlen = mips_pc_is_mips16 (pc) ? MIPS_INSN16_SIZE : MIPS_INSN32_SIZE;
 
+  inf = current_inferior ();
+
   /* search back for previous return */
   for (start_pc -= instlen;; start_pc -= instlen)
     if (start_pc < fence)
@@ -2513,7 +2516,7 @@ heuristic_proc_start (struct gdbarch *gd
 	   stop_soon, but with this test, at least we
 	   don't print out warnings for every child forked (eg, on
 	   decstation).  22apr93 rich@cygnus.com.  */
-	if (stop_soon == NO_STOP_QUIETLY)
+	if (inf->stop_soon == NO_STOP_QUIETLY)
 	  {
 	    static int blurb_printed = 0;
 
Index: src/gdb/nto-procfs.c
===================================================================
--- src.orig/gdb/nto-procfs.c	2008-09-12 12:45:09.000000000 +0100
+++ src/gdb/nto-procfs.c	2008-09-12 13:36:49.000000000 +0100
@@ -1101,7 +1101,6 @@ procfs_create_inferior (char *exec_file,
   if (exec_bfd != NULL
       || (symfile_objfile != NULL && symfile_objfile->obfd != NULL))
     solib_create_inferior_hook ();
-  stop_soon = 0;
 }
 
 static void
Index: src/gdb/solib-irix.c
===================================================================
--- src.orig/gdb/solib-irix.c	2008-09-12 12:27:24.000000000 +0100
+++ src/gdb/solib-irix.c	2008-09-12 13:36:49.000000000 +0100
@@ -422,6 +422,7 @@ enable_break (void)
 static void
 irix_solib_create_inferior_hook (void)
 {
+  struct inferior *inf;
   struct thread_info *tp;
 
   if (!enable_break ())
@@ -435,10 +436,14 @@ irix_solib_create_inferior_hook (void)
      can go groveling around in the dynamic linker structures to find
      out what we need to know about them. */
 
+  inf = current_inferior ();
   tp = inferior_thread ();
+
   clear_proceed_status ();
-  stop_soon = STOP_QUIETLY;
+
+  inf->stop_soon = STOP_QUIETLY;
   tp->stop_signal = TARGET_SIGNAL_0;
+
   do
     {
       target_resume (pid_to_ptid (-1), 0, tp->stop_signal);
@@ -463,7 +468,7 @@ irix_solib_create_inferior_hook (void)
      Delaying the resetting of stop_soon until after symbol loading
      suppresses the warning.  */
   solib_add ((char *) 0, 0, (struct target_ops *) 0, auto_solib_add);
-  stop_soon = NO_STOP_QUIETLY;
+  inf->stop_soon = NO_STOP_QUIETLY;
 }
 
 /* LOCAL FUNCTION
Index: src/gdb/solib-osf.c
===================================================================
--- src.orig/gdb/solib-osf.c	2008-09-12 12:27:24.000000000 +0100
+++ src/gdb/solib-osf.c	2008-09-12 13:36:49.000000000 +0100
@@ -307,6 +307,7 @@ osf_clear_solib (void)
 static void
 osf_solib_create_inferior_hook (void)
 {
+  struct inferior *inf;
   struct thread_info *tp;
 
   /* If we are attaching to the inferior, the shared libraries
@@ -333,9 +334,10 @@ osf_solib_create_inferior_hook (void)
   if (!target_can_run (&current_target))
     return;
 
+  inf = current_inferior ();
   tp = inferior_thread ();
   clear_proceed_status ();
-  stop_soon = STOP_QUIETLY;
+  inf->stop_soon = STOP_QUIETLY;
   tp->stop_signal = TARGET_SIGNAL_0;
   do
     {
@@ -351,7 +353,7 @@ osf_solib_create_inferior_hook (void)
      Delaying the resetting of stop_soon until after symbol loading
      suppresses the warning.  */
   solib_add ((char *) 0, 0, (struct target_ops *) 0, auto_solib_add);
-  stop_soon = NO_STOP_QUIETLY;
+  inf->stop_soon = NO_STOP_QUIETLY;
 }
 
 /* target_so_ops callback.  Do additional symbol handling, lookup, etc. after
Index: src/gdb/solib-sunos.c
===================================================================
--- src.orig/gdb/solib-sunos.c	2008-09-12 12:27:24.000000000 +0100
+++ src/gdb/solib-sunos.c	2008-09-12 13:36:49.000000000 +0100
@@ -739,6 +739,7 @@ static void
 sunos_solib_create_inferior_hook (void)
 {
   struct thread_info *tp;
+  struct inferior *inf;
 
   if ((debug_base = locate_base ()) == 0)
     {
@@ -761,9 +762,12 @@ sunos_solib_create_inferior_hook (void)
      can go groveling around in the dynamic linker structures to find
      out what we need to know about them. */
 
+  inf = current_inferior ();
   tp = inferior_thread ();
+
   clear_proceed_status ();
-  stop_soon = STOP_QUIETLY;
+
+  inf->stop_soon = STOP_QUIETLY;
   tp->stop_signal = TARGET_SIGNAL_0;
   do
     {
@@ -771,7 +775,7 @@ sunos_solib_create_inferior_hook (void)
       wait_for_inferior (0);
     }
   while (tp->stop_signal != TARGET_SIGNAL_TRAP);
-  stop_soon = NO_STOP_QUIETLY;
+  inf->stop_soon = NO_STOP_QUIETLY;
 
   /* We are now either at the "mapping complete" breakpoint (or somewhere
      else, a condition we aren't prepared to deal with anyway), so adjust
Index: src/gdb/solib-svr4.c
===================================================================
--- src.orig/gdb/solib-svr4.c	2008-09-12 12:27:24.000000000 +0100
+++ src/gdb/solib-svr4.c	2008-09-12 13:36:49.000000000 +0100
@@ -1570,6 +1570,7 @@ svr4_relocate_main_executable (void)
 static void
 svr4_solib_create_inferior_hook (void)
 {
+  struct inferior *inf;
   struct thread_info *tp;
 
   /* Relocate the main executable if necessary.  */
@@ -1591,10 +1592,11 @@ svr4_solib_create_inferior_hook (void)
      can go groveling around in the dynamic linker structures to find
      out what we need to know about them. */
 
+  inf = current_inferior ();
   tp = inferior_thread ();
 
   clear_proceed_status ();
-  stop_soon = STOP_QUIETLY;
+  inf->stop_soon = STOP_QUIETLY;
   tp->stop_signal = TARGET_SIGNAL_0;
   do
     {
@@ -1602,7 +1604,7 @@ svr4_solib_create_inferior_hook (void)
       wait_for_inferior (0);
     }
   while (tp->stop_signal != TARGET_SIGNAL_TRAP);
-  stop_soon = NO_STOP_QUIETLY;
+  inf->stop_soon = NO_STOP_QUIETLY;
 #endif /* defined(_SCO_DS) */
 }
 
Index: src/gdb/win32-nat.c
===================================================================
--- src.orig/gdb/win32-nat.c	2008-09-12 12:45:09.000000000 +0100
+++ src/gdb/win32-nat.c	2008-09-12 13:36:49.000000000 +0100
@@ -1523,6 +1523,7 @@ do_initial_win32_stuff (DWORD pid)
 {
   extern int stop_after_trap;
   int i;
+  struct inferior *inf;
   struct thread_info *tp;
 
   last_sig = TARGET_SIGNAL_0;
@@ -1544,12 +1545,12 @@ do_initial_win32_stuff (DWORD pid)
   clear_proceed_status ();
   init_wait_for_inferior ();
 
-  add_inferior (pid);
+  inf = add_inferior (pid);
 
   terminal_init_inferior_with_pgrp (pid);
   target_terminal_inferior ();
 
-  stop_soon = STOP_QUIETLY;
+  inf->stop_soon = STOP_QUIETLY;
   while (1)
     {
       stop_after_trap = 1;
@@ -1561,7 +1562,7 @@ do_initial_win32_stuff (DWORD pid)
 	break;
     }
 
-  stop_soon = NO_STOP_QUIETLY;
+  inf->stop_soon = NO_STOP_QUIETLY;
   stop_after_trap = 0;
   return;
 }
Index: src/gdb/alpha-tdep.c
===================================================================
--- src.orig/gdb/alpha-tdep.c	2008-09-12 12:27:24.000000000 +0100
+++ src/gdb/alpha-tdep.c	2008-09-12 13:36:49.000000000 +0100
@@ -909,6 +909,7 @@ alpha_heuristic_proc_start (struct gdbar
   CORE_ADDR fence = pc - heuristic_fence_post;
   CORE_ADDR orig_pc = pc;
   CORE_ADDR func;
+  struct inferior *inf;
 
   if (pc == 0)
     return 0;
@@ -946,10 +947,12 @@ alpha_heuristic_proc_start (struct gdbar
 	}
     }
 
+  inf = current_inferior ();
+
   /* It's not clear to me why we reach this point when stopping quietly,
      but with this test, at least we don't print out warnings for every
      child forked (eg, on decstation).  22apr93 rich@cygnus.com.  */
-  if (stop_soon == NO_STOP_QUIETLY)
+  if (inf->stop_soon == NO_STOP_QUIETLY)
     {
       static int blurb_printed = 0;
 

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