[comp.sys.next] GDB bug

patl@athena.mit.edu (Patrick J. LoPresti) (02/12/91)

Consider the following C program (compiled with "cc -g foo.c -o foo"):

#include <stdio.h>
#include <signal.h>

void MyHandler(int, int, struct sigcontext *);
int number = 6;

main(int argc, char *argv[])
{
  signal(SIGFPE, MyHandler);
  number = number / 0;
  exit(0);  /* never gets here */
}

void MyHandler(int type, int code, struct sigcontext *scp)
{
  printf("Boom!  Type = %d\n",type);
  exit(-1);
}


When I run this on my NeXTStation, it does the right thing ("Boom!  Type
= 8").  When I run under GDB, MyHandler never executes no matter what I
do.  In particular, I ask GDB to "handle 8 nostop" (i.e., do not stop on
FPE signal), but GDB insists on stopping anyway.  The "cont" command,
instead of calling my handler, falls through to the exit(0), causing the
program to "exit normally".

I try the same thing on a VAX (compile with gcc -g, run under GDB, ask
it to "handle 8 nostop") and it works.  That is, GDB passes the signal
like it should, the code in MyHandler executes, and my program exits
with a status of -1.

Also, if I replace "number = number / 0" with "while (1);", then do a
"kill -FPE <pid>" from a different window, it works fine on both NeXT
and VAX.  For some reason, GDB on the NeXT never allows my handler to
execute if the signal is generated internally, but *will* allow it to
execute if the signal is generated externally.

What gives?  If this is a GDB bug, where do I go for a working version?

-Pat

P.S. NeXT GDB version 3.1; VAX GDB version 3.5.