When debugging with Intel's debugger, gdb-ia, if the application encounters an error in the Fortran compiler runtime library (RTL), the application exits without returning control to the debugger. This makes it impossible to obtain a stack trace to locate the error or to continue debugging.
Linux; IA-32, Intel64 and IA-64; Intel Fortran Compiler and Debugger
When the Fortran compiler runtime library encounters an error, the default behavior is to print a diagnostic and then exit, unless the user requests otherwise.
There are two ways to resolve this and get a stack trace.
(1) The Fortran runtime library needs to know that the debugger is running, (or at least, that it shouldn't exit). You may tell it this by setting the environment variable f77_dump_file=TRUE. The RTL then knows not to exit, and Intel's debugger, gdb-ia, can give you a stack trace, for example:
> ifort -g kr.f90 > export f77_dump_flag=TRUE > gdb-ia ./a.out GNU gdb (GDB) 7.12-18.0.1053 Copyright (C) 2016 Free Software Foundation, Inc; (C) 2017 Intel Corp. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-pc-linux-gnu". Type "show configuration" for configuration details. For information about how to find Technical Support, Product Updates, User Forums, FAQs, tips and tricks, and other support information, please visit: <http://www.intel.com/software/products/support/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from ./a.out...done. (gdb) run Starting program: ./a.out [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib64/libthread_db.so.1". forrtl: No such file or directory forrtl: severe (29): file not found, unit 51, file /<path>/__I_Do_Not_Exist.dat Image PC Routine Line Source a.out 0000000000431E7E Unknown Unknown Unknown a.out 0000000000408E05 Unknown Unknown Unknown a.out 0000000000402D5D Unknown Unknown Unknown a.out 0000000000402C5E Unknown Unknown Unknown libc-2.17.so 00007FFFF751DAF5 __libc_start_main Unknown Unknown a.out 0000000000402B69 Unknown Unknown Unknown Program received signal SIGABRT, Aborted. 0x00007ffff75315d7 in raise () from /lib64/libc.so.6 (gdb) where #0 0x00007ffff75315d7 in raise () from /lib64/libc.so.6 #1 0x00007ffff7532cc8 in abort () from /lib64/libc.so.6 #2 0x0000000000433021 in for.issue_diagnostic () #3 0x0000000000431e7e in for.io_return () #4 0x0000000000408e05 in for_open () #5 0x0000000000402d5d in krmain () at kr2.f90:5 #6 0x0000000000402c5e in main () #7 0x00007ffff751daf5 in __libc_start_main () from /lib64/libc.so.6 #8 0x0000000000402b69 in _start () (gdb) quit
(2) Another way to get a traceback after an exception or an error in the Fortran runtime library is to build with the -traceback option. This has a low overhead and is designed for use in non-debug, production builds. It does not require the application to be built with debug symbols (-g).
$ ifort -traceback kr2.f90 $ ./a.out forrtl: No such file or directory forrtl: severe (29): file not found, unit 51, file /<path>/__I_Do_Not_Exist.dat Image PC Routine Line Source a.out 00000000004322DE Unknown Unknown Unknown a.out 0000000000409265 Unknown Unknown Unknown a.out 0000000000402D2A MAIN__ 5 kr2.f90 a.out 0000000000402C5E Unknown Unknown Unknown libc-2.17.so 00007F5D6CDF5AF5 __libc_start_main Unknown Unknown a.out 0000000000402B69 Unknown Unknown Unknown forrtl: error (76): Abort trap signal Image PC Routine Line Source a.out 000000000040408E Unknown Unknown Unknown libpthread-2.17.s 00007F5D6D3A8130 Unknown Unknown Unknown libc-2.17.so 00007F5D6CE095D7 gsignal Unknown Unknown libc-2.17.so 00007F5D6CE0ACC8 abort Unknown Unknown a.out 0000000000433481 Unknown Unknown Unknown a.out 00000000004322DE Unknown Unknown Unknown a.out 0000000000409265 Unknown Unknown Unknown a.out 0000000000402D2A MAIN__ 5 kr2.f90 a.out 0000000000402C5E Unknown Unknown Unknown libc-2.17.so 00007F5D6CDF5AF5 __libc_start_main Unknown Unknown a.out 0000000000402B69 Unknown Unknown Unknown Aborted (core dumped)
The test program for this article was the following:
PROGRAM krmain INTEGER :: a(8192) DO i=1,10 WRITE (50) a OPEN (51,NAME='__I_Do_Not_Exist.dat',STATUS='OLD') END DO END PROGRAM krmain
In this example, the RTL could also be prevented from aborting by adding an ERR=
or an IOSTAT= parameter to the I/O statements.