+ TRY
+ {
+ /* Wait for events. This will return when all event sources
+ are removed from the event loop. */
+ start_event_loop ();
+
+ /* If an exit was requested (using the "monitor exit"
+ command), terminate now. The only other way to get
+ here is for getpkt to fail; close the connection
+ and reopen it at the top of the loop. */
+
+ if (exit_requested || run_once)
+ throw_quit ("Quit");
+
+ fprintf (stderr,
+ "Remote side has terminated connection. "
+ "GDBserver will reopen the connection.\n");
+
+ /* Get rid of any pending statuses. An eventual reconnection
+ (by the same GDB instance or another) will refresh all its
+ state from scratch. */
+ discard_queued_stop_replies (-1);
+ for_each_inferior (&all_threads,
+ clear_pending_status_callback);
+
+ if (tracing)
+ {
+ if (disconnected_tracing)
+ {
+ /* Try to enable non-stop/async mode, so we we can
+ both wait for an async socket accept, and handle
+ async target events simultaneously. There's also
+ no point either in having the target always stop
+ all threads, when we're going to pass signals
+ down without informing GDB. */
+ if (!non_stop)
+ {
+ if (start_non_stop (1))
+ non_stop = 1;
+
+ /* Detaching implicitly resumes all threads;
+ simply disconnecting does not. */
+ }
+ }
+ else
+ {
+ fprintf (stderr,
+ "Disconnected tracing disabled; "
+ "stopping trace run.\n");
+ stop_tracing ();
+ }
+ }
+ }
+ CATCH (exception, RETURN_MASK_ERROR)