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

标签 visual-studio-code fortran gdb gfortran 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


这显然很费时间,不知道为什么VSCode应该不能检查全局变量。有任何想法吗?以下是我目前在 makefile 中打开的 gfortran 编译器标志
-Og -g -Wall -Wextra -Wline-truncation -pedantic -fimplicit-none -fcheck=all -fbacktrace

最佳答案

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

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

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

    关于visual-studio-code - 在 VSCode Fortran 调试中检查从另一个模块导入的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68287991/

    相关文章:

    Fortran 错误 : Unit connected to formatted file

    algorithm - 如何旋转粒子系统(大小为 =num_particles*3 的二维矩阵),以便某些条目变为零

    c - Mac OS Sierra 上的 GDB,试图完全卸载和删除所有文件但不能

    c printf ("%x"),它会打印什么?

    javascript - VSCode Javascript - 获取准确的本地新 Date() 值

    c - Linux 原生 C 库 : How to configure Visual Studio Code to work with them on Windows?

    typescript - 调试并重新启动更改 typescript vscode

    javascript - 更漂亮 : prevent Prettier of removing parentheses

    c - C中初始化多维数组类似于Fortran

    gdb - 如何停止或阻止 GDB 搜索所有符号