David LaFrance-Linden wrote:
> If you can get a traceback for IO errors or FP exceptions, then in
> theory you can get them for SEGV.
This is what I thought. I thought I could just install my signal handler
for SIGSEGV to be a routine which aborts with a traceback (some vendors
provide a callable routine like ABORT to do this, otherwise just do
WRITE(-1,*) and this will abort). But when I try it on linux (2.4
kernel, IA32, if it matters), it does not work:
I have:
REAL, POINTER :: null_ptr=>NULL()
REAL :: temp
Now I register the signal handlers (this just calls the C signal under
the covers):
CALL RegisterSignalHandler (SIGFPE, &
C_LOC_Subroutine(TracebackExecution), C_NULL_PTR)
CALL RegisterSignalHandler (SIGSEGV, &
C_LOC_Subroutine(TracebackExecution), C_NULL_PTR)
Now I try a SIGFPE:
WRITE(*,*) "TRYING SIGFPE"
temp=EXP(HUGE(1.0))
WRITE(*,*) temp
And it works, a traceback is produced:
TRYING SIGFPE
Signal received: Floating point exception
In TRACEBACK, line 1332 of F2x.f90
Called by TRACEBACKEXECUTION, line 64 of Signals.f90
Called by PACKLSD_HS2, line 61 of PackLSD.f90
Called by PACK_LSD, line 21 of PackLSD.f90
Aborted
Now I try a SIGSEGV:
WRITE(*,*) "TRYING SIGSEGV"
temp=null_ptr
WRITE(*,*) temp
and it does not work:
TRYING SIGSEGV
Segmentation fault
I have observed weird behavior with signal handlers in other situations,
and I am not sure how much is the Fortran RTL, how much the OS, and how
much optimization. In any case, any help will be greatly appreciated.
I don't like cores much because they tend to be huge and clumsy to work
with.
Thanks,
Aleks
|