How do you print an allocatable array defined in a Fortran type with gdb?
Suppose I have the following Fortran 90 code:
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
Running it with gdb, I can use the print
function to view the content of fixed_array
, but not alloc_array
(gdb) print fixed_array
$1 = (( 11, 21) ( 12, 22) ( 13, 23) )
(gdb) print alloc_array
$2 = (( 0) )
To view the content of alloc_array
I must use
(gdb) print *((real_8 *)alloc_array )@6
$3 = (11, 21, 12, 22, 13, 23)
Now I want to view the content of buzz%alloc_array
. None of the above commands work here:
(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.
From the gdb documentation, it seems like I should use the explore
function. But nothing gets printed when I try it:
(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)
What should I do to view the content of buzz%alloc_array
?