如何从旧版 FORTRAN 中调试二进制文件?帮助

如何从旧版 FORTRAN 中调试二进制文件?帮助

我正在使用来自特定公司的较旧的专有 FORTRAN 遗留代码(因此无法发布太多源代码),我在文件交互方面遇到了问题。我的编译器 bash shellInstall正在调用,make newspaper它通过 bash shell 调用一系列其他函数makefile来创建newspaper.但是,newspaper然后Install在输入文件中调用 when 来与输出文件进行比较,newspaper然后返回not found。我尝试打开该文件newspaper来查看它是否有错误。

我尝试过转换newspaper为文本,只是生成一个充满数字的文本文件。我需要将文件作为“代码”来读取,以找出出了什么问题并导致not found出现问题。

为了澄清:

  • newspaper是一个二进制文件,就像less newspaper在终端中执行时一样,我的 Linux 操作员说它是一个二进制文件
  • newspaperinside的调用Install具有以下格式,newspaper < xfile1R.in > f1.test后面是diff xfile1R.out f1.test > f1.dif
  • gfortran是Ubuntu中使用的编译器,c盘是挂载盘
  • 小端应该是根据使用的二进制格式这个网站

当谈到 Linux 和 FORTRAN 时,我是一个菜鸟,我可能只是犯了一个菜鸟错误,非常感谢任何建议,我不确定这是 Linux 还是 FORTRAN 问题。

roman@DESKTOP-QKJTF3S:/mnt/c/Users/roman/Documents/NEWSPAPER/Newspaper/Newspaper$ sh ./Install.sh
cat makefile.sh >makefile
chmod a+x makefile
make: 'newspaper' is up to date.
./Install.sh: 10: newspaper: not found
./Install.sh: 12: newspaper: not found
./Install.sh: 14: newspaper: not found
./Install.sh: 16: newspaper: not found
./Install.sh: 18: newspaper: not found
./Install.sh: 20: newspaper: not found
 84 -rwxrwxrwx 1 roman roman  83071 Feb 17 16:08 f1.dif
152 -rwxrwxrwx 1 roman roman 153543 Feb 17 16:08 f2.dif
108 -rwxrwxrwx 1 roman roman 109718 Feb 17 16:08 f3.dif
232 -rwxrwxrwx 1 roman roman 236209 Feb 17 16:08 f4.dif
164 -rwxrwxrwx 1 roman roman 166612 Feb 17 16:08 f5.dif
 48 -rwxrwxrwx 1 roman roman  48898 Feb 17 16:08 f6.dif
./Install.sh: 31: Syntax error: newline unexpected

编辑1:尝试file newspaper检查PATH

roman@DESKTOP-QKJTF3S:/mnt/c/Users/roman/Documents/NEWSPAPER/Newspaper/Newspaper$ file newspaper
newspaper: ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=8ac6de30da50639d7e3ea55a09416b049a5291c0, for GNU/Linux 3.2.0, not stripped

编辑2:修复文件?

#
# Makefile for newspaper
#

OBJF = \
    sfun1.o \
    sfun2.o \
    sfun3.o \
    sfun4.o \
    sfun5.o \
    sfun6.o \
    sfun7.o 


FLAGS = -O2 -static -std=legacy
COMP  = gfortran

newspaper: $(OBJF)
    $(COMP) $(FLAGS) -o newspaper $(OBJF)

.f.o:
    $(COMP) $(FLAGS) -c $< -o $*.o

编辑3:Install错误

#! /bin/csh -f

make flops

./newspaper < xfile1R.in > f1.test
diff xfile1R.out f1.test > f1.dif
./newspaper < xfile2R.in > f2.test
diff xfile2R.out f2.test > f2.dif
./newspaper < xfile3R.in > f3.test
diff xfile3R.out f3.test > f3.dif
./newspaper < xfile4R.in > f4.test
diff xfile4R.out f4.test > f4.dif
./newspaper < xfile5R.in > f5.test
diff xfile5R.out f5.test > f5.dif
./newspaper < xfile6.in > f6.test
diff xfile6.out f6.test > f6.dif

ls -als *.dif

# User input for directory to put executable
if ( $1 == '' ) then
   echo " "
   echo -n "Enter directory for executable file: "
   set Edir = $<
else
   set Edir = $1
endif

if ( $Edir != '' ) then
   mv newspaper $Edir
endif

编辑4:更多语法错误,同样的错误

./Install.sh: 30: Syntax error: newline unexpected
roman@DESKTOP-QKJTF3S:/mnt/c/Users/roman/Documents/NEWSPAPER/Newspaper/Newspaper$ ./
-bash: ./: Is a directory
roman@DESKTOP-QKJTF3S:

编辑5:csh检查

roman@DESKTOP-QKJTF3S:/mnt/c/Users/roman/Documents/NEWSPAPER/Newspaper/Newspaper$ sudo apt-get install csh
Reading package lists... Done
Building dependency tree
Reading state information... Done
csh is already the newest version (20110502-5).
0 upgraded, 0 newly installed, 0 to remove and 20 not upgraded.

编辑6:成功了!!感谢 @steeldriver 指导我这个菜鸟

164 -rwxrwxrwx 1 roman roman 164829 Feb 17 21:36 f1.dif
304 -rwxrwxrwx 1 roman roman 307257 Feb 17 21:36 f2.dif
216 -rwxrwxrwx 1 roman roman 217791 Feb 17 21:36 f3.dif
460 -rwxrwxrwx 1 roman roman 468651 Feb 17 21:36 f4.dif
324 -rwxrwxrwx 1 roman roman 331213 Feb 17 21:36 f5.dif
 96 -rwxrwxrwx 1 roman roman  96955 Feb 17 21:36 f6.dif

Enter directory for executable file: ./Outputs
roman@DESKTOP-QKJTF3S:/mnt/c/Users/roman/

答案1

调试成功后,由于使用了 bash shell,makefile 需要进行一些编辑,因此newspaper <input_file.in>...将变成./newspaper <input_file.in>....大多数修复都是在显式运行脚本中进行的,sh这是错误的这样做的方法是因为该Install文件明确指出了csh哪个是不同的 shell 编译器,因此更好地运行Install./Install会导致文件newspaper完全生成。

相关内容