• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

修订版6efcd9a8b3dc6a01cd1f212a2d854e5f8896715e (tree)
时间2015-12-01 03:36:37
作者Pedro Alves <palves@redh...>
CommiterPedro Alves

Log Message

Remote all-stop-on-top-of-non-stop

This is the first pass at implementing support for all-stop mode
running against the remote target using the non-stop variant of the
protocol.

The trickiest part here is the initial connection setup/synching. We
need to fetch all inferiors' target descriptions etc. before stopping
threads, because stop_all_threads needs to read the threads' registers
(to record each thread's stop_pc). But OTOH, the initial inferior
setup (target_post_attach, post_create_inferior, etc.), only works
correctly if the inferior is stopped... So I've split that initial
setup part from attach_command_post_wait to a separate function, and
added a "still needs setup" flag to the inferior structure. This is
similar to gdbserver/linux-low.c's handling of discovering the
process's target description). Then if on connection all threads of
the remote inferior are running, when we go about stopping them, as
soon as they stop we call setup_inferior, from within
stop_all_threads.

Also, in all-stop, we need to process all the initial stop replies to
learn about all the pending signal the threads may already be stopped
for, and pick the one to report as current. This is exposed by
gdb.threads/reconnect-signal.exp.

gdb/
2015-11-30 Pedro Alves <palves@redhat.com>

* gdbthread.h (switch_to_thread_no_regs): Declare.
* infcmd.c (setup_inferior): New function, factored out from ...
(attach_command_post_wait): ... this. Rename to ...
(attach_post_wait): ... this. Replace parameter async_exec with
attach_post_wait_mode parameter. Adjust.
(enum attach_post_wait_mode): New enum.
(struct attach_command_continuation_args): Replace 'async_exec'
field with 'mode' field.
(attach_command_continuation): Adjust.
(attach_command): Add comment. Mark the inferior as needing
setup. Adjust to use enum attach_post_wait_mode.
(notice_new_inferior): Use switch_to_thread_no_regs. Adjust to
use enum attach_post_wait_mode.
* inferior.h (setup_inferior): Declare.
(struct inferior) <needs_setup>: New field.
* infrun.c (set_last_target_status): Make extern.
(stop_all_threads): Make extern. Setup inferior, if necessary.
* infrun.h (set_last_target_status, stop_all_threads): Declare.
* remote-notif.c (remote_async_get_pending_events_handler)
(handle_notification): Replace non_stop checks with
target_is_non_stop_p() checks.
* remote.c (remote_notice_new_inferior): Remove non_stop check.
(remote_update_thread_list): Replace non_stop check with
target_is_non_stop_p() check.
(print_one_stopped_thread): New function.
(process_initial_stop_replies): New 'from_tty' parameter.
"Notice" all new live inferiors after storing initial stops as
pending status in each corresponding thread. If all-stop, stop
all threads, try picking a signalled thread as current, and print
the status of that one thread. Record the last target status.
(remote_start_remote): Replace non_stop checks with
target_is_non_stop_p() checks. Don't query for the remote current
thread of use qOffsets here. Pass from_tty to
process_initial_stop_replies.
(extended_remote_attach): Replace non_stop checks with
target_is_non_stop_p() checks.
(extended_remote_post_attach): Send qOffsets here.
(remote_vcont_resume, remote_resume, remote_stop)
(remote_interrupt, remote_parse_stop_reply, remote_wait): Replace
non_stop checks with target_is_non_stop_p() checks.
(remote_async): If target is non-stop, mark/clear the pending
events token.
* thread.c (switch_to_thread_no_regs): New function.

更改概述

差异

--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,51 @@
11 2015-11-30 Pedro Alves <palves@redhat.com>
22
3+ * gdbthread.h (switch_to_thread_no_regs): Declare.
4+ * infcmd.c (setup_inferior): New function, factored out from ...
5+ (attach_command_post_wait): ... this. Rename to ...
6+ (attach_post_wait): ... this. Replace parameter async_exec with
7+ attach_post_wait_mode parameter. Adjust.
8+ (enum attach_post_wait_mode): New enum.
9+ (struct attach_command_continuation_args): Replace 'async_exec'
10+ field with 'mode' field.
11+ (attach_command_continuation): Adjust.
12+ (attach_command): Add comment. Mark the inferior as needing
13+ setup. Adjust to use enum attach_post_wait_mode.
14+ (notice_new_inferior): Use switch_to_thread_no_regs. Adjust to
15+ use enum attach_post_wait_mode.
16+ * inferior.h (setup_inferior): Declare.
17+ (struct inferior) <needs_setup>: New field.
18+ * infrun.c (set_last_target_status): Make extern.
19+ (stop_all_threads): Make extern. Setup inferior, if necessary.
20+ * infrun.h (set_last_target_status, stop_all_threads): Declare.
21+ * remote-notif.c (remote_async_get_pending_events_handler)
22+ (handle_notification): Replace non_stop checks with
23+ target_is_non_stop_p() checks.
24+ * remote.c (remote_notice_new_inferior): Remove non_stop check.
25+ (remote_update_thread_list): Replace non_stop check with
26+ target_is_non_stop_p() check.
27+ (print_one_stopped_thread): New function.
28+ (process_initial_stop_replies): New 'from_tty' parameter.
29+ "Notice" all new live inferiors after storing initial stops as
30+ pending status in each corresponding thread. If all-stop, stop
31+ all threads, try picking a signalled thread as current, and print
32+ the status of that one thread. Record the last target status.
33+ (remote_start_remote): Replace non_stop checks with
34+ target_is_non_stop_p() checks. Don't query for the remote current
35+ thread of use qOffsets here. Pass from_tty to
36+ process_initial_stop_replies.
37+ (extended_remote_attach): Replace non_stop checks with
38+ target_is_non_stop_p() checks.
39+ (extended_remote_post_attach): Send qOffsets here.
40+ (remote_vcont_resume, remote_resume, remote_stop)
41+ (remote_interrupt, remote_parse_stop_reply, remote_wait): Replace
42+ non_stop checks with target_is_non_stop_p() checks.
43+ (remote_async): If target is non-stop, mark/clear the pending
44+ events token.
45+ * thread.c (switch_to_thread_no_regs): New function.
46+
47+2015-11-30 Pedro Alves <palves@redhat.com>
48+
349 * gdb.mi/mi-nonstop.exp: Append "set non-stop on" to GDBFLAGS
450 instead of issuing "-gdb-set non-stop 1" after starting gdb.
551 Use mi_is_target_remote instead of checking "is_remote target".
--- a/gdb/gdbthread.h
+++ b/gdb/gdbthread.h
@@ -411,9 +411,14 @@ extern struct thread_info *iterate_over_threads (thread_callback_func, void *);
411411
412412 extern int thread_count (void);
413413
414-/* Switch from one thread to another. */
414+/* Switch from one thread to another. Also sets the STOP_PC
415+ global. */
415416 extern void switch_to_thread (ptid_t ptid);
416417
418+/* Switch from one thread to another. Does not read registers and
419+ sets STOP_PC to -1. */
420+extern void switch_to_thread_no_regs (struct thread_info *thread);
421+
417422 /* Marks or clears thread(s) PTID as resumed. If PTID is
418423 MINUS_ONE_PTID, applies to all threads. If ptid_is_pid(PTID) is
419424 true, applies to all threads of the process pointed at by PTID. */
--- a/gdb/infcmd.c
+++ b/gdb/infcmd.c
@@ -2609,18 +2609,15 @@ proceed_after_attach (int pid)
26092609 do_cleanups (old_chain);
26102610 }
26112611
2612-/* attach_command --
2613- takes a program started up outside of gdb and ``attaches'' to it.
2614- This stops it cold in its tracks and allows us to start debugging it.
2615- and wait for the trace-trap that results from attaching. */
2612+/* See inferior.h. */
26162613
2617-static void
2618-attach_command_post_wait (char *args, int from_tty, int async_exec)
2614+void
2615+setup_inferior (int from_tty)
26192616 {
26202617 struct inferior *inferior;
26212618
26222619 inferior = current_inferior ();
2623- inferior->control.stop_soon = NO_STOP_QUIETLY;
2620+ inferior->needs_setup = 0;
26242621
26252622 /* If no exec file is yet known, try to determine it from the
26262623 process itself. */
@@ -2636,8 +2633,37 @@ attach_command_post_wait (char *args, int from_tty, int async_exec)
26362633 target_post_attach (ptid_get_pid (inferior_ptid));
26372634
26382635 post_create_inferior (&current_target, from_tty);
2636+}
2637+
2638+/* What to do after the first program stops after attaching. */
2639+enum attach_post_wait_mode
2640+{
2641+ /* Do nothing. Leaves threads as they are. */
2642+ ATTACH_POST_WAIT_NOTHING,
2643+
2644+ /* Re-resume threads that are marked running. */
2645+ ATTACH_POST_WAIT_RESUME,
2646+
2647+ /* Stop all threads. */
2648+ ATTACH_POST_WAIT_STOP,
2649+};
2650+
2651+/* Called after we've attached to a process and we've seen it stop for
2652+ the first time. If ASYNC_EXEC is true, re-resume threads that
2653+ should be running. Else if ATTACH, */
2654+
2655+static void
2656+attach_post_wait (char *args, int from_tty, enum attach_post_wait_mode mode)
2657+{
2658+ struct inferior *inferior;
26392659
2640- if (async_exec)
2660+ inferior = current_inferior ();
2661+ inferior->control.stop_soon = NO_STOP_QUIETLY;
2662+
2663+ if (inferior->needs_setup)
2664+ setup_inferior (from_tty);
2665+
2666+ if (mode == ATTACH_POST_WAIT_RESUME)
26412667 {
26422668 /* The user requested an `attach&', so be sure to leave threads
26432669 that didn't get a signal running. */
@@ -2657,7 +2683,7 @@ attach_command_post_wait (char *args, int from_tty, int async_exec)
26572683 }
26582684 }
26592685 }
2660- else
2686+ else if (mode == ATTACH_POST_WAIT_STOP)
26612687 {
26622688 /* The user requested a plain `attach', so be sure to leave
26632689 the inferior stopped. */
@@ -2685,7 +2711,7 @@ struct attach_command_continuation_args
26852711 {
26862712 char *args;
26872713 int from_tty;
2688- int async_exec;
2714+ enum attach_post_wait_mode mode;
26892715 };
26902716
26912717 static void
@@ -2697,7 +2723,7 @@ attach_command_continuation (void *args, int err)
26972723 if (err)
26982724 return;
26992725
2700- attach_command_post_wait (a->args, a->from_tty, a->async_exec);
2726+ attach_post_wait (a->args, a->from_tty, a->mode);
27012727 }
27022728
27032729 static void
@@ -2710,12 +2736,18 @@ attach_command_continuation_free_args (void *args)
27102736 xfree (a);
27112737 }
27122738
2739+/* "attach" command entry point. Takes a program started up outside
2740+ of gdb and ``attaches'' to it. This stops it cold in its tracks
2741+ and allows us to start debugging it. */
2742+
27132743 void
27142744 attach_command (char *args, int from_tty)
27152745 {
27162746 int async_exec;
27172747 struct cleanup *args_chain;
27182748 struct target_ops *attach_target;
2749+ struct inferior *inferior = current_inferior ();
2750+ enum attach_post_wait_mode mode;
27192751
27202752 dont_repeat (); /* Not for the faint of heart */
27212753
@@ -2775,6 +2807,8 @@ attach_command (char *args, int from_tty)
27752807 init_wait_for_inferior ();
27762808 clear_proceed_status (0);
27772809
2810+ inferior->needs_setup = 1;
2811+
27782812 if (target_is_non_stop_p ())
27792813 {
27802814 /* If we find that the current thread isn't stopped, explicitly
@@ -2790,12 +2824,13 @@ attach_command (char *args, int from_tty)
27902824 target_stop (pid_to_ptid (ptid_get_pid (inferior_ptid)));
27912825 }
27922826
2827+ mode = async_exec ? ATTACH_POST_WAIT_RESUME : ATTACH_POST_WAIT_STOP;
2828+
27932829 /* Some system don't generate traps when attaching to inferior.
27942830 E.g. Mach 3 or GNU hurd. */
27952831 if (!target_attach_no_wait)
27962832 {
27972833 struct attach_command_continuation_args *a;
2798- struct inferior *inferior = current_inferior ();
27992834
28002835 /* Careful here. See comments in inferior.h. Basically some
28012836 OSes don't ignore SIGSTOPs on continue requests anymore. We
@@ -2808,7 +2843,7 @@ attach_command (char *args, int from_tty)
28082843 a = XNEW (struct attach_command_continuation_args);
28092844 a->args = xstrdup (args);
28102845 a->from_tty = from_tty;
2811- a->async_exec = async_exec;
2846+ a->mode = mode;
28122847 add_inferior_continuation (attach_command_continuation, a,
28132848 attach_command_continuation_free_args);
28142849 /* Done with ARGS. */
@@ -2822,7 +2857,7 @@ attach_command (char *args, int from_tty)
28222857 /* Done with ARGS. */
28232858 do_cleanups (args_chain);
28242859
2825- attach_command_post_wait (args, from_tty, async_exec);
2860+ attach_post_wait (args, from_tty, mode);
28262861 }
28272862
28282863 /* We had just found out that the target was already attached to an
@@ -2837,7 +2872,7 @@ void
28372872 notice_new_inferior (ptid_t ptid, int leave_running, int from_tty)
28382873 {
28392874 struct cleanup* old_chain;
2840- int async_exec;
2875+ enum attach_post_wait_mode mode;
28412876
28422877 old_chain = make_cleanup (null_cleanup, NULL);
28432878
@@ -2845,12 +2880,14 @@ notice_new_inferior (ptid_t ptid, int leave_running, int from_tty)
28452880 they're stopped for some reason other than us telling it to, the
28462881 target reports a signal != GDB_SIGNAL_0. We don't try to
28472882 resume threads with such a stop signal. */
2848- async_exec = non_stop;
2883+ mode = non_stop ? ATTACH_POST_WAIT_RESUME : ATTACH_POST_WAIT_NOTHING;
28492884
28502885 if (!ptid_equal (inferior_ptid, null_ptid))
28512886 make_cleanup_restore_current_thread ();
28522887
2853- switch_to_thread (ptid);
2888+ /* Avoid reading registers -- we haven't fetched the target
2889+ description yet. */
2890+ switch_to_thread_no_regs (find_thread_ptid (ptid));
28542891
28552892 /* When we "notice" a new inferior we need to do all the things we
28562893 would normally do if we had just attached to it. */
@@ -2871,7 +2908,7 @@ notice_new_inferior (ptid_t ptid, int leave_running, int from_tty)
28712908 a = XNEW (struct attach_command_continuation_args);
28722909 a->args = xstrdup ("");
28732910 a->from_tty = from_tty;
2874- a->async_exec = async_exec;
2911+ a->mode = mode;
28752912 add_inferior_continuation (attach_command_continuation, a,
28762913 attach_command_continuation_free_args);
28772914
@@ -2879,8 +2916,8 @@ notice_new_inferior (ptid_t ptid, int leave_running, int from_tty)
28792916 return;
28802917 }
28812918
2882- async_exec = leave_running;
2883- attach_command_post_wait ("" /* args */, from_tty, async_exec);
2919+ mode = leave_running ? ATTACH_POST_WAIT_RESUME : ATTACH_POST_WAIT_NOTHING;
2920+ attach_post_wait ("" /* args */, from_tty, mode);
28842921
28852922 do_cleanups (old_chain);
28862923 }
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -143,6 +143,12 @@ extern char *construct_inferior_arguments (int, char **);
143143
144144 /* From infcmd.c */
145145
146+/* Initial inferior setup. Determines the exec file is not yet known,
147+ takes any necessary post-attaching actions, fetches the target
148+ description and syncs the shared library list. */
149+
150+extern void setup_inferior (int from_tty);
151+
146152 extern void post_create_inferior (struct target_ops *, int);
147153
148154 extern void attach_command (char *, int);
@@ -364,6 +370,12 @@ struct inferior
364370 specific thread, see `struct thread_info'. */
365371 struct continuation *continuations;
366372
373+ /* True if setup_inferior wasn't called for this inferior yet.
374+ Until that is done, we must not access inferior memory or
375+ registers, as we haven't determined the target
376+ architecture/description. */
377+ int needs_setup;
378+
367379 /* Private data used by the target vector implementation. */
368380 struct private_inferior *priv;
369381
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -2052,7 +2052,6 @@ static void keep_going_pass_signal (struct execution_control_state *ecs);
20522052 static void prepare_to_wait (struct execution_control_state *ecs);
20532053 static int keep_going_stepped_thread (struct thread_info *tp);
20542054 static step_over_what thread_still_needs_step_over (struct thread_info *tp);
2055-static void stop_all_threads (void);
20562055
20572056 /* Are there any pending step-over requests? If so, run all we can
20582057 now and return true. Otherwise, return false. */
@@ -4015,7 +4014,7 @@ init_thread_stepping_state (struct thread_info *tss)
40154014
40164015 /* Set the cached copy of the last ptid/waitstatus. */
40174016
4018-static void
4017+void
40194018 set_last_target_status (ptid_t ptid, struct target_waitstatus status)
40204019 {
40214020 target_last_wait_ptid = ptid;
@@ -4437,9 +4436,9 @@ save_waitstatus (struct thread_info *tp, struct target_waitstatus *ws)
44374436 }
44384437 }
44394438
4440-/* Stop all threads. */
4439+/* See infrun.h. */
44414440
4442-static void
4441+void
44434442 stop_all_threads (void)
44444443 {
44454444 /* We may need multiple passes to discover all threads. */
@@ -4548,6 +4547,8 @@ stop_all_threads (void)
45484547 }
45494548 else
45504549 {
4550+ struct inferior *inf;
4551+
45514552 t = find_thread_ptid (event_ptid);
45524553 if (t == NULL)
45534554 t = add_thread (event_ptid);
@@ -4557,6 +4558,15 @@ stop_all_threads (void)
45574558 t->resumed = 0;
45584559 t->control.may_range_step = 0;
45594560
4561+ /* This may be the first time we see the inferior report
4562+ a stop. */
4563+ inf = find_inferior_ptid (event_ptid);
4564+ if (inf->needs_setup)
4565+ {
4566+ switch_to_thread_no_regs (t);
4567+ setup_inferior (0);
4568+ }
4569+
45604570 if (ws.kind == TARGET_WAITKIND_STOPPED
45614571 && ws.value.sig == GDB_SIGNAL_0)
45624572 {
--- a/gdb/infrun.h
+++ b/gdb/infrun.h
@@ -112,6 +112,12 @@ extern int normal_stop (void);
112112 extern void get_last_target_status (ptid_t *ptid,
113113 struct target_waitstatus *status);
114114
115+extern void set_last_target_status (ptid_t ptid,
116+ struct target_waitstatus status);
117+
118+/* Stop all threads. Only returns after everything is halted. */
119+extern void stop_all_threads (void);
120+
115121 extern void prepare_for_detach (void);
116122
117123 extern void fetch_inferior_event (void *);
--- a/gdb/remote-notif.c
+++ b/gdb/remote-notif.c
@@ -116,7 +116,7 @@ remote_notif_process (struct remote_notif_state *state,
116116 static void
117117 remote_async_get_pending_events_handler (gdb_client_data data)
118118 {
119- gdb_assert (non_stop);
119+ gdb_assert (target_is_non_stop_p ());
120120 remote_notif_process ((struct remote_notif_state *) data, NULL);
121121 }
122122
@@ -166,7 +166,7 @@ handle_notification (struct remote_notif_state *state, char *buf)
166166 /* Notify the event loop there's a stop reply to acknowledge
167167 and that there may be more events to fetch. */
168168 QUEUE_enque (notif_client_p, state->notif_queue, nc);
169- if (non_stop)
169+ if (target_is_non_stop_p ())
170170 {
171171 /* In non-stop, We mark REMOTE_ASYNC_GET_PENDING_EVENTS_TOKEN
172172 in order to go on what we were doing and postpone
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -1887,7 +1887,7 @@ remote_notice_new_inferior (ptid_t currthread, int running)
18871887 {
18881888 struct remote_state *rs = get_remote_state ();
18891889
1890- if (non_stop || !rs->starting_up)
1890+ if (!rs->starting_up)
18911891 notice_new_inferior (currthread, running, 0);
18921892 }
18931893 }
@@ -3165,7 +3165,7 @@ remote_update_thread_list (struct target_ops *ops)
31653165 running until proven otherwise with a stop reply. In
31663166 all-stop, we can only get here if all threads are
31673167 stopped. */
3168- int running = non_stop ? 1 : 0;
3168+ int running = target_is_non_stop_p () ? 1 : 0;
31693169
31703170 remote_notice_new_inferior (item->ptid, running);
31713171
@@ -3706,15 +3706,44 @@ add_current_inferior_and_thread (char *wait_status)
37063706 add_thread_silent (inferior_ptid);
37073707 }
37083708
3709+/* Print info about a thread that was found already stopped on
3710+ connection. */
3711+
3712+static void
3713+print_one_stopped_thread (struct thread_info *thread)
3714+{
3715+ struct target_waitstatus *ws = &thread->suspend.waitstatus;
3716+
3717+ switch_to_thread (thread->ptid);
3718+ stop_pc = get_frame_pc (get_current_frame ());
3719+ set_current_sal_from_frame (get_current_frame ());
3720+
3721+ thread->suspend.waitstatus_pending_p = 0;
3722+
3723+ if (ws->kind == TARGET_WAITKIND_STOPPED)
3724+ {
3725+ enum gdb_signal sig = ws->value.sig;
3726+
3727+ if (signal_print_state (sig))
3728+ observer_notify_signal_received (sig);
3729+ }
3730+ observer_notify_normal_stop (NULL, 1);
3731+}
3732+
37093733 /* Process all initial stop replies the remote side sent in response
37103734 to the ? packet. These indicate threads that were already stopped
37113735 on initial connection. We mark these threads as stopped and print
37123736 their current frame before giving the user the prompt. */
37133737
37143738 static void
3715-process_initial_stop_replies (void)
3739+process_initial_stop_replies (int from_tty)
37163740 {
37173741 int pending_stop_replies = stop_reply_queue_length ();
3742+ struct inferior *inf;
3743+ struct thread_info *thread;
3744+ struct thread_info *selected = NULL;
3745+ struct thread_info *lowest_stopped = NULL;
3746+ struct thread_info *first = NULL;
37183747
37193748 /* Consume the initial pending events. */
37203749 while (pending_stop_replies-- > 0)
@@ -3723,6 +3752,7 @@ process_initial_stop_replies (void)
37233752 ptid_t event_ptid;
37243753 struct target_waitstatus ws;
37253754 int ignore_event = 0;
3755+ struct thread_info *thread;
37263756
37273757 memset (&ws, 0, sizeof (ws));
37283758 event_ptid = target_wait (waiton_ptid, &ws, TARGET_WNOHANG);
@@ -3751,12 +3781,7 @@ process_initial_stop_replies (void)
37513781 if (ignore_event)
37523782 continue;
37533783
3754- switch_to_thread (event_ptid);
3755- set_executing (event_ptid, 0);
3756- set_running (event_ptid, 0);
3757-
3758- stop_pc = get_frame_pc (get_current_frame ());
3759- set_current_sal_from_frame (get_current_frame ());
3784+ thread = find_thread_ptid (event_ptid);
37603785
37613786 if (ws.kind == TARGET_WAITKIND_STOPPED)
37623787 {
@@ -3766,15 +3791,106 @@ process_initial_stop_replies (void)
37663791 instead of signal 0. Suppress it. */
37673792 if (sig == GDB_SIGNAL_TRAP)
37683793 sig = GDB_SIGNAL_0;
3769- inferior_thread ()->suspend.stop_signal = sig;
3794+ thread->suspend.stop_signal = sig;
3795+ ws.value.sig = sig;
3796+ }
37703797
3771- if (signal_print_state (sig))
3772- observer_notify_signal_received (sig);
3773- }
3798+ thread->suspend.waitstatus = ws;
3799+
3800+ if (ws.kind != TARGET_WAITKIND_STOPPED
3801+ || ws.value.sig != GDB_SIGNAL_0)
3802+ thread->suspend.waitstatus_pending_p = 1;
3803+
3804+ set_executing (event_ptid, 0);
3805+ set_running (event_ptid, 0);
3806+ }
3807+
3808+ /* "Notice" the new inferiors before anything related to
3809+ registers/memory. */
3810+ ALL_INFERIORS (inf)
3811+ {
3812+ if (inf->pid == 0)
3813+ continue;
3814+
3815+ inf->needs_setup = 1;
3816+
3817+ if (non_stop)
3818+ {
3819+ thread = any_live_thread_of_process (inf->pid);
3820+ notice_new_inferior (thread->ptid,
3821+ thread->state == THREAD_RUNNING,
3822+ from_tty);
3823+ }
3824+ }
3825+
3826+ /* If all-stop on top of non-stop, pause all threads. Note this
3827+ records the threads' stop pc, so must be done after "noticing"
3828+ the inferiors. */
3829+ if (!non_stop)
3830+ {
3831+ stop_all_threads ();
3832+
3833+ /* If all threads of an inferior were already stopped, we
3834+ haven't setup the inferior yet. */
3835+ ALL_INFERIORS (inf)
3836+ {
3837+ if (inf->pid == 0)
3838+ continue;
37743839
3775- print_stack_frame (get_selected_frame (NULL), 1, SRC_AND_LOC, 1);
3776- observer_notify_normal_stop (NULL, 1);
3840+ if (inf->needs_setup)
3841+ {
3842+ thread = any_live_thread_of_process (inf->pid);
3843+ switch_to_thread_no_regs (thread);
3844+ setup_inferior (0);
3845+ }
3846+ }
37773847 }
3848+
3849+ /* Now go over all threads that are stopped, and print their current
3850+ frame. If all-stop, then if there's a signalled thread, pick
3851+ that as current. */
3852+ ALL_NON_EXITED_THREADS (thread)
3853+ {
3854+ struct target_waitstatus *ws;
3855+
3856+ if (first == NULL)
3857+ first = thread;
3858+
3859+ if (!non_stop)
3860+ set_running (thread->ptid, 0);
3861+ else if (thread->state != THREAD_STOPPED)
3862+ continue;
3863+
3864+ ws = &thread->suspend.waitstatus;
3865+
3866+ if (selected == NULL
3867+ && thread->suspend.waitstatus_pending_p)
3868+ selected = thread;
3869+
3870+ if (lowest_stopped == NULL || thread->num < lowest_stopped->num)
3871+ lowest_stopped = thread;
3872+
3873+ if (non_stop)
3874+ print_one_stopped_thread (thread);
3875+ }
3876+
3877+ /* In all-stop, we only print the status of one thread, and leave
3878+ others with their status pending. */
3879+ if (!non_stop)
3880+ {
3881+ thread = selected;
3882+ if (thread == NULL)
3883+ thread = lowest_stopped;
3884+ if (thread == NULL)
3885+ thread = first;
3886+
3887+ print_one_stopped_thread (thread);
3888+ }
3889+
3890+ /* For "info program". */
3891+ thread = inferior_thread ();
3892+ if (thread->state == THREAD_STOPPED)
3893+ set_last_target_status (inferior_ptid, thread->suspend.waitstatus);
37783894 }
37793895
37803896 static void
@@ -3852,7 +3968,7 @@ remote_start_remote (int from_tty, struct target_ops *target, int extended_p)
38523968 if (gdbarch_has_global_solist (target_gdbarch ()))
38533969 solib_add (NULL, from_tty, target, auto_solib_add);
38543970
3855- if (non_stop)
3971+ if (target_is_non_stop_p ())
38563972 {
38573973 if (packet_support (PACKET_QNonStop) != PACKET_ENABLE)
38583974 error (_("Non-stop mode requested, but remote "
@@ -3896,7 +4012,7 @@ remote_start_remote (int from_tty, struct target_ops *target, int extended_p)
38964012 putpkt ("?");
38974013 getpkt (&rs->buf, &rs->buf_size, 0);
38984014
3899- if (!non_stop)
4015+ if (!target_is_non_stop_p ())
39004016 {
39014017 ptid_t ptid;
39024018 int fake_pid_p = 0;
@@ -3989,8 +4105,6 @@ remote_start_remote (int from_tty, struct target_ops *target, int extended_p)
39894105 }
39904106 else
39914107 {
3992- ptid_t current_ptid;
3993-
39944108 /* Clear WFI global state. Do this before finding about new
39954109 threads and inferiors, and setting the current inferior.
39964110 Otherwise we would clear the proceed status of the current
@@ -4025,19 +4139,6 @@ remote_start_remote (int from_tty, struct target_ops *target, int extended_p)
40254139 return;
40264140 }
40274141
4028- /* Let the stub know that we want it to return the thread. */
4029-
4030- /* Force the stub to choose a thread. */
4031- set_general_thread (null_ptid);
4032-
4033- /* Query it. */
4034- current_ptid = remote_current_thread (minus_one_ptid);
4035- if (ptid_equal (inferior_ptid, minus_one_ptid))
4036- error (_("remote didn't report the current thread in non-stop mode"));
4037-
4038- inferior_ptid = current_ptid;
4039- get_offsets (); /* Get text, data & bss offsets. */
4040-
40414142 /* In non-stop mode, any cached wait status will be stored in
40424143 the stop reply queue. */
40434144 gdb_assert (wait_status == NULL);
@@ -4047,9 +4148,7 @@ remote_start_remote (int from_tty, struct target_ops *target, int extended_p)
40474148
40484149 /* If there are already stopped threads, mark them stopped and
40494150 report their stops before giving the prompt to the user. */
4050- process_initial_stop_replies ();
4051-
4052- switch_to_thread (current_ptid);
4151+ process_initial_stop_replies (from_tty);
40534152
40544153 if (target_can_async_p ())
40554154 target_async (1);
@@ -5001,7 +5100,7 @@ extended_remote_attach (struct target_ops *target, const char *args,
50015100 &remote_protocol_packets[PACKET_vAttach]))
50025101 {
50035102 case PACKET_OK:
5004- if (!non_stop)
5103+ if (!target_is_non_stop_p ())
50055104 {
50065105 /* Save the reply for later. */
50075106 wait_status = (char *) alloca (strlen (rs->buf) + 1);
@@ -5023,7 +5122,7 @@ extended_remote_attach (struct target_ops *target, const char *args,
50235122
50245123 inferior_ptid = pid_to_ptid (pid);
50255124
5026- if (non_stop)
5125+ if (target_is_non_stop_p ())
50275126 {
50285127 struct thread_info *thread;
50295128
@@ -5052,7 +5151,7 @@ extended_remote_attach (struct target_ops *target, const char *args,
50525151 this before anything involving memory or registers. */
50535152 target_find_description ();
50545153
5055- if (!non_stop)
5154+ if (!target_is_non_stop_p ())
50565155 {
50575156 /* Use the previously fetched status. */
50585157 gdb_assert (wait_status != NULL);
@@ -5082,6 +5181,9 @@ extended_remote_attach (struct target_ops *target, const char *args,
50825181 static void
50835182 extended_remote_post_attach (struct target_ops *ops, int pid)
50845183 {
5184+ /* Get text, data & bss offsets. */
5185+ get_offsets ();
5186+
50855187 /* In certain cases GDB might not have had the chance to start
50865188 symbol lookup up until now. This could happen if the debugged
50875189 binary is not using shared libraries, the vsyscall page is not
@@ -5314,7 +5416,7 @@ remote_vcont_resume (ptid_t ptid, int step, enum gdb_signal siggnal)
53145416 gdb_assert (strlen (rs->buf) < get_remote_packet_size ());
53155417 putpkt (rs->buf);
53165418
5317- if (non_stop)
5419+ if (target_is_non_stop_p ())
53185420 {
53195421 /* In non-stop, the stub replies to vCont with "OK". The stop
53205422 reply will be reported asynchronously by means of a `%Stop'
@@ -5342,7 +5444,7 @@ remote_resume (struct target_ops *ops,
53425444 it is safe to start a 'vNotif' sequence. It is good to do it
53435445 before resuming inferior, because inferior was stopped and no RSP
53445446 traffic at that moment. */
5345- if (!non_stop)
5447+ if (!target_is_non_stop_p ())
53465448 remote_notif_process (rs->notif_state, &notif_client_stop);
53475449
53485450 rs->last_sent_signal = siggnal;
@@ -5406,7 +5508,7 @@ remote_resume (struct target_ops *ops,
54065508 only to the base all-stop protocol, however. In non-stop (which
54075509 only supports vCont), the stub replies with an "OK", and is
54085510 immediate able to process further serial input. */
5409- if (!non_stop)
5511+ if (!target_is_non_stop_p ())
54105512 rs->waiting_for_stop_reply = 1;
54115513 }
54125514
@@ -5593,7 +5695,7 @@ remote_stop (struct target_ops *self, ptid_t ptid)
55935695 if (remote_debug)
55945696 fprintf_unfiltered (gdb_stdlog, "remote_stop called\n");
55955697
5596- if (non_stop)
5698+ if (target_is_non_stop_p ())
55975699 remote_stop_ns (ptid);
55985700 else
55995701 {
@@ -5611,7 +5713,7 @@ remote_interrupt (struct target_ops *self, ptid_t ptid)
56115713 if (remote_debug)
56125714 fprintf_unfiltered (gdb_stdlog, "remote_interrupt called\n");
56135715
5614- if (non_stop)
5716+ if (target_is_non_stop_p ())
56155717 {
56165718 /* We don't currently have a way to ^C the remote target in
56175719 non-stop mode. Stop it (with no signal) instead. */
@@ -6405,7 +6507,7 @@ Packet: '%s'\n"),
64056507 break;
64066508 }
64076509
6408- if (non_stop && ptid_equal (event->ptid, null_ptid))
6510+ if (target_is_non_stop_p () && ptid_equal (event->ptid, null_ptid))
64096511 error (_("No process or thread specified in stop reply: %s"), buf);
64106512 }
64116513
@@ -6755,7 +6857,7 @@ remote_wait (struct target_ops *ops,
67556857 {
67566858 ptid_t event_ptid;
67576859
6758- if (non_stop)
6860+ if (target_is_non_stop_p ())
67596861 event_ptid = remote_wait_ns (ptid, status, options);
67606862 else
67616863 event_ptid = remote_wait_as (ptid, status, options);
@@ -7984,7 +8086,9 @@ putpkt_binary (const char *buf, int cnt)
79848086 case it's not possible to issue a command while the target is
79858087 running. This is not a problem in non-stop mode, because in that
79868088 case, the stub is always ready to process serial input. */
7987- if (!non_stop && target_is_async_p () && rs->waiting_for_stop_reply)
8089+ if (!target_is_non_stop_p ()
8090+ && target_is_async_p ()
8091+ && rs->waiting_for_stop_reply)
79888092 {
79898093 error (_("Cannot execute this command while the target is running.\n"
79908094 "Use the \"interrupt\" command to stop the target\n"
@@ -12959,11 +13063,23 @@ remote_async (struct target_ops *ops, int enable)
1295913063 event loop to process them. */
1296013064 if (!QUEUE_is_empty (stop_reply_p, stop_reply_queue))
1296113065 mark_async_event_handler (remote_async_inferior_event_token);
13066+ /* For simplicity, below we clear the pending events token
13067+ without remembering whether it is marked, so here we always
13068+ mark it. If there's actually no pending notification to
13069+ process, this ends up being a no-op (other than a spurious
13070+ event-loop wakeup). */
13071+ if (target_is_non_stop_p ())
13072+ mark_async_event_handler (rs->notif_state->get_pending_events_token);
1296213073 }
1296313074 else
1296413075 {
1296513076 serial_async (rs->remote_desc, NULL, NULL);
13077+ /* If the core is disabling async, it doesn't want to be
13078+ disturbed with target events. Clear all async event sources
13079+ too. */
1296613080 clear_async_event_handler (remote_async_inferior_event_token);
13081+ if (target_is_non_stop_p ())
13082+ clear_async_event_handler (rs->notif_state->get_pending_events_token);
1296713083 }
1296813084 }
1296913085
--- a/gdb/thread.c
+++ b/gdb/thread.c
@@ -1321,6 +1321,22 @@ info_threads_command (char *arg, int from_tty)
13211321 print_thread_info (current_uiout, arg, -1);
13221322 }
13231323
1324+/* See gdbthread.h. */
1325+
1326+void
1327+switch_to_thread_no_regs (struct thread_info *thread)
1328+{
1329+ struct inferior *inf;
1330+
1331+ inf = find_inferior_ptid (thread->ptid);
1332+ gdb_assert (inf != NULL);
1333+ set_current_program_space (inf->pspace);
1334+ set_current_inferior (inf);
1335+
1336+ inferior_ptid = thread->ptid;
1337+ stop_pc = ~(CORE_ADDR) 0;
1338+}
1339+
13241340 /* Switch from one thread to another. */
13251341
13261342 void