Could not run debugger for fortran. Visual Studio Code
Asked Answered
C

3

7

I am trying to debug a fortran file on Visual Studio code(ubuntu 18.04).

I have the following installed extensions

enter image description here

My launch.json file is the following

"version": "0.0.1",
"configurations": [
    {
        "name": "Fortran Launch (GDB)",
        "type": "cppdbg",
        "request": "launch",
        "targetArchitecture": "x86",
        "program": "${workspaceRoot}/./a.out",
        "miDebuggerPath": "gdb",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceRoot}",
        "externalConsole": true,
        "preLaunchTask": "gfortran"
    }
]

since I am using linux, i dont need to give the path for gfortran. Also I tried changing the launch.json a little by changing .exe to linux extensions. I have updated it in the question. However the debugger still doesn't run and gives the following error in the console

and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word".
=cmd-param-changed,param="pagination",value="off"
Stopped due to shared library event (no libraries added or removed)
Loaded '/lib64/ld-linux-x86-64.so.2'. Symbols loaded.
Breakpoint 1, 0x0000555555554a60 in main ()
[Inferior 1 (process 24472) exited normally]
The program '/home/m/gSoC/GasSimulator/./a.out' has exited with code 0 (0x00000000).
Contamination answered 15/8, 2018 at 20:32 Comment(2)
I've been trying for months to get VScode to run fortran code with no luck. If it works for you could you add same pointers here? Not the debugger but just run a simple code.Endowment
@jmh I am not sure if this is what you want, but i compiled the code from the terminal console in VS code and did a ./a.out to normally run it in the terminal inside VS Code.Contamination
D
4

I don't know how to fix your specific problem, but here how I debugged a Fortran program in Visual Studio Code.

  1. I installed 3 plugins: "C/C++", "fortran" from Xavier Hahn and "Fortran Breakpoint Support"
  2. I compiled my program following the advices from fortranwiki.org.
gfortran SOME FORTRAN FILES -g -Wall -Wextra -Warray-temporaries -Wconversion -fimplicit-none -fbacktrace -ffree-line-length-0 -fcheck=all -ffpe-trap=zero,overflow,underflow -finit-real=nan
  1. I generated a launch.json file and only changed my program path and args, nothing else. Which gives something like
    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "(gdb) Lancer",
                "type": "cppdbg",
                "request": "launch",
                "program": "${workspaceFolder}/a.out",    // <-- Change this
                "args": [],                               // <-- Change this
                "stopAtEntry": false,
                "cwd": "${workspaceFolder}",              // <-- And maybe this
                "environment": [],
                "externalConsole": false,
                "MIMode": "gdb",
            }
        ]
    }

Maybe it was impossible or super hard to do in 2018, who knows? There have been a lot of update in VSCode and its plugins since then.

Disjoin answered 13/4, 2020 at 14:57 Comment(0)
J
2

For future reference, I had the same problem and it got fixed by passing the -g option to the compiler

Jin answered 22/9, 2021 at 13:37 Comment(2)
This is covered by @Nil’s comprehensive answer from last year, among other advice.Windpollinated
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Befool
E
0

Go to Settings under the Code / Preferences menu item and in the search box that appears enter fortran. You'll see a line that reads: "fortran.gfortranExecutable": "gfortran",

The heading to that line reads: // Specifies the complete path of the gfortran executable.

So try changing gfortran to the response you get when you type which gfortran on the command line of a terminal.

You might want to change the "preLaunchTask" variable in your json file to the gfortran path as well.

Endowment answered 15/8, 2018 at 21:11 Comment(1)
since I am using linux, i dont need to give the path for gfortran. Also I tried changing the launch.json a little by changing .exe to linux extensions. I have updated it in the question. However the debugger still doesn't run and gives the following error in the consoleContamination

© 2022 - 2025 — McMap. All rights reserved.