Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Value of f90 module variables not visible from either gdb or idb

454 views
Skip to first unread message

LokiDawg

unread,
Jan 2, 2009, 10:19:34 AM1/2/09
to
I've seen references to this problem in previous posts, but no generic
solution. How does one make variables declared as public within a
module visible within a debugger? I've tested the simple code below
both with gfortran (using gdb as debugger) and ifort (using idb as
debugger). The code runs fine in either; however, I can't see the
value of the public module variable using gdb; idb can't report the
value either (even if I provide the scope operator ::), although idb's
whatis does report the variable's type correctly. Any insight as to
how to access module variables within a debugger would be welcome,
thanks.

The test code is very simple:

MODULE mymod

IMPLICIT NONE
INTEGER, PARAMETER, PRIVATE :: double = SELECTED_REAL_KIND (8)
REAL (KIND = double), PUBLIC :: xpublic

END MODULE mymod

PROGRAM moduleTest

USE mymod
IMPLICIT NONE
INTEGER, PARAMETER :: double = SELECTED_REAL_KIND (8)
REAL (KIND = double) :: xlocal
xlocal = -1.d0
xpublic = -5.d0
PRINT *, 'xpublic = ', xpublic
PRINT *, 'xlocal = ', xlocal
CONTINUE
END PROGRAM moduleTest

Here's a log of the gdb session:
$ gfortran -Werror -Wall -g testmod.f90 -o testgdb
$ gdb ./testgdb
GNU gdb 6.7.1
Copyright (C) 2007 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/
gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show
copying"
and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu"...
Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) break 19
Breakpoint 1 at 0x400939: file testmod.f90, line 19.
(gdb) run
Starting program: testgdb
xpublic = -5.0000000000000000
xlocal = -1.0000000000000000

Breakpoint 1, moduletest () at testmod.f90:19
19 CONTINUE
Current language: auto; currently fortran
(gdb) print xlocal
$1 = -1
(gdb) print xpublic
No symbol "xpublic" in current context.
(gdb) cont
Continuing.

Program exited normally.
(gdb) quit
$

Here is the idb session:
$ ifort -W1 -g testmod.f90 -o testidb
$ idb ./testidb
Intel(R) Debugger for applications running on Intel(R) 64, Version
10.1-35 , Build 20080310
------------------
object file name: ./testidb
Reading symbols from testidb...done.
(idb) break 19
Breakpoint 1 at 0x402d14: file testmod.f90, line 19.
(idb) run
Starting program: ./testidb
xpublic = -5.00000000000000
xlocal = -1.00000000000000

Breakpoint 1, moduletest () at testmod.f90:19
19 CONTINUE
(idb) print xlocal
$1 = -1
(idb) print xpublic
$2 = <no value>
(idb) print mymod::xpublic
$3 = <no value>
(idb) whatis mymod::xpublic
type = REAL(8)
(idb) whatis xpublic
type = REAL(8)
(idb) whatis xlocal
type = REAL(8)
(idb) cont
Continuing.
Program exited normally.
(idb) quit
$

David Duffy

unread,
Jan 2, 2009, 5:19:40 PM1/2/09
to
LokiDawg <rsa...@gmail.com> wrote:
> I've seen references to this problem in previous posts, but no generic
> solution. How does one make variables declared as public within a
> module visible within a debugger?

They are mangled eg mymod_MP_xpublic

Cheers, David Duffy.
--
| David Duffy (MBBS PhD) ,-_|\
| email: dav...@qimr.edu.au ph: INT+61+7+3362-0217 fax: -0101 / *
| Epidemiology Unit, Queensland Institute of Medical Research \_,-._/
| 300 Herston Rd, Brisbane, Queensland 4029, Australia GPG 4D0B994A v

rusi_pathan

unread,
Jan 2, 2009, 6:00:51 PM1/2/09
to
On Jan 2, 5:19 pm, David Duffy <dav...@orpheus.qimr.edu.au> wrote:

And you can use "nm ./a.out | grep xpublic" to see the name and then
use that (p __mymod__xpublic) in the debugger.

LokiDawg

unread,
Jan 2, 2009, 6:28:05 PM1/2/09
to
David and rusi, thanks both for your replies.

$ nm ./testgdb | grep xpublic
0000000000601060 B __mymod_MOD_xpublic
$ gdb testgdb


GNU gdb 6.7.1
Copyright (C) 2007 Free Software Foundation, Inc.

< ... snip ... >
(gdb) break 19
Breakpoint 1 at 0x4008fa: file testmod.f90, line 19.
(gdb) r
Starting program: /tmp/testgdb
xpublic = -5.0000000000000000
xlocal = -1.00000000000000000

Breakpoint 1, moduletest () at testmod.f90:19
19 CONTINUE
Current language: auto; currently fortran

(gdb) p __mymod_MOD_xpublic
$1 = 0
(gdb)

gdb now finds the symbol correctly, but seems to fail to give the
right value, or do I need to furnish more than just
p __mymod_MOD_xpublic ? Thanks again for your help.

David Duffy

