views:

26

answers:

2

I am still green to debugging F77 and am having some problems with array bounds. I recently modified a lengthy code to have new array sizes. Everything 'seemed' okay until I noticed methods to alter one array, altered another. Somewhere in this code, I assume, an assignment is out of bounds and writing to the other arrays.

Is there a debugger/tool in the linux environment that will 'catch' the out of bounds exception?

I am currently using gfortran

+1  A: 

If this is at an employer, you may want to have them buy a license for "flint" - it's like "lint" for C, but for fortran.

Also, doesn't gdb/dbx/ddd do fortran debugging?

Oh, sometimes you need to turn on special flags in f77 in order to maintain the strings and debugging info in the executables and object files, much like "cc -g".

eruciform
Academic setting... Can gdb/dbx/ddd do this? I'm not a pro at these.
ccook
I have tried the -g flag on the compiler. Has helped a bunch, just not on the array bounds, unfortunately.
ccook
I could swear that the standard debuggers allows working on fortran things. It was always c++ objects that confused things back at my old job where we had C and fortran mixed together. Also note that f77 may have compiler requirements for debugging symbols.
eruciform
I found a good document on flint: http://www.nas.nasa.gov/News/Techreports/1991/PDF/rnd-91-013.pdf
ccook
Okay, I will take another survey on the debuggers and see if it can provide more assistance. Thanks!
ccook
Have you looked into http://www.ibm.com/software/awdtools/purify/ ?
eruciform
It looks promising, but it looks to be for c/c++. I've been making way with eclipse/photran/gfortran. I found a lot of warnings, but nothing about array bounds.
ccook
A: 

There is a flag for gfortran to insert checks for out of bounds

-fbounds-check Enable generation of run-time checks for array subscripts and against the declared minimum and maximum values. It also checks array indices for assumed and deferred shape arrays against the actual allocated bounds. In the future this may also include other forms of checking, eg. checking substring references.

http://linux.die.net/man/1/gfortran

The output is as desired:

At line 2153 of file src/cdtm0402.f
Fortran runtime error: Array reference out of bounds for array 'wv1mp', upper bound of dimension 1 exceeded (78 > 77)

Backtrace for this error:
  + function coefdp (0x448BC3)
    at line 2153 of file cdtm0402.f
  + in the main program
    at line 371 of file cdtm0402.f
  + /lib64/libc.so.6(__libc_start_main+0xfd) [0x7ffff703da7d]
ccook