aboutsummaryrefslogtreecommitdiff
path: root/gdb/infcmd.c
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2009-03-04 22:50:59 +0000
committerPedro Alves <palves@redhat.com>2009-03-04 22:50:59 +0000
commit1941c569e4194f66d980d62eb3ab534d8011c3ce (patch)
tree1b190f2c2c066a4cb4af981b1e7cdb0bf1209f9b /gdb/infcmd.c
parent9bde073247a88977fb7cb88974f0b0310f86ebeb (diff)
downloadgdb-1941c569e4194f66d980d62eb3ab534d8011c3ce.zip
gdb-1941c569e4194f66d980d62eb3ab534d8011c3ce.tar.gz
gdb-1941c569e4194f66d980d62eb3ab534d8011c3ce.tar.bz2
* inferior.h (notice_new_inferior): Declare.
* infcmd.c (notice_new_inferior): New. * remote.c (remote_add_inferior, remote_add_thread): New. (notice_new_inferiors): Rename to... (remote_notice_new_inferior): ... this. Add RUNNING argument. Use remote_add_thread instead of add_thread, passing it the RUNNING argument. Add an inferior with remote_add_inferior. If we just learned about an inferior, call notice_new_inferior. (record_currthread): Adjust. (remote_threads_info): Adjust to use remote_notice_new_inferior. (remote_start_remote, extended_remote_attach_1): Use remote_add_inferior. (process_stop_reply): Adjust. Call remote_notice_new_inferior after handling expedited registers and watchpoint state. (extended_remote_create_inferior_1): Use remote_add_inferior.
Diffstat (limited to 'gdb/infcmd.c')
-rw-r--r--gdb/infcmd.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/gdb/infcmd.c b/gdb/infcmd.c
index 37a237a..6aed426 100644
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -2313,6 +2313,72 @@ attach_command (char *args, int from_tty)
discard_cleanups (back_to);
}
+/* We had just found out that the target was already attached to an
+ inferior. PTID points at a thread of this new inferior, that is
+ the most likely to be stopped right now, but not necessarily so.
+ The new inferior is assumed to be already added to the inferior
+ list at this point. If LEAVE_RUNNING, then leave the threads of
+ this inferior running, except those we've explicitly seen reported
+ as stopped. */
+
+void
+notice_new_inferior (ptid_t ptid, int leave_running, int from_tty)
+{
+ struct cleanup* old_chain;
+ int async_exec;
+
+ old_chain = make_cleanup (null_cleanup, NULL);
+
+ /* If in non-stop, leave threads as running as they were. If
+ they're stopped for some reason other than us telling it to, the
+ target reports a signal != TARGET_SIGNAL_0. We don't try to
+ resume threads with such a stop signal. */
+ async_exec = non_stop;
+
+ if (!ptid_equal (inferior_ptid, null_ptid))
+ make_cleanup_restore_current_thread ();
+
+ switch_to_thread (ptid);
+
+ /* When we "notice" a new inferior we need to do all the things we
+ would normally do if we had just attached to it. */
+
+ if (is_executing (inferior_ptid))
+ {
+ struct inferior *inferior = current_inferior ();
+
+ /* We're going to install breakpoints, and poke at memory,
+ ensure that the inferior is stopped for a moment while we do
+ that. */
+ target_stop (inferior_ptid);
+
+ inferior->stop_soon = STOP_QUIETLY_REMOTE;
+
+ /* Wait for stop before proceeding. */
+ if (target_can_async_p ())
+ {
+ struct attach_command_continuation_args *a;
+
+ a = xmalloc (sizeof (*a));
+ a->args = xstrdup ("");
+ a->from_tty = from_tty;
+ a->async_exec = async_exec;
+ add_inferior_continuation (attach_command_continuation, a,
+ attach_command_continuation_free_args);
+
+ do_cleanups (old_chain);
+ return;
+ }
+ else
+ wait_for_inferior (0);
+ }
+
+ async_exec = leave_running;
+ attach_command_post_wait ("" /* args */, from_tty, async_exec);
+
+ do_cleanups (old_chain);
+}
+
/*
* detach_command --
* takes a program previously attached to and detaches it.