* gnu-nat.c (gnu_attach): Add process to inferiors table.
authorPedro Alves <palves@redhat.com>
Mon, 22 Sep 2008 15:16:51 +0000 (15:16 +0000)
committerPedro Alves <palves@redhat.com>
Mon, 22 Sep 2008 15:16:51 +0000 (15:16 +0000)
(gnu_detach): Remove it.
* go32-nat.c (go32_create_inferior): Add process to gdb's inferior
table.
* inf-ptrace.c (inf_ptrace_follow_fork): Delete and add inferiors
to inferior table accordingly.
(inf_ptrace_attach): Add new process to inferior table.
(inf_ptrace_detach): Remove it.
* inf-ttrace.c (inf_ttrace_follow_fork): Delete and add inferiors
to inferior table accordingly.
(inf_ttrace_attach): Add process to inferior table.
(inf_ttrace_detach): Remove it.
* linux-fork.c (init_fork_list): Delete any left over inferior.
(linux_fork_mourn_inferior, detach_fork_command): Also delete
processes from inferior list.
* monitor.c (monitor_open): Add process to inferior list.
(monitor_close): Remove it.
* nto-procfs.c (procfs_attach): Add process to inferior list.
Find threads after pushing the target.
(procfs_detach): Remove process from inferior list.
(procfs_create_inferior): Add process to inferior list.
* procfs.c (procfs_detach): Remove process from inferior list.
(do_attach): Add process to inferior list.
* remote-sim.c (sim_create_inferior): Add process to inferior list.
(gdbsim_close): Remove it.
* target.c (generic_mourn_inferior): If inferior_ptid is not
null_ptid, remove the corresponding inferior from inferior list.
* win32-nat.c (do_initial_win32_stuff): Add process to inferior list.
(win32_detach): Remove it.
* linux-nat.c (linux_child_follow_fork): Delete and add inferiors
to inferior list accordingly.
* fork-child.c (fork_inferior): Add process to inferior list.
* corelow.c (CORELOW_PID): Define.
(core_close): Remove core from inferior list.
(core_open): Add it.

16 files changed:
gdb/ChangeLog
gdb/corelow.c
gdb/fork-child.c
gdb/gnu-nat.c
gdb/go32-nat.c
gdb/inf-ptrace.c
gdb/inf-ttrace.c
gdb/linux-fork.c
gdb/linux-nat.c
gdb/monitor.c
gdb/nto-procfs.c
gdb/procfs.c
gdb/remote-sim.c
gdb/target.c
gdb/win32-nat.c
gdb/windows-nat.c

index 8a406dc177698688091c9d6d8bc19afa60f8411d..84bfa92c333fd69edd7db103049fd17087a5a33c 100644 (file)
@@ -1,3 +1,41 @@
+2008-09-22  Pedro Alves  <pedro@codesourcery.com>
+
+       * gnu-nat.c (gnu_attach): Add process to inferiors table.
+       (gnu_detach): Remove it.
+       * go32-nat.c (go32_create_inferior): Add process to gdb's inferior
+       table.
+       * inf-ptrace.c (inf_ptrace_follow_fork): Delete and add inferiors
+       to inferior table accordingly.
+       (inf_ptrace_attach): Add new process to inferior table.
+       (inf_ptrace_detach): Remove it.
+       * inf-ttrace.c (inf_ttrace_follow_fork): Delete and add inferiors
+       to inferior table accordingly.
+       (inf_ttrace_attach): Add process to inferior table.
+       (inf_ttrace_detach): Remove it.
+       * linux-fork.c (init_fork_list): Delete any left over inferior.
+       (linux_fork_mourn_inferior, detach_fork_command): Also delete
+       processes from inferior list.
+       * monitor.c (monitor_open): Add process to inferior list.
+       (monitor_close): Remove it.
+       * nto-procfs.c (procfs_attach): Add process to inferior list.
+       Find threads after pushing the target.
+       (procfs_detach): Remove process from inferior list.
+       (procfs_create_inferior): Add process to inferior list.
+       * procfs.c (procfs_detach): Remove process from inferior list.
+       (do_attach): Add process to inferior list.
+       * remote-sim.c (sim_create_inferior): Add process to inferior list.
+       (gdbsim_close): Remove it.
+       * target.c (generic_mourn_inferior): If inferior_ptid is not
+       null_ptid, remove the corresponding inferior from inferior list.
+       * win32-nat.c (do_initial_win32_stuff): Add process to inferior list.
+       (win32_detach): Remove it.
+       * linux-nat.c (linux_child_follow_fork): Delete and add inferiors
+       to inferior list accordingly.
+       * fork-child.c (fork_inferior): Add process to inferior list.
+       * corelow.c (CORELOW_PID): Define.
+       (core_close): Remove core from inferior list.
+       (core_open): Add it.
+
 2008-09-22  Pedro Alves  <pedro@codesourcery.com>
 
        * inferior.h: Forward declare struct ui_out.
