idb cannot print USEd mod variables

Problem :--

Debugger does not print the use-associated variables

module mod
integer :: i, j, k, l
contains
subroutine init
i = 1
j = 2
k = 3
l = 4
end subroutine init
end module mod
use mod
call init
print *, i, j
end

with ifort 11 or with gfortran 4.4 one cannot print the values of k and l in the main program.
For "ifort -g -O0 test2.f90":
$ idbc a.out
[...]
Breakpoint 1, main$test2_$BLK () at test2.f90:13
13 print *, i, j
(idb) p i
$1 = 1
(idb) p j
$2 = 2
(idb) p l
No symbol "l" in current context.
cannot evaluate l
(idb) p k
No symbol "k" in current context.
cannot evaluate k

Not only in Fortran one would expect that k and l are available (use associated) also the DWARF3 specification implies that DW_TAG_imported_module with DW_AT_import @DW_TAG_module is enough to get access to all module variables in "m".

With gfortran 4.4 compiled programs the result is even worse: As gfortran (contrary to ifort) does not emit DW_TAG_imported_declaration for used use-associated variables, not even printing "i" and "j" works:

Breakpoint 1, MAIN_ () at test2.f90:13
13 print *, i, j
(idb) p i
No symbol "i" in current context.
cannot evaluate i
(idb) p j
No symbol "j" in current context.
cannot evaluate j

Problem versions:--
10.1, 11.0

Environment:-- Linux Fortran Intel64

Workaround:--
1) Print the variables k , l in the program, then the debugger prints them.
The reason that it works is that ifort emits a DW_TAG_imported_declaration for "i" and "j" (but not for "k" and "l"). Using DW_TAG_imported_declaration is not needed, using a single DW_TAG_imported_module with DW_AT_import @DW_TAG_module should be enough.
2) IDB supports a command notation for accessing members of a module. For example, to print a module variable you should be able to do the following:

(idb) print `module`variable

3) The variables that are in USE, ONLY are in the DWARF sub-entries inside the subroutine which uses the module. So, instead of <USE mod> , use <USE mod, only: I,j,k,l >

Remarks:--
The debug info currently being emitted is appropriate given what is defined in the DWARF v2 spec. The DWARF v3 spec added a means to represent the "use" so it is now possible for the compiler to do better. This is along the same lines as the C++ namespace support also introduced with DWARF v3.

Resolution:-- The fix would be available in later versions, the exact one is indefinite now.


Einzelheiten zur Compiler-Optimierung finden Sie in unserem Optimierungshinweis.