Silverfrost Forums

Welcome to our forums

Debugger displays garbage for local array

10 Dec 2008 11:24 #4091

Hello,

the following code compiles fine, but the debugger displays garbage for the array 'ar':

module fdmod integer :: maxar end module

program fdebug use fdmod maxar = 10 call subtest maxar = 20 call subtest end program

subroutine subtest use fdmod integer, dimension(maxar) :: ar ar(1:maxar) = 0 ar(2) = 5 write(,) ar(1),ar(2),lbound(ar),ubound(ar) end subroutine

I'm well aware that it is not hard to work around this problem, like passing the dimensionality to the subroutine. But it occurred in a more complex scenario in some very old sources. Also I'm not fully sure if it is legal fortran code as the array dimensions are variable bound. The code runs correctly as far as I can tell, the array resides on the stack (locally allocated) so it's not 'somewhere' in memory by accident.

The source compiles with e.g.

ftn95 /full_debug /restrict_syntax /iso fdebug.f90 /link

(ftn95 v5.21 reg) and also the intel compiler (v10) and gfortran have been checked, they compile without any complaint even when enabling all warnings.

Thanks.

10 Dec 2008 1:54 #4092

This appears to be a problem with the debugger (SDBG) This simplest work-around could be

module fdmod 
integer :: maxar 
end module 

program fdebug 
use fdmod 
maxar = 10 
call subtest 
maxar = 20 
call subtest 
end program 

subroutine subtest 
use fdmod 
integer,allocatable :: ar(:)
allocate(ar(maxar))
ar = 0 
ar(2) = 5 
write(*,*) ar(1),ar(2),lbound(ar),ubound(ar) 
end subroutine
10 Dec 2008 11:29 #4093

Paul,

I tried the original version of SUBTEST, using Sebastian's compilation options and neither of the following statements were implemented as I stepped (F7) in SDBG.

ar(1:maxar) = 0 ar(2) = 5

How extensive is this problem ?

11 Dec 2008 8:05 #4094

and neither of the following statements were implemented as I stepped (F7) in SDBG.

As noted above they ARE implemented, and judging the disassembly the generated code is correct. Only the debugger fails to display the content of the array correctly.

Please login to reply.