Honour SIGILL and SIGSEGV in cancel breakpoint and event lwp selection
authorYao Qi <yao@codesourcery.com>
Fri, 12 Sep 2014 05:35:11 +0000 (13:35 +0800)
committerYao Qi <yao@codesourcery.com>
Tue, 23 Sep 2014 12:36:38 +0000 (20:36 +0800)
I see the following fail on arm-none-linux-gnueabi testing,

(gdb) continue^M
Continuing.^M
^M
Program received signal SIGILL, Illegal instruction.^M
[Switching to Thread 1003]^M
handler (signo=10) at
/scratch/yqi/arm-none-linux-gnueabi/src/gdb-trunk/gdb/testsuite/gdb.threads/sigstep-threads.c:33^M
33        tgkill (getpid (), gettid (), SIGUSR1);       /* step-2 */^M
(gdb) FAIL: gdb.threads/sigstep-threads.exp: continue

the cause is that GDBserver doesn't cancel the breakpoint if the stop
signal is SIGILL.  The kernel used here is a little old, 2.6.x, and
doesn't translate SIGILL to SIGTRAP when program hits breakpoint
instruction (which is an illegal instruction actually).  GDB and
GDBserver can translate SIGILL to SIGTRAP under certain circumstance,
so it is not a problem here.  See gdbserver/linux-low.c:linux_wait_1

  /* 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))));

However, SIGILL and SIGSEGV is not considered when cancelling
breakpoint, which causes the fail above.  That is, when GDB is doing
software single step on address ADDR, both thread A and thread B hits the
software single step breakpoint, and get SIGILL.  GDB selects the event
from thread A, removes the software single step breakpoint, and resume
the program.  The event (SIGILL) from thread B is reported to GDB, but
GDB doesn't regard this SIGILL as SIGTRAP, because the breakpoint on
address ADDR was removed, so GDB reports "Program received signal
SIGILL".

The patch is to allow calling cancel_breakpoint if the signal is
SIGILL and SIGSEGV.  This patch fixes the fail above.  Likewise, event
lwp selection should honour SIGILL and SIGSEGV too.

gdb/gdbserver:

2014-09-23  Yao Qi  <yao@codesourcery.com>

* linux-low.c (lp_status_maybe_breakpoint): New function.
(linux_low_filter_event): Call lp_status_maybe_breakpoint.
(count_events_callback): Likewise.
(select_event_lwp_callback): Likewise.
(cancel_breakpoints_callback): Likewise.

gdb/gdbserver/ChangeLog
gdb/gdbserver/linux-low.c

index 240554ef882aefde3c81230e90b978315388915f..a7efe8ef8970eac154246370e420241de9ac5d29 100644 (file)
@@ -1,3 +1,11 @@
+2014-09-23  Yao Qi  <yao@codesourcery.com>
+
+       * linux-low.c (lp_status_maybe_breakpoint): New function.
+       (linux_low_filter_event): Call lp_status_maybe_breakpoint.
+       (count_events_callback): Likewise.
+       (select_event_lwp_callback): Likewise.
+       (cancel_breakpoints_callback): Likewise.
+
 2014-09-19  Don Breazeal  <donb@codesourcery.com>
 
        * linux-low.c (handle_extended_wait): Call
index 8f0985a1394f80e7d1a2913fe60e9a65a7aa48d2..8776670b4966dd678d57f06a42328adc949162c6 100644 (file)
@@ -1739,6 +1739,20 @@ cancel_breakpoint (struct lwp_info *lwp)
   return 0;
 }
 
+/* Return true if the event in LP may be caused by breakpoint.  */
+
+static int
+lp_status_maybe_breakpoint (struct lwp_info *lp)
+{
+  return (lp->status_pending_p
+         && WIFSTOPPED (lp->status_pending)
+         && (WSTOPSIG (lp->status_pending) == SIGTRAP
+             /* SIGILL and SIGSEGV are also treated as traps in case a
+                breakpoint is inserted at the current PC.  */
+             || WSTOPSIG (lp->status_pending) == SIGILL
+             || WSTOPSIG (lp->status_pending) == SIGSEGV));
+}
+
 /* Do low-level handling of the event, and check if we should go on
    and pass it to caller code.  Return the affected lwp if we are, or
    NULL otherwise.  */
@@ -1936,7 +1950,7 @@ linux_low_filter_event (ptid_t filter_ptid, int lwpid, int wstat)
                 the core before this one is handled.  All-stop always
                 cancels breakpoint hits in all threads.  */
              if (non_stop
-                 && WSTOPSIG (wstat) == SIGTRAP
+                 && lp_status_maybe_breakpoint (child)
                  && cancel_breakpoint (child))
                {
                  /* Throw away the SIGTRAP.  */
@@ -2197,9 +2211,7 @@ count_events_callback (struct inferior_list_entry *entry, void *data)
      should be reported to GDB.  */
   if (thread->last_status.kind == TARGET_WAITKIND_IGNORE
       && thread->last_resume_kind != resume_stop
-      && lp->status_pending_p
-      && WIFSTOPPED (lp->status_pending)
-      && WSTOPSIG (lp->status_pending) == SIGTRAP
+      && lp_status_maybe_breakpoint (lp)
       && !breakpoint_inserted_here (lp->stop_pc))
     (*count)++;
 
@@ -2237,9 +2249,7 @@ select_event_lwp_callback (struct inferior_list_entry *entry, void *data)
   /* Select only resumed LWPs that have a SIGTRAP event pending. */
   if (thread->last_resume_kind != resume_stop
       && thread->last_status.kind == TARGET_WAITKIND_IGNORE
-      && lp->status_pending_p
-      && WIFSTOPPED (lp->status_pending)
-      && WSTOPSIG (lp->status_pending) == SIGTRAP
+      && lp_status_maybe_breakpoint (lp)
       && !breakpoint_inserted_here (lp->stop_pc))
     if ((*selector)-- == 0)
       return 1;
@@ -2271,9 +2281,7 @@ cancel_breakpoints_callback (struct inferior_list_entry *entry, void *data)
 
   if (thread->last_resume_kind != resume_stop
       && thread->last_status.kind == TARGET_WAITKIND_IGNORE
-      && lp->status_pending_p
-      && WIFSTOPPED (lp->status_pending)
-      && WSTOPSIG (lp->status_pending) == SIGTRAP
+      && lp_status_maybe_breakpoint (lp)
       && !lp->stepping
       && !lp->stopped_by_watchpoint
       && cancel_breakpoint (lp))
This page took 0.036966 seconds and 4 git commands to generate.