Debugging with GDB (September 2007)

Chapter 14: HP-UX Configuration-Specific Information 183
unset env
until
14.25.1 Debugging Optimized Code at Various Optimization
Levels
The following sections describe debugging optimized code support at each optimization
level.
14.25.1.1 +O0 and +O1
At +O1 level, optimizations that affect the user visible state of a program are avoided.
Line numbers are accurately associated with each machine instruction. Global or
local variables may be examined, except for unused variables (which may be elimi-
nated). New values may be assigned to a global and a local variable (set <var> =
<expression>) when stepping by line (step/next/break <line>). However, while
stepping by instruction (stepi/nexti) at optimization level +O1, assign a value to a
variable only if stopped at the very first instruction. This is a must as local optimiza-
tions are performed within a statement.
Backtrace commands (backtrace) may be used to display the current nest of function
calls, including for calls that are inlined. Note that even at +O1, C++ methods that
are defined within a class and Fortran arithmetic statement functions are implicitly
inlinable and are inlined. Other functions are not inlined, regardless of the inline
pragmas or keywords.
14.25.1.2 +O2/+O3/+O4/-ipo
Stepping by line number (step/next) and running to a breakpoint(break) moves the
state of a program forward. However, the program execution does not necessarily stop
at the given line.
You can set breakpoints (break) at the entry to a routine that is not inlined and
examine the values of parameters when the program execution s tops at the entry of a
routine. The local variables can be examined within a function. However, the values of
the local variables may not be available at all code locations in the function. Assignment
of new values to formal parameters or local variables is NOT supported in code compiled
with optimization above +O1.
Optimization of code results in the reordering of the instructions and the source line-
numb e rs. Hence, the value of the variable, which is printed by the debugger may not
correspond to the reported source code location. The debugger may print the value of
the variable at a source code location either before or after the reported source code
location.(If the printed value is not current with respect to the current source line,
the printed value will be the immediately previous or immediately later value for the
variable.)
Backtrace commands (backtrace) can be used to display the current nest of function
calls, including calls that are inlined. When stopped within the code for an inlined