Re: [PATCH 02/18] Remote all-stop-on-top-of-non-stop

Yao Qi
2015-10-23T15:30:25Z

Pedro Alves <palves@redhat.com> writes:

> @@ -2636,8 +2633,37 @@ attach_command_post_wait (char *args, int from_tty, int async_exec)
> target_post_attach (ptid_get_pid (inferior_ptid));
>
> post_create_inferior (&current_target, from_tty);
> +}
> +
> +/* What to do after the first program stops after attaching. */
> +enum attach_post_wait_mode
> +{
> + /* Do nothing. Leaves threads as they are. */
> + ATTACH_POST_WAIT_NOTHING,
> +
> + /* Re-resume threads that are marked running. */
> + ATTACH_POST_WAIT_RESUME,
> +
> + /* Stop all threads. */
> + ATTACH_POST_WAIT_STOP,
> +};
> +
> +/* Called after we've attached to a process and we've seen it stop for
> + the first time. If ASYNC_EXEC is true, re-resume threads that
> + should be running. Else if ATTACH, */
> +

Comments are not complete.

> +
> + /* Now go over all threads that are stopped, and print their current
> + frame. If all-stop, then if there's a signalled thread, pick
> + that as current. */

Is it the code you described in the last paragraph of the commit log?

> + ALL_NON_EXITED_THREADS (thread)
> + {
> + struct target_waitstatus *ws;
> +
> + if (first == NULL)
> + first = thread;
> +
> + if (!non_stop)
> + set_running (thread->ptid, 0);
> + else if (thread->state != THREAD_STOPPED)
> + continue;
> +
> + ws = &thread->suspend.waitstatus;
> +
> + if (selected == NULL
> + && thread->suspend.waitstatus_pending_p)
> + selected = thread;
> +
> + if (lowest == NULL || thread->num < lowest->num)
> + lowest = thread;
> +
> + if (non_stop)
> + print_one_stopped_thread (thread);
> + }
> +
> + /* In all-stop, we only print the status of one thread, and leave
> + others with their status pending. */
> + if (!non_stop)
> + {
> + thread = selected;
> + if (thread == NULL)
> + thread = lowest;
> + if (thread == NULL)
> + thread = first;

Looks lowest can't be NULL, so first isn't used.

> +
> + print_one_stopped_thread (thread);
> + }
> +
> + /* For "info program". */
> + thread = inferior_thread ();
> + if (thread->state == THREAD_STOPPED)
> + set_last_target_status (inferior_ptid, thread->suspend.waitstatus);
> }
>
> static void
> @@ -3826,7 +3942,7 @@ remote_start_remote (int from_tty, struct target_ops *target, int extended_p)

> @@ -12936,11 +13040,15 @@ remote_async (struct target_ops *ops, int enable)
> event loop to process them. */
> if (!QUEUE_is_empty (stop_reply_p, stop_reply_queue))
> mark_async_event_handler (remote_async_inferior_event_token);
> + if (target_is_non_stop_p ())
> + mark_async_event_handler (rs->notif_state->get_pending_events_token);

I don't understand why do we need to mark the pending event token.
Previously, we only need to do so when GDB sees a notification.

> }
> else
> {
> serial_async (rs->remote_desc, NULL, NULL);
> clear_async_event_handler (remote_async_inferior_event_token);
> + if (target_is_non_stop_p ())
> + clear_async_event_handler (rs->notif_state->get_pending_events_token);
> }
> }
>

--
Yao (齐尧)