This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

sigfpe signals get squashed when run under gdb


Hi,

I'm trying to figure out why gdb is changing behaviour of a little test
program I've written to test sigfpe() handling on SPARC hardware. The
program runs as expected from the command line but under gdb the OS
signal handler raises and abort():

11:05 alexjb@enzo [precise_exceptions] >gdb --args ./a.out
GNU gdb 6.3.50_2004-11-23-cvs
<snip>
This GDB was configured as "sparc-sun-solaris2.11"...
(gdb) r
Starting program: ./a.out
1:x is @ ffbffae4 and set to 99
1: sigfpe result 0

Program received signal SIGFPE, Arithmetic exception.
0xff2a265c in .div () from /lib/libc.so.1
(gdb) c
Continuing.

Program received signal SIGABRT, Aborted.
0xff31da3c in _lwp_kill () from /lib/libc.so.1
(gdb) bt
#0  0xff31da3c in _lwp_kill () from /lib/libc.so.1
#1  0xff2de6bc in raise () from /lib/libc.so.1
#2  0xff2bee3c in abort () from /lib/libc.so.1
#3  0xff2bc060 in _sigfpe_master () from /lib/libc.so.1
#4  0xff31c984 in __sighndlr () from /lib/libc.so.1
#5  0xff311a54 in call_user_handler () from /lib/libc.so.1
#6  0x00010ab0 in do_test1 () at pe_wierd.c:43
#7  0x00010af4 in main (argc=1, argv=0xffbffbcc) at pe_wierd.c:52

Trying a "handle SIGFPE nostop noprint" doesn't help but running from
mdb or command line produces the expected output:

1:x is @ ffbffb24 and set to 99
1: sigfpe result 0
signal_handler: caught 8
  siginfo:
    si_code = 1
1:x is @ ffbffb24 and set to -2

The test case is as follows:

#include <floatingpoint.h>
#include <siginfo.h>

#include <stdlib.h>
#include <ucontext.h>

void fp_handler1(int sig, siginfo_t* siginfo, ucontext_t* uctx)
{
    mcontext_t *ctx = (mcontext_t *)&(uctx->uc_mcontext);

    printf("signal_handler: caught %d\n", sig);
    printf("  siginfo:\n");
    printf("    si_code = %d\n", siginfo->si_code);

    uctx->uc_mcontext.gregs[REG_PC] = uctx->uc_mcontext.gregs[REG_nPC]; 
}
                                               
void do_test1(void)
{                                  
   int x = 99;
   int result;

   printf("1:x is @ %p and set to %d\n", &x, x);
   
   result = sigfpe(FPE_INTDIV, (sigfpe_handler_type) fp_handler1);

   printf("1: sigfpe result %d\n", result);
   
   x = 1/0;

   printf("1:x is @ %p and set to %d\n", &x, x);
} 

int main(int argc, char** argv)    
{
    do_test1();
}

Can anyone replicate this behaviour and/or explain whats going on?

--
Alex, homepage: http://www.bennee.com/~alex/
Disc space -- the final frontier!


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]