+static void
+attach_command_post_wait (char *args, int from_tty, int async_exec)
+{
+ char *exec_file;
+ char *full_exec_path = NULL;
+ struct inferior *inferior;
+
+ inferior = current_inferior ();
+ inferior->stop_soon = NO_STOP_QUIETLY;
+
+ /* If no exec file is yet known, try to determine it from the
+ process itself. */
+ exec_file = (char *) get_exec_file (0);
+ if (!exec_file)
+ {
+ exec_file = target_pid_to_exec_file (PIDGET (inferior_ptid));
+ if (exec_file)
+ {
+ /* It's possible we don't have a full path, but rather just a
+ filename. Some targets, such as HP-UX, don't provide the
+ full path, sigh.
+
+ Attempt to qualify the filename against the source path.
+ (If that fails, we'll just fall back on the original
+ filename. Not much more we can do...)
+ */
+ if (!source_full_path_of (exec_file, &full_exec_path))
+ full_exec_path = xstrdup (exec_file);
+
+ exec_file_attach (full_exec_path, from_tty);
+ symbol_file_add_main (full_exec_path, from_tty);
+ }
+ }
+ else
+ {
+ reopen_exec_file ();
+ reread_symbols ();
+ }
+
+ /* Take any necessary post-attaching actions for this platform. */
+ target_post_attach (PIDGET (inferior_ptid));
+
+ post_create_inferior (¤t_target, from_tty);
+
+ /* Install inferior's terminal modes. */
+ target_terminal_inferior ();
+
+ if (async_exec)
+ {
+ /* The user requested an `attach&', so be sure to leave threads
+ that didn't get a signal running. */
+
+ /* Immediatelly resume all suspended threads of this inferior,
+ and this inferior only. This should have no effect on
+ already running threads. If a thread has been stopped with a
+ signal, leave it be. */
+ if (non_stop)
+ proceed_after_attach (inferior->pid);
+ else
+ {
+ if (inferior_thread ()->stop_signal == TARGET_SIGNAL_0)
+ {
+ clear_proceed_status ();
+ proceed ((CORE_ADDR) -1, TARGET_SIGNAL_DEFAULT, 0);
+ }
+ }
+ }
+ else
+ {
+ /* The user requested a plain `attach', so be sure to leave
+ the inferior stopped. */
+
+ if (target_can_async_p ())
+ async_enable_stdin ();
+
+ /* At least the current thread is already stopped. */
+
+ /* In all-stop, by definition, all threads have to be already
+ stopped at this point. In non-stop, however, although the
+ selected thread is stopped, others may still be executing.
+ Be sure to explicitly stop all threads of the process. This
+ should have no effect on already stopped threads. */
+ if (non_stop)
+ target_stop (pid_to_ptid (inferior->pid));
+
+ /* Tell the user/frontend where we're stopped. */
+ normal_stop ();
+ if (deprecated_attach_hook)
+ deprecated_attach_hook ();
+ }
+}
+
+struct attach_command_continuation_args
+{
+ char *args;
+ int from_tty;
+ int async_exec;
+};
+
+static void
+attach_command_continuation (void *args)
+{
+ struct attach_command_continuation_args *a = args;
+ attach_command_post_wait (a->args, a->from_tty, a->async_exec);
+}
+
+static void
+attach_command_continuation_free_args (void *args)
+{
+ struct attach_command_continuation_args *a = args;
+ xfree (a->args);
+ xfree (a);
+}
+