+#if USE_SIGTRAP_SIGINFO
+ if (linux_nat_get_siginfo (lp->ptid, &siginfo))
+ {
+ if (siginfo.si_signo == SIGTRAP)
+ {
+ if (GDB_ARCH_IS_TRAP_BRKPT (siginfo.si_code)
+ && GDB_ARCH_IS_TRAP_HWBKPT (siginfo.si_code))
+ {
+ /* The si_code is ambiguous on this arch -- check debug
+ registers. */
+ if (!check_stopped_by_watchpoint (lp))
+ lp->stop_reason = TARGET_STOPPED_BY_SW_BREAKPOINT;
+ }
+ else if (GDB_ARCH_IS_TRAP_BRKPT (siginfo.si_code))
+ {
+ /* If we determine the LWP stopped for a SW breakpoint,
+ trust it. Particularly don't check watchpoint
+ registers, because at least on s390, we'd find
+ stopped-by-watchpoint as long as there's a watchpoint
+ set. */
+ lp->stop_reason = TARGET_STOPPED_BY_SW_BREAKPOINT;
+ }
+ else if (GDB_ARCH_IS_TRAP_HWBKPT (siginfo.si_code))
+ {
+ /* This can indicate either a hardware breakpoint or
+ hardware watchpoint. Check debug registers. */
+ if (!check_stopped_by_watchpoint (lp))
+ lp->stop_reason = TARGET_STOPPED_BY_HW_BREAKPOINT;
+ }
+ else if (siginfo.si_code == TRAP_TRACE)
+ {
+ if (debug_linux_nat)
+ fprintf_unfiltered (gdb_stdlog,
+ "CSBB: %s stopped by trace\n",
+ target_pid_to_str (lp->ptid));
+
+ /* We may have single stepped an instruction that
+ triggered a watchpoint. In that case, on some
+ architectures (such as x86), instead of TRAP_HWBKPT,
+ si_code indicates TRAP_TRACE, and we need to check
+ the debug registers separately. */
+ check_stopped_by_watchpoint (lp);
+ }
+ }
+ }
+#else
+ if ((!lp->step || lp->stop_pc == sw_bp_pc)
+ && software_breakpoint_inserted_here_p (get_regcache_aspace (regcache),
+ sw_bp_pc))
+ {
+ /* The LWP was either continued, or stepped a software
+ breakpoint instruction. */
+ lp->stop_reason = TARGET_STOPPED_BY_SW_BREAKPOINT;
+ }
+
+ if (hardware_breakpoint_inserted_here_p (get_regcache_aspace (regcache), pc))
+ lp->stop_reason = TARGET_STOPPED_BY_HW_BREAKPOINT;
+
+ if (lp->stop_reason == TARGET_STOPPED_BY_NO_REASON)
+ check_stopped_by_watchpoint (lp);
+#endif
+
+ if (lp->stop_reason == TARGET_STOPPED_BY_SW_BREAKPOINT)
+ {
+ if (debug_linux_nat)
+ fprintf_unfiltered (gdb_stdlog,
+ "CSBB: %s stopped by software breakpoint\n",
+ target_pid_to_str (lp->ptid));
+
+ /* Back up the PC if necessary. */
+ if (pc != sw_bp_pc)
+ regcache_write_pc (regcache, sw_bp_pc);
+
+ /* Update this so we record the correct stop PC below. */
+ pc = sw_bp_pc;
+ }
+ else if (lp->stop_reason == TARGET_STOPPED_BY_HW_BREAKPOINT)
+ {
+ if (debug_linux_nat)
+ fprintf_unfiltered (gdb_stdlog,
+ "CSBB: %s stopped by hardware breakpoint\n",
+ target_pid_to_str (lp->ptid));
+ }
+ else if (lp->stop_reason == TARGET_STOPPED_BY_WATCHPOINT)
+ {
+ if (debug_linux_nat)
+ fprintf_unfiltered (gdb_stdlog,
+ "CSBB: %s stopped by hardware watchpoint\n",
+ target_pid_to_str (lp->ptid));
+ }
+
+ lp->stop_pc = pc;
+}
+
+
+/* Returns true if the LWP had stopped for a software breakpoint. */
+
+static int
+linux_nat_stopped_by_sw_breakpoint (struct target_ops *ops)
+{
+ struct lwp_info *lp = find_lwp_pid (inferior_ptid);
+
+ gdb_assert (lp != NULL);
+
+ return lp->stop_reason == TARGET_STOPPED_BY_SW_BREAKPOINT;
+}
+
+/* Implement the supports_stopped_by_sw_breakpoint method. */
+
+static int
+linux_nat_supports_stopped_by_sw_breakpoint (struct target_ops *ops)
+{
+ return USE_SIGTRAP_SIGINFO;
+}
+
+/* Returns true if the LWP had stopped for a hardware
+ breakpoint/watchpoint. */
+
+static int
+linux_nat_stopped_by_hw_breakpoint (struct target_ops *ops)
+{
+ struct lwp_info *lp = find_lwp_pid (inferior_ptid);
+
+ gdb_assert (lp != NULL);
+
+ return lp->stop_reason == TARGET_STOPPED_BY_HW_BREAKPOINT;
+}
+
+/* Implement the supports_stopped_by_hw_breakpoint method. */
+
+static int
+linux_nat_supports_stopped_by_hw_breakpoint (struct target_ops *ops)
+{
+ return USE_SIGTRAP_SIGINFO;