在 VSCode Fortran 调试中检查从另一个模块导入的变量 [英] Inspect variable imported from another module in VSCode Fortran debugging
问题描述
我正在调试一些包含许多 Fortran 模块的代码,其中一些模块彼此共享变量.不幸的是,带有 VScode 的 gdb 在调试时似乎无法检查导入的变量.
I am debugging some code that contains many Fortran modules, some of which share variables between each other. Unfortunately, gdb with VScode seems to have trouble inspecting imported variables when debugging.
目前,当我需要检查导入的变量时,唯一的方法是停止调试,并手动更改代码以包含与导入变量相等的局部变量.在下面的示例中,要找出将 foo%bar
的值传递给函数 a_function
,我必须声明一个新变量,就像这样
Currently when I need to inspect an imported variable, the only way to do so is to stop debugging, and manually alter the code to include a local variable equal to the imported variable. In the example below, to find out what value of foo%bar
is passed to the function a_function
I would have to declare a new variable, like so
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 编译器标志
This is obviously very time consuming, and I don't know why VSCode should not be able to inspect global variables. Any ideas? The following are the gfortran compiler flags I currently have turned on in the makefile
-Og -g -Wall -Wextra -Wline-truncation -pedantic -fimplicit-none -fcheck=all -fbacktrace
推荐答案
此问题已部分处理:调试器中不可访问的 Fortran 模块变量.基本上,在 Visual Studio Code 的 WATCH 面板中,您可以添加表达式".并使用语法 module::variable
观察模块变量.
This issue has been partly treated in: Fortran module variables not accessible in debuggers.
Basically, in the WATCH panel from Visual Studio Code, you can "add expression" and watch for a module variable using the syntax module::variable
.
- 不太确定您是否可以轻松地观察具有这种语法的派生类型.
- 如果
variable
是一个(例如 2d)数组,您可以使用通常的 Fortran 索引(如module::variable(12,457)
)单独访问其元素 - 可以通过 VS Code 的调试控制台"中的 gdb 查询访问数组的多个元素.使用
-exec
前缀传递gdb指令,如:-exec p module::variable@100
显示module::variable<的前100个元素/code>.
- 手表"中可以显示多个元素面板通过指定起始索引如下:
module::variable(1,1)@100
.
- Not quite sure whether you can easily watch for derived types with such a syntax.
- if
variable
is an (e.g. 2d) array, you can access to its elements individualy with usual fortran indexing likemodule::variable(12,457)
- Multiple elements of an array can be accessed via gdb queries in VS Code's "debug console". Use
-exec
prefix to pass gdb instructions, such as:-exec p module::variable@100
to display the 100 first elements ofmodule::variable
. - Multiple elements can be displayed in the "watch" panel by specifying a starting index as follows:
module::variable(1,1)@100
.
有用的来源:https://numericalnoob.blogspot.com/2012/08/fortran-allocatable-arrays-and-pointers.html和 https://www.gnu.org/software/gdb/documentation/当然.
Useful sources: https://numericalnoob.blogspot.com/2012/08/fortran-allocatable-arrays-and-pointers.html and https://www.gnu.org/software/gdb/documentation/ of course.
这篇关于在 VSCode Fortran 调试中检查从另一个模块导入的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!