-g
Category
Pragma equivalent
None.
Purpose
Generates debugging information for use by a symbolic debugger, and makes the program state available to the debugging session at selected source locations.
Program state refers to the values of user variables at certain points during the execution of a program.
You can use different -g levels to balance between debug capability and compiler optimization. Higher -g levels provide a more complete debug support, at the cost of runtime or possible compile-time performance, while lower -g levels provide higher runtime performance, at the cost of some capability in the debugging session.
When the -O2 optimization level is in effect, the debug capability is completely supported.
When an optimization level higher than -O2 is in effect, the debug capability is limited.
Syntax
.-2-. >>--- -g--+---+------------------------------------------------>< +-0-+ +-1-+ +-8-+ '-9-'
Defaults
If -g is not specified, -g0 takes effect, which means that the compiler does not generate any debug information or preserve program state.
- When no optimization is enabled (-qnoopt), -g is equivalent to -g9.
- When the -O2 optimization level is in effect, -g is equivalent to -g2.
Parameters
- -g0
- Generates no debugging information. No program state is preserved.
- -g1
- Generates minimal read-only debugging information about line numbers and source file names. No program state is preserved. This option is equivalent to -qlinedebug.
- -g2
- Generates read-only debugging information about line numbers,
source file names, and variables.
When the -O2 or higher optimization level is in effect, no program state is preserved.
- -g8
- Generates read-only debugging information about line numbers,
source file names, and variables. When the -O2 optimization level is in effect:
- Program state is available to the debugger at the beginning of every executable statement.
- Function parameter values are available to the debugger at the beginning of each function.
- Debugging inlined functions is supported.
- -g9
- Generates debugging information about line numbers, source file
names, and variables. You can modify the value of the variables in
the debugger. When the -O2 optimization level is in effect:
- Program state is available to the debugger at the beginning of every executable statement.
- Function parameter values are available to the debugger at the beginning of each function.
- Debugging inlined functions is supported.
Usage
When no optimization is enabled, the debugging information is always available if you specify -g2, -g8, or -g9.
When the -O2 optimization level is in effect, the debugging information is available at every source line with an executable statement if you specify -g8 or -g9.
When you specify -g with -fstandalone-debug, the compiler generates the debugging information for all symbols whether or not these symbols are referenced by the program. When you specify -g with -fno-standalone-debug, the compiler generates debugging information only for symbols that are referenced by the program.
Examples
xlc myprogram.c -o testing -g
xlc myprogram.c -O2 -g8