if (pid == getpid ()) /* Trying to masturbate? */
error (_("I refuse to debug myself!"));
- if (from_tty)
- {
- const char *exec_file = get_exec_file (0);
-
- if (exec_file)
- printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file,
- target_pid_to_str (ptid_t (pid)).c_str ());
- else
- printf_unfiltered (_("Attaching to %s\n"),
- target_pid_to_str (ptid_t (pid)).c_str ());
- }
+ target_announce_attach (from_tty, pid);
if (pid == 0 || ::kill (pid, 0) < 0)
error (_("Can't attach to process %d: %s (%d)"),
if (pid == getpid ()) /* Trying to masturbate? */
error (_("I refuse to debug myself!"));
- if (from_tty)
- {
- const char *exec_file = get_exec_file (0);
-
- if (exec_file)
- printf_unfiltered ("Attaching to program `%s', pid %d\n",
- exec_file, pid);
- else
- printf_unfiltered ("Attaching to pid %d\n", pid);
- }
+ target_announce_attach (from_tty, pid);
inf_debug (inf, "attaching to pid: %d", pid);
unpusher.reset (this);
}
- if (from_tty)
- {
- const char *exec_file = get_exec_file (0);
-
- if (exec_file)
- printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file,
- target_pid_to_str (ptid_t (pid)).c_str ());
- else
- printf_unfiltered (_("Attaching to %s\n"),
- target_pid_to_str (ptid_t (pid)).c_str ());
- }
+ target_announce_attach (from_tty, pid);
#ifdef PT_ATTACH
errno = 0;
if (pid == getpid ())
error (_("Attaching GDB to itself is not a good idea..."));
- if (from_tty)
- {
- const char *exec_file = get_exec_file (0);
+ target_announce_attach (from_tty, pid);
- if (exec_file)
- printf_unfiltered ("Attaching to program `%s', %s\n", exec_file,
- target_pid_to_str (ptid_t (pid)).c_str ());
- else
- printf_unfiltered ("Attaching to %s\n",
- target_pid_to_str (ptid_t (pid)).c_str ());
- }
ptid_t ptid = do_attach (ptid_t (pid));
inf = current_inferior ();
inferior_appeared (inf, pid);
unpusher.reset (this);
}
- if (from_tty)
- {
- const char *exec_file = get_exec_file (0);
-
- if (exec_file)
- printf_filtered (_("Attaching to program `%s', %s\n"),
- exec_file, target_pid_to_str (ptid_t (pid)).c_str ());
- else
- printf_filtered (_("Attaching to %s\n"),
- target_pid_to_str (ptid_t (pid)).c_str ());
-
- fflush (stdout);
- }
+ target_announce_attach (from_tty, pid);
do_attach (ptid_t (pid));
if (packet_support (PACKET_vAttach) == PACKET_DISABLE)
error (_("This target does not support attaching to a process"));
- if (from_tty)
- {
- const char *exec_file = get_exec_file (0);
-
- if (exec_file)
- printf_unfiltered (_("Attaching to program: %s, %s\n"), exec_file,
- target_pid_to_str (ptid_t (pid)).c_str ());
- else
- printf_unfiltered (_("Attaching to %s\n"),
- target_pid_to_str (ptid_t (pid)).c_str ());
- }
+ target_announce_attach (from_tty, pid);
xsnprintf (rs->buf.data (), get_remote_packet_size (), "vAttach;%x", pid);
putpkt (rs->buf);
target_pid_to_str (ptid_t (pid)).c_str ());
}
+/* See target.h */
+
+void
+target_announce_attach (int from_tty, int pid)
+{
+ if (!from_tty)
+ return;
+
+ const char *exec_file = get_exec_file (0);
+
+ if (exec_file)
+ printf_unfiltered ("Attaching to program: %s, %s\n", exec_file,
+ target_pid_to_str (ptid_t (pid)).c_str ());
+ else
+ printf_unfiltered ("Attaching to %s\n",
+ target_pid_to_str (ptid_t (pid)).c_str ());
+}
+
/* The inferior process has died. Long live the inferior! */
void
extern void target_post_attach (int pid);
+/* Display a message indicating we're about to attach to a given
+ process. */
+
+extern void target_announce_attach (int from_tty, int pid);
+
/* Display a message indicating we're about to detach from the current
inferior process. */
DebugSetProcessKillOnExit (FALSE);
- if (from_tty)
- {
- const char *exec_file = get_exec_file (0);
-
- if (exec_file)
- printf_unfiltered ("Attaching to program `%s', %s\n", exec_file,
- target_pid_to_str (ptid_t (pid)).c_str ());
- else
- printf_unfiltered ("Attaching to %s\n",
- target_pid_to_str (ptid_t (pid)).c_str ());
- }
+ target_announce_attach (from_tty, pid);
#ifdef __x86_64__
HANDLE h = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, pid);