"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;
+ struct inferior *inf;
+ struct thread_info *tp;
last_sig = TARGET_SIGNAL_0;
event_count = 0;
clear_proceed_status ();
init_wait_for_inferior ();
+ inf = add_inferior (pid);
+ inf->attach_flag = attaching;
+
+ /* Make the new process the current inferior, so terminal handling
+ can rely on it. When attaching, we don't know about any thread
+ id here, but that's OK --- nothing should be referencing the
+ current thread until we report an event out of win32_wait. */
+ inferior_ptid = pid_to_ptid (pid);
+
terminal_init_inferior_with_pgrp (pid);
target_terminal_inferior ();
- stop_soon = STOP_QUIETLY;
+ inf->stop_soon = STOP_QUIETLY;
while (1)
{
stop_after_trap = 1;
wait_for_inferior (0);
- if (stop_signal != TARGET_SIGNAL_TRAP)
- resume (0, stop_signal);
+ tp = inferior_thread ();
+ if (tp->stop_signal != TARGET_SIGNAL_TRAP)
+ resume (0, tp->stop_signal);
else
break;
}
- stop_soon = NO_STOP_QUIETLY;
+ inf->stop_soon = NO_STOP_QUIETLY;
stop_after_trap = 0;
return;
}
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 ();
}
current_event.dwProcessId);
gdb_flush (gdb_stdout);
}
+
inferior_ptid = null_ptid;
+ detach_inferior (current_event.dwProcessId);
+
unpush_target (&win32_ops);
}
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); */
}