Fortran Process Ends Unexpectedly
Fault Locating
The program is running properly, but the output is different from the expected result. Figure 1 shows how to locate and rectify the fault.
- Confirm that the Fortran process ends unexpectedly.
- Modify the compilation script or enable the debugging macro to recompile a program that can be debugged.
- Enable the core dump function so that a core dump file can be generated when an exception occurs.
- Run the program. When the program stops unexpectedly, confirm that a core dump file is generated in the specified path.
- Use GDB to debug the core dump file and locate the cause.
- Modify the code. Compile the code again to verify the modification.
- If the problem is resolved, integrate the modification into the code.
- If the problem persists, run the program again and generate a core dump file for fault locating.
If there is no location information, add the location information to the code, and recompile and run the code.
Case: Unexpected Program Stop Caused by Wild Pointers
Symptom
A Fortran program ends unexpectedly.
Fault Locating
- Run the top command to confirm the program exits.
- Compile a program version that can be debugged, enable core dump, and then run the new program again.
- Use GDB to debug the core dump file and locate the code where the exception occurs.


- The core dump file records the memory address qtt accessed by grb2_inq. Normally, grb2_inq reads the grb2 file memory based on input parameters. If the operation is successful, the memory address qtt is returned. It is possible that the read of grb2_inq fails, which makes qtt is a wild pointer.
- The GDB debugging information shows that the memory address of qtt in is not allocated. As a result, the access fails and a core dump occurs. (Note: In the C language, NULL is returned when the memory application fails. For the Fortran interface, a wild pointer is returned. Therefore, a core dump may or may not occur the next time the program accesses the memory.)
Parent topic: Troubleshooting
