aboutsummaryrefslogtreecommitdiff
path: root/gdb/gdbserver
diff options
context:
space:
mode:
authorPedro Alves <palves@redhat.com>2016-02-24 22:52:06 +0000
committerPedro Alves <palves@redhat.com>2016-02-24 22:52:06 +0000
commite7ad2f145c05bc60b1cd2796c8f3b72f02e3e730 (patch)
treeb977a7b52d8dbb2c626494ded7fabab6b1c0c729 /gdb/gdbserver
parent338435ef105ff51e967571ad073830ec1eb5a4ab (diff)
downloadgdb-e7ad2f145c05bc60b1cd2796c8f3b72f02e3e730.zip
gdb-e7ad2f145c05bc60b1cd2796c8f3b72f02e3e730.tar.gz
gdb-e7ad2f145c05bc60b1cd2796c8f3b72f02e3e730.tar.bz2
Handle MIPS Linux SIGTRAP siginfo.si_code values
This unbreaks pending/delayed breakpoints handling, as well as hardware watchpoints, on MIPS. Ref: https://sourceware.org/ml/gdb-patches/2016-02/msg00681.html The MIPS kernel reports SI_KERNEL for all kernel generated traps, instead of TRAP_BRKPT / TRAP_HWBKPT, but GDB isn't aware of this. Basically, this commit: - Folds watchpoints logic into check_stopped_by_breakpoint, and renames it to save_stop_reason. - Adds GDB_ARCH_IS_TRAP_HWBKPT. - Makes MIPS set both GDB_ARCH_IS_TRAP_BRPT and GDB_ARCH_IS_TRAP_HWBKPT to SI_KERNEL. In save_stop_reason, we handle the case of the same si_code returning true for both TRAP_BRPT and TRAP_HWBKPT by looking at what the debug registers say. Tested on x86-64 Fedora 20, native and gdbserver. gdb/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-nat.c (save_sigtrap) Delete. (stop_wait_callback): Call save_stop_reason instead of save_sigtrap. (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Bits of save_sigtrap folded here. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_nat_filter_event): Call save_stop_reason instead of save_sigtrap. * nat/linux-ptrace.h: Check for both SI_KERNEL and TRAP_BRKPT si_code for MIPS. * nat/linux-ptrace.h: Fix "TRAP_HWBPT" typo in x86 table. Add comments on MIPS behavior. (GDB_ARCH_IS_TRAP_HWBKPT): Define for all archs. gdb/gdbserver/ChangeLog: 2016-02-24 Pedro Alves <palves@redhat.com> * linux-low.c (check_stopped_by_breakpoint): Rename to ... (save_stop_reason): ... this. Use GDB_ARCH_IS_TRAP_HWBKPT and handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT. Factor out common code between the USE_SIGTRAP_SIGINFO and !USE_SIGTRAP_SIGINFO blocks. (linux_low_filter_event): Call save_stop_reason instead of check_stopped_by_breakpoint and check_stopped_by_watchpoint. Update comments. (linux_wait_1): Update comments.
Diffstat (limited to 'gdb/gdbserver')
-rw-r--r--gdb/gdbserver/ChangeLog12
-rw-r--r--gdb/gdbserver/linux-low.c170
2 files changed, 84 insertions, 98 deletions
diff --git a/gdb/gdbserver/ChangeLog b/gdb/gdbserver/ChangeLog
index 8c4dab4..3ec48fa 100644
--- a/gdb/gdbserver/ChangeLog
+++ b/gdb/gdbserver/ChangeLog
@@ -1,3 +1,15 @@
+2016-02-24 Pedro Alves <palves@redhat.com>
+
+ * linux-low.c (check_stopped_by_breakpoint): Rename to ...
+ (save_stop_reason): ... this. Use GDB_ARCH_IS_TRAP_HWBKPT and
+ handle ambiguous GDB_ARCH_IS_TRAP_BRKPT / GDB_ARCH_IS_TRAP_HWBKPT.
+ Factor out common code between the USE_SIGTRAP_SIGINFO and
+ !USE_SIGTRAP_SIGINFO blocks.
+ (linux_low_filter_event): Call save_stop_reason instead of
+ check_stopped_by_breakpoint and check_stopped_by_watchpoint.
+ Update comments.
+ (linux_wait_1): Update comments.
+
2016-02-24 Wei-cheng Wang <cole945@gmail.com>
* linux-ppc-low.c (ppc_supports_z_point_type): New function:
diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c
index 8b025bd..5e7560f 100644
--- a/gdb/gdbserver/linux-low.c
+++ b/gdb/gdbserver/linux-low.c
@@ -735,32 +735,16 @@ get_syscall_trapinfo (struct lwp_info *lwp, int *sysno, int *sysret)
current_thread = saved_thread;
}
-/* This function should only be called if LWP got a SIGTRAP.
- The SIGTRAP could mean several things.
+static int check_stopped_by_watchpoint (struct lwp_info *child);
- On i386, where decr_pc_after_break is non-zero:
-
- If we were single-stepping this process using PTRACE_SINGLESTEP, we
- will get only the one SIGTRAP. The value of $eip will be the next
- instruction. If the instruction we stepped over was a breakpoint,
- we need to decrement the PC.
-
- If we continue the process using PTRACE_CONT, we will get a
- SIGTRAP when we hit a breakpoint. The value of $eip will be
- the instruction after the breakpoint (i.e. needs to be
- decremented). If we report the SIGTRAP to GDB, we must also
- report the undecremented PC. If the breakpoint is removed, we
- must resume at the decremented PC.
-
- On a non-decr_pc_after_break machine with hardware or kernel
- single-step:
-
- If we either single-step a breakpoint instruction, or continue and
- hit a breakpoint instruction, our PC will point at the breakpoint
- instruction. */
+/* Called when the LWP stopped for a signal/trap. If it stopped for a
+ trap check what caused it (breakpoint, watchpoint, trace, etc.),
+ and save the result in the LWP's stop_reason field. If it stopped
+ for a breakpoint, decrement the PC if necessary on the lwp's
+ architecture. Returns true if we now have the LWP's stop PC. */
static int
-check_stopped_by_breakpoint (struct lwp_info *lwp)
+save_stop_reason (struct lwp_info *lwp)
{
CORE_ADDR pc;
CORE_ADDR sw_breakpoint_pc;
@@ -785,56 +769,39 @@ check_stopped_by_breakpoint (struct lwp_info *lwp)
{
if (siginfo.si_signo == SIGTRAP)
{
- if (GDB_ARCH_IS_TRAP_BRKPT (siginfo.si_code))
+ if (GDB_ARCH_IS_TRAP_BRKPT (siginfo.si_code)
+ && GDB_ARCH_IS_TRAP_HWBKPT (siginfo.si_code))
{
- if (debug_threads)
- {
- struct thread_info *thr = get_lwp_thread (lwp);
-
- debug_printf ("CSBB: %s stopped by software breakpoint\n",
- target_pid_to_str (ptid_of (thr)));
- }
-
- /* Back up the PC if necessary. */
- if (pc != sw_breakpoint_pc)
- {
- struct regcache *regcache
- = get_thread_regcache (current_thread, 1);
- (*the_low_target.set_pc) (regcache, sw_breakpoint_pc);
- }
-
- lwp->stop_pc = sw_breakpoint_pc;
+ /* The si_code is ambiguous on this arch -- check debug
+ registers. */
+ if (!check_stopped_by_watchpoint (lwp))
+ lwp->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. */
lwp->stop_reason = TARGET_STOPPED_BY_SW_BREAKPOINT;
- current_thread = saved_thread;
- return 1;
}
- else if (siginfo.si_code == TRAP_HWBKPT)
+ else if (GDB_ARCH_IS_TRAP_HWBKPT (siginfo.si_code))
{
- if (debug_threads)
- {
- struct thread_info *thr = get_lwp_thread (lwp);
-
- debug_printf ("CSBB: %s stopped by hardware "
- "breakpoint/watchpoint\n",
- target_pid_to_str (ptid_of (thr)));
- }
-
- lwp->stop_pc = pc;
- lwp->stop_reason = TARGET_STOPPED_BY_HW_BREAKPOINT;
- current_thread = saved_thread;
- return 1;
+ /* This can indicate either a hardware breakpoint or
+ hardware watchpoint. Check debug registers. */
+ if (!check_stopped_by_watchpoint (lwp))
+ lwp->stop_reason = TARGET_STOPPED_BY_HW_BREAKPOINT;
}
else if (siginfo.si_code == TRAP_TRACE)
{
- if (debug_threads)
- {
- struct thread_info *thr = get_lwp_thread (lwp);
-
- debug_printf ("CSBB: %s stopped by trace\n",
- target_pid_to_str (ptid_of (thr)));
- }
-
- lwp->stop_reason = TARGET_STOPPED_BY_SINGLE_STEP;
+ /* 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. */
+ if (!check_stopped_by_watchpoint (lwp))
+ lwp->stop_reason = TARGET_STOPPED_BY_SINGLE_STEP;
}
}
}
@@ -845,6 +812,16 @@ check_stopped_by_breakpoint (struct lwp_info *lwp)
case we need to report the breakpoint PC. */
if ((!lwp->stepping || lwp->stop_pc == sw_breakpoint_pc)
&& (*the_low_target.breakpoint_at) (sw_breakpoint_pc))
+ lwp->stop_reason = TARGET_STOPPED_BY_SW_BREAKPOINT;
+
+ if (hardware_breakpoint_inserted_here (pc))
+ lwp->stop_reason = TARGET_STOPPED_BY_HW_BREAKPOINT;
+
+ if (lwp->stop_reason == TARGET_STOPPED_BY_NO_REASON)
+ check_stopped_by_watchpoint (lwp);
+#endif
+
+ if (lwp->stop_reason == TARGET_STOPPED_BY_SW_BREAKPOINT)
{
if (debug_threads)
{
@@ -856,19 +833,16 @@ check_stopped_by_breakpoint (struct lwp_info *lwp)
/* Back up the PC if necessary. */
if (pc != sw_breakpoint_pc)
- {
+ {
struct regcache *regcache
= get_thread_regcache (current_thread, 1);
(*the_low_target.set_pc) (regcache, sw_breakpoint_pc);
}
- lwp->stop_pc = sw_breakpoint_pc;
- lwp->stop_reason = TARGET_STOPPED_BY_SW_BREAKPOINT;
- current_thread = saved_thread;
- return 1;
+ /* Update this so we record the correct stop PC below. */
+ pc = sw_breakpoint_pc;
}
-
- if (hardware_breakpoint_inserted_here (pc))
+ else if (lwp->stop_reason == TARGET_STOPPED_BY_HW_BREAKPOINT)
{
if (debug_threads)
{
@@ -877,16 +851,31 @@ check_stopped_by_breakpoint (struct lwp_info *lwp)
debug_printf ("CSBB: %s stopped by hardware breakpoint\n",
target_pid_to_str (ptid_of (thr)));
}
+ }
+ else if (lwp->stop_reason == TARGET_STOPPED_BY_WATCHPOINT)
+ {
+ if (debug_threads)
+ {
+ struct thread_info *thr = get_lwp_thread (lwp);
- lwp->stop_pc = pc;
- lwp->stop_reason = TARGET_STOPPED_BY_HW_BREAKPOINT;
- current_thread = saved_thread;
- return 1;
+ debug_printf ("CSBB: %s stopped by hardware watchpoint\n",
+ target_pid_to_str (ptid_of (thr)));
+ }
}
-#endif
+ else if (lwp->stop_reason == TARGET_STOPPED_BY_SINGLE_STEP)
+ {
+ if (debug_threads)
+ {
+ struct thread_info *thr = get_lwp_thread (lwp);
+ debug_printf ("CSBB: %s stopped by trace\n",
+ target_pid_to_str (ptid_of (thr)));
+ }
+ }
+
+ lwp->stop_pc = pc;
current_thread = saved_thread;
- return 0;
+ return 1;
}
static struct lwp_info *
@@ -2434,8 +2423,8 @@ linux_low_filter_event (int lwpid, int wstat)
child->syscall_state = TARGET_WAITKIND_IGNORE;
}
- /* Be careful to not overwrite stop_pc until
- check_stopped_by_breakpoint is called. */
+ /* Be careful to not overwrite stop_pc until save_stop_reason is
+ called. */
if (WIFSTOPPED (wstat) && WSTOPSIG (wstat) == SIGTRAP
&& linux_is_extended_waitstatus (wstat))
{
@@ -2448,27 +2437,12 @@ linux_low_filter_event (int lwpid, int wstat)
}
}
- /* Check first whether this was a SW/HW breakpoint before checking
- watchpoints, because at least s390 can't tell the data address of
- hardware watchpoint hits, and returns stopped-by-watchpoint as
- long as there's a watchpoint set. */
if (WIFSTOPPED (wstat) && linux_wstatus_maybe_breakpoint (wstat))
{
- if (check_stopped_by_breakpoint (child))
+ if (save_stop_reason (child))
have_stop_pc = 1;
}
- /* Note that TRAP_HWBKPT can indicate either a hardware breakpoint
- or hardware watchpoint. Check which is which if we got
- TARGET_STOPPED_BY_HW_BREAKPOINT. Likewise, 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. */
- if (WIFSTOPPED (wstat) && WSTOPSIG (wstat) == SIGTRAP
- && child->stop_reason != TARGET_STOPPED_BY_SW_BREAKPOINT)
- check_stopped_by_watchpoint (child);
-
if (!have_stop_pc)
child->stop_pc = get_pc (child);
@@ -3209,7 +3183,7 @@ linux_wait_1 (ptid_t ptid,
hardware single step it means a gdb/gdbserver breakpoint had been
planted on top of a permanent breakpoint, in the case of a software
single step it may just mean that gdbserver hit the reinsert breakpoint.
- The PC has been adjusted by check_stopped_by_breakpoint to point at
+ The PC has been adjusted by save_stop_reason to point at
the breakpoint address.
So in the case of the hardware single step advance the PC manually
past the breakpoint and in the case of software single step advance only