aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gdb/ChangeLog38
-rw-r--r--gdb/corelow.c9
-rw-r--r--gdb/fork-child.c2
-rw-r--r--gdb/gnu-nat.c7
-rw-r--r--gdb/go32-nat.c2
-rw-r--r--gdb/inf-ptrace.c11
-rw-r--r--gdb/inf-ttrace.c10
-rw-r--r--gdb/linux-fork.c7
-rw-r--r--gdb/linux-nat.c10
-rw-r--r--gdb/monitor.c2
-rw-r--r--gdb/nto-procfs.c13
-rw-r--r--gdb/procfs.c4
-rw-r--r--gdb/remote-sim.c2
-rw-r--r--gdb/target.c9
-rw-r--r--gdb/win32-nat.c5
-rw-r--r--gdb/windows-nat.c5
16 files changed, 126 insertions, 10 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 8a406dc..84bfa92 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,43 @@
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.
Forward declare struct private_inferior.
(struct inferior): New.
diff --git a/gdb/corelow.c b/gdb/corelow.c
index 2f2e0f5..14868e2 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 d850792..86c5e91 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 0c37142..3753523 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 88bbddf..d978303 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 301d59d..797a70a 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 5521eab..b34e02e 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 443b63d..f80fe5f 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 bbf8fb7..c1cb563 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 69632f6..c5b0ec6 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 23b76ce..9e569c5 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 703415c..658ec10 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 9d014e1..6735046 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 231a6bb..2fefa84 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 0671470..becd3ca 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 0671470..becd3ca 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);
}