我目前正在调试用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)
答案 0 :(得分:0)
对我来说,你的代码适用于gdb。用gfortran 4.5.5和gdb 7.2测试。它不应该是这种编程风格的任何固有限制。
[testy]$ gfortran -g -fbacktrace common2.f90
[testy]$ gdb ./a.out
GNU gdb (GDB) Red Hat Enterprise Linux (7.2-48.el6)
Copyright (C) 2010 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-redhat-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/x/f/testy/a.out...done.
(gdb) break common2.f90:73
Breakpoint 1 at 0x400a2d: file common2.f90, line 73.
(gdb) run
Starting program: /home/x/f/testy/a.out
enter nnn:
4
Breakpoint 1, input (id=...) at common2.f90:73
73 do i=1,5
(gdb) whatis id
type = integer(kind=4) (5,4)
(gdb) print id
$1 = (( 0, 0, 0, 0, 0) ( 0, 0, 0, 0, 0) ( 0, 0, 0, 0, 0) ( 0, 0, 0, 0, 0) )
(gdb) print nnn
$2 = 4
(gdb)