kern/115469: [kernel] [patch] ptrace(2) signal delivery broken

Tijl Coosemans tijl at ulyssis.org
Fri Aug 24 13:40:08 PDT 2007


The following reply was made to PR kern/115469; it has been noted by GNATS.

From: Tijl Coosemans <tijl at ulyssis.org>
To: bug-followup at freebsd.org
Cc:  
Subject: Re: kern/115469: [kernel] [patch] ptrace(2) signal delivery broken
Date: Fri, 24 Aug 2007 22:38:10 +0200

 The following session shows the problem. The sample code is
 FreeBSD/i386 specific, but it can be easily adopted to other platforms.
 
 tijl at kalimero gdbsignal% cat segv.c
 #include <sys/ucontext.h>
 #include <signal.h>
 #include <stdio.h>
 
 int sayhi = 0;
 
 void sig_handler( int sig, siginfo_t *si, void *context ) {
         ucontext_t *uctx = context;
         /* skip faulting instruction (assumed to be mov (%eax),%al) */
         uctx->uc_mcontext.mc_eip += 2;
         sayhi = 1;
 }
 
 int main( int argc, char **argv ) {
         char c;
         struct sigaction sa;
         sa.sa_sigaction = &sig_handler;
         sa.sa_flags = SA_SIGINFO;
         sigfillset( &sa.sa_mask );
         sigaction( SIGSEGV, &sa, NULL );
         c = *(( char * ) NULL );
         if( sayhi ) {
                 printf( "hello world!\n" );
         }
         return 0;
 }
 tijl at kalimero gdbsignal% cc -Wall -ggdb -O0 -march=i486 -o segv segv.c
 tijl at kalimero gdbsignal% ./segv
 hello world!
 tijl at kalimero gdbsignal% gdb segv
 GNU gdb 6.1.1 [FreeBSD]
 Copyright 2004 Free Software Foundation, Inc.
 GDB is free software, covered by the GNU General Public License, and you are
 welcome to change it and/or distribute copies of it under certain conditions.
 Type "show copying" to see the conditions.
 There is absolutely no warranty for GDB.  Type "show warranty" for details.
 This GDB was configured as "i386-marcel-freebsd"...
 (gdb) r
 Starting program: /home/tijl/tests/gdbsignal/segv
 
 Program received signal SIGSEGV, Segmentation fault.
 0x080484a9 in main () at segv.c:21
 21              c = *(( char * ) NULL );
 (gdb) c
 Continuing.
 
 Program received signal SIGSEGV, Segmentation fault.
 0x080484ab in main () at segv.c:21
 21              c = *(( char * ) NULL );
 (gdb) c
 Continuing.
 
 Program received signal SIGSEGV, Segmentation fault.
 0x080484ad in main () at segv.c:21
 21              c = *(( char * ) NULL );
 (gdb) c
 Continuing.
 
 Program received signal SIGSEGV, Segmentation fault.
 0x080484af in main () at segv.c:22
 22              if( sayhi ) {
 (gdb) c
 Continuing.
 
 Program received signal SIGSEGV, Segmentation fault.
 0x080484b1 in main () at segv.c:22
 22              if( sayhi ) {
 (gdb) and so on...
 
 
 
 With the patch the gdb session becomes:
 
 tijl at kalimero gdbsignal% gdb segv
 GNU gdb 6.1.1 [FreeBSD]
 Copyright 2004 Free Software Foundation, Inc.
 GDB is free software, covered by the GNU General Public License, and you are
 welcome to change it and/or distribute copies of it under certain conditions.
 Type "show copying" to see the conditions.
 There is absolutely no warranty for GDB.  Type "show warranty" for details.
 This GDB was configured as "i386-marcel-freebsd"...
 (gdb) r
 Starting program: /home/tijl/tests/gdbsignal/segv
 
 Program received signal SIGSEGV, Segmentation fault.
 0x080484a9 in main () at segv.c:21
 21              c = *(( char * ) NULL );
 (gdb) c
 Continuing.
 hello world!
 
 Program exited normally.
 (gdb)
 
 
 
 Since this affects debugging/devlopment in general, maybe this PR
 should get a higher priority than low.


More information about the freebsd-bugs mailing list