[PATCH,fortran]: Emit COMMON identifiers in proper debug scope

FX Coudert fxcoudert@gmail.com
Sun Oct 28 14:23:00 GMT 2007


Hi George,

First, thanks for contributing! The current state of the debug info  
emitted by gfortran is far from very good (not to mention work  
required on gdb to make it understand Fortran better), so we're  
always happy to fix this.

> This patch fixes scope bug arising with Fortran symbols defined in  
> COMMON.  They get emitted in the wrong debug scope unless they are  
> put on the symbol list associated with each function.  Bug shows up  
> with stabs-type debug information and fixes that; other debug forms  
> possibly also a problem.  Patch follows:

Unfortunately, I don't think we can apply this patch as such. For the  
following simple code:

$ cat x.f90
program test
   integer ii, jj
   common /foo/ ii,jj

   ii = 42
   jj = ii / 2
   print *, ii, jj
   call sub
end program test

subroutine sub
   integer aa, bb
   common /foo/ aa,bb
   print *, aa, bb
end subroutine sub

the current situation with DWARF is fairly satisfying (I set  
breakpoints on each of the "print" lines):

> Breakpoint 1, MAIN__ () at x.f90:7
> 7         print *, ii, jj
> Current language:  auto; currently fortran
> (gdb) p ii
> $1 = 42
> (gdb) p jj
> $2 = 21
> (gdb) c
> Continuing.
>           42          21
>
> Breakpoint 2, sub_ () at x.f90:14
> 14        print *, aa, bb
> (gdb) p aa
> $3 = 42
> (gdb) p bb
> $4 = 21
> (gdb) c
> Continuing.
>           42          21

while for stabs+, it's not working at all:

> Breakpoint 1, MAIN__ () at x.f90:7
> 7         print *, ii, jj
> (gdb) p ii
> Address of symbol "ii" is unknown.
> (gdb) p jj
> No symbol "jj" in current context.
> (gdb) p aa
> $1 = 0
> (gdb) p bb
> $2 = 1431662116
> (gdb) c
> Continuing.
>           42          21
>
> Breakpoint 2, sub_ () at x.f90:14
> 14        print *, aa, bb
> (gdb) p aa
> $5 = 0
> (gdb) p bb
> $6 = 1431662116
> (gdb) p ii
> Address of symbol "ii" is unknown.
> (gdb) p jj
> No symbol "jj" in current context.
> (gdb) c
> Continuing.
>           42          21

With your patch added, it partly fixes stabs+ (partly only: see how  
neither i nor a are displayed ok):

> Breakpoint 1, MAIN__ () at x.f90:7
> 7         print *, ii, jj
> (gdb) p ii
> Address of symbol "ii" is unknown.
> (gdb) p jj
> $1 = 21
> (gdb) p aa
> $2 = 0
> (gdb) p bb
> $3 = 1431662116
> (gdb) c
> Continuing.
>           42          21
>
> Breakpoint 2, sub_ () at x.f90:14
> 14        print *, aa, bb
> (gdb) p ii
> Address of symbol "ii" is unknown.
> (gdb) p jj
> No symbol "jj" in current context.
> (gdb) p aa
> $4 = 0
> (gdb) p bb
> $5 = 21
> (gdb) c
> Continuing.
>           42          21

But it breaks DWARF:

> Breakpoint 1, MAIN__ () at x.f90:7
> 7         print *, ii, jj
> Current language:  auto; currently fortran
> (gdb) p ii
> No symbol "ii" in current context.
> (gdb) p jj
> No symbol "jj" in current context.
> (gdb) p aa
> $1 = 0
> (gdb) p bb
> $2 = 1431662116
> (gdb) c
> Continuing.
>           42          21
>
> Breakpoint 2, sub_ () at x.f90:14
> 14        print *, aa, bb
> (gdb) p aa
> $3 = 0
> (gdb) p bb
> $4 = 1431662116
> (gdb) p ii
> No symbol "ii" in current context.
> (gdb) p jj
> No symbol "jj" in current context.
> (gdb) c
> Continuing.
>           42          21

So, while I agree that the current behaviour is not good for stabs  
and not perfect for dwarf (because the scope of common variables is  
too large, ie we can access aa and bb in the main program, where they  
don't belong), I think it's more complicated than that. I'm fairly  
new to this debug info issues (I started understanding dwarf, and  
haven't yet done anything on stabs), so I'm not sure what is  
happening there, but maybe you have an idea?

Regards,
FX



More information about the Fortran mailing list