unread,
Jan 3, 2009, 6:44:46 PM1/3/09
to
LokiDawg <rsa...@gmail.com> wrote:

> $ nm ./testgdb | grep xpublic
> 0000000000601060 B __mymod_MOD_xpublic

...


> (gdb) p __mymod_MOD_xpublic
> $1 = 0
> (gdb)

> gdb now finds the symbol correctly, but seems to fail to give the
> right value, or do I need to furnish more than just
> p __mymod_MOD_xpublic ? Thanks again for your help.

I used g95, where it is accessible. If you use compile with "-S",
g95 generates (on linux, i686)

mymod_MP_xpublic:
.zero 8
.ident "GCC: (GNU) 4.0.3 (g95 0.91!) Nov 29 2007"
.section .note.GNU-stack,"",@progbits

while gfortran has

__mymod_MOD_xpublic:
.zero 8
.section .rodata
.align 4
.type options.0.556, @object
.size options.0.556, 28

I'm afraid I'm not clever enough to work out where to point gdb in the
gfortran case. I'm sure almost exactly this comparison of how the older
gcc underlying g95 and gcc 4.4 onwards do things has come up before.

Cheers, David Duffy.

LokiDawg

unread,
Jan 3, 2009, 8:27:02 PM1/3/09
to
On Jan 3, 5:44 pm, David Duffy <dav...@orpheus.qimr.edu.au> wrote:

David,
Thanks much for your insight and help -- I will look into g95 and post
back. Cheers, Rolf

Tobias Burnus

unread,
Jan 5, 2009, 7:29:00 AM1/5/09
to
Hi,

LokiDawg wrote:
> I've seen references to this problem in previous posts, but no generic
> solution. How does one make variables declared as public within a
> module visible within a debugger?

I think one needs a compiler and a debugger which properly support
DWARF3 (http://en.wikipedia.org/wiki/DWARF). (I don't know whether it
works with other debugging formats such as stab, but I doubt it.)


> I've tested the simple code below
> both with gfortran (using gdb as debugger) and ifort (using idb as
> debugger). The code runs fine in either; however, I can't see the
> value of the public module variable using gdb; idb can't report the
> value either (even if I provide the scope operator ::), although idb's
> whatis does report the variable's type correctly. Any insight as to
> how to access module variables within a debugger would be welcome,
> thanks.

gfortran/GCC only recently (August 2008 in 4.4.0) added support for
DW_TAG_module/DW_TAG_imported_{declaration,module}, which is needed for
this. Unfortunately, GNU's gdb does not yet seem to handle this and
Intel idb's implementation is incomplete and not bugfree. (Note: The
combinations ifort + gdb and gfortran + idb work as well - at least
under Linux.)


> The test code is very simple:
> MODULE mymod
> IMPLICIT NONE
> INTEGER, PARAMETER, PRIVATE :: double = SELECTED_REAL_KIND (8)
> REAL (KIND = double), PUBLIC :: xpublic
> END MODULE mymod
>
> PROGRAM moduleTest
> USE mymod

Using gfortran with idb the result that "ptype xpublic" works can be
obtained using "use mymod, only: xpublic". Using the latter gfortran
emits DW_TAG_imported_declaration. (Note: ifort also emits it if no ONLY
is used. The DW_TAG_imported_declaration is not needed [without ONLY]
according to the DWARF3 standard but seemingly idb needs it.)

I don't see ad hoc why one can access the type of xpublic but not print
its value and why printing the type of the mangled symbol works but not
printing the value. I think the reason that it works with g95 is that it
does not yet use the fancy DWARF3 stuff, which ifort and gfortran are using.

Tobias

PS: One can use readelf --debug-dump=info to see the stored debugging
information. (To check the compiler; it unfortunately won't help
debugging the actual program.)

PPS: The DWARF3 support in GDB is improving. Jan Kratochvil of Red Hat
has some patches for supporting Fortran 90 arrays (allocatable, assumed
shape...), which will be merged hopefully in a not to far future. See
http://people.redhat.com/jkratoch/vla/MOVED and the last preparational
merge at http://sourceware.org/ml/gdb-patches/2008-12/msg00421.html

LokiDawg

unread,
Jan 5, 2009, 4:33:55 PM1/5/09
to

Tobias, thanks very much for your informative post -- that was a big
help. I did retry this using Kratochvil's patches from the links you
supplied to rebuild gdb (6.8.50.20081228-cvs; previous examples used
6.7.1), as well as adding the ONLY: qualifier, and recompiling using
gcc/gfortran 4.4.0. Same result, i.e.,
(gdb) b 19
Breakpoint 1 at 0x400915: file testmod.f90, line 19.
(gdb) r
Starting program: /home/rolf/test/test


xpublic = -5.0000000000000000
xlocal = -1.0000000000000000

Breakpoint 1, moduletest () at testmod.f90:19
19 CONTINUE
Current language: auto; currently fortran

(gdb) p __mymod_MOD_xpublic
$1 = 0
(gdb)

But I will watch for changes in gcc/gdb in terms of evolving DWARF3
support. Thanks again for your help!

0 new messages