Can GDB be used to print values of allocatable arrays of a derived type in Fortran 90? -


this question has answer here:

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:

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

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -