用VSCODE编译Fortran时无法设置断点

问题描述 投票:0回答:1

我是 Visual Studio Code 新手,在调试 Fortran 代码时遇到问题,因为我无法在 Windows 11 中的 VS Code 中设置断点

我将用于测试的代码放在下面。

! main program
program main

    use InputRead
    implicit none

    CALL InputRead_init()

end program main

正常情况下,vscode可以通过点击代码左侧空白处来设置断点,但是当我将鼠标移到代码左侧空白处时,并没有代表断点的红点,我无法右键设置“断点”或使用“运行此处功能”。

这是tasks.json

{
    "version": "2.0.0",
    "command": "gfortran",
    "args": [
        "-g",
        "${fileDirname}\\Common\\*.f90",
        "-g",
        "${fileDirname}\\Module\\InputRead\\*.f90",
        "-g",
        "${fileDirname}\\*.f90",        
        "-o",
        "${fileDirname}\\${fileBasenameNoExtension}"
    ]
}

这是launch.json

{
    "version": "0.0.1",
    "configurations": [
        {
            "name": "Fortran Launch (GDB)",
            "type": "cppdbg",
            "request": "launch",
            "targetArchitecture": "x86",
            "program": "${fileDirname}\\${fileBasenameNoExtension}",
            "miDebuggerPath": "gdb.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "externalConsole": true,
            "preLaunchTask": "gfortran",
        },
        {
            "name": "Intel Debug Attach",
            "type": "cppvsdbg",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ]
}

这是settings.json

{
 "[fortran]": {
    "editor.acceptSuggestionOnEnter": "on"
},
"[fortran_fixed-form]": {
    "editor.acceptSuggestionOnEnter": "on"
},
 "[FortranFreeForm]": {
     "editor.acceptSuggestionOnEnter": "on"
 },
 "C_Cpp.errorSquiggles": "disabled"
 }

我安装了扩展 C/C++、Xavier Hahn 的 fortran、Miguel Carvajal 的 Modern Fortran、Fortran IntelliSense 和 Fortran Breakpoint Support。而我的gfortran版本是gcc版本8.1.0。

这是底部的输出。

=thread-group-added,id="i1"
GNU gdb (GDB) 8.1
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-w64-mingw32".
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"
[New Thread 4320.0x8d8]
[New Thread 4320.0x4e88]
[New Thread 4320.0x577c]
[New Thread 4320.0x4acc]

Thread 1 hit Breakpoint 1, 0x00000000004038a8 in main (argc=1, argv=0xf11780) at E:\Fortran\test\test.f90:5
5       use InputRead
Loaded 'C:\windows\SYSTEM32\ntdll.dll'. Symbols loaded.
Loaded 'C:\windows\System32\kernel32.dll'. Symbols loaded.
Loaded 'C:\windows\System32\KernelBase.dll'. Symbols loaded.
Loaded 'C:\windows\System32\msvcrt.dll'. Symbols loaded.
Loaded 'C:\windows\System32\user32.dll'. Symbols loaded.
Loaded 'C:\windows\System32\win32u.dll'. Symbols loaded.
Loaded 'C:\windows\System32\gdi32.dll'. Symbols loaded.
Loaded 'D:\mingw64\opt\bin\libgcc_s_seh-1.dll'. Symbols loaded.
Loaded 'C:\windows\System32\gdi32full.dll'. Symbols loaded.
Loaded 'C:\windows\System32\msvcp_win.dll'. Symbols loaded.
Loaded 'C:\windows\System32\ucrtbase.dll'. Symbols loaded.
Loaded 'D:\mingw64\bin\libquadmath-0.dll'. Symbols loaded.
Loaded 'C:\windows\System32\imm32.dll'. Symbols loaded.
[Thread 4320.0x4e88 exited with code 0]
[Thread 4320.0x577c exited with code 0]
[Thread 4320.0x4acc exited with code 0]
[Inferior 1 (process 4320) exited normally]
The program 'E:\Fortran\test\test' has exited with code 0 (0x00000000).

我尝试使用vscode菜单栏上的“开始调试”功能进行调试。我成功编译了一个可执行文件,但是没有办法一步步调试。 我期望可以使用调试功能来实现逐步调试

windows visual-studio-code fortran gfortran
1个回答
0
投票

正如评论中提到的,您只需要 Modern Fortran 作为扩展(请安装预发布版本)。如果您在 Windows 上使用调试器,则会存在一些限制,但这仅适用于英特尔编译器。

您构建任务,即tasks.json,我认为它并不健壮,因为它使用正则表达式,而不是像GNU Make或CMake这样形成依赖树来编译源代码的适当构建工具。这意味着您无法保证源文件之间使用的模块是最新版本。这肯定会导致调试器无法工作。

在 Windows 10 上,我能够完美地设置断点并逐步执行代码(带有模块),因此如果您希望我们仔细查看,请发布完整的最小工作示例。

© www.soinside.com 2019 - 2024. All rights reserved.