Arrays 如何在GDB中探索Fortran数组结构组件?

Arrays 如何在GDB中探索Fortran数组结构组件?,arrays,types,fortran,gdb,Arrays,Types,Fortran,Gdb,如何使用gdb打印Fortran类型中定义的可分配数组 假设我有以下Fortran 90代码: program test implicit none type :: t_buzzer real(8), allocatable :: alloc_array(:,:) end type integer, parameter :: nx=2, ny=3 integer :: ii, jj real(8) :: fixed_array(nx,ny) real(8), allocatable :

如何使用gdb打印Fortran类型中定义的可分配数组

假设我有以下Fortran 90代码:

program test

implicit none

type :: t_buzzer
  real(8), allocatable :: alloc_array(:,:)
end type

integer, parameter :: nx=2, ny=3
integer :: ii, jj
real(8) :: fixed_array(nx,ny)
real(8), allocatable :: alloc_array(:,:)
type(t_buzzer) :: buzz

allocate(alloc_array(nx,ny))
allocate(buzz%alloc_array(nx,ny))

do jj=1,ny
  do ii=1,nx
    fixed_array(ii,jj) = 10.0 * real(ii) + real(jj)
  end do
end do

alloc_array = fixed_array
buzz%alloc_array = alloc_array

write(*,*) fixed_array
write(*,*) alloc_array
write(*,*) buzz%alloc_array

deallocate(alloc_array)
deallocate(buzz%alloc_array)

end program test
使用gdb运行它,我可以使用
print
功能查看
fixed\u array
的内容,但不能使用
alloc\u array

(gdb) print fixed_array 
$1 = (( 11, 21) ( 12, 22) ( 13, 23) )
(gdb) print alloc_array
$2 = (( 0) )
要查看
alloc\u数组的内容,我必须使用

(gdb) print *((real_8 *)alloc_array )@6
$3 = (11, 21, 12, 22, 13, 23)
现在我想查看buzz%alloc\u数组的内容。以上命令在此处均无效:

(gdb) print buzz%alloc_array
$4 = (( 0) )
(gdb) print *((real_8 *)buzz%alloc_array )@6
Attempt to extract a component of a value that is not a structure.
从gdb文档来看,似乎我应该使用
explore
函数。但当我尝试时,什么都不会打印出来:

(gdb) explore buzz
The value of 'buzz' is a struct/class of type 'Type t_buzzer
real(kind=8) :: alloc_array(*,*)
End Type t_buzzer' with the following fields:

  alloc_array = <Enter 0 to explore this field of type 'real(kind=8) (*,*)'>

Enter the field number of choice: 0
'buzz.alloc_array' is an array of 'real(kind=8) (*)'.
Enter the index of the element you want to explore in 'buzz.alloc_array': 1,1

Returning to parent value...

The value of 'buzz' is a struct/class of type 'Type t_buzzer
real(kind=8) :: alloc_array(*,*)
End Type t_buzzer' with the following fields:

  alloc_array = <Enter 0 to explore this field of type 'real(kind=8) (*,*)'>

Enter the field number of choice: 
(gdb) 
(gdb)探索buzz
“buzz”的值是“type t_蜂鸣器”类型的结构/类
实数(种类=8)::alloc_数组(*,*)
带有以下字段的终端类型t_蜂鸣器:
alloc_数组=
输入选择的字段编号:0
“buzz.alloc_数组”是一个“real(kind=8)(*)”数组。
在“buzz.alloc_数组”中输入要探索的元素的索引:1,1
正在返回父值。。。
“buzz”的值是“type t_蜂鸣器”类型的结构/类
实数(种类=8)::alloc_数组(*,*)
带有以下字段的终端类型t_蜂鸣器:
alloc_数组=
输入所选字段编号:
(gdb)

我应该如何查看buzz%alloc\u数组的内容?

只需执行与普通数组相同的操作即可

(gdb) print alloc_array
$1 = (( 11, 21) ( 12, 22) ( 13, 23) )
(gdb) print buzz%alloc_array
$2 = (( 11, 21) ( 12, 22) ( 13, 23) )
为什么您认为您需要
explore
功能

顺便说一句,real(8)
很难看而且不可移植(它并不总是意味着8字节)


作为一种解决方法,您可以尝试这个,但我没有办法在您的GDB版本中测试它。也许这只适用于弓箭手补丁

(gdb) set lang c
Warning: the current language does not match this frame.
(gdb) print buzz.alloc_array[1]
$10 = {11, 21}
(gdb) print buzz.alloc_array[2]
$11 = {12, 22}
(gdb) print buzz.alloc_array[3]
$12 = {13, 23}

只需执行与普通数组相同的操作

(gdb) print alloc_array
$1 = (( 11, 21) ( 12, 22) ( 13, 23) )
(gdb) print buzz%alloc_array
$2 = (( 11, 21) ( 12, 22) ( 13, 23) )
为什么您认为您需要
explore
功能

顺便说一句,real(8)很难看而且不可移植(它并不总是意味着8字节)


作为一种解决方法,您可以尝试这个,但我没有办法在您的GDB版本中测试它。也许这只适用于弓箭手补丁

(gdb) set lang c
Warning: the current language does not match this frame.
(gdb) print buzz.alloc_array[1]
$10 = {11, 21}
(gdb) print buzz.alloc_array[2]
$11 = {12, 22}
(gdb) print buzz.alloc_array[3]
$12 = {13, 23}

这是行不通的。执行
print alloc_array
操作将返回一个没有用的值
((0))
。看起来这是您告诉我们gdb版本和正在使用的编译器以及用于编译的标志的时候了。它当然对我有用。我正在使用
GNU Fortran(自制gcc 6.1.0)6.1.0
编译,使用标志
-g-O0
,gdb版本是
GNU gdb(gdb)7.9.1
。您的操作系统是Os X El Capitan 10.11.6。我应该明白我看到的不是正常的gdb行为吗?那是行不通的。执行
print alloc_array
操作将返回一个没有用的值
((0))
。看起来这是您告诉我们gdb版本和正在使用的编译器以及用于编译的标志的时候了。它当然对我有用。我正在使用
GNU Fortran(自制gcc 6.1.0)6.1.0
编译,使用标志
-g-O0
,gdb版本是
GNU gdb(gdb)7.9.1
。您的操作系统是Os X El Capitan 10.11.6。我应该明白我看到的不是正常的gdb行为吗