Theodore Papadopoulo wrote:
gdb and similar tools are confused, notably because local variables
are
"optimsed out" (which I suspect is related to frame pointer).
It is not.
This is related to compiling with any optimization at all, and you
definitely do not want production binaries compiled without optimization
(with -O0), they would be extremely slow and large.
Local variables are allocated to registers for as long as they are needed,
and then evicted (overwritten by other data that needs the register) when
the compiler finds they are "dead", i.e., no longer referenced in the rest
of the function. Only when no registers are left, the variables are
"spilled" to the stack (which is the only place where the frame pointer
makes a difference, and only in the way the variables are accessed, i.e.,
they can be accessed relative to %rfp rather than %rsp). And some variables
can be optimized out entirely, e.g., by inlining them into the computation
of some other variable.
If anything, enabling the frame pointer will make it *more* likely that
variables get optimized out because there will be one fewer register to use
to hold their contents.
Kevin Kofler