在 VSCode Fortran 调试中检查从另一个模块导入的变量

Wil*_*gyi 5 fortran gdb gfortran visual-studio-code vscode-debugger

我正在调试一些包含许多 Fortran 模块的代码,其中一些模块彼此共享变量。不幸的是,带有 VScode 的 gdb 在调试时似乎无法检查导入的变量。

目前,当我需要检查导入的变量时,唯一的方法是停止调试,并手动更改代码以包含等于导入变量的局部变量。在下面的示例中,要找出foo%bar传递给函数的值a_function,我必须声明一个新变量,如下所示

module setup
  type(customDerived) :: foo
  foo%bar = 1
end module setup

module example
  use setup, only: foo
  integer(ik) :: foobar    <-- Stop debugging, add these lines, restart and inspect 'foobar'
  foobar = foo%bar         <--
  a_function(foo%bar)
end module example


Run Code Online (Sandbox Code Playgroud)

这显然非常耗时,而且我不知道为什么 VSCode 不能检查全局变量。有任何想法吗?以下是我当前在 makefile 中打开的 gfortran 编译器标志

-Og -g -Wall -Wextra -Wline-truncation -pedantic -fimplicit-none -fcheck=all -fbacktrace
Run Code Online (Sandbox Code Playgroud)

bbe*_*rcz 6

此问题已在以下部分得到部分处理:Fortran module Variables notaccessed in debuggers。基本上,在 Visual Studio Code 的 WATCH 面板中,您可以“添加表达式”并使用语法监视模块变量module::variable

  • 不太确定是否可以使用这种语法轻松监视派生类型。
  • 如果variable是一个(例如二维)数组,您可以使用通常的 Fortran 索引单独访问其元素,例如module::variable(12,457)
  • 可以通过 VS Code 的“调试控制台”中的 gdb 查询来访问数组的多个元素。使用-execprefix 传递 gdb 指令,如:-exec p module::variable@100显示 的前 100 个元素module::variable
  • 通过指定起始索引,可以在“监视”面板中显示多个元素,如下所示:module::variable(1,1)@100

有用的来源: https: //numericalnoob.blogspot.com/2012/08/fortran-allocatable-arrays-and-pointers.htmlhttps://www.gnu.org/software/gdb/documentation/当然。