From 7f9f62ba187205cd123fd2e96909e6d19ad708eb Mon Sep 17 00:00:00 2001 From: Pedro Alves Date: Mon, 22 Sep 2008 15:16:51 +0000 Subject: [PATCH] * 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. --- gdb/ChangeLog | 38 ++++++++++++++++++++++++++++++++++++++ gdb/corelow.c | 9 +++++++-- gdb/fork-child.c | 2 ++ gdb/gnu-nat.c | 7 +++++++ gdb/go32-nat.c | 2 ++ gdb/inf-ptrace.c | 11 +++++++++-- gdb/inf-ttrace.c | 10 ++++++++-- gdb/linux-fork.c | 7 +++++++ gdb/linux-nat.c | 10 +++++++++- gdb/monitor.c | 2 ++ gdb/nto-procfs.c | 13 +++++++++++-- gdb/procfs.c | 4 +++- gdb/remote-sim.c | 2 ++ gdb/target.c | 9 +++++++++ gdb/win32-nat.c | 5 +++++ gdb/windows-nat.c | 5 +++++ 16 files changed, 126 insertions(+), 10 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 8a406dc177..84bfa92c33 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,41 @@ +2008-09-22 Pedro Alves + + * 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 * inferior.h: Forward declare struct ui_out. diff --git a/gdb/corelow.c b/gdb/corelow.c index 2f2e0f5011..14868e2657 100644 --- a/gdb/corelow.c +++ b/gdb/corelow.c @@ -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 diff --git a/gdb/fork-child.c b/gdb/fork-child.c index d850792cb6..86c5e91169 100644 --- a/gdb/fork-child.c +++ b/gdb/fork-child.c @@ -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); diff --git a/gdb/gnu-nat.c b/gdb/gnu-nat.c index 0c3714214c..3753523f96 100644 --- a/gdb/gnu-nat.c +++ b/gdb/gnu-nat.c @@ -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 */ } diff --git a/gdb/go32-nat.c b/gdb/go32-nat.c index 88bbddffc7..d978303900 100644 --- a/gdb/go32-nat.c +++ b/gdb/go32-nat.c @@ -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); diff --git a/gdb/inf-ptrace.c b/gdb/inf-ptrace.c index 301d59d586..797a70a7ea 100644 --- a/gdb/inf-ptrace.c +++ b/gdb/inf-ptrace.c @@ -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); } diff --git a/gdb/inf-ttrace.c b/gdb/inf-ttrace.c index 5521eab160..b34e02e460 100644 --- a/gdb/inf-ttrace.c +++ b/gdb/inf-ttrace.c @@ -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 diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c index 443b63de9f..f80fe5fa0a 100644 --- a/gdb/linux-fork.c +++ b/gdb/linux-fork.c @@ -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. */ diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c index bbf8fb75fd..c1cb563d09 100644 --- a/gdb/linux-nat.c +++ b/gdb/linux-nat.c @@ -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). */ diff --git a/gdb/monitor.c b/gdb/monitor.c index 69632f6778..c5b0ec669c 100644 --- a/gdb/monitor.c +++ b/gdb/monitor.c @@ -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 diff --git a/gdb/nto-procfs.c b/gdb/nto-procfs.c index 23b76ce1b4..9e569c590a 100644 --- a/gdb/nto-procfs.c +++ b/gdb/nto-procfs.c @@ -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) diff --git a/gdb/procfs.c b/gdb/procfs.c index 703415c98f..658ec10f21 100644 --- a/gdb/procfs.c +++ b/gdb/procfs.c @@ -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; diff --git a/gdb/remote-sim.c b/gdb/remote-sim.c index 9d014e16df..673504621f 100644 --- a/gdb/remote-sim.c +++ b/gdb/remote-sim.c @@ -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. diff --git a/gdb/target.c b/gdb/target.c index 231a6bb0e9..2fefa840c3 100644 --- a/gdb/target.c +++ b/gdb/target.c @@ -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 (); diff --git a/gdb/win32-nat.c b/gdb/win32-nat.c index 0671470e39..becd3ca8e2 100644 --- a/gdb/win32-nat.c +++ b/gdb/win32-nat.c @@ -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); } diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c index 0671470e39..becd3ca8e2 100644 --- a/gdb/windows-nat.c +++ b/gdb/windows-nat.c @@ -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); } -- 2.34.1