+ /* If this event was not handled before, and is not a SIGTRAP, we
+ report it. SIGILL and SIGSEGV are also treated as traps in case
+ a breakpoint is inserted at the current PC. If this target does
+ not support internal breakpoints at all, we also report the
+ SIGTRAP without further processing; it's of no concern to us. */
+ maybe_internal_trap
+ = (supports_breakpoints ()
+ && (WSTOPSIG (w) == SIGTRAP
+ || ((WSTOPSIG (w) == SIGILL
+ || WSTOPSIG (w) == SIGSEGV)
+ && (*the_low_target.breakpoint_at) (event_child->stop_pc))));
+
+ if (maybe_internal_trap)
+ {
+ /* Handle anything that requires bookkeeping before deciding to
+ report the event or continue waiting. */
+
+ /* First check if we can explain the SIGTRAP with an internal
+ breakpoint, or if we should possibly report the event to GDB.
+ Do this before anything that may remove or insert a
+ breakpoint. */
+ bp_explains_trap = breakpoint_inserted_here (event_child->stop_pc);
+
+ /* We have a SIGTRAP, possibly a step-over dance has just
+ finished. If so, tweak the state machine accordingly,
+ reinsert breakpoints and delete any reinsert (software
+ single-step) breakpoints. */
+ step_over_finished = finish_step_over (event_child);
+
+ /* Now invoke the callbacks of any internal breakpoints there. */
+ check_breakpoints (event_child->stop_pc);
+
+ /* Handle tracepoint data collecting. This may overflow the
+ trace buffer, and cause a tracing stop, removing
+ breakpoints. */
+ trace_event = handle_tracepoints (event_child);
+
+ if (bp_explains_trap)
+ {
+ /* If we stepped or ran into an internal breakpoint, we've
+ already handled it. So next time we resume (from this
+ PC), we should step over it. */
+ if (debug_threads)
+ fprintf (stderr, "Hit a gdbserver breakpoint.\n");
+
+ if (breakpoint_here (event_child->stop_pc))
+ event_child->need_step_over = 1;
+ }
+ }
+ else
+ {
+ /* We have some other signal, possibly a step-over dance was in
+ progress, and it should be cancelled too. */
+ step_over_finished = finish_step_over (event_child);
+ }
+
+ /* We have all the data we need. Either report the event to GDB, or
+ resume threads and keep waiting for more. */
+
+ /* If we're collecting a fast tracepoint, finish the collection and
+ move out of the jump pad before delivering a signal. See
+ linux_stabilize_threads. */
+
+ if (WIFSTOPPED (w)
+ && WSTOPSIG (w) != SIGTRAP
+ && supports_fast_tracepoints ()
+ && agent_loaded_p ())
+ {
+ if (debug_threads)
+ fprintf (stderr,
+ "Got signal %d for LWP %ld. Check if we need "
+ "to defer or adjust it.\n",
+ WSTOPSIG (w), lwpid_of (event_child));
+
+ /* Allow debugging the jump pad itself. */
+ if (current_inferior->last_resume_kind != resume_step
+ && maybe_move_out_of_jump_pad (event_child, &w))
+ {
+ enqueue_one_deferred_signal (event_child, &w);
+
+ if (debug_threads)
+ fprintf (stderr,
+ "Signal %d for LWP %ld deferred (in jump pad)\n",
+ WSTOPSIG (w), lwpid_of (event_child));
+
+ linux_resume_one_lwp (event_child, 0, 0, NULL);
+ goto retry;
+ }
+ }
+
+ if (event_child->collecting_fast_tracepoint)
+ {
+ if (debug_threads)
+ fprintf (stderr, "\
+LWP %ld was trying to move out of the jump pad (%d). \
+Check if we're already there.\n",
+ lwpid_of (event_child),
+ event_child->collecting_fast_tracepoint);
+
+ trace_event = 1;
+
+ event_child->collecting_fast_tracepoint
+ = linux_fast_tracepoint_collecting (event_child, NULL);
+
+ if (event_child->collecting_fast_tracepoint != 1)
+ {
+ /* No longer need this breakpoint. */
+ if (event_child->exit_jump_pad_bkpt != NULL)
+ {
+ if (debug_threads)
+ fprintf (stderr,
+ "No longer need exit-jump-pad bkpt; removing it."
+ "stopping all threads momentarily.\n");
+
+ /* Other running threads could hit this breakpoint.
+ We don't handle moribund locations like GDB does,
+ instead we always pause all threads when removing
+ breakpoints, so that any step-over or
+ decr_pc_after_break adjustment is always taken
+ care of while the breakpoint is still
+ inserted. */
+ stop_all_lwps (1, event_child);
+ cancel_breakpoints ();
+
+ delete_breakpoint (event_child->exit_jump_pad_bkpt);
+ event_child->exit_jump_pad_bkpt = NULL;
+
+ unstop_all_lwps (1, event_child);
+
+ gdb_assert (event_child->suspended >= 0);
+ }
+ }
+
+ if (event_child->collecting_fast_tracepoint == 0)
+ {
+ if (debug_threads)
+ fprintf (stderr,
+ "fast tracepoint finished "
+ "collecting successfully.\n");
+
+ /* We may have a deferred signal to report. */
+ if (dequeue_one_deferred_signal (event_child, &w))
+ {
+ if (debug_threads)
+ fprintf (stderr, "dequeued one signal.\n");
+ }
+ else
+ {
+ if (debug_threads)
+ fprintf (stderr, "no deferred signals.\n");
+
+ if (stabilizing_threads)
+ {
+ ourstatus->kind = TARGET_WAITKIND_STOPPED;
+ ourstatus->value.sig = TARGET_SIGNAL_0;
+ return ptid_of (event_child);
+ }
+ }
+ }
+ }
+
+ /* Check whether GDB would be interested in this event. */
+
+ /* If GDB is not interested in this signal, don't stop other
+ threads, and don't report it to GDB. Just resume the inferior
+ right away. We do this for threading-related signals as well as
+ any that GDB specifically requested we ignore. But never ignore
+ SIGSTOP if we sent it ourselves, and do not ignore signals when
+ stepping - they may require special handling to skip the signal
+ handler. */
+ /* FIXME drow/2002-06-09: Get signal numbers from the inferior's
+ thread library? */
+ if (WIFSTOPPED (w)
+ && current_inferior->last_resume_kind != resume_step
+ && (
+#if defined (USE_THREAD_DB) && !defined (__ANDROID__)
+ (current_process ()->private->thread_db != NULL
+ && (WSTOPSIG (w) == __SIGRTMIN
+ || WSTOPSIG (w) == __SIGRTMIN + 1))
+ ||
+#endif
+ (pass_signals[target_signal_from_host (WSTOPSIG (w))]
+ && !(WSTOPSIG (w) == SIGSTOP
+ && current_inferior->last_resume_kind == resume_stop))))
+ {
+ siginfo_t info, *info_p;
+
+ if (debug_threads)
+ fprintf (stderr, "Ignored signal %d for LWP %ld.\n",
+ WSTOPSIG (w), lwpid_of (event_child));
+
+ if (ptrace (PTRACE_GETSIGINFO, lwpid_of (event_child), 0, &info) == 0)
+ info_p = &info;
+ else
+ info_p = NULL;
+ linux_resume_one_lwp (event_child, event_child->stepping,
+ WSTOPSIG (w), info_p);
+ goto retry;
+ }
+
+ /* If GDB wanted this thread to single step, we always want to
+ report the SIGTRAP, and let GDB handle it. Watchpoints should
+ always be reported. So should signals we can't explain. A
+ SIGTRAP we can't explain could be a GDB breakpoint --- we may or
+ not support Z0 breakpoints. If we do, we're be able to handle
+ GDB breakpoints on top of internal breakpoints, by handling the
+ internal breakpoint and still reporting the event to GDB. If we
+ don't, we're out of luck, GDB won't see the breakpoint hit. */
+ report_to_gdb = (!maybe_internal_trap
+ || current_inferior->last_resume_kind == resume_step
+ || event_child->stopped_by_watchpoint
+ || (!step_over_finished
+ && !bp_explains_trap && !trace_event)
+ || (gdb_breakpoint_here (event_child->stop_pc)
+ && gdb_condition_true_at_breakpoint (event_child->stop_pc)));
+
+ /* We found no reason GDB would want us to stop. We either hit one
+ of our own breakpoints, or finished an internal step GDB
+ shouldn't know about. */
+ if (!report_to_gdb)
+ {
+ if (debug_threads)
+ {
+ if (bp_explains_trap)
+ fprintf (stderr, "Hit a gdbserver breakpoint.\n");
+ if (step_over_finished)
+ fprintf (stderr, "Step-over finished.\n");
+ if (trace_event)
+ fprintf (stderr, "Tracepoint event.\n");
+ }
+
+ /* We're not reporting this breakpoint to GDB, so apply the
+ decr_pc_after_break adjustment to the inferior's regcache
+ ourselves. */
+
+ if (the_low_target.set_pc != NULL)
+ {
+ struct regcache *regcache
+ = get_thread_regcache (get_lwp_thread (event_child), 1);
+ (*the_low_target.set_pc) (regcache, event_child->stop_pc);
+ }
+
+ /* We may have finished stepping over a breakpoint. If so,
+ we've stopped and suspended all LWPs momentarily except the
+ stepping one. This is where we resume them all again. We're
+ going to keep waiting, so use proceed, which handles stepping
+ over the next breakpoint. */
+ if (debug_threads)
+ fprintf (stderr, "proceeding all threads.\n");
+
+ if (step_over_finished)
+ unsuspend_all_lwps (event_child);
+
+ proceed_all_lwps ();
+ goto retry;
+ }
+
+ if (debug_threads)
+ {
+ if (current_inferior->last_resume_kind == resume_step)
+ fprintf (stderr, "GDB wanted to single-step, reporting event.\n");
+ if (event_child->stopped_by_watchpoint)
+ fprintf (stderr, "Stopped by watchpoint.\n");
+ if (gdb_breakpoint_here (event_child->stop_pc))
+ fprintf (stderr, "Stopped by GDB breakpoint.\n");
+ if (debug_threads)
+ fprintf (stderr, "Hit a non-gdbserver trap event.\n");
+ }
+
+ /* Alright, we're going to report a stop. */
+
+ if (!non_stop && !stabilizing_threads)
+ {
+ /* In all-stop, stop all threads. */
+ stop_all_lwps (0, NULL);
+
+ /* If we're not waiting for a specific LWP, choose an event LWP
+ from among those that have had events. Giving equal priority
+ to all LWPs that have had events helps prevent
+ starvation. */
+ if (ptid_equal (ptid, minus_one_ptid))
+ {
+ event_child->status_pending_p = 1;
+ event_child->status_pending = w;
+
+ select_event_lwp (&event_child);
+
+ event_child->status_pending_p = 0;
+ w = event_child->status_pending;
+ }
+
+ /* Now that we've selected our final event LWP, cancel any
+ breakpoints in other LWPs that have hit a GDB breakpoint.
+ See the comment in cancel_breakpoints_callback to find out
+ why. */
+ find_inferior (&all_lwps, cancel_breakpoints_callback, event_child);
+
+ /* If we were going a step-over, all other threads but the stepping one
+ had been paused in start_step_over, with their suspend counts
+ incremented. We don't want to do a full unstop/unpause, because we're
+ in all-stop mode (so we want threads stopped), but we still need to
+ unsuspend the other threads, to decrement their `suspended' count
+ back. */
+ if (step_over_finished)
+ unsuspend_all_lwps (event_child);
+
+ /* Stabilize threads (move out of jump pads). */
+ stabilize_threads ();
+ }
+ else
+ {
+ /* If we just finished a step-over, then all threads had been
+ momentarily paused. In all-stop, that's fine, we want
+ threads stopped by now anyway. In non-stop, we need to
+ re-resume threads that GDB wanted to be running. */
+ if (step_over_finished)
+ unstop_all_lwps (1, event_child);
+ }