Can GDB be used to print values ​​of distributed arrays of derived type in Fortran 90?

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, for example:

 (gdb) p arrayOfDerivedTypes(1)%name 

I get insensitive values ​​(often strings of zeros, slashes, and letters) or completely incorrect values ​​(e.g. arrayOfDerivedTypes (1)% name = 9 when I know it = 2). How can I get gdb to print the correct values?

Background

I know:

I don’t want to have difficulty compiling a separate GDB branch to check if it solves this problem if someone already knows that it will not or if there is a better solution.

It’s hard for me to imagine that there is no solution yet. Does the fortran community have no better solution for a free debugger?

+6
source share
2 answers

What version of gdb and fortran compiler (gfortran?) Are you using? Since I have no problem 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 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 will compile it as

 gfortran -o test -g -O0 -Wall test.f90 

Then run 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 see everything.

There is also http://brulermavie.org/2012/02/how-to-debug-fortran-programs-using-gdb/ , which did not help me, since I do not see the problem.

+1
source

I know it might answer a little, but Sun studio (sdb) and intel fortran also come with a debugger

+1
source

Source: https://habr.com/ru/post/944556/


All Articles