From: Jacek Dziedzic on
Hi!

I have to (unfortunately) debug a FORTRAN-77 program
written by somebody else. The program crashes with a
SIGSEGV, but I can't point the gdb debugger to a line
in code, because SIGSEGV is trapped by the Fortran
Runtime Library, so that it can display a stack trace
and do some cleanup.

What is the way out of this? I tried to turn off this
"feature" during compilation, but to no avail. I tried
forcing gdb to catch the signal, but:
(gdb) catch signal
Catch of signal not yet implemented

How would you go about isolating the problem? The compiler
is Intel's ifort, but I guess I could switch to g77 for
debugging if it helps.

TIA,
- J/
From: Paul Pluzhnikov on
Jacek Dziedzic <jacek.dziedzic__no--spam__(a)gmail.com> writes:

> I have to (unfortunately) debug a FORTRAN-77 program
> written by somebody else. The program crashes with a
> SIGSEGV, but I can't point the gdb debugger to a line
> in code, because SIGSEGV is trapped by the Fortran
> Runtime Library, so that it can display a stack trace
> and do some cleanup.
>
> What is the way out of this?

You must be debugging a core?

If you run the program under gdb from the start, it should stop with
"program received SIGSEGV" message *before* FORTRAN runtime had
any chance to catch/handle the signal.

Cheers,
--
In order to understand recursion you must first understand recursion.
Remove /-nsp/ for email.
From: fjblurt on
On Jul 22, 1:52 am, Jacek Dziedzic <jacek.dziedzic__no--
spa...(a)gmail.com> wrote:
> Hi!
>
> I have to (unfortunately) debug a FORTRAN-77 program
> written by somebody else. The program crashes with a
> SIGSEGV, but I can't point the gdb debugger to a line
> in code, because SIGSEGV is trapped by the Fortran
> Runtime Library, so that it can display a stack trace
> and do some cleanup.
>
> What is the way out of this? I tried to turn off this
> "feature" during compilation, but to no avail. I tried
> forcing gdb to catch the signal, but:
> (gdb) catch signal
> Catch of signal not yet implemented
>
> How would you go about isolating the problem? The compiler
> is Intel's ifort, but I guess I could switch to g77 for
> debugging if it helps.

What system are you on? On most systems I've tried (I just tried
FreeBSD), a debugger gets to see signals like SIGSEGV before the
program itself does.

What happens when you run gdb on a program like this?

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

void handler(int sig) {
printf("Ha ha ha!\n");
}

int main(void) {
signal(SIGSEGV, handler);
*(volatile int *)0 = 42;
return 0;
}


From: Jacek Dziedzic on
Paul Pluzhnikov pisze:
> Jacek Dziedzic <jacek.dziedzic__no--spam__(a)gmail.com> writes:
>
>> I have to (unfortunately) debug a FORTRAN-77 program
>> written by somebody else. The program crashes with a
>> SIGSEGV, but I can't point the gdb debugger to a line
>> in code, because SIGSEGV is trapped by the Fortran
>> Runtime Library, so that it can display a stack trace
>> and do some cleanup.
>>
>> What is the way out of this?
>
> You must be debugging a core?

Nope, no core is generated, since the SIGSEGV is
trapped by fortran RTL, which tries to shut down
gracefully. The compiler doc says there's an environment
variable one can set to have the core generated, yet
even then it is not generated. Maybe the admins turned
cores off for some reason (security?).

> If you run the program under gdb from the start, it should stop with
> "program received SIGSEGV" message *before* FORTRAN runtime had
> any chance to catch/handle the signal.

Yep, I know it should. It does, in fact, do that for
my C and C++ programs.

- J.
From: Jacek Dziedzic on
fjblurt(a)yahoo.com pisze:
>
> What system are you on?

uname -a says:
Linux [hostname] 2.6.24-etchnhalf.1-amd64 #1 SMP Mon Jul 21 10:36:02
UTC 2008 x86_64 GNU/Linux

> On most systems I've tried (I just tried
> FreeBSD), a debugger gets to see signals like SIGSEGV before the
> program itself does.

This is also the case on this system, except for Fortran
programs.

> What happens when you run gdb on a program like this?
> [...]

It traps correctly:
Program received signal SIGSEGV, Segmentation fault.
0x00000000004004f7 in main () at 1.c:10
10 *(volatile int *)0 = 42;

Pretty weird, this fortran, huh? :)

- J.