index 2f2e0f501170c288549adf8f14fb8bf78bb07dc7..14868e26570877e8dcec3010dc1d5f336b21b700 100644 (file)
@@ -93,6 +93,9 @@ void _initialize_corelow (void);
 
 struct target_ops core_ops;
 
+/* An arbitrary identifier for the core inferior.  */
+#define CORELOW_PID 1
+
 /* Link a new core_fns into the global core_file_fns list.  Called on gdb
    startup by the _initialize routine in each core file register reader, to
    register information about each format the the reader is prepared to
@@ -197,6 +200,7 @@ core_close (int quitting)
   if (core_bfd)
     {
       inferior_ptid = null_ptid;       /* Avoid confusion from thread stuff */
+      delete_inferior_silent (CORELOW_PID);
 
       /* Clear out solib state while the bfd is still open. See
          comments in clear_solib in solib.c. */
@@ -270,8 +274,7 @@ core_open (char *filename, int from_tty)
   bfd *temp_bfd;
   int scratch_chan;
   int flags;
-  /* An arbitrary identifier for the core inferior.  */
-  int corelow_pid = 1;
+  int corelow_pid = CORELOW_PID;
 
   target_preopen (from_tty);
   if (!filename)
@@ -355,6 +358,8 @@ core_open (char *filename, int from_tty)
   push_target (&core_ops);
   discard_cleanups (old_chain);
 
+  add_inferior_silent (corelow_pid);
+
   /* Do this before acknowledging the inferior, so if
      post_create_inferior throws (can happen easilly if you're loading
      a core file with the wrong exec), we aren't left with threads
index d850792cb6836009f9f3759b6dcd94a3dfe3c668..86c5e9116936e505fa0e68b361280e333f5f900b 100644 (file)
@@ -394,6 +394,8 @@ fork_inferior (char *exec_file_arg, char *allargs, char **env,
 
   init_thread_list ();
 
+  add_inferior (pid);
+
   /* Needed for wait_for_inferior stuff below.  */
   inferior_ptid = pid_to_ptid (pid);
 
index 0c3714214c05d6e0220bc5d035e82693d429c4f6..3753523f9680eafe37e9bbb21b9697432eaa9306 100644 (file)
@@ -2173,6 +2173,8 @@ gnu_attach (char *args, int from_tty)
 
   push_target (&gnu_ops);
 
+  add_inferior (pid);
+
   inf_update_procs (inf);
 
   inferior_ptid = ptid_build (pid, 0, inf_pick_first_thread ());
@@ -2206,6 +2208,8 @@ gnu_attach (char *args, int from_tty)
 static void
 gnu_detach (char *args, int from_tty)
 {
+  int pid;
+
   if (from_tty)
     {
       char *exec_file = get_exec_file (0);
@@ -2217,9 +2221,12 @@ gnu_detach (char *args, int from_tty)
       gdb_flush (gdb_stdout);
     }
 
+  pid = current_inferior->pid;
+
   inf_detach (current_inferior);
 
   inferior_ptid = null_ptid;
+  detach_inferior (pid);
 
   unpush_target (&gnu_ops);    /* Pop out of handling an inferior */
 }
index 88bbddffc779329e697243119c39e53bc5376437..d97830390079ad0d4151f1cf649c0632210f2b5b 100644 (file)
@@ -662,6 +662,8 @@ go32_create_inferior (char *exec_file, char *args, char **env, int from_tty)
 #endif
 
   inferior_ptid = pid_to_ptid (SOME_PID);
+  add_inferior_silent (SOME_PID);
+
   push_target (&go32_ops);
 
   add_thread_silent (inferior_ptid);
index 301d59d58621720eb018dcf883545e8c6b4ca46e..797a70a7ea9a13f4f78f27f8dba3006646d382b1 100644 (file)
@@ -89,11 +89,14 @@ inf_ptrace_follow_fork (struct target_ops *ops, int follow_child)
       if (ptrace (PT_DETACH, pid, (PTRACE_TYPE_ARG3)1, 0) == -1)
        perror_with_name (("ptrace"));
 
