* [RFA 02/08] multi-process support: all targets manage inferior list
@ 2008-09-12 15:38 Pedro Alves
2008-09-18 22:52 ` Daniel Jacobowitz
0 siblings, 1 reply; 8+ messages in thread
From: Pedro Alves @ 2008-09-12 15:38 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 460 bytes --]
This patch makes all targets (except the remote target, which will be
done later in the series) manage the inferior table. For most targets,
there will ever only be one entry in the table, until they gain support
for multi-process.
Will notice that this colides a bit with the linux-fork.c list of
forks. Over time, I'd like to migrate "info forks" functionality
into the common inferior list. For now, inferiors are listed in
both lists.
--
Pedro Alves
[-- Attachment #2: 002-all_targets_manage_inferiors.diff --]
[-- Type: text/x-diff, Size: 16205 bytes --]
2008-09-12 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.
---
gdb/corelow.c | 9 +++++++--
gdb/fork-child.c | 2 ++
gdb/gnu-nat.c | 7 +++++++
gdb/go32-nat.c | 3 +++
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 +++++
14 files changed, 84 insertions(+), 10 deletions(-)
Index: src/gdb/gnu-nat.c
===================================================================
--- src.orig/gdb/gnu-nat.c 2008-09-11 20:11:32.000000000 +0100
+++ src/gdb/gnu-nat.c 2008-09-11 22:04:05.000000000 +0100
@@ -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: src/gdb/go32-nat.c
===================================================================
--- src.orig/gdb/go32-nat.c 2008-09-11 20:11:32.000000000 +0100
+++ src/gdb/go32-nat.c 2008-09-11 22:00:02.000000000 +0100
@@ -662,6 +662,9 @@ go32_create_inferior (char *exec_file, c
#endif
inferior_ptid = pid_to_ptid (SOME_PID);
+ add_inferior (SOME_PID);
+ add_thread_silent (inferior_ptid);
+
push_target (&go32_ops);
add_thread_silent (inferior_ptid);
Index: src/gdb/inf-ptrace.c
===================================================================
--- src.orig/gdb/inf-ptrace.c 2008-09-11 20:11:32.000000000 +0100
+++ src/gdb/inf-ptrace.c 2008-09-11 22:34:01.000000000 +0100
@@ -89,11 +89,14 @@ inf_ptrace_follow_fork (struct target_op
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_op
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_
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_
#endif
inferior_ptid = null_ptid;
+ detach_inferior (pid);
unpush_target (ptrace_ops_hack);
}
Index: src/gdb/inf-ttrace.c
===================================================================
--- src.orig/gdb/inf-ttrace.c 2008-09-11 20:11:32.000000000 +0100
+++ src/gdb/inf-ttrace.c 2008-09-11 22:40:13.000000000 +0100
@@ -468,6 +468,7 @@ inf_ttrace_follow_fork (struct target_op
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
/* 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_
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_
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: src/gdb/linux-fork.c
===================================================================
--- src.orig/gdb/linux-fork.c 2008-09-11 20:11:32.000000000 +0100
+++ src/gdb/linux-fork.c 2008-09-11 22:36:46.000000000 +0100
@@ -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 fro
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 fro
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: src/gdb/monitor.c
===================================================================
--- src.orig/gdb/monitor.c 2008-09-11 20:11:32.000000000 +0100
+++ src/gdb/monitor.c 2008-09-11 21:58:44.000000000 +0100
@@ -817,6 +817,7 @@ monitor_open (char *args, struct monitor
/* 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: src/gdb/nto-procfs.c
===================================================================
--- src.orig/gdb/nto-procfs.c 2008-09-11 20:11:32.000000000 +0100
+++ src/gdb/nto-procfs.c 2008-09-11 22:44:25.000000000 +0100
@@ -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,
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: src/gdb/procfs.c
===================================================================
--- src.orig/gdb/procfs.c 2008-09-11 20:11:32.000000000 +0100
+++ src/gdb/procfs.c 2008-09-11 22:47:09.000000000 +0100
@@ -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: src/gdb/remote-sim.c
===================================================================
--- src.orig/gdb/remote-sim.c 2008-09-11 20:11:32.000000000 +0100
+++ src/gdb/remote-sim.c 2008-09-11 21:58:44.000000000 +0100
@@ -480,6 +480,7 @@ gdbsim_create_inferior (char *exec_file,
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: src/gdb/target.c
===================================================================
--- src.orig/gdb/target.c 2008-09-11 20:11:32.000000000 +0100
+++ src/gdb/target.c 2008-09-11 21:58:44.000000000 +0100
@@ -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: src/gdb/win32-nat.c
===================================================================
--- src.orig/gdb/win32-nat.c 2008-09-11 20:11:32.000000000 +0100
+++ src/gdb/win32-nat.c 2008-09-11 21:58:44.000000000 +0100
@@ -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: src/gdb/linux-nat.c
===================================================================
--- src.orig/gdb/linux-nat.c 2008-09-11 20:11:32.000000000 +0100
+++ src/gdb/linux-nat.c 2008-09-11 21:58:44.000000000 +0100
@@ -711,6 +711,10 @@ linux_child_follow_fork (struct target_o
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_o
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_o
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: src/gdb/fork-child.c
===================================================================
--- src.orig/gdb/fork-child.c 2008-09-11 20:11:32.000000000 +0100
+++ src/gdb/fork-child.c 2008-09-11 21:58:44.000000000 +0100
@@ -394,6 +394,8 @@ fork_inferior (char *exec_file_arg, char
init_thread_list ();
+ add_inferior (pid);
+
/* Needed for wait_for_inferior stuff below. */
inferior_ptid = pid_to_ptid (pid);
Index: src/gdb/corelow.c
===================================================================
--- src.orig/gdb/corelow.c 2008-09-11 20:11:32.000000000 +0100
+++ src/gdb/corelow.c 2008-09-11 21:58:44.000000000 +0100
@@ -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
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [RFA 02/08] multi-process support: all targets manage inferior list
2008-09-12 15:38 [RFA 02/08] multi-process support: all targets manage inferior list Pedro Alves
@ 2008-09-18 22:52 ` Daniel Jacobowitz
2008-09-19 13:59 ` Pedro Alves
0 siblings, 1 reply; 8+ messages in thread
From: Daniel Jacobowitz @ 2008-09-18 22:52 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches
On Fri, Sep 12, 2008 at 04:38:18PM +0100, Pedro Alves wrote:
> @@ -662,6 +662,9 @@ go32_create_inferior (char *exec_file, c
> #endif
>
> inferior_ptid = pid_to_ptid (SOME_PID);
> + add_inferior (SOME_PID);
> + add_thread_silent (inferior_ptid);
> +
> push_target (&go32_ops);
>
> add_thread_silent (inferior_ptid);
Is the new add_thread_silent a typo, or did you mean to remove the
second call?
This looks otherwise OK (though I don't understand when you use
add_inferior vs add_inferior_silent).
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [RFA 02/08] multi-process support: all targets manage inferior list
2008-09-18 22:52 ` Daniel Jacobowitz
@ 2008-09-19 13:59 ` Pedro Alves
2008-09-19 14:08 ` Daniel Jacobowitz
2008-09-19 15:28 ` Eli Zaretskii
0 siblings, 2 replies; 8+ messages in thread
From: Pedro Alves @ 2008-09-19 13:59 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 1414 bytes --]
On Thursday 18 September 2008 23:51:18, Daniel Jacobowitz wrote:
> On Fri, Sep 12, 2008 at 04:38:18PM +0100, Pedro Alves wrote:
> > @@ -662,6 +662,9 @@ go32_create_inferior (char *exec_file, c
> > #endif
> >
> > inferior_ptid = pid_to_ptid (SOME_PID);
> > + add_inferior (SOME_PID);
> > + add_thread_silent (inferior_ptid);
> > +
> > push_target (&go32_ops);
> >
> > add_thread_silent (inferior_ptid);
>
> Is the new add_thread_silent a typo, or did you mean to remove the
> second call?
Just a typo. Thanks. Fixed.
> This looks otherwise OK (though I don't understand when you use
> add_inferior vs add_inferior_silent).
Hmmm, the initial thought was somewhat similar to the
use of add_thread_silent in targets that didn't add the main thread
to the list because they don't support multi-threads. (monitor,
remote-sim). As in, don't emit a CLI note notification if
the target pid was made up by GDB and thus should not be visible
to the user, and emit if otherwise. This one seems to have been
missed by that logic.
But I agree that this sounds somewhat bogus. It should be the
the target that should decide what to print... I'll need
to do a few further adjustments for that to be possible
though. These CLI notifications are off by default, so we
can either get rid of add_inferior_silent, or make
go32-nat.c also use it. Any preference? The attached does
the latter.
--
Pedro Alves
[-- Attachment #2: 002-all_targets_manage_inferiors.diff --]
[-- Type: text/x-diff, Size: 16173 bytes --]
2008-09-19 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.
---
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 +++++
14 files changed, 83 insertions(+), 10 deletions(-)
Index: src/gdb/gnu-nat.c
===================================================================
--- src.orig/gdb/gnu-nat.c 2008-09-19 13:57:04.000000000 +0100
+++ src/gdb/gnu-nat.c 2008-09-19 14:35:03.000000000 +0100
@@ -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: src/gdb/go32-nat.c
===================================================================
--- src.orig/gdb/go32-nat.c 2008-09-19 13:57:04.000000000 +0100
+++ src/gdb/go32-nat.c 2008-09-19 14:55:15.000000000 +0100
@@ -662,6 +662,8 @@ go32_create_inferior (char *exec_file, c
#endif
inferior_ptid = pid_to_ptid (SOME_PID);
+ add_inferior_silent (SOME_PID);
+
push_target (&go32_ops);
add_thread_silent (inferior_ptid);
Index: src/gdb/inf-ptrace.c
===================================================================
--- src.orig/gdb/inf-ptrace.c 2008-09-19 13:57:04.000000000 +0100
+++ src/gdb/inf-ptrace.c 2008-09-19 14:35:03.000000000 +0100
@@ -89,11 +89,14 @@ inf_ptrace_follow_fork (struct target_op
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_op
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_
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_
#endif
inferior_ptid = null_ptid;
+ detach_inferior (pid);
unpush_target (ptrace_ops_hack);
}
Index: src/gdb/inf-ttrace.c
===================================================================
--- src.orig/gdb/inf-ttrace.c 2008-09-19 13:57:04.000000000 +0100
+++ src/gdb/inf-ttrace.c 2008-09-19 14:35:03.000000000 +0100
@@ -468,6 +468,7 @@ inf_ttrace_follow_fork (struct target_op
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
/* 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_
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_
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: src/gdb/linux-fork.c
===================================================================
--- src.orig/gdb/linux-fork.c 2008-09-19 13:57:04.000000000 +0100
+++ src/gdb/linux-fork.c 2008-09-19 14:35:03.000000000 +0100
@@ -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 fro
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 fro
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: src/gdb/monitor.c
===================================================================
--- src.orig/gdb/monitor.c 2008-09-19 13:57:04.000000000 +0100
+++ src/gdb/monitor.c 2008-09-19 14:35:03.000000000 +0100
@@ -817,6 +817,7 @@ monitor_open (char *args, struct monitor
/* 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: src/gdb/nto-procfs.c
===================================================================
--- src.orig/gdb/nto-procfs.c 2008-09-19 13:57:04.000000000 +0100
+++ src/gdb/nto-procfs.c 2008-09-19 14:42:10.000000000 +0100
@@ -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,
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: src/gdb/procfs.c
===================================================================
--- src.orig/gdb/procfs.c 2008-09-19 13:57:04.000000000 +0100
+++ src/gdb/procfs.c 2008-09-19 14:35:03.000000000 +0100
@@ -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: src/gdb/remote-sim.c
===================================================================
--- src.orig/gdb/remote-sim.c 2008-09-19 13:57:04.000000000 +0100
+++ src/gdb/remote-sim.c 2008-09-19 14:35:03.000000000 +0100
@@ -480,6 +480,7 @@ gdbsim_create_inferior (char *exec_file,
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: src/gdb/target.c
===================================================================
--- src.orig/gdb/target.c 2008-09-19 13:57:04.000000000 +0100
+++ src/gdb/target.c 2008-09-19 14:35:03.000000000 +0100
@@ -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: src/gdb/win32-nat.c
===================================================================
--- src.orig/gdb/win32-nat.c 2008-09-19 13:57:04.000000000 +0100
+++ src/gdb/win32-nat.c 2008-09-19 14:35:03.000000000 +0100
@@ -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: src/gdb/linux-nat.c
===================================================================
--- src.orig/gdb/linux-nat.c 2008-09-19 13:57:04.000000000 +0100
+++ src/gdb/linux-nat.c 2008-09-19 14:42:05.000000000 +0100
@@ -711,6 +711,10 @@ linux_child_follow_fork (struct target_o
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_o
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_o
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: src/gdb/fork-child.c
===================================================================
--- src.orig/gdb/fork-child.c 2008-09-19 13:57:04.000000000 +0100
+++ src/gdb/fork-child.c 2008-09-19 14:35:03.000000000 +0100
@@ -394,6 +394,8 @@ fork_inferior (char *exec_file_arg, char
init_thread_list ();
+ add_inferior (pid);
+
/* Needed for wait_for_inferior stuff below. */
inferior_ptid = pid_to_ptid (pid);
Index: src/gdb/corelow.c
===================================================================
--- src.orig/gdb/corelow.c 2008-09-19 13:57:04.000000000 +0100
+++ src/gdb/corelow.c 2008-09-19 14:35:03.000000000 +0100
@@ -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
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: [RFA 02/08] multi-process support: all targets manage inferior list
2008-09-19 13:59 ` Pedro Alves
@ 2008-09-19 14:08 ` Daniel Jacobowitz
2008-09-19 15:28 ` Eli Zaretskii
1 sibling, 0 replies; 8+ messages in thread
From: Daniel Jacobowitz @ 2008-09-19 14:08 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches
On Fri, Sep 19, 2008 at 02:59:10PM +0100, Pedro Alves wrote:
> But I agree that this sounds somewhat bogus. It should be the
> the target that should decide what to print... I'll need
> to do a few further adjustments for that to be possible
> though. These CLI notifications are off by default, so we
> can either get rid of add_inferior_silent, or make
> go32-nat.c also use it. Any preference? The attached does
> the latter.
This one's fine.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [RFA 02/08] multi-process support: all targets manage inferior list
2008-09-19 13:59 ` Pedro Alves
2008-09-19 14:08 ` Daniel Jacobowitz
@ 2008-09-19 15:28 ` Eli Zaretskii
2008-09-22 15:43 ` Pedro Alves
1 sibling, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2008-09-19 15:28 UTC (permalink / raw)
To: Pedro Alves; +Cc: drow, gdb-patches
> From: Pedro Alves <pedro@codesourcery.com>
> Date: Fri, 19 Sep 2008 14:59:10 +0100
> Cc: gdb-patches@sourceware.org
>
> > This looks otherwise OK (though I don't understand when you use
> > add_inferior vs add_inferior_silent).
>
> Hmmm, the initial thought was somewhat similar to the
> use of add_thread_silent in targets that didn't add the main thread
> to the list because they don't support multi-threads. (monitor,
> remote-sim). As in, don't emit a CLI note notification if
> the target pid was made up by GDB and thus should not be visible
> to the user, and emit if otherwise. This one seems to have been
> missed by that logic.
>
> But I agree that this sounds somewhat bogus. It should be the
> the target that should decide what to print... I'll need
> to do a few further adjustments for that to be possible
> though. These CLI notifications are off by default, so we
> can either get rid of add_inferior_silent, or make
> go32-nat.c also use it. Any preference? The attached does
> the latter.
I prefer the way of letting the target decide what to print. Can we
do that?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [RFA 02/08] multi-process support: all targets manage inferior list
2008-09-19 15:28 ` Eli Zaretskii
@ 2008-09-22 15:43 ` Pedro Alves
2008-09-22 19:01 ` Eli Zaretskii
2008-09-22 19:02 ` Eli Zaretskii
0 siblings, 2 replies; 8+ messages in thread
From: Pedro Alves @ 2008-09-22 15:43 UTC (permalink / raw)
To: gdb-patches, Eli Zaretskii
On Friday 19 September 2008 16:27:44, Eli Zaretskii wrote:
> I prefer the way of letting the target decide what to print. Can we
> do that?
Yes, but not yet. First, I need to make sure the correct target
is already set everywhere when we emit those notifications. Currently,
it isn't. That is my preference too, and we're going in that direction.
--
Pedro Alves
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [RFA 02/08] multi-process support: all targets manage inferior list
2008-09-22 15:43 ` Pedro Alves
@ 2008-09-22 19:01 ` Eli Zaretskii
2008-09-22 19:02 ` Eli Zaretskii
1 sibling, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2008-09-22 19:01 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches
> From: Pedro Alves <pedro@codesourcery.com>
> Date: Mon, 22 Sep 2008 16:42:54 +0100
>
> On Friday 19 September 2008 16:27:44, Eli Zaretskii wrote:
>
> > I prefer the way of letting the target decide what to print. Can we
> > do that?
>
> Yes, but not yet. First, I need to make sure the correct target
> is already set everywhere when we emit those notifications. Currently,
> it isn't. That is my preference too, and we're going in that direction.
Great, thanks.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [RFA 02/08] multi-process support: all targets manage inferior list
2008-09-22 15:43 ` Pedro Alves
2008-09-22 19:01 ` Eli Zaretskii
@ 2008-09-22 19:02 ` Eli Zaretskii
1 sibling, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2008-09-22 19:02 UTC (permalink / raw)
To: Pedro Alves; +Cc: gdb-patches
> From: Pedro Alves <pedro@codesourcery.com>
> Date: Mon, 22 Sep 2008 16:42:54 +0100
>
> On Friday 19 September 2008 16:27:44, Eli Zaretskii wrote:
>
> > I prefer the way of letting the target decide what to print. Can we
> > do that?
>
> Yes, but not yet. First, I need to make sure the correct target
> is already set everywhere when we emit those notifications. Currently,
> it isn't. That is my preference too, and we're going in that direction.
Great, thanks.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2008-09-22 19:02 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-12 15:38 [RFA 02/08] multi-process support: all targets manage inferior list Pedro Alves
2008-09-18 22:52 ` Daniel Jacobowitz
2008-09-19 13:59 ` Pedro Alves
2008-09-19 14:08 ` Daniel Jacobowitz
2008-09-19 15:28 ` Eli Zaretskii
2008-09-22 15:43 ` Pedro Alves
2008-09-22 19:01 ` Eli Zaretskii
2008-09-22 19:02 ` Eli Zaretskii
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox