It’s well known that Fortran in nature is a type of compiled language. To make matters worse, there are very few IDEs specially developed for Fortran, which is especially true on Linux systems.
So, I want to know if there are some elegant methods of debugging the Fortran project on Linux operating system, especially when using Intel oneAPI Toolkits.
Intel has one of the more extensive suites of tools for debugging and optimizing codes, with much of the documentation available on their web site as well as a good amount that comes with the tools when you install them; there are a few IDEs for Fortran on Linux, and I would hazard to say that TotalView is one of the most commonly used commercial debuggers. Apparently gdb is not what you have in mind? If you are interested primarily in Intel products have you tried their web site already? If you compile with the major debug flags on you can often detect problems without the need for a debugger. Debuggers are useful for investigating logic problems in code but generally fail on actual bugs; the compiler flags are generally more useful with that category (over and under-indexing arrays, type mismatches, …).
After that, it depends on whether you are using Intel processors, whether you are interested in parallel processing, whether tuning the code is part of what you consider to be debugging, … this can take a few days to read:
gdb(1) is worth trying to master in line mode, and a lot of GUI users get converted over to CLI users using it; but there are a lot of wrappers for gdb; ddd may already be on your system, but also take a look at http://sourceware.org/gdb/wiki/GDB%20Front%20Ends
If you are an fpm(1) user you can easily run in the TDU world half-way between GUI and CLI with something like this:
fpm run --runner ‘gdb -tui’
What editor do you use? If you are a vim(1) user edit your code and enter
:packadd termdebug
:Termdebug
If you use emacs(1) there are web books on using gdb(1) and everything else in there (but I am a vi/vim user unless working with an emacs(1) fan so I’ll leave that up to others – no editor holy wars please).
Hi @Hongyi, for Linux regardless of if you are using ifort or gfortran you should be able to use VS Code + the Modern Fortran extension. Please use the pre-Release version and allow it to install fortls.
That should give you an IDE level debugging functionality with breaking points, hover, watch windows, stepping, etc. OpenMP threads should also work, but no MPI, conditional or functional breakpoint support.
FYI You will need to make sure you use Intel’s GDB version in your launch.json, see the docs for how to do that
I use VS code with Modern Fortran, it is very nice and user-friendly. I did not use it for debugging purposes.
However, whenever I try to create a new program, the program template appears with 2 cursors and leads to simultaneous writing in two-place (though useful), which leads to the wrong syntax. (for clarity see the attached image file). Maybe someone has a better experience (and is willing to share it) in using VS code with Modern Fortran.
This is because you are using the program snippet of the extension, which generates the template. Snippets insert code with placeholders, which the user can then navigate using Tab. The two cursors are basically VS Code’s way of typing at the same time the program name at both the start and end of the scope. Once done, press Tab to move to the body of the scope.
I should also add, that snippets will not necessarily fit all your cases, so it does not always make sense to use them. Let me know if you would like to see certain snippets in the extension.
Are you using GUI emacs or terminal emacs? I find the built-in gdb integration reasonably nice to use in GUI emacs. Open up your main program, then M-x gdb to start a session, then M-x gdb-many-windows to get buffers for tracking variables and the call stack. You can set breakpoints by clicking in the gutter of your source file buffer, like in most IDEs. Control the debugger with the gdb prompt (like terminal) or with the menu.
Thanks for the suggestion. I will try them. Further, custom snippets seem pretty new to me and hopefully fantastic in the future as I continue using Modern Fortran in more depth.
Emacs is just using gdb, so if you are able to debug the executable with gdb in your terminal, then it will also work when using emacs. I have debugged programs built with ifort and gfortran this way. I would guess ifx works the same, but I’ve never done it myself.