
GDBのランタイムエラーが原因でFortran 90がクラッシュする可能性がありますか?ここではMWEの簡単なルーチンを示しますテスト.f90範囲外のエラーが発生します。
program main
implicit none
integer :: i
integer, parameter :: npt = 10
real, dimension(npt) :: A
real :: B
!
do i = 1,npt
A(i) = i
enddo
B = A(npt+1)
!
end program main
私はそれを次のようにコンパイルします:
gfortran test.f90 -O0 -fbacktrace -fbounds-check -g -Wall -w -o test.x
デフォルトでは、予想通り、トレースは次のようになります。
Error termination. Backtrace:
#0 0x7ffff7a0f2ed in ???
#1 0x7ffff7a0fed5 in ???
#2 0x7ffff7a102a7 in ???
#3 0x55555555480e in MAIN__
at ~/test.f90:11
#4 0x555555554844 in main
at ~/test.f90:13
GDBで実行するときにcatch catch
キャプチャcatch throw
ポイントを設定しましたが、GDBを実行してもプログラムが終了し、ボールフレームがありません。
(gdb) catch catch
Catchpoint 1 (catch)
(gdb) catch throw
Catchpoint 2 (throw)
(gdb) r test.x
`~/test.x' has changed; re-reading symbols.
Starting program: ~/test.x test.x
warning: Probes-based dynamic linker interface failed.
Reverting to original interface.
[Inferior 1 (process 3769) exited normally]
(gdb) where
No stack.
(gdb) bt
No stack.
(gdb)
GDBにこのようなエラーをキャッチし、犯人からデバッグを開始させるにはどうすればよいですか?明らかに小さなスクリプトでは便利なブレークポイントを識別するのは簡単ですが、大規模なレガシーFortranコードでは時間と労力を大幅に節約できます。
答え1
でこれを行うことができるかどうかはわかりませんが、catch
中断を設定してから逆追跡で_gfortran_runtime_error_at
犯人行を識別できます(その後、ブレークポイントを設定するなど)。
$ gdb -q ./test.x
Reading symbols from ./test.x...done.
(gdb) br _gfortran_runtime_error_at
Breakpoint 1 at 0x1030
(gdb) r
Starting program: /tmp/test.x
Breakpoint 1, 0x00007ffff7d5e670 in _gfortran_runtime_error_at ()
from /lib/x86_64-linux-gnu/libgfortran.so.5
(gdb) bt
#0 0x00007ffff7d5e670 in _gfortran_runtime_error_at ()
from /lib/x86_64-linux-gnu/libgfortran.so.5
#1 0x00005555555551fa in MAIN__ () at test.f90:11
(gdb) fram 1
#1 0x00005555555551fa in MAIN__ () at test.f90:11
11 B = A(npt+1)