Can GDB be used to print values of allocatable arrays of a derived type in Fortran 90? -
this question has answer here:
- fortran print allocatable array in gdb 3 answers
i have following data structure in fortran90 program:
type derivedtype character(100) :: name = ' ' integer :: type = 0 real(kind(1.0d0)) :: property = 0.0 end type derivedtype type (derivedtype), allocatable, dimension(:) :: arrayofderivedtypes
when try debug , print values in gdb like:
(gdb) p arrayofderivedtypes(1)%name
i non-sensical values (often strings of zeros, forward slashes , letters), or wrong values (like arrayofderivedtypes(1)%name = 9, when know = 2). how can gdb print correct values?
background
i aware of:
- this bug: http://sourceware.org/bugzilla/show_bug.cgi?id=9395
- this branch of gdb: http://sourceware.org/gdb/wiki/projectarcher
- and blog post on printing allocatable arrays: http://numericalnoob.blogspot.be/2012/08/fortran-allocatable-arrays-and-pointers.html
i don't want go through trouble of compiling separate branch of gdb test if solves problem if knows won't or if there better solution available.
i have hard time imagining there not solution yet. fortran community not have better solution free debugger yet?
which version of gdb , fortran compiler (gfortran?) using? have no problems with
- gdb - gnu gdb (gdb) red hat enterprise linux (7.2-56.el6)
- gfortran - gnu fortran (gcc) 4.4.6 20120305 (red hat 4.4.6-4)
here's test program:
program test implicit none type derivedtype character(100) :: name = ' ' integer :: type = 0 real(kind(1.0d0)) :: property = 0.0 end type derivedtype type (derivedtype), allocatable, dimension(:) :: arrayofderivedtypes allocate(arrayofderivedtypes(10)) write(6,*) arrayofderivedtypes(1)%type end program test
and compile as
gfortran -o test -g -o0 -wall test.f90
then start debugger, set breakpoint , run
$ gdb test (gdb) break test.f90:14 breakpoint 1 @ 0x402c8a: file test.f90, line 14. (gdb) r [thread debugging using libthread_db enabled] breakpoint 1, test () @ test.f90:14 14 write(6,*) arrayofderivedtypes(1)%type (gdb) p arrayofderivedtypes $3 = (( ' ' <repeats 100 times>, 0, 0 ), ( ' ' <repeats 100 times>, 0, 0 ), ( ' ' <repeats 100 times>, 0, 0 ), ( ' ' <repeats 100 times>, 0, 0 ), ( ' ' <repeats 100 times>, 0, 0 ), ( ' ' <repeats 100 times>, 0, 0 ), ( ' ' <repeats 100 times>, 0, 0 ), ( ' ' <repeats 100 times>, 0, 0 ), ( ' ' <repeats 100 times>, 0, 0 ), ( ' ' <repeats 100 times>, 0, 0 )) (gdb) p arrayofderivedtypes(1) $4 = ( ' ' <repeats 100 times>, 0, 0 ) (gdb) p arrayofderivedtypes(1)%property $5 = 0 (gdb) p arrayofderivedtypes(1)%name $6 = ' ' <repeats 100 times>
i can see everything.
there http://brulermavie.org/2012/02/how-to-debug-fortran-programs-using-gdb/ didn't me, don't see problem.
Comments
Post a Comment