【发布时间】:2011-12-13 17:26:59
【问题描述】:
我目前正在调试一个用 fortran 编写并用 gfortran 编译的代码。
我在使用 gdb 打印一些变量时遇到了问题。
例如,当我在一个子程序内部并且我想打印一个来自“外部”的变量并且其大小取决于在另一个子程序中计算的参数时,看起来 gdb 无法识别大小矩阵,无法打印。
我在下面给出一个简化的例子,以便清楚:
subroutine stiff(id)
implicit real*8 (a-h,o-z)
common /a/nnp
dimension id(5,nnp)
这是gdb给出的一些结果
(gdb) print id
$6 = ()
(gdb) whatis id
type = integer(kind=4) (5,0)
(gdb) print nnp
$7 = 15
有没有办法解决这个问题,还是编程方式固有的?这段代码是别人开发的,而且很大,所以我可以改变所有声明变量的方式。
提前感谢您的帮助。
编辑:
看下面一个简单的程序(我能做到的最简单的)。它与我正在处理的代码具有全局相同的结构,并且与我之前描述的 gdb 具有相同的行为。当进入输入子程序时,我无法打印“id”变量。
implicit real*8 (a-h,o-z)
dimension a(1000)
call markaz(a)
stop
end
subroutine markaz(a)
implicit real*8 (a-h,o-z)
dimension a(1000)
common /a/nnn
call dim1(l1,l2)
call input(a(l1))
return
end
subroutine dim1(l1,l2)
implicit real*8 (a-h,o-z)
common /a/nnn
print*, 'enter nnn: ';read(*,*) nnn
l1=1
l2=l1+(nnn*5+1)/2
return
end
subroutine input(id)
implicit real*8 (a-h,o-z)
common /a/nnn
dimension id(5,nnn)
do i=1,5
do j=1,nnn
id(i,j)=1.0
enddo
enddo
return
end
这是我使用 gfortran 4.4.5 和 gdb 7.0.1 得到的结果
$ gfortran -g -fbacktrace test.for
$ gdb ./a.out
GNU gdb (GDB) 7.0.1-debian
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /test_print/a.out...done.
(gdb) break test.for :36
Breakpoint 1 at 0x400a7d: file test.for, line 36.
(gdb) run
Starting program: /test_print/a.out
enter nnn:
2
Breakpoint 1, input (id=...) at test.for:37
37 do i=1,5
Current language: auto
The current source language is "auto; currently fortran".
(gdb) whatis id
type = integer(kind=4) (5,0)
(gdb) print id
$1 = ()
(gdb) print nnn
$2 = 2
(gdb)
【问题讨论】:
-
我试过了,我的 gdb 打印了正确的答案。你能补充更多细节吗?也许一些最小的测试程序?