Debug Cray C and C++ Code

The TotalView symbolic debugger is available to help debug C and C++ codes. In addition, the Cray C and C++ compilers provide the following features to help in debugging codes.

The TotalView symbolic debugger is available to help debug C and C++ codes. In addition, the Cray C and C++ compilers provide the following features to help in debugging codes:
  • The -G and -g compiler options provide symbol information about the source code for use by the TotalView debugger. For more information about these compiler options, see -G degub_lvl, -g.
  • The -h [no]bounds option and the #pragma _CRI [no]bounds directive allows for checking pointer and array references. The -h [no]bounds option is described in -h [no]bounds (cc). The #pragma _CRI [no]bounds directive is described in #pragma _CRI [no]bounds.
  • The -G3 option optimizes code for use with Cray fast-track debugging and requires use of a debugger that supports fast-track debugging. For more information, see the lgdb(1) man page.
  • The #pragma _CRI message directive allows for adding warning messages to sections of code where problems are suspected. The #pragma _CRI message directive is described in message.
  • The #pragma _CRI [no]opt directive allows for selectively isolating portions of the code to optimize, or to toggle optimization on and off in selected portions of the code. The #pragma _CRI [no]opt directive is described in [no]opt.

TotalView Debugger

Some of the functions available in the TotalView debugger allow for the performance of the following actions:
  • Set and clear breakpoints, which can be conditional, at both the source code level and the assembly code level
  • Examine core files
  • Step through a program, including across function calls
  • Reattach to the executable file after editing and recompiling
  • Edit values of variables and memory locations
  • Evaluate code fragments

Compiler Debug Options

Compiler options control the trade-offs between ease of debugging and compiler optimizations. The compiler produces internal debugger information (DWARF) at all times. The DWARF data provides function and line information to debuggers for tracebacks and breakpoints, as well as type and location information about data variables.

These options are specified as follows:
-G3
This option permits both full code optimization and the greatest flexibility in setting breakpoints, but requires use of the Cray fast-track debugger. For more information, see the lgdb(1) man page.
-G2
With no DWARF, the executable is optimized and as small as possible, but cannot be easily debugged. Only assembly instructions will be visible and only global symbols will be available.
-G1
With partial DWARF and at least some optimization, tracebacks and limited breakpoints are available in the debugger. The source code will be visible and many more symbols will be available. The executable will be somewhat slower and larger in exchange for increased debugger functionality.
-g or -G0
With full DWARF and no optimizations, full debugging will be available, but at the cost of a slower and larger executable.
The -g or -G options may be specified on a per file basis so that only part of an application incurs the overhead of improved debugging.
However, consider the following cases in which optimization is affected by the -G1 and -G2 debugging options:
  • Vectorization can be inhibited if a label exists within the vectorizable loop.
  • Vectorization can be inhibited if the loop contains a nested block and the -G1 option is specified.
  • When the -G1 option is specified, setting a breakpoint at the first statement in a vectorized loop allows for stop and display at each vector iteration. However, setting a breakpoint at the first statement in an unrolled loop may not allow a stop at each vector iteration.