bug-gdb
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

A problem with gdb when debugging fortran


From: Dr. H. Ramachandran
Subject: A problem with gdb when debugging fortran
Date: Thu, 2 Aug 2001 16:05:06 +0530

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi all,

I have encountered a problem with debugging arrays in fortran. The compiler 
seems to work correctly, but the debugger appears to have problems. The 
problem appears when the dimensions of the arrays are unequal, which suggests 
an address calculation error in gdb. In the attached program, if the array 
were declared A(1:N,1:N), gdb displays its elements correctly.

Besides being a bug report, this is also a request of how to work around this
problem. Can I write a macro in gdb using define to generate the correct slice
of a fortran array? If so, what is the formula to use to address a 2D or 3D 
array element?

Please answer me directly as I am not yet subscribed to the mailing list.

Thanks!

ps: Here is a piece of code that produces the error, and a transcript of the 
gdb session with the erroneous output:
====================== gdbarray.f ===============================
! program to use on gdb for testing array addressing.
      PROGRAM array
         IMPLICIT NONE
         INTEGER N
         PARAMETER (N=5)
         REAL A(1:N-1,1:N)      ! A matrix to be filled with data
         INTEGER i,j

         DO i=1,N
            DO j=1,N-1
               A(j,i)=i+j*j
            END DO
            WRITE(*,*)(A(j,i),j=1,N-1)
         END DO
      END
! Compiled with 'g77 -g gdbarray.f' to get an executable 'a.out'.
!
! When run under gdb (lines starting with '!**' are my 
! interpoliations):

!   Current directory is /home/hari/fort/bugs/
!   GNU gdb 5.0rh-5 Red Hat Linux 7.1
!   Copyright 2001 Free Software Foundation, Inc.
!   GDB is free software, covered by the GNU General Public License, and you 
are
!   welcome to change it and/or distribute copies of it under certain 
conditions.
!   Type "show copying" to see the conditions.
!   There is absolutely no warranty for GDB.  Type "show warranty" for 
details.
!   This GDB was configured as "i386-redhat-linux".../home/hari/.gdbinit:3: 
Error in sourced command file:
!   No symbol table is loaded.  Use the "file" command.
!   
!   (gdb) b MAIN__

!** Required by gdb when debugging Fortran code

!   Breakpoint 1 at 0x8048e96: file gdbarray.f, line 9.
!   (gdb) r
!   Starting program: /home/hari/fort/bugs/a.out 
!   
!   Breakpoint 1, MAIN__ () at gdbarray.f:9
!   Current language:  auto; currently fortran
!   (gdb) b 15
!   Breakpoint 2 at 0x8048eaf: file gdbarray.f, line 15.
!   (gdb) c
!   Continuing.
!     2.  5.  10.  17.
!     3.  6.  11.  18.
!     4.  7.  12.  19.
!     5.  8.  13.  20.
!     6.  9.  14.  21.
!   
!   Breakpoint 2, MAIN__ () at gdbarray.f:15

!** At this point the program has executed (correctly) and has reached
!** the end statement. Use gdb to explore the contents of the array 'a',
!** that has been printed out above.

!   (gdb) p a
!   $1 = (( 2, 5, 10, 17) ( 3, 6, 11, 18) ( 4, 7, 12, 19) ( 5, 8, 13, 20) ( 
6, 9, 14, 21) )

!** This output is correct, showing five columns of four elements each. 
!** Note: Fortran stores arrays columnwise! So above output was
!** the transpose of the matrix.

!   (gdb) p a(1,2)
!   $2 = 6

!** This output is wrong, as element a(1,2) should be 3. gdb has printed
!** element a(2,2) instead. More generally, gdb seems to print a(i+j-1,i) 
!** instead of a(j,i). Another example:

!   (gdb) p a(3,3)
!   $2 = 5

!** gdb has printed the value of a(1,4) instead of g(3,3). This is 
!** because it is trying to print a(3+3-1,3)=a(5,3). Since there are
!** only 4 elements to a column, this wraps around to a(1,4)

!   (gdb) 

! Note: Problem was present under redhat 7.0 distribution as well.
- -- 
Dr. Hari Ramachandran                           W-10, extn 235
Institute for Plasma Research           email: address@hidden
Bhat, Gandhinagar                tel: 91-79-3269001 to 3269015
India 382 428                               fax: 91-79-3269017
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE7aSzfmVraBokhpxURAi9vAJwLNS4E3lIPMuQWhnc+cjuiY0sWlACgj/gj
bVHfC83RTzENuOVJ//zXEV0=
=Yfr/
-----END PGP SIGNATURE-----




reply via email to

[Prev in Thread] Current Thread [Next in Thread]