+      /* Switch inferior_ptid out of the parent's way.  */
+      inferior_ptid = pid_to_ptid (fpid);
+
       /* Delete the parent.  */
-      delete_thread_silent (last_tp->ptid);
+      detach_inferior (pid);
 
       /* Add the child.  */
-      inferior_ptid = pid_to_ptid (fpid);
+      add_inferior (fpid);
       tp = add_thread_silent (inferior_ptid);
 
       tp->step_resume_breakpoint = step_resume_breakpoint;
@@ -111,6 +114,7 @@ inf_ptrace_follow_fork (struct target_ops *ops, int follow_child)
 
       if (ptrace (PT_DETACH, fpid, (PTRACE_TYPE_ARG3)1, 0) == -1)
        perror_with_name (("ptrace"));
+      detach_inferior (pid);
     }
 
   return 0;
@@ -247,6 +251,8 @@ inf_ptrace_attach (char *args, int from_tty)
 
   inferior_ptid = pid_to_ptid (pid);
 
+  add_inferior (pid);
+
   /* Always add a main thread.  If some target extends the ptrace
      target, it should decorate the ptid later with more info.  */
   add_thread_silent (inferior_ptid);
@@ -307,6 +313,7 @@ inf_ptrace_detach (char *args, int from_tty)
 #endif
 
   inferior_ptid = null_ptid;
+  detach_inferior (pid);
   unpush_target (ptrace_ops_hack);
 }
 
index 5521eab160a81f7d664ff34d5588d2bafa550f62..b34e02e4607521eec714daf8a79b54a30f732d95 100644 (file)
@@ -468,6 +468,7 @@ inf_ttrace_follow_fork (struct target_ops *ops, int follow_child)
       last_tp->step_resume_breakpoint = NULL;
 
       inferior_ptid = ptid_build (fpid, flwpid, 0);
+      add_inferior (fpid);
       detach_breakpoints (pid);
 
       target_terminal_ours ();
@@ -537,8 +538,9 @@ Detaching after fork from child process %ld.\n"), (long)fpid);
 
       /* Delete parent.  */
       delete_thread_silent (ptid_build (pid, lwpid, 0));
+      detach_inferior (pid);
 
-      /* Add child.  inferior_ptid was already set above.  */
+      /* Add child thread.  inferior_ptid was already set above.  */
       ti = add_thread_silent (inferior_ptid);
       ti->private =
        xmalloc (sizeof (struct inf_ttrace_private_thread_info));
@@ -742,6 +744,8 @@ inf_ttrace_attach (char *args, int from_tty)
     perror_with_name (("ttrace"));
   attach_flag = 1;
 
+  add_inferior (pid);
+
   /* Set the initial event mask.  */
   memset (&tte, 0, sizeof (tte));
   tte.tte_events |= TTEVT_EXEC | TTEVT_EXIT | TTEVT_FORK | TTEVT_VFORK;
@@ -796,8 +800,10 @@ inf_ttrace_detach (char *args, int from_tty)
   inf_ttrace_num_lwps = 0;
   inf_ttrace_num_lwps_in_syscall = 0;
 
-  unpush_target (ttrace_ops_hack);
   inferior_ptid = null_ptid;
+  detach_inferior (pid);
+
+  unpush_target (ttrace_ops_hack);
 }
 
 static void
index 443b63de9fb4dde65c31dbb80a8620c883ae78d9..f80fe5fa0a8317d2e5d5d646988a0a1f0d51643e 100644 (file)
@@ -210,6 +210,7 @@ init_fork_list (void)
   for (fp = fork_list; fp; fp = fpnext)
     {
       fpnext = fp->next;
+      delete_inferior (ptid_get_pid (fp->ptid));
       free_fork (fp);
     }
 
@@ -369,6 +370,8 @@ linux_fork_mourn_inferior (void)
      We need to delete that one from the fork_list, and switch
      to the next available fork.  */
   delete_fork (inferior_ptid);
+  /* Delete process from GDB's inferior list.  */
+  delete_inferior (ptid_get_pid (inferior_ptid));
 
   /* There should still be a fork - if there's only one left,
      delete_fork won't remove it, because we haven't updated
@@ -408,6 +411,8 @@ delete_fork_command (char *args, int from_tty)
     printf_filtered (_("Killed %s\n"), target_pid_to_str (ptid));
 
   delete_fork (ptid);
+  /* Delete process from GDB's inferior list.  */
+  delete_inferior (ptid_get_pid (ptid));
 }
 
 static void
