Debugging with GDB Manual HP WDB v6.3 (5900-2180, August 2012)
• unset env
• until
14.30.1 Debugging Optimized Code at Various Optimization Levels
The following sections describe debugging optimized code support at each optimization level.
14.30.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 eliminated). 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 optimizations 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.30.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 stops 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- numbers.
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 call, the parameters
and the local variables of the inlined routine are not reported or available. The disassem command
does not work for functions that have no code (because all calls to these functions are inlined or
these functions are not called at all). HP WDB 5.7 and later versions provide support to prevent
the debugged program from stopping at instructions that are predicated false. The program
execution can be stopped by a software breakpoint, a hardware breakpoint, or an asynchronous
signal. In the case of optimizations such as if-conversion, the predicated false instructions indicate
that an alternate source path is executed. Hence, stopping the program at a predicated false
instruction results in the misleading conclusion that the path corresponding to the predicated false
instruction is executed. To prevent this ambiguity, HP WDB does not stop at predicated false
instructions.
The predicated false instructions are equated to NOPs (No OPeration), because these instructions
do not modify the processor state. The exception to this rule is the use of certain instructions, such
as wtop, wexit, and frcpa, which modify the processor state even when predicated false. In
such cases, the debugger stops at the instructions irrespective of the predicate value of the
instructions. Assembly and low-level programmers, who require the old behavior of the debugger
14.30 Debugging optimized code 181