Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fortran variables are sometimes not accessible #310

Closed
Ben136KBC opened this issue Dec 1, 2021 · 8 comments
Closed

Fortran variables are sometimes not accessible #310

Ben136KBC opened this issue Dec 1, 2021 · 8 comments
Assignees
Labels
external Issues related to external dependencies e.g. fortls, GDB, C++ extension, etc.

Comments

@Ben136KBC
Copy link

Ben136KBC commented Dec 1, 2021

Attached a solution which can be unzipped. It contains one C++ file compiled via Visual Studio 2019, and one Fortran file compiled via Intel Fortran, all native Windows code using OBJ / PDB file format. The C++ code calls into the Fortran code.

The Visual Studio Code version and installed extensions is shown in ConsoleApplicaiton4.png

Open the top folder in Visual Studio Code. If you put a breakpoint in the Fortran file in test, it hits it and you can local variables and NOPROP. See ConsoleApplication1.png.

However, now put a breakpoint in the larger method, see ConsoleApplicaiton3.png. Now you cant see any variables.

If you debug this using Visual Studio 2019 with Intel Fortran, you can see all the variables.

Can you please investigate? I can log this with the C++ extension if that is where the problem lies?
ConsoleApplication1
ConsoleApplication2
ConsoleApplication3
image
ConsoleApplication1.zip

@Ben136KBC Ben136KBC added the bug label Dec 1, 2021
@Ben136KBC
Copy link
Author

Ben136KBC commented Dec 1, 2021

You can see the Fortran compiler flags under consoleapplication1\x64\debug\kbclib.fcf. Note that it works fine for "simpler" Fortran methods, but it does not seem to like the bigger beasties.

C/C++ extension v1.8.0-insiders
Modern Fortran v2.6.2

@Ben136KBC
Copy link
Author

By the way, THANK YOU, for this extension. I know it must have taken a lot of work, but its essential, thank you!

@gnikit
Copy link
Member

gnikit commented Dec 1, 2021

I will have a look but FYI I am on Linux, so I might have to spin up a VM if I can't replicate the problem on my machine. Also, I feel that I need to mention that VSCode and VS in terms of project setups are vastly different so a 1:1 comparison might not be particularly helpful.

@gnikit gnikit self-assigned this Dec 1, 2021
@gnikit
Copy link
Member

gnikit commented Dec 1, 2021

I am not able to replicate the bug on Linux, the debugger (gdb-oneapi) works fine for both cases, I will spin up a VM and see what happens then.
I also had a look at your ifort compiler flags, there are a lot of options there to unpack, not sure what all of them do but I would start by compiling the program through a terminal with only the most minimal setup. In Linux/Mac that looks something like:

ifort -c -g -o Fortran1.o Fortran1.f90
icpx -g -o test ConsoleApplication1.cpp Fortran1.o

Then use the newly created test binary into your VSCode debugger.
For Linux/MacOs this can be done with the following launch.json for Windows I think it simpler

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/test",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            // This is only available for Linux and Mac
            "miDebuggerPath": "/home/gn/intel/oneapi/debugger/10.1.1/gdb/intel64/bin/gdb-oneapi",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "Set Disassembly Flavor to Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

Debugger output Linux

image

@Ben136KBC
Copy link
Author

I am sorry for all the effort, where in your extensions is the code the evaluates the watch window? Maybe the issue is really in the C++ debug API to which it must call up, it does it do a lot more?

@gnikit
Copy link
Member

gnikit commented Dec 1, 2021

No need to apologise. Modern Fortran does not have a debug adapter of its own, we plug in to Microsoft's C/C++ extension Debug component. We rely on the fact that C++ debuggers understand Fortran, however when it comes to Windows and Intel compilers I am not sure if that is the case and/or you have to use a specific version of the MSVC debugger.

Maybe you can ask the C/C++ devs if they have any insights as to why it is not working on Windows.


PS It just ocured to me that I don't have a Windows VM with Intel compilers in it so testing on Windows for me might not be possible.

PPS I was not familiar with the way you bind Fortran with C++, I suppose that is not considered standard, right? You might want to consider using bind(C) to allow compilation and linting with your existing version of Modern Fortran. I have added linting support for ifort but that is still in a (almost complete) dev branch.

@Ben136KBC
Copy link
Author

Thank you, yes, we have tons of old Fortran code. I have also logged this issue here: microsoft/vscode-cpptools#8479

@gnikit
Copy link
Member

gnikit commented Dec 5, 2021

I had a look at the C++ issue you linked, it would appear that there is not much we could do from our end either.
The only 2 solutions I can think of are

  1. Using gfortran for development and ifort for production
  2. Switching your development environment to Linux/WSL and then using ifort with intel-gdb.

Both of them are extremely inconvenient IMO but I don't see another solution.

I will be closing this issue now. Feel free to reopen if you think there is something else that can be done through Modern Fortran.

@gnikit gnikit closed this as completed Dec 5, 2021
@gnikit gnikit added external Issues related to external dependencies e.g. fortls, GDB, C++ extension, etc. and removed bug labels Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external Issues related to external dependencies e.g. fortls, GDB, C++ extension, etc.
Projects
None yet
Development

No branches or pull requests

2 participants