Understanding the backtrace error in fortran

时间秒杀一切 提交于 2019-12-02 16:13:21

问题


I get the following error when I execute a fortran code compiled with gfortran. The error is followed by a backtrace for this error pointing to memory locations.

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0x2b2f8e39da2d in ???
#1  0x2b2f8e39cc63 in ???
#2  0x311823256f in ???
#3  0x311827a7be in ???
#4  0x2b2f8e39cff2 in ???
#5  0x2b2f8e4adde6 in ???
#6  0x2b2f8e4ae047 in ???
#7  0x2b2f8e4a62d7 in ???
#8  0x40482a in instrument_
    at /home/user/model/instrument.f:90
#9  0x406c1e in funcdet
    at /home/user/model/funcsynth.f:67
#10  0x406c98 in main
    at /home/user/model/funcsynth.f:78
Segmentation fault (core dumped)

I would like to know where the first instance of error arises - is it the first line of the backtrace or the lastline? Also, strategies that might help me debug the issue.

Update:

Upon backtracing, the line 90 of instrument involves opening a file like so:

  out_file3 = 'new_file'
  OPEN(unit=3,file=out_file3,status='unknown')

To determine the issue behind I've incorporated error checking by doing so:

  OPEN(unit=3,file=out_file3,status='unknown',iostat=io_status, err=100)
  100  write(STDOUT,*) 'io status=', io_status 

The code exits with the error: Error: Invalid value for ERR specification at (1). How do I determine the appropriate value for ERR specification? This led me to suspect that unit=3 might be the cause for error, I've changed the value for unit, but everytime get the "Segmentation fault (core dumped)" error.

Update 2:

OPEN(unit=3,file=out_file3,status='unknown',err=17)
17  write(STDOUT,*) 'Problem' 

Still get the Segmentation fault (core dumped) error at the line corresponding to OPEN.... I can only guess that unit=3 is the root cause of the problem.

Update 3

Attempt at a self sufficient example:

  character*280       testfile,finalfile,outfile
  DIR = '/storage/work/user/'
  testfile = 'test.dat'
  CALL getenv(DIR,outfile)
  CALL sappend(outfile,testfile,finalfile)
  OPEN(unit=3,file=finalfine,status='new')
  write(3,*) 'Test'
  END

来源:https://stackoverflow.com/questions/58344596/understanding-the-backtrace-error-in-fortran

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