Fortran 77 debugger to check array bounds

◇◆丶佛笑我妖孽 提交于 2019-12-11 12:48:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!