GDB debugger hangs on Fortran READ command when reading from a text file

限于喜欢 提交于 2019-12-11 17:05:25

问题


This is my fortran code (fortcode.for)

        CHARACTER  TITLE*80                                                                                                                                         
        COMMON   IN                                                                                                        
        COMMON   TITLE 
        PARAMETER (MAXTIT=20)
  20    FORMAT (A80)    

  C*****FORTRAN LOGICAL UNIT NUMBER OF INPUT FILE                      
        IN  = 5                                  

        DO 1665 I=1, MAXTIT
          READ (IN,20) TITLE

  1665  CONTINUE

        CLOSE (IN)                        

        END  

I compile the fortran file into an executable (fortexec.exe) using the following command.

gfortran -g -fno-align-commons fortcode.for -o fortexec.exe

I then use gdb debugger by typing

gdb fortexec

I then give it the following file input (input.inp)

  testx testy testz                    
  testx testy testz
  testk tety
  testk tety
  testk tety
  testk tety
  testk tety
  testk tety
  testk tety
  testk tety
  testk tety
  testk tety
  testk tety
  testk tety
  testk tety
  testk tety
  testk tety
  testk tety
  testk tety
  testk tety
  testk tety
  testk tety 

By typing the following

run < input.inp

It starts running but then just hangs.

I type Ctrl-C to interrupt it, and then it gives me the following result

  [New Thread 10804.0x5b6c]
  [New Thread 10804.0x4974]
  [New Thread 10804.0x3c24]
  [New Thread 10804.0x4ae8]
  At line 11 of file fortcode.for (unit = 5, file = 'stdin')
  Fortran runtime error: [New Thread 10804.0x48e8]
  End of file

  Error termination. Backtrace:

  Program received signal SIGINT, Interrupt.
  [Switching to Thread 10804.0x48e8]
  0x765b1985 in KERNELBASE!CtrlRoutine () from 
  C:\WINDOWS\SysWOW64\KernelBase.dll

Any ideas how to stop it hanging, and make it debug with the file input? Thanks


回答1:


you probably did not give proper input file name, your setup ran no problem with gfortran on my laptop. if I give unexisting input it freezes and after CTRL+C I get the same warning.I would print what is read just to verify that it is working properly



来源:https://stackoverflow.com/questions/57859014/gdb-debugger-hangs-on-fortran-read-command-when-reading-from-a-text-file

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