Hello everyone,
I’m testing to use VSCode + FPM + gfortran (on windows with conda) to do interactive debugging.
Discussing with our new global friend ChatGPT it proposed me the following:
Add two files to my project within the .vscode folder:
task.json
{
"version": "2.0.0",
"tasks": [
{
"label": "fpm-build-debug",
"type": "shell",
"command": "fpm build --profile debug"
}
]
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Fortran with GDB",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/debug/<executable-name>",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"preLaunchTask": "fpm-build-debug"
}
]
}
This will not work because FPM does not produce predictable build directories.
So I have to hand-pick everytime I clean the project from whatever tag within
build\gfortran_XXXXXXXXXXX\app\<executable-name> or build\gfortran_XXXXXXXXXXX\test\<executable-name> etc etc.
Replacing manually in the launch.json the line "program": "${workspaceFolder}/build/debug/<executable-name>" enables interactive debugging when pressing F5, this is good but is not enough.
The ideal scenario, just like when working in python, would be to make it such that when having your current program file opened in the workspace, it could use this info to go and pick the right executable and pass it to GDB when pressing F5. This could in principle be double if it wasn’t for
FPM does not produce predictable build directories
Ideally, FPM should produce predictable build directories and it would make life easier. In the mean time, could there be some way of extracting the executables relative path when running fpm such that it could be passed to GDB ? I know that running fpm run --verbose or fpm test --verbose would print that path to the terminal, but I don’t know how to extract within this framework for GDB to catch it and use it. I’m exploring adding an intermediate python script as a runner for the debugging.
Any advise would be welcome.
Thanks,
