Debugging a Program With dbx

Fortran 90 Allocatable Arrays

The following example shows how to work with allocated arrays in dbx.


 Alloc.f90
  demo% f90 -g Alloc.f90
  demo% dbx a.out
  (dbx) list 1,99
      1   PROGRAM TestAllocate
      2   INTEGER n, status 
      3   INTEGER, ALLOCATABLE :: buffer(:)
      4           PRINT *, 'Size?'
      5           READ *, n
      6           ALLOCATE( buffer(n), STAT=status )
      7           IF ( status /= 0 ) STOP 'cannot allocate buffer'
      8           buffer(n) = n
      9           PRINT *, buffer(n)
     10           DEALLOCATE( buffer, STAT=status)
     11   END








Unknown size at line 6









Known size at line 9




buffer(1000) holds 1000
 (dbx) stop at 6
 (2) stop at "alloc.f90":6
 (dbx) stop at 9
 (3) stop at "alloc.f90":9
 (dbx) run
 Running: a.out 
 (process id 10749)
  Size?
 1000
 stopped in main at line 6 in file "alloc.f90"
     6           ALLOCATE( buffer(n), STAT=status )
 (dbx) whatis buffer
 integer*4 , allocatable::buffer(:) 
 (dbx) next
 continuing
 stopped in main at line 7 in file "alloc.f90"
     7           IF ( status /= 0 ) STOP 'cannot allocate buffer'
 (dbx) whatis buffer
 integer*4 buffer(1:1000) 
 (dbx) cont
 stopped in main at line 9 in file "alloc.f90"
     9           PRINT *, buffer(n)
 (dbx) print n
 n = 1000
 (dbx) print buffer(n)
 buffer(n) = 1000






    

Unknown size at line 6









Known size at line 9




buffer(1000) holds 1000
 (dbx) stop at 6
 (2) stop at "alloc.f90":6
 (dbx) stop at 9
 (3) stop at "alloc.f90":9
 (dbx) run
 Running: a.out 
 (process id 10749)
  Size?
 1000
 stopped in main at line 6 in file "alloc.f90"
     6           ALLOCATE( buffer(n), STAT=status )
 (dbx) whatis buffer
 integer*4 , allocatable::buffer(:) 
 (dbx) next
 continuing
 stopped in main at line 7 in file "alloc.f90"
     7           IF ( status /= 0 ) STOP 'cannot allocate buffer'
 (dbx) whatis buffer
 integer*4 buffer(1:1000) 
 (dbx) cont
 stopped in main at line 9 in file "alloc.f90"
     9           PRINT *, buffer(n)
 (dbx) print n     
 n = 1000
 (dbx) print buffer(n)
 buffer(n) = 1000