Since there is no real debug adapter for Fortran in VS Code, the debug adapter for C/C++ is used which can be obtained via the C/C++ extension for VS Code.
When debugging on Linux or in general when using gdb
or lldb
for debugging, this is done via the MIEngine and the cppdbg
debug adapter and should not impose any problems.
But when debugging binaries that have been compiled for native Windows via Intel ifort
or ifx
(or any other compiler that emits PDB debug information), we have to use the cppvsdbg
adapter in VS Code, which is based on the Visual Studio debug engine (formerly codenamed "Concord").
The problem with using cppvsdbg
is that it is not very well suited to debug Fortran code. Most notably it is not possible to examine arrays in the debugger.
For further details of the problem, see:
In general it is possible to write extensions to the Visual Studio debug engine. For us, the most important part of such an extension is an Expression Evaluator and Intel provides one for Visual Studio. Luckily VS Code uses the same debug engine as Visual Studio and hence it is possible to load the debug engine extension that Intel provides for Visual Studio in VS Code.
After having oneAPI from Intel installed one should be able to find the installer for the extension at:
C:\Program Files (x86)\Intel\oneAPI\debugger\latest\ide_support\fee\vs2022\FEE_VSIX_v17.vsix
This file is basically just a ZIP file and can be extracted as such. Let's assume we have extracted the file to a path <FEE_ROOT>
. Within that directory there should be at least the following files:
FEE.pkgdef
FEE.vsdconfig
x64\FEE.dll
(or any other architecture respectively)
To make the extension loadable in VS Code we need to convert the FEE.pkgdef
file into a file called .vsdbg-config.json
. To this end we create a file called .vsdbg-config.json
in <FEE_ROOT>
with the following content:
{
"$schema": "https://aka.ms/vs/vsdbg-config-schema",
"languages": [
{
"languageId": "{8e546c6f-4819-4dde-83dd-f998d52e6f33}",
"vendorId": "{2a333b19-f91e-477b-8032-22de549d925a}",
"name": "Fortran",
"codeViewCompilerIds": [ { "code": 2 } ]
}
]
}
Please note that the languageId
and vendorId
have been copied from the FEE.pkgdef
file and codeViewCompilerIds
has been determined to be 2
from using CV_CFL_FORTRAN
of the CV_CFL_LANG
enum.
Now we are only left to create a file ~/.cppvsdbg/extensions/FEE.link
that consists of a single line which states <FEE_ROOT>
(the actual path, not the placeholder).
Finally, when debugging a Fortran executable in VS Code, we should now see the following in the beginning of the DEBUG CONSOLE
output view:
-------------------------------------------------------------------
You may only use the C/C++ Extension for Visual Studio Code
with Visual Studio Code, Visual Studio or Visual Studio for Mac
software to help you develop and test your applications.
-------------------------------------------------------------------
Loading extensions from 'C:\my\fee\root\FEE_VSIX_v17'.
Amazing, cheers for this.