我正在调试一些包含许多 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)
-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/