@@ -432,6 +437,8 @@ detach_fork_command (char *args, int from_tty)
     printf_filtered (_("Detached %s\n"), target_pid_to_str (ptid));
 
   delete_fork (ptid);
+  /* Delete process from GDB's process table.  */
+  detach_inferior (ptid_get_pid (ptid));
 }
 
 /* Print information about currently known forks.  */
index bbf8fb75fd3b156aef2b07278aefe58ef4f3d5cb..c1cb563d09a0c6bcbfa630f4c35e9dc8ed4e2b28 100644 (file)
@@ -711,6 +711,10 @@ linux_child_follow_fork (struct target_ops *ops, int follow_child)
       else
        {
          struct fork_info *fp;
+
+         /* Add process to GDB's tables.  */
+         add_inferior (child_pid);
+
          /* Retain child fork in ptrace (stopped) state.  */
          fp = find_fork_pid (child_pid);
          if (!fp)
@@ -822,7 +826,10 @@ linux_child_follow_fork (struct target_ops *ops, int follow_child)
         safely resume it.  */
 
       if (has_vforked)
-       linux_parent_pid = parent_pid;
+       {
+         linux_parent_pid = parent_pid;
+         detach_inferior (parent_pid);
+       }
       else if (!detach_fork)
        {
          struct fork_info *fp;
@@ -836,6 +843,7 @@ linux_child_follow_fork (struct target_ops *ops, int follow_child)
        target_detach (NULL, 0);
 
       inferior_ptid = ptid_build (child_pid, child_pid, 0);
+      add_inferior (child_pid);
 
       /* Reinstall ourselves, since we might have been removed in
         target_detach (which does other necessary cleanup).  */
index 69632f6778dc483f3ed6e85bc83c8080171c3a37..c5b0ec669c699580fec8c72837976dbe7ace28d9 100644 (file)
@@ -817,6 +817,7 @@ monitor_open (char *args, struct monitor_ops *mon_ops, int from_tty)
 
   /* Make run command think we are busy...  */
   inferior_ptid = monitor_ptid;
+  add_inferior_silent (ptid_get_pid (inferior_ptid));
   add_thread_silent (inferior_ptid);
 
   /* Give monitor_wait something to read */
@@ -845,6 +846,7 @@ monitor_close (int quitting)
   monitor_desc = NULL;
 
   delete_thread_silent (monitor_ptid);
+  delete_inferior_silent (ptid_get_pid (monitor_ptid));
 }
 
 /* Terminate the open connection to the remote debugger.  Use this
index 23b76ce1b45e12f3e332da2018012d55492e96da..9e569c590af8c9f7e0461bde27a080946adf4c3f 100644 (file)
@@ -535,8 +535,11 @@ procfs_attach (char *args, int from_tty)
       gdb_flush (gdb_stdout);
     }
   inferior_ptid = do_attach (pid_to_ptid (pid));
-  procfs_find_new_threads ();
+  add_inferior (pid);
+
   push_target (&procfs_ops);
+
+  procfs_find_new_threads ();
 }
 
 static void
@@ -770,6 +773,7 @@ static void
 procfs_detach (char *args, int from_tty)
 {
   int siggnal = 0;
+  int pid;
 
   if (from_tty)
     {
@@ -788,9 +792,12 @@ procfs_detach (char *args, int from_tty)
 
   close (ctl_fd);
   ctl_fd = -1;
-  init_thread_list ();
+
+  pid = ptid_get_pid (inferior_ptid);
   inferior_ptid = null_ptid;
   attach_flag = 0;
+  detach_inferior (pid);
+  init_thread_list ();
   unpush_target (&procfs_ops); /* Pop out of handling an inferior.  */
 }
 
