delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/05/15/21:24:49

Message-Id: <199605160119.AA13044@interlock.wdni.com>
Date: Wed, 15 May 1996 11:11:46 -0700 (PDT)
From: Jeff Welty <jwelty AT wdni DOT com>
To: djgpp AT delorie DOT com
Subject: Re: How do I get a stack trace after a SIGFPE?
In-Reply-To: <01I4PN4C3SAA000TIU@mail.rwth-aachen.de>
Mime-Version: 1.0

On Tue, 14 May 1996 Broeker%physik DOT rwth-aachen DOT de AT ans DOT nccf DOT weyer DOT com wrote:

> I don't think anyone can help you if you don't tell us a bit more:
[clip]

OK.  Here's the situation.  I frequently have programs which are several
thousand lines of code long, which process 100's of megabytes of data.
While I'm developing the code, I sometimes encounter a floating point error
at run time because of bad data, or bad code.  I'd like to be able to just
recompile the program with -g, and at least know which line of code generated
the FPE. 

I am running this on a compaq deskpro XL with a 120 MHZ Pentium using
NT 3.51


Here's my test code I've been trying to see if I can do just that:

/*--------------------  Listing of test.c ----------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

#ifdef __cplusplus
   typedef void (*fptr)(int);
#else
   typedef void (*fptr)();
#endif

void ErrorCatcher(int *reglist)
{
   long inst_o = 1 ;
   int plot_o = 1 ;

   fprintf(stderr, "ErrorCatcher: Died on %ld %d\n\n", inst_o, plot_o) ;

   /* force a stack dump */
   asm("int $3") ;

   exit(1) ;
}

int main(int argc, char **argv)
{
    double x, y ;

    /* cast Catcher to appropriate type */
    signal(SIGFPE, (fptr)ErrorCatcher);

    x = 10. ;
    y = 0. ;

    printf("Hello, world\n") ;
    fflush(stdout) ;

    x /= y ;

    printf("%lf\n", x) ;
    x = x ;
}
/* -------------   End of test.c */

Now I compile and run it:

C:\djgpp>gcc -g test.c
C:\djgpp>a

Hello, world
ErrorCatcher: Died on 1 1

Exiting due to signal SIGTRAP
Breakpoint at eip=0000158b
eax=0000001b ebx=00000121 ecx=00000000 edx=00000000 esi=00000121 edi=0000b6c0
ebp=0004b600 esp=0004b5f8 cs=01c7 ds=01cf es=01cf fs=0197 gs=01d7 ss=01cf
Call frame traceback EIPs:
  0x0000158b   _ErrorCatcher+47, line 22 of test.c
  0x000027eb   _raise+593
  0x00002845   _raise+149xception_processor+25
  0x00000000   0

C:\djgpp>symify a.out

------------  NOW COMMENT OUT THE CALL TO SIGNAL --------------------------
/*      signal(SIGFPE, (fptr)ErrorCatcher);  */

C:\djgpp>gcc -g test.c

C:\djgpp>a
Hello, world
Exiting due to signal SIGFPE
Floating Point exception at eip=000026b8
eax=00000000 ebx=0004f280 ecx=00007f34 edx=00000016 esi=00000054 edi=0000b6c0
ebp=000446de esp=0004b688 cs=00c7 ds=01cf es=00b7 fs=0197 gs=01d7 ss=01cf
Call frame traceback EIPs:
  0x000026b8   _fflush+1676

C:\djgpp>symify a.out

-------------------------------------------------------------------------------

The last result here is of no apparent help to me.

Now, I can run the program with gdb and put a breakpoint in the ErrorCatcher
function, but I can't get a trace of the calls that led me there.  I believe
this is because a setjmp is executed to the raise() function and it looses
the stack information.

My intuition tells me that I must be doing something wrong.  Is there a
flag for the compiler or an option for gdb that will help me out?  I've looked
at the documentation for both and didn't see anything, but I've missed
things before...

Thanks for any help!

Jeff

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019