1

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

ccook
  • 5,869
  • 6
  • 56
  • 81

2 Answers2

2

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
  • 5,869
  • 6
  • 56
  • 81
1

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
  • 7,680
  • 1
  • 35
  • 47
  • Academic setting... Can gdb/dbx/ddd do this? I'm not a pro at these. – ccook Jul 08 '10 at 19:51
  • I have tried the -g flag on the compiler. Has helped a bunch, just not on the array bounds, unfortunately. – ccook Jul 08 '10 at 19:53
  • 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 Jul 08 '10 at 19:54
  • I found a good document on flint: http://www.nas.nasa.gov/News/Techreports/1991/PDF/rnd-91-013.pdf – ccook Jul 08 '10 at 19:55
  • Okay, I will take another survey on the debuggers and see if it can provide more assistance. Thanks! – ccook Jul 08 '10 at 19:56
  • 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 Jul 09 '10 at 09:49