@@ -1077,7 +1084,9 @@ procfs_create_inferior (char *exec_file, char *allargs, char **env,
 
   inferior_ptid = do_attach (pid_to_ptid (pid));
 
+  add_inferior (pid);
   attach_flag = 0;
+
   flags = _DEBUG_FLAG_KLC;     /* Kill-on-Last-Close flag.  */
   errn = devctl (ctl_fd, DCMD_PROC_SET_FLAG, &flags, sizeof (flags), 0);
   if (errn != EOK)
index 703415c98f7cab9a26c850d91d5e3cf1d659277b..658ec10f21122af0ae5ed000188fc5f06ef8e748 100644 (file)
@@ -3634,13 +3634,13 @@ static void
 procfs_detach (char *args, int from_tty)
 {
   int sig = 0;
+  int pid = PIDGET (inferior_ptid);
 
   if (args)
     sig = atoi (args);
 
   if (from_tty)
     {
-      int pid = PIDGET (inferior_ptid);
       char *exec_file;
 
       exec_file = get_exec_file (0);
@@ -3655,6 +3655,7 @@ procfs_detach (char *args, int from_tty)
   do_detach (sig);
 
   inferior_ptid = null_ptid;
+  detach_inferior (pid);
   unpush_target (&procfs_ops);
 }
 
@@ -3711,6 +3712,7 @@ do_attach (ptid_t ptid)
   if ((fail = procfs_debug_inferior (pi)) != 0)
     dead_procinfo (pi, "do_attach: failed in procfs_debug_inferior", NOKILL);
 
+  add_inferior (pi->pid);
   /* Let GDB know that the inferior was attached.  */
   attach_flag = 1;
 
index 9d014e16dff3897b6de370ff98234c9bcf74fbc7..673504621fcaefb6856b7c929fcb7735bf1ab6a0 100644 (file)
@@ -480,6 +480,7 @@ gdbsim_create_inferior (char *exec_file, char *args, char **env, int from_tty)
   sim_create_inferior (gdbsim_desc, exec_bfd, argv, env);
 
   inferior_ptid = remote_sim_ptid;
+  add_inferior_silent (ptid_get_pid (inferior_ptid);
   add_thread_silent (inferior_ptid);
 
   target_mark_running (&gdbsim_ops);
@@ -591,6 +592,7 @@ gdbsim_close (int quitting)
   end_callbacks ();
   generic_mourn_inferior ();
   delete_thread_silent (remote_sim_ptid);
+  delete_inferior_silent (ptid_get_pid (remote_sim_ptid));
 }
 
 /* Takes a program previously attached to and detaches it.
index 231a6bb0e929d2108336e1c780b50b3b5dfc796b..2fefa840c3b08b19cb78c67b5ee819232bfa613c 100644 (file)
@@ -2338,8 +2338,17 @@ void
 generic_mourn_inferior (void)
 {
   extern int show_breakpoint_hit_counts;
+  ptid_t ptid;
 
+  ptid = inferior_ptid;
   inferior_ptid = null_ptid;
+
+  if (!ptid_equal (ptid, null_ptid))
+    {
+      int pid = ptid_get_pid (ptid);
+      delete_inferior (pid);
+    }
+
   attach_flag = 0;
   breakpoint_init_inferior (inf_exited);
   registers_changed ();
index 0671470e39193a6c97e92aca0402cd4e607db047..becd3ca8e2b7542bfbe54523089346176707bea3 100644 (file)
@@ -1544,6 +1544,8 @@ do_initial_win32_stuff (DWORD pid)
   clear_proceed_status ();
   init_wait_for_inferior ();
 
+  add_inferior (pid);
+
   terminal_init_inferior_with_pgrp (pid);
   target_terminal_inferior ();
 
@@ -1756,7 +1758,10 @@ win32_detach (char *args, int from_tty)
                         current_event.dwProcessId);
       gdb_flush (gdb_stdout);
     }
+
   inferior_ptid = null_ptid;
+  detach_inferior (current_event.dwProcessId);
+
   unpush_target (&win32_ops);
 }
 
index 0671470e39193a6c97e92aca0402cd4e607db047..becd3ca8e2b7542bfbe54523089346176707bea3 100644 (file)
@@ -1544,6 +1544,8 @@ do_initial_win32_stuff (DWORD pid)
   clear_proceed_status ();
   init_wait_for_inferior ();
 
+  add_inferior (pid);
+
   terminal_init_inferior_with_pgrp (pid);
   target_terminal_inferior ();
 
@@ -1756,7 +1758,10 @@ win32_detach (char *args, int from_tty)
                         current_event.dwProcessId);
       gdb_flush (gdb_stdout);
     }
+
   inferior_ptid = null_ptid;
+  detach_inferior (current_event.dwProcessId);
+
   unpush_target (&win32_ops);
 }
 
This page took 0.036073 seconds and 4 git commands to generate.