when linux gdb debug, print a variable, such as i, by command p i;
The gdb output value optimized out.
The solution for the problem is off the compile optimation option -Ox, x note digital, such 2, 3, 4 etc
The better way is that changing -Ox to -O0.
The -O0 denotes there is no optimization. It will avoid gdb mislead source code line issue.
本文介绍了在使用Linux GDB进行调试时遇到变量值被优化掉的问题及解决方案。当使用如-O2等优化选项编译时,可能会导致GDB无法正确显示变量值。解决办法是关闭编译优化选项,改为使用-O0,这样可以避免源代码行误导问题。
2902

被折叠的 条评论
为什么被折叠?



