2016-10-09 12 views
1

gdbでFortran型で定義された割り当て可能な配列をどのように出力しますか?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でそれを実行し、私は表示するにはalloc_array

(gdb) print fixed_array 
$1 = ((11, 21) (12, 22) (13, 23)) 
(gdb) print alloc_array 
$2 = ((0)) 

fixed_arrayのコンテンツを視聴するprint機能を使用することはできませんが、内容はalloc_arrayです。使用する必要があります

(gdb) print *((real_8 *)alloc_array)@6 
$3 = (11, 21, 12, 22, 13, 23) 

今度はbuzz%alloc_arrayの内容を見たいと思います。上記のコマンドのいずれもがここで働いていない:

(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) 

私はbuzz%alloc_arrayのコンテンツを視聴するにはどうすればよいですか?

+0

http://stackoverflow.com/questions/16447741/can-gdb-be-used-to-print-values-of-allocatable-arrays-of-a-derived-type-in​​-を見ますfortr?noredirect = 1&lq = 1 –

答えて

0

はちょうどあなたがあなたがexplore機能が必要だと思うのはなぜ通常の配列

(gdb) print alloc_array 
$1 = ((11, 21) (12, 22) (13, 23)) 
(gdb) print buzz%alloc_array 
$2 = ((11, 21) (12, 22) (13, 23)) 

と同じ操作を行いますか?

BTW 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} 
+0

これは動作しません。 'print alloc_array'は有用ではない値'((0)) 'を返します。 – Antonius

+0

あなたが使用しているgdbとコンパイラのバージョンと、コンパイルに使用しているフラグを教えてくれるのは間違いないようです。それは確かに**私のために働く**です。 –

+0

'GNU Fortran(Homebrew gcc 6.1.0)6.1.0'でフラグ' -g -O0'を使ってコンパイルしています。gdbのバージョンは 'GNU gdb(GDB)7.9.1'です。 – Antonius