I have the following data structure in a 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 I try to debug and print values in GDB like:
(gdb) p arrayOfDerivedTypes(1)%name
I get non-sensical values (often strings of zeros, forward slashes and letters), or completely wrong values (like arrayOfDerivedTypes(1)%name = 9, when I know that it is = 2). How can I get GDB to print the correct values?
I am aware of:
I don't want to go through the trouble of compiling a separate branch of GDB to test if it solves this problem if someone already knows that it won't or if there is a better solution available.
I have a hard time imagining that there is not a solution to this yet. Does the fortran community not have a better solution for a free debugger yet?
Which version of gdb and fortran compiler (gfortran?) are you using? As I have no problems with
Here's the 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 I compile it as
gfortran -o test -g -O0 -Wall test.f90
Then start up the debugger, set a breakpoint and run
$ gdb test
(gdb) break test.f90:14
Breakpoint 1 at 0x402c8a: file test.f90, line 14.
(gdb) r
[Thread debugging using libthread_db enabled]
Breakpoint 1, test () at 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 is also http://brulermavie.org/2012/02/how-to-debug-fortran-programs-using-gdb/ which didn't help me, as I don't see the problem.
I know may answer is a little off but Sun studio (sdb) and intel fortran also come with a debugger
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With