问题
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:
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]
回答2:
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".
来源:https://stackoverflow.com/questions/3207153/fortran-77-debugger-to-check-array-bounds