13 ms·
> in gdb, it prints many variable values as "optimized out". This is because your contract with the C/C++ compiler is not "produce machine instructions that fa
by 95014_refugee 5y ago
> in gdb, it prints many variable values as "optimized out".
This is because your contract with the C/C++ compiler is not "produce machine instructions that faithfully implement the program as written", but "produce machine instructions that have the same side-effects as the program".
Anything that is not explicitly marked as observable (and whose state is thus a side-effect) is fair game. Arguments passed to functions out of scope (remember LTO...), memory same, volatile-qualified storage... that's about it. Debuggability of an optimised program is an accident, not an objective.
- roca 5y agoThat's not really true. A ton of intentional work has been done to make optimized builds debuggable ... unfortunately, not enough yet, but it is definitely "an objective".
- nyanpasu64 5y agoI suppose. When I debug system software, I usually recompile Arch Linux packages with options=(!strip debug), which turns off stripping and enables debug symbols. I don't know if it disables optimizations which impair debugging though.