Fortran module variables not accessible in debuggers
I've compiled a Fortran code, which contains several modules, using both gfortran 4.4 and intel 11.1 and subsequently tried to debug it using both gdb and DDT. In all cases, I cannot see the values of any variables that are declared in modules. These global variables have values, as the code still runs correctly, but I can't see what the values are in my debuggers. Local variables are fine. I've had trouble finding a solution to this problem elsewhere online, so perhaps there is no straightforward solution, but it's going to be really difficult to debug my code if I can't see the values of any of my global variables.
With newer GDBs (7.2 if I recall correctly), debugging modules is simple. Take the following program:
module modname integer :: var1 = 1 , var2 = 2 end module modname use modname, only: newvar => var2 newvar = 7 end
You can now run:
$ gfortran -g -o mytest test.f90; gdb --quiet ./mytest Reading symbols from /dev/shm/mytest...done. (gdb) b 6 Breakpoint 1 at 0x4006a0: file test.f90, line 6. (gdb) run Starting program: /dev/shm/mytest Breakpoint 1, MAIN__ () at test.f90:6 6 newvar = 7 (gdb) p newvar $1 = 2 (gdb) p var1 No symbol "var1" in current context. (gdb) p modname::var1 $2 = 1 (gdb) p modname::var2 $3 = 2 (gdb) n 7 end (gdb) p modname::var2 $4 = 7 (gdb)
Acces to Fortran module variables while debugging, with Intet Fortran 2013, I no longer have acces to all my modules variables in If I execute it in debug mode, let's say with a break point at the "write" line, I can Hence the module variable Y is not accessible from the main our Fortran symbol info expert had a closer look at this issue for me: The situation is that our compiler emits symbol information only for those module variables that are referenced in the source code. Hence the module variable Y is not accessible from the main program TestMod because it is not referenced there.
In gdb, try referencing the global variables with names like __modulename__variablename
You can check that this is the right mangling scheme using nm and grep to find one of your global variables in the symbols of your program.
If that doesn't work, make sure you're using a recent version of gdb.
Here's a thread on this issue: http://gcc.gnu.org/ml/fortran/2005-04/msg00064.html
Value of f90 module variables not visible from either gdb or idb , both with gfortran (using gdb as debugger) and ifort (using idb as how to access module variables within a debugger would be welcome, Tips for Debugging Run-time Failures in Applications Built with the Intel® Fortran Compiler. Your app builds successfully, but crashes at runtime. What Next? Try some useful Intel compiler diagnostic options before launching into lengthy debugger sessions. 1) Build with /traceback (Windows*) or –traceback (Linux* or MacOS*).
I had the same issue (GNU gdb 7.9 running in parallel with MPI). What worked for me was the following:
That is: double underscore, the name of the module, underscore, mod, the name of the variable.
Compiling with -gstabs+ instead of -g may also fix some issues (but not the present one).
1.63. gdb Red Hat Enterprise Linux 5, The GNU Project debugger (normally referred to as GDB) debugs programs written Variables imported from Fortran modules can be now accessed from GDB As a result, GDB could not access Thread Local Storage (TLS) variables from a ModuleNotFoundError: No module named 'werkzeug.wrappers.json'; 'werkzeug.wrappers' is not a package. whenever I issue the command. from flask import Flask while developing and debugging. This even happens in the Flask __init__.py script if I run it in either the Spyder or VSCode debuggers.
Compaq Fortran, You can use these debuggers to debug Compaq Fortran programs: -ladebug, Yes, Allows access to Fortran 95/90 dynamic arrays using standard Fortran 95/90 Because the watchpoint ( watch variable k command) does not occur, the value a variable named J defined in a module named modfile (statement MODULE That's a huge time sink. I would like to call the module procedure (construct the data structure) once and set this data structure as a global variable accessible to the main program and all subroutines. I do not want to pass this data structure as an argument to every subroutine, as I have many nested procedures. – jkedmond May 27 '17 at 16:53
428761, The variable 'm' declared inside the module 'dummy' acts as a alpha Current language: auto; currently fortran (gdb) p m No symbol "m" in current context. As you can see, we can access the variable 'm' inside the program. Accessibility of Variables and Subroutines in a Module. By default, all the variables and subroutines in a module is made available to the program that is using the module code, by the use statement. However, you can control the accessibility of module code using the private and public attributes. When you declare some variable or subroutine as private, it is not available outside the module.
dbx90: Fortran debugger, dbx90 — a Fortran-oriented debugger for use with the NAG Fortran compiler. If the environment variable DBX90_DBXPATH is defined, dbx90 will use it to This is only used for finding the module information (.mod) files for intrinsic modules. if expr, This is actually a suffix to the breakpoint ('stop') commands not an Can define global variables in modules to be used in several different routines. In Fortran 77 this had to be done with common blocks — much less elegant. Subroutine/function interface information is generated to aid in checking that proper arguments are passed. It’s often best to put all subroutines and functions in modules for this reason.
- Are you compiling with flags -O0 and -g?
- I've seen this, and what I did was to enclose the variables in a user type, and keep one global (saved) record. Then you access in the debugger with % (example OT%POINT_COUNT when OT contains my gobals)
- To Nick Atoms, compiling with -O0 did the trick, but for non-array elements only. I read that optimization can cause global variables to not be accessible, but I thought that if no optimization flags were used, then the compiler did no optimization by default. Apparently, I was wrong. However, I still cannot access any information in my global arrays. Again, they're being read in and assigned values correctly, but I can't print the whole array or any individual elements in the array in the debugger.
- I asked a similar question and later was able to answer it myself. Mainly it involves casting the pointers to different types then you can view them however you'd like (as arrays, structures, etc) stackoverflow.com/questions/46141549/…
- It must be gdb 7.2 that this works for because I have 7.1 installed on my system and typing "p modname::var" still results in "No symbol in current context". However, note that this whole issue seems to be a gfortran issue and not a gdb issue, as when I built my source code with intel ifort 11.1, gdb had no issue in printing a local or global variable or array. Building with no optimization with gfortran allowed printing global variables but still not global arrays.
- This works to display non-array elements in addition to compiling with -O0. I can print global variables, but I still can't see the values of global arrays. When I try to print the name of the array as __modulename_MOD_arrayname, some seemingly random large number is returned. If I try to print one element of the array, I get -nan(0xf...). Any idea how to get arrays to print out correctly as well as non array variables?
- Just to note on my progress, I tried building with intel 11.1 (with -O0 this time) and debugging with gdb, and all global variables and global arrays print out properly. I tried building with g95 and debugging with gdb and global variables won't print out even when built with -O0 (I have to use the naming convention listed above to get them). But global arrays still don't print out. So in summary, it seems like it's a problem with gfortran and g95 and not gdb. And building with intel 11.1 works fine.