Fortran模块变量无法在调试器中访问 [英] Fortran module variables not accessible in debuggers

查看:157
本文介绍了Fortran模块变量无法在调试器中访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编译了一个Fortran代码,它包含几个模块,同时使用gfortran 4.4和intel 11.1,随后尝试使用gdb和DDT进行调试。在所有情况下,我都看不到在模块中声明的任何变量的值。这些全局变量具有值,因为代码仍然正常运行,但我看不到在调试器中的值。局部变量很好。我很难在其他地方找到解决方案,所以也许没有简单的解决方案,但如果我看不到任何全局变量的值,那么调试我的代码将会非常困难。对于更新的GDB(7.2,如果我正确记得),调试模块很简单。以下程序:

  module modname 
integer :: var1 = 1,var2 = 2
end模块modname

使用modname,仅:newvar => var2
newvar = 7
end

您现在可以运行:

  $ gfortran -g -o mytest test.f90; gdb --quiet ./mytest 
从/dev/shm/mytest...done读取符号。
(gdb)b 6
0x4006a0的断点1:file test.f90,第6行。
(gdb)run
启动程序:/ dev / shm / mytest
断点1,MAIN__()在test.f90:6
6 newvar = 7
(gdb)p newvar
$ 1 = 2
(gdb)p var1
在当前上下文中没有符号var1。
(gdb)p modname :: var1
$ 2 = 1
(gdb)p modname :: var2
$ 3 = 2
(gdb)n
7结束
(gdb)p modname :: var2
$ 4 = 7
(gdb)


I've compiled a Fortran code, which contains several modules, using both gfortran 4.4 and intel 11.1 and subsequently tried to debug it using both gdb and DDT. In all cases, I cannot see the values of any variables that are declared in modules. These global variables have values, as the code still runs correctly, but I can't see what the values are in my debuggers. Local variables are fine. I've had trouble finding a solution to this problem elsewhere online, so perhaps there is no straightforward solution, but it's going to be really difficult to debug my code if I can't see the values of any of my global variables.

解决方案

With newer GDBs (7.2 if I recall correctly), debugging modules is simple. Take the following program:

module modname
  integer :: var1 = 1 , var2 = 2
end module modname

use modname, only: newvar => var2
newvar = 7
end

You can now run:

$ gfortran -g -o mytest test.f90; gdb --quiet ./mytest
Reading symbols from /dev/shm/mytest...done.
(gdb) b 6
Breakpoint 1 at 0x4006a0: file test.f90, line 6.
(gdb) run
Starting program: /dev/shm/mytest
Breakpoint 1, MAIN__ () at test.f90:6
6       newvar = 7
(gdb) p newvar
$1 = 2
(gdb) p var1
No symbol "var1" in current context.
(gdb) p modname::var1
$2 = 1
(gdb) p modname::var2
$3 = 2
(gdb) n
7       end
(gdb) p modname::var2
$4 = 7
(gdb)

这篇关于Fortran模块变量无法在调试器中访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