Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Breakpoints not working in Fortran code in Visual Studio Code

I'm new to VS Code and I'm having trouble with debugging a fortran code, as breakpoints never work and are skipped as if they were not there.

I've made a test program with the same problem:

program test

implicit none
real :: x

x = 10.0
print*, x

end program test

If I place a breakpoint at the print statement, the debugger does not stop.

During the run the breakpoint becomes grey and I get this message

Module containing this breakpoint has not yet loaded or the breakpoint address could not be obtained.

This is tasks.json

{
"version": "2.0.0",
"tasks": [
    {
        "label": "compile",
        "type": "shell",
        "command": "gfortran",
        "args": [
            "test.f90"
        ],
        "options": {
            "cdw": "${workspaceRoot}"
        }
    }
]
}

and this launch.json

{
"version": "0.2.0",
"configurations": [
    {
        "name": "Run GDB",
        "type": "cppdbg",
        "request": "launch",
        "program":"${workspaceRoot}/a.out",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceRoot}",
        "externalConsole": false,
        "MIMode": "gdb",
        "preLaunchTask": "compile",
    },
    {
        "name": "Intel Debug Attach",
        "type": "cppvsdbg",
        "request": "attach",
        "processId": "${command:pickProcess}"
    }
]
}

I installed the extensions C/C++, fortran by Xavier Hahn, Modern Fortran by Miguel Carvajal, Fortran IntelliSense, and Fortran Breakpoint Support.

Is anyone willing to give me a hand?

like image 265
matteeeo Avatar asked Oct 22 '25 15:10

matteeeo


1 Answers

You are missing the debug symbols from your binary. You need to include -g as an argument in the tasks.json

{
"version": "2.0.0",
"tasks": [
    {
        "label": "compile",
        "type": "shell",
        "command": "gfortran",
        "args": [
            "-g",
            "-Wall",
            "test.f90"
        ],
        "options": {
            "cdw": "${workspaceRoot}"
        }
    }
]
}

As a side note you only need the Modern Fortran extension


Full disclosure I am one of the devs of the extension

like image 123
gnikit Avatar answered Oct 25 '25 05:10

gnikit