Compiling with Debugging Symbols
The first step in getting a program ready for debugging is to add your compiler's –g debugging command line option. This option tells your compiler to generate symbol table debugging information; for example:
cc -g -o executable-name source-file
Here are a couple of general considerations about compiling your code:
|
Compiler option |
What it does |
When to use it |
|
Debugging symbols option (usually –g) |
Generates debugging information in the symbol table. |
Before debugging any program with TotalView. |
|
Optimization option (usually –O) |
Rearranges code to optimize your program's execution. Some compilers let you use the –O option with the ‑g option, but we advise against doing this before using the debugger as unexpected results often occur. |
After you finish debugging your program. |
The following table lists the procedures to compile C/C++ programs on Linux platforms.
|
Compiler |
Compiler Command Line |
|
GCC C |
gcc -g source.c |
|
GCC C++ |
g++ -g source.cxx |
|
clang C |
clang -g source.c |
|
clang C++ |
clang++ -gsource.cxx |
|
Oracle Studio C |
cc -g source.c |
|
Oracle Studio C++ |
CC -g source.cxx |
|
Intel C++ Compiler |
icc -g source.cxx |
|
PGI CC |
pgcc -g source.c |
|
PGI C++ |
pgc++ -gsource.cxx |
The following table lists the procedures to compile Fortran programs on Linux platforms.
|
Compiler |
Compiler Command Line |
|
Absoft Fortran 77 |
f77 -g program |
|
Absoft Fortran 90 |
f90 -g program.f90 |
|
Absoft Fortran 95 |
f95 -g program.f95 |
|
G77 |
g77 -g program.f |
|
Intel Fortran Compiler |
ifort -g program.f |
|
Lahey/Fujitsu Fortran |
lf95 -g program.f |
|
PGI Fortran 77 |
pgf77 -g program.f |
|
PGI Fortran 90 |
pgf90 -g program.f |
The following table lists the procedures to compile programs on ARM64 platforms.
|
Compiler |
Compiler Command Line |
|
GCC C |
gcc -g program.c |
|
GCC C++ |
g++ -g program.cxx |
|
G77 |
g77 -g program.f |
The following table lists the procedures to compile programs on Mac OS platforms.
|
Compiler |
Compiler Command Line |
|
Absoft Fortran 77 |
f77 -gprogram |
|
Absoft Fortran 90 |
f90 -gprogram.f90 |
|
Absoft Fortran 95 |
f95 -g program.f95 |
|
GCC C |
gcc -g program.c |
|
GCC C++ |
g++ -gprogram.cxx |
|
GCC Fortran |
gfortran -gprogram.f |
|
clang C |
clang -g source.c |
|
clang C++ |
clang++ -gsource.cxx |
|
Intel C++ Compiler |
icc -g source.cxx |
|
Intel Fortran Compiler |
ifort -g program.f |