Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save albertziegenhagel/6431811950864bd0009b6a1fa78e7f2b to your computer and use it in GitHub Desktop.
Save albertziegenhagel/6431811950864bd0009b6a1fa78e7f2b to your computer and use it in GitHub Desktop.
How-To: Enable Intel Fortran Debugging Support in VS Code

How-To: Enable Intel Fortran Debugging Support in VS Code

Introduction and Problem

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:

Solution:

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'.
@MBirn
Copy link

MBirn commented Jun 6, 2024

Thanks! Works like a charm.
In the 2024 version, the installer can be found at:
C:\Program Files (x86)\Intel\oneAPI\debugger\latest\share\ide_support\visual_studio\debugger\vs2022\FEE_VSIX_v17.vsix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment