1

How can I make totalview offer access to all the variables in my code?

I'm trying to debug a Fortran90 program using totalview. I compiled and linked with Intel's ifort, using the "-g" flag. totalview can step through my program, but only offers "dive" for four of the variables in my subroutine, and many executable source lines have no box I can check to set an action point. Of all the variables declared below, only cell_EW, cell_NS, area, and pct are available to dive later in the subroutine.

164  REAL, allocatable, DIMENSION(:), INTENT(in) :: lon, lat
165  REAL, ALLOCATABLE, DIMENSION(:, :, :, :) :: area, pct
166  REAL, ALLOCATABLE, DIMENSION(:, :, :), INTENT(in) :: in_flux
167  REAL, ALLOCATABLE, DIMENSION(:, :, :), INTENT(inout) :: out_flux
168  REAL :: cell_EW, cell_NS
169  INTEGER status, ierr, dimid, nlon, nlat, ntimes
170  INTEGER i, j, k, LOGDEV, this_var, this_t
171  INTEGER jdate, jtime, this_date, this_time

another example: line 190 does not allow me to set an action point, and ntimes is unrecognized as a variable.

189  CALL calc_land_area(pct, cell_EW, cell_NS, lon, lat, area)
190  ntimes = SIZE(in_flux, 1)  ! first dimension is time
191  do i = 1, ntimes
  • 1
    Other than `-g` what compiler flags do you specify? I've not used totalview but the faq [here](https://computing.llnl.gov/tutorials/totalview/#Compiling) says not to use optimisation flags. By default I think `ifort` will use `-O2`, so you might want to try explicitly stating `-O0` or similar. (actually `-g` may imply `-O0` but it can be overriden) – d_1999 Mar 02 '17 at 17:58
  • 1
    wow, @d_1999, you nailed it. I had seen that FAQ and removed an explicit `-O2` flag (and set `-g`) for debugging, but it hadn't occurred to me to use an explicit `-O0`. I recompiled with `-O0 -g` and all my variables are now available. Many thanks! If you add your comment as an answer I'll gladly accept it. – Timothy W. Hilton Mar 02 '17 at 18:28

1 Answers1

3

When variables are not available in inspection tools like gdb and totalview it's often because the compiler has optimised them away. This is hinted at in the totalview faq

Don't compile your program with optimization flags while you are debugging it. Compiler optimizations can "rewrite" your program and produce machine code that doesn't necessarily match your source code.

As different compilers have different default optimisation levels (and potentially -g may have additional implications other than just including symbols) it's usually a good idea to include an explicit -O0 or equivalent in order to disable any optimisation. Some compilers (e.g. gfortran version >= v4.8) provide a specific debugging optimisation level with the -Og flag as noted in this answer. This allows optimisations that don't impact on the ability to debug.

Community
  • 1
  • 1
d_1999
  • 854
  • 6
  • 16