Turing: Debugging options of the IBM compilers

In a debugging phase, the following options can be of great assistance:

  • -g (default option activated by IDRIS) generates a table of symbols (line number, variables, …) which can be used at a later time. It also allows generating the instruction numbers in the tracebacks. Attention: Exceptionally among the compilers, this option does not inhibit optimisation but to the contrary, it retains the requested optimisation level. You should also test the persistence of your bug without optimisation (or with an inferior optimisation level).
  • -qfullpath includes the access path to the source files which are found in the object files (must be combined with -g). This permits the debugger to find the source files automatically.
  • -O0 -qnohot -qnosmp -qstrict permits inhibiting all optimisation.
  • -qoptdebug permits keeping the optimisation level. For each source file, a file is generated (having the extension .optdbg). It contains an optimised pseudocode which is readable by a debugger.
  • -qinitauto=pattern preliminary initialisation of the memory corresponding to all the temporary variables with the given pattern (or to zero if only -qinitauto) :
    • pattern=FFFFFFFF to initialise all the single and double precision floats with NaNq.
  • -C (only in Fortran) generates a SIGTRAP signal when an array is referenced outside of its bounds (bounds checking). In order to catch this signal, it is necessary to use the option -qsigtrap described below.
  • -qcheck=bounds (only in C/C++) verifies whether we are addressing a table outside of its bounds (bounds checking).
  • -qcheck=nullptr (only in C/C++) verifies the validity of the addresses contained in the pointer variables.
  • -qcheck=divzero (only in C++) permits the detection of integer division by zero.
  • -qcheck=all (only in C++) groups together the three preceding options.
  • -qflttrap=overflow:underflow:nanq:zerodivide:invalid:qpxstore:enable allows detecting exceptions (overflow, underflow, NaNq, division by zero and NaN on the QPX vector unit). When using Fortran, it is necessary to specify -qsigtrap in order to catch the exceptions.
  • -qsigtrap (only in Fortran) catches the SIGTRAP signal emitted following an exception or a table overflow and interrupts the execution with the impression of a traceback (also see option - g).
  • -qsave (only in Fortran) sets the execution mode in static. On Turing, the default mode is stack (recommended but it reveals programming errors hidden by the static model!): The local variables are, therefore, stored temporarily in the stack memory zone. If this option causes the program to run normally, it might be because of neglecting to initialise or save local variables (cf. attribute SAVE) such as counters which are incremented at every procedure call if not saved.
  • -qkeepparm to force the compiler to keep the values of the call arguments in the stack (because certain optimisations can change this). These values can then be recovered in any debugger.
  • -qdbxextra(only in C/C++) includes all the definitions of the enum, struct, union types in the object files so that they can be used by a debugger (must be combined with -g).

The option -qlanglvl verifies whether the source conforms to the Fortran or C/C++ norms. For example, there is -qlanglvl=95std for the Fortran 95 norm and -qlanglvl=stdc99 for the C99 norm.

Example of table overflow management:

$ mpixlf95_r -g -C -qsigtrap overflowing.f90
$ runjob --np 1024 --ranks-per-node 16 : ./my_exe my_arg1 my_arg2

  Signal received: SIGTRAP - Trace trap
    Fortran language trap: subscript out of bounds

  Traceback:
    Offset 0x00000090 in procedure overflow, near line 6 in file overflowing.f90
    --- End of call chain ---

Example using all the options described in Fortran :

$ mpixlf95_r -g -qsigtrap -qoptdebug -qfullpath -C -qinitauto=7FBFFFFF 
      -qflttrap=overflow:underflow:zerodivide:invalid:qpxstore:enable 
      -qfloat=nans -qsigtrap -qkeepparm -qlanglvl=95std test.f90

In C and in C++ :

$ mpixlc_r -g -qoptdebug -qcheck=all -qinitauto=7FBFFFFF 
    -qflttrap=overflow:underflow:zerodivide:invalid:qpxstore:enable 
    -qfloat=nans:spnans -qkeepparm -qdbxextra -qfullpath source.c

$ mpixlcxx_r -g -qqoptdebug -qcheck=all -qinitauto=7FBFFFFF 
    -qflttrap=overflow:underflow:zerodivide:invalid:qpxstore:enable 
    -qfloat=nans:spnans -qkeepparm -qdbxextra -qfullpath source.C