+ if (inf->pid == 0)
+ continue;
+
+ inf->needs_setup = 1;
+
+ if (non_stop)
+ {
+ thread = any_live_thread_of_process (inf->pid);
+ notice_new_inferior (thread->ptid,
+ thread->state == THREAD_RUNNING,
+ from_tty);
+ }
+ }
+
+ /* If all-stop on top of non-stop, pause all threads. Note this
+ records the threads' stop pc, so must be done after "noticing"
+ the inferiors. */
+ if (!non_stop)
+ {
+ stop_all_threads ();
+
+ /* If all threads of an inferior were already stopped, we
+ haven't setup the inferior yet. */
+ ALL_INFERIORS (inf)
+ {
+ if (inf->pid == 0)
+ continue;
+
+ if (inf->needs_setup)
+ {
+ thread = any_live_thread_of_process (inf->pid);
+ switch_to_thread_no_regs (thread);
+ setup_inferior (0);
+ }
+ }
+ }
+
+ /* 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. */
+ ALL_NON_EXITED_THREADS (thread)
+ {
+ if (first == NULL)
+ first = thread;
+
+ if (!non_stop)
+ set_running (thread->ptid, 0);
+ else if (thread->state != THREAD_STOPPED)
+ continue;
+
+ if (selected == NULL
+ && thread->suspend.waitstatus_pending_p)
+ selected = thread;
+
+ if (lowest_stopped == NULL
+ || thread->inf->num < lowest_stopped->inf->num
+ || thread->per_inf_num < lowest_stopped->per_inf_num)
+ lowest_stopped = 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_stopped;
+ if (thread == NULL)
+ thread = first;
+
+ 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);
+}
+
+/* Start the remote connection and sync state. */
+
+static void
+remote_start_remote (int from_tty, struct target_ops *target, int extended_p)
+{
+ struct remote_state *rs = get_remote_state ();
+ struct packet_config *noack_config;
+ char *wait_status = NULL;
+
+ /* Signal other parts that we're going through the initial setup,
+ and so things may not be stable yet. E.g., we don't try to
+ install tracepoints until we've relocated symbols. Also, a
+ Ctrl-C before we're connected and synced up can't interrupt the
+ target. Instead, it offers to drop the (potentially wedged)
+ connection. */
+ rs->starting_up = 1;
+
+ QUIT;
+
+ if (interrupt_on_connect)
+ send_interrupt_sequence ();
+
+ /* Ack any packet which the remote side has already sent. */
+ remote_serial_write ("+", 1);
+
+ /* The first packet we send to the target is the optional "supported
+ packets" request. If the target can answer this, it will tell us
+ which later probes to skip. */
+ remote_query_supported ();
+
+ /* If the stub wants to get a QAllow, compose one and send it. */
+ if (packet_support (PACKET_QAllow) != PACKET_DISABLE)
+ remote_set_permissions (target);
+
+ /* gdbserver < 7.7 (before its fix from 2013-12-11) did reply to any
+ unknown 'v' packet with string "OK". "OK" gets interpreted by GDB
+ as a reply to known packet. For packet "vFile:setfs:" it is an
+ invalid reply and GDB would return error in
+ remote_hostio_set_filesystem, making remote files access impossible.
+ Disable "vFile:setfs:" in such case. Do not disable other 'v' packets as
+ other "vFile" packets get correctly detected even on gdbserver < 7.7. */
+ {
+ const char v_mustreplyempty[] = "vMustReplyEmpty";
+
+ putpkt (v_mustreplyempty);
+ getpkt (&rs->buf, &rs->buf_size, 0);
+ if (strcmp (rs->buf, "OK") == 0)
+ remote_protocol_packets[PACKET_vFile_setfs].support = PACKET_DISABLE;
+ else if (strcmp (rs->buf, "") != 0)
+ error (_("Remote replied unexpectedly to '%s': %s"), v_mustreplyempty,
+ rs->buf);
+ }
+
+ /* Next, we possibly activate noack mode.
+
+ If the QStartNoAckMode packet configuration is set to AUTO,
+ enable noack mode if the stub reported a wish for it with
+ qSupported.
+
+ If set to TRUE, then enable noack mode even if the stub didn't
+ report it in qSupported. If the stub doesn't reply OK, the
+ session ends with an error.
+
+ If FALSE, then don't activate noack mode, regardless of what the
+ stub claimed should be the default with qSupported. */
+
+ noack_config = &remote_protocol_packets[PACKET_QStartNoAckMode];
+ if (packet_config_support (noack_config) != PACKET_DISABLE)
+ {
+ putpkt ("QStartNoAckMode");
+ getpkt (&rs->buf, &rs->buf_size, 0);
+ if (packet_ok (rs->buf, noack_config) == PACKET_OK)
+ rs->noack_mode = 1;
+ }
+
+ if (extended_p)
+ {
+ /* Tell the remote that we are using the extended protocol. */
+ putpkt ("!");
+ getpkt (&rs->buf, &rs->buf_size, 0);
+ }
+
+ /* Let the target know which signals it is allowed to pass down to
+ the program. */
+ update_signals_program_target ();
+
+ /* Next, if the target can specify a description, read it. We do
+ this before anything involving memory or registers. */
+ target_find_description ();
+
+ /* Next, now that we know something about the target, update the
+ address spaces in the program spaces. */
+ update_address_spaces ();
+
+ /* On OSs where the list of libraries is global to all
+ processes, we fetch them early. */
+ if (gdbarch_has_global_solist (target_gdbarch ()))
+ solib_add (NULL, from_tty, target, auto_solib_add);
+
+ if (target_is_non_stop_p ())
+ {
+ if (packet_support (PACKET_QNonStop) != PACKET_ENABLE)