* inferior.h (attach_flag): Delete.
(inferior_process): Declare.
* solib.c (update_solib_list): Adjust.
* gnu-nat.c (gnu_create_inferior, gnu_attach): Adjust.
* inf-ptrace.c (inf_ptrace_detach): Adjust.
(inf_ptrace_files_info): Get it from the current inferior.
* inf-ttrace.c (inf_ttrace_attach): Adjust.
(inf_ttrace_files_info): Get it from the current
inferior.
* inflow.c (terminal_inferior, terminal_ours_1, set_sigint_trap)
(clear_sigint_trap): Get it from the current process.
* remote.c (extended_remote_attach_1)
(extended_remote_create_inferior_1): Adjust.
* top.c (quit_confirm, quit_target): Get it from the current inferior.
* procfs.c (do_detach): Adjust.
(procfs_wait): Get it from the event inferior.
(procfs_files_info): Get it from the current inferior.
* nto-procfs.c (procfs_files_info): Likewise.
(procfs_attach): Adjust. Set the attach_flag here.
(do_attach): Don't set it here.
(procfs_detach): Don't clear it.
(procfs_mourn_inferior): Don't clear it.
* solib-osf.c (osf_solib_create_inferior_hook): Adjust.
* target.c (attach_flag): Delete.
(generic_mourn_inferior): Don't clear it.
* win32-nat.c (get_win32_debug_event): Get it from the event
process.
(do_initial_win32_stuff): Add attaching argument. Set attach_flag
in the inferior accordingly.
(win32_attach): Don't set the attach_flag here. Pass 1 to
do_intial_win32_stuff.
(win32_files_info): Get it from the current inferior.
(win32_create_inferior): Dont clear attach_flag here. Pass 0 to
do_intial_win32_stuff.
+2008-09-22 Pedro Alves <pedro@codesourcery.com>
+
+ Remove the attach_flag global, and make it per-inferior.
+
+ * inferior.h (attach_flag): Delete.
+ (inferior_process): Declare.
+ * solib.c (update_solib_list): Adjust.
+ * gnu-nat.c (gnu_create_inferior, gnu_attach): Adjust.
+ * inf-ptrace.c (inf_ptrace_detach): Adjust.
+ (inf_ptrace_files_info): Get it from the current inferior.
+ * inf-ttrace.c (inf_ttrace_attach): Adjust.
+ (inf_ttrace_files_info): Get it from the current
+ inferior.
+ * inflow.c (terminal_inferior, terminal_ours_1, set_sigint_trap)
+ (clear_sigint_trap): Get it from the current process.
+ * remote.c (extended_remote_attach_1)
+ (extended_remote_create_inferior_1): Adjust.
+ * top.c (quit_confirm, quit_target): Get it from the current inferior.
+ * procfs.c (do_detach): Adjust.
+ (procfs_wait): Get it from the event inferior.
+ (procfs_files_info): Get it from the current inferior.
+ * nto-procfs.c (procfs_files_info): Likewise.
+ (procfs_attach): Adjust. Set the attach_flag here.
+ (do_attach): Don't set it here.
+ (procfs_detach): Don't clear it.
+ (procfs_mourn_inferior): Don't clear it.
+ * solib-osf.c (osf_solib_create_inferior_hook): Adjust.
+ * target.c (attach_flag): Delete.
+ (generic_mourn_inferior): Don't clear it.
+ * win32-nat.c (get_win32_debug_event): Get it from the event
+ process.
+ (do_initial_win32_stuff): Add attaching argument. Set attach_flag
+ in the inferior accordingly.
+ (win32_attach): Don't set the attach_flag here. Pass 1 to
+ do_intial_win32_stuff.
+ (win32_files_info): Get it from the current inferior.
+ (win32_create_inferior): Dont clear attach_flag here. Pass 0 to
+ do_intial_win32_stuff.
+
2008-09-22 Pedro Alves <pedro@codesourcery.com>
Make the stop_soon global be per-inferior instead.
inf_attach (inf, pid);
- attach_flag = 0;
push_target (&gnu_ops);
inf->pending_execs = 2;
int pid;
char *exec_file;
struct inf *inf = cur_inf ();
+ struct inferior *inferior;
if (!args)
error_no_arg (_("process-id to attach"));
push_target (&gnu_ops);
- add_inferior (pid);
+ inferior = add_inferior (pid);
+ inferior->attach_flag = 1;
inf_update_procs (inf);
inferior_ptid = ptid_build (pid, 0, inf_pick_first_thread ());
- attach_flag = 1;
-
/* We have to initialize the terminal settings now, since the code
below might try to restore them. */
target_terminal_init ();
char *exec_file;
pid_t pid;
char *dummy;
+ struct inferior *inf;
if (!args)
error_no_arg (_("process-id to attach"));
ptrace (PT_ATTACH, pid, (PTRACE_TYPE_ARG3)0, 0);
if (errno != 0)
perror_with_name (("ptrace"));
- attach_flag = 1;
#else
error (_("This system does not support attaching to a process"));
#endif
inferior_ptid = pid_to_ptid (pid);
- add_inferior (pid);
+ inf = add_inferior (pid);
+ inf->attach_flag = 1;
/* Always add a main thread. If some target extends the ptrace
target, it should decorate the ptid later with more info. */
ptrace (PT_DETACH, pid, (PTRACE_TYPE_ARG3)1, sig);
if (errno != 0)
perror_with_name (("ptrace"));
- attach_flag = 0;
#else
error (_("This system does not support detaching from a process"));
#endif
static void
inf_ptrace_files_info (struct target_ops *ignore)
{
+ struct inferior *inf = current_inferior ();
+
printf_filtered (_("\tUsing the running image of %s %s.\n"),
- attach_flag ? "attached" : "child",
+ inf->attach_flag ? "attached" : "child",
target_pid_to_str (inferior_ptid));
}
pid_t pid;
char *dummy;
ttevent_t tte;
+ struct inferior *inf;
if (!args)
error_no_arg (_("process-id to attach"));
if (ttrace (TT_PROC_ATTACH, pid, 0, TT_KILL_ON_EXIT, TT_VERSION, 0) == -1)
perror_with_name (("ttrace"));
- attach_flag = 1;
- add_inferior (pid);
+ inf = add_inferior (pid);
+ inf->attach_flag = 1;
/* Set the initial event mask. */
memset (&tte, 0, sizeof (tte));
static void
inf_ttrace_files_info (struct target_ops *ignore)
{
+ struct inferior *inf = current_inferior ();
printf_filtered (_("\tUsing the running image of %s %s.\n"),
- attach_flag ? "attached" : "child",
+ inf->attach_flag ? "attached" : "child",
target_pid_to_str (inferior_ptid));
}
extern struct regcache *stop_registers;
-/* Nonzero if the child process in inferior_ptid was attached rather
- than forked. */
-
-extern int attach_flag;
-
/* True if we are debugging displaced stepping. */
extern int debug_displaced;
/* See the definition of stop_kind above. */
enum stop_kind stop_soon;
+ /* Nonzero if this child process was attached rather than
+ forked. */
+ int attach_flag;
+
/* Private data used by the target vector implementation. */
struct private_inferior *private;
};
if (job_control)
{
+ struct inferior *inf = current_inferior ();
#ifdef HAVE_TERMIOS
result = tcsetpgrp (0, inferior_process_group);
- if (!attach_flag)
+ if (!inf->attach_flag)
OOPSY ("tcsetpgrp");
#endif
#ifdef HAVE_SGTTY
result = ioctl (0, TIOCSPGRP, &inferior_process_group);
- if (!attach_flag)
+ if (!inf->attach_flag)
OOPSY ("TIOCSPGRP");
#endif
}
if (!terminal_is_ours)
{
+ struct inferior *inf = current_inferior ();
+
#ifdef SIGTTOU
/* Ignore this signal since it will happen when we try to set the
pgrp. */
inferior_ttystate = serial_get_tty_state (stdin_serial);
#ifdef PROCESS_GROUP_TYPE
- if (!attach_flag)
+ if (!inf->attach_flag)
/* If setpgrp failed in terminal_inferior, this would give us
our process group instead of the inferior's. See
terminal_inferior for details. */
void
set_sigint_trap (void)
{
- if (attach_flag || inferior_thisrun_terminal)
+ struct inferior *inf = current_inferior ();
+ if (inf->attach_flag || inferior_thisrun_terminal)
{
osig = (void (*)()) signal (SIGINT, pass_signal);
}
void
clear_sigint_trap (void)
{
- if (attach_flag || inferior_thisrun_terminal)
+ struct inferior *inf = current_inferior ();
+ if (inf->attach_flag || inferior_thisrun_terminal)
{
signal (SIGINT, osig);
}
static void
procfs_files_info (struct target_ops *ignore)
{
+ struct inferior *inf = current_inferior ();
+
printf_unfiltered ("\tUsing the running image of %s %s via %s.\n",
- attach_flag ? "attached" : "child",
+ pi->attach_flag ? "attached" : "child",
target_pid_to_str (inferior_ptid), nto_procfs_path);
}
{
char *exec_file;
int pid;
+ struct inferior *inf;
if (!args)
error_no_arg (_("process-id to attach"));
gdb_flush (gdb_stdout);
}
inferior_ptid = do_attach (pid_to_ptid (pid));
- add_inferior (pid);
+ inf = add_inferior (pid);
+ inf->attach_flag = 1;
push_target (&procfs_ops);
if (devctl (ctl_fd, DCMD_PROC_STATUS, &status, sizeof (status), 0) == EOK
&& status.flags & _DEBUG_FLAG_STOPPED)
SignalKill (nto_node (), PIDGET (ptid), 0, SIGCONT, 0, 0);
- attach_flag = 1;
nto_init_solib_absolute_prefix ();
return ptid;
}
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. */
init_thread_list ();
unpush_target (&procfs_ops);
generic_mourn_inferior ();
- attach_flag = 0;
}
/* This function breaks up an argument string into an argument
do_attach (ptid_t ptid)
{
procinfo *pi;
+ struct inferior *inf;
int fail;
int lwpid;
if ((fail = procfs_debug_inferior (pi)) != 0)
dead_procinfo (pi, "do_attach: failed in procfs_debug_inferior", NOKILL);
- add_inferior (pi->pid);
+ inf = add_inferior (pi->pid);
/* Let GDB know that the inferior was attached. */
- attach_flag = 1;
+ inf->attach_flag = 1;
/* Create a procinfo for the current lwp. */
lwpid = proc_get_current_thread (pi);
proc_warn (pi, "do_detach, set_rlc", __LINE__);
}
- attach_flag = 0;
destroy_procinfo (pi);
}
}
else if (syscall_is_exit (pi, what))
{
+ struct inferior *inf;
+
/* Handle SYS_exit call only */
/* Stopped at entry to SYS_exit.
Make it runnable, resume it, then use
TARGET_WAITKIND_SPURIOUS. */
if (!proc_run_process (pi, 0, 0))
proc_error (pi, "target_wait, run_process", __LINE__);
- if (attach_flag)
+
+ inf = find_inferior_pid (pi->pid);
+ if (inf->attach_flag)
{
/* Don't call wait: simulate waiting for exit,
return a "success" exit code. Bogus: what if
static void
procfs_files_info (struct target_ops *ignore)
{
+ struct inferior *inf = current_inferior ();
printf_filtered (_("\tUsing the running image of %s %s via /proc.\n"),
- attach_flag? "attached": "child",
+ inf->attach_flag? "attached": "child",
target_pid_to_str (inferior_ptid));
}
int pid;
char *dummy;
char *wait_status = NULL;
+ struct inferior *inf;
if (!args)
error_no_arg (_("process-id to attach"));
/* Now, if we have thread information, update inferior_ptid. */
inferior_ptid = remote_current_thread (inferior_ptid);
- add_inferior (pid);
+ inf = add_inferior (pid);
+ inf->attach_flag = 1;
/* Now, add the main thread to the thread list. */
add_thread_silent (inferior_ptid);
- attach_flag = 1;
-
/* Next, if the target can specify a description, read it. We do
this before anything involving memory or registers. */
target_find_description ();
init_wait_for_inferior ();
/* Now mark the inferior as running before we do anything else. */
- attach_flag = 0;
inferior_ptid = magic_null_ptid;
add_inferior (ptid_get_pid (inferior_ptid));
struct inferior *inf;
struct thread_info *tp;
+ inf = current_inferior ();
+
/* If we are attaching to the inferior, the shared libraries
have already been mapped, so nothing more to do. */
- if (attach_flag)
+ if (inf->attach_flag)
return;
/* Nothing to do for statically bound executables. */
if (!target_can_run (¤t_target))
return;
- inf = current_inferior ();
tp = inferior_thread ();
clear_proceed_status ();
inf->stop_soon = STOP_QUIETLY;
struct so_list *inferior = ops->current_sos();
struct so_list *gdb, **gdb_link;
- /* If we are attaching to a running process for which we
- have not opened a symbol file, we may be able to get its
- symbols now! */
- if (attach_flag &&
- symfile_objfile == NULL)
- catch_errors (ops->open_symbol_file_object, &from_tty,
- "Error reading attached process's symbol file.\n",
- RETURN_MASK_ALL);
+ /* We can reach here due to changing solib-search-path or the
+ sysroot, before having any inferior. */
+ if (target_has_execution)
+ {
+ struct inferior *inf = current_inferior ();
+
+ /* If we are attaching to a running process for which we
+ have not opened a symbol file, we may be able to get its
+ symbols now! */
+ if (inf->attach_flag && symfile_objfile == NULL)
+ catch_errors (ops->open_symbol_file_object, &from_tty,
+ "Error reading attached process's symbol file.\n",
+ RETURN_MASK_ALL);
+ }
/* GDB and the inferior's dynamic linker each maintain their own
list of currently loaded shared objects; we want to bring the
static struct cmd_list_element *targetlist = NULL;
-/* Nonzero if we are debugging an attached outside process
- rather than an inferior. */
-
-int attach_flag;
-
/* Nonzero if we should trust readonly sections from the
executable when reading memory. */
delete_inferior (pid);
}
- attach_flag = 0;
breakpoint_init_inferior (inf_exited);
registers_changed ();
if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
{
char *s;
+ struct inferior *inf = current_inferior ();
/* This is something of a hack. But there's no reliable way to
see if a GUI is running. The `use_windows' variable doesn't
cut it. */
if (deprecated_init_ui_hook)
s = "A debugging session is active.\nDo you still want to close the debugger?";
- else if (attach_flag)
+ else if (inf->attach_flag)
s = "The program is running. Quit anyway (and detach it)? ";
else
s = "The program is running. Quit anyway (and kill it)? ";
if (! ptid_equal (inferior_ptid, null_ptid) && target_has_execution)
{
- if (attach_flag)
+ struct inferior *inf = current_inferior ();
+ if (inf->attach_flag)
target_detach (qt->args, qt->from_tty);
else
target_kill ();
"CREATE_THREAD_DEBUG_EVENT"));
if (saw_create != 1)
{
- if (!saw_create && attach_flag)
+ struct inferior *inf;
+ inf = find_inferior_pid (current_event.dwProcessId);
+ if (!saw_create && inf->attach_flag)
{
/* Kludge around a Windows bug where first event is a create
thread event. Caused when attached process does not have
a main thread. */
retval = fake_create_process ();
- if (retval)
- saw_create++;
+ if (retval)
+ saw_create++;
}
break;
}
}
static void
-do_initial_win32_stuff (DWORD pid)
+do_initial_win32_stuff (DWORD pid, int attaching)
{
extern int stop_after_trap;
int i;
init_wait_for_inferior ();
inf = add_inferior (pid);
+ inf->attach_flag = attaching;
terminal_init_inferior_with_pgrp (pid);
target_terminal_inferior ();
if (has_detach_ability ())
DebugSetProcessKillOnExit (FALSE);
- attach_flag = 1;
-
if (from_tty)
{
char *exec_file = (char *) get_exec_file (0);
gdb_flush (gdb_stdout);
}
- do_initial_win32_stuff (pid);
+ do_initial_win32_stuff (pid, 1);
target_terminal_ours ();
}
static void
win32_files_info (struct target_ops *ignore)
{
+ struct inferior *inf = current_inferior ();
+
printf_unfiltered ("\tUsing the running image of %s %s.\n",
- attach_flag ? "attached" : "child", target_pid_to_str (inferior_ptid));
+ inf->attach_flag ? "attached" : "child",
+ target_pid_to_str (inferior_ptid));
}
static void
if (new_console)
flags |= CREATE_NEW_CONSOLE;
- attach_flag = 0;
-
args = alloca (strlen (toexec) + strlen (allargs) + 2);
strcpy (args, toexec);
strcat (args, " ");
else
saw_create = 0;
- do_initial_win32_stuff (pi.dwProcessId);
+ do_initial_win32_stuff (pi.dwProcessId, 0);
/* win32_continue (DBG_CONTINUE, -1); */
}
"CREATE_THREAD_DEBUG_EVENT"));
if (saw_create != 1)
{
- if (!saw_create && attach_flag)
+ struct inferior *inf;
+ inf = find_inferior_pid (current_event.dwProcessId);
+ if (!saw_create && inf->attach_flag)
{
/* Kludge around a Windows bug where first event is a create
thread event. Caused when attached process does not have
a main thread. */
retval = fake_create_process ();
- if (retval)
- saw_create++;
+ if (retval)
+ saw_create++;
}
break;
}
}
static void
-do_initial_win32_stuff (DWORD pid)
+do_initial_win32_stuff (DWORD pid, int attaching)
{
extern int stop_after_trap;
int i;
init_wait_for_inferior ();
inf = add_inferior (pid);
+ inf->attach_flag = attaching;
terminal_init_inferior_with_pgrp (pid);
target_terminal_inferior ();
if (has_detach_ability ())
DebugSetProcessKillOnExit (FALSE);
- attach_flag = 1;
-
if (from_tty)
{
char *exec_file = (char *) get_exec_file (0);
gdb_flush (gdb_stdout);
}
- do_initial_win32_stuff (pid);
+ do_initial_win32_stuff (pid, 1);
target_terminal_ours ();
}
static void
win32_files_info (struct target_ops *ignore)
{
+ struct inferior *inf = current_inferior ();
+
printf_unfiltered ("\tUsing the running image of %s %s.\n",
- attach_flag ? "attached" : "child", target_pid_to_str (inferior_ptid));
+ inf->attach_flag ? "attached" : "child",
+ target_pid_to_str (inferior_ptid));
}
static void
if (new_console)
flags |= CREATE_NEW_CONSOLE;
- attach_flag = 0;
-
args = alloca (strlen (toexec) + strlen (allargs) + 2);
strcpy (args, toexec);
strcat (args, " ");
else
saw_create = 0;
- do_initial_win32_stuff (pi.dwProcessId);
+ do_initial_win32_stuff (pi.dwProcessId, 0);
/* win32_continue (DBG_CONTINUE, -1); */
}