使用带有 -g 和 -O2 标志的 gdb 跳过偶尔的步骤到上一行。删除 -O2 标志,它按预期工作。谁能解释为什么会这样?
我是 eclipse CDT 中 gdb 的新手,并通过“标准创建进程启动器”在 C++ 代码上使用它。
这是预期的行为还是有解决方案将优化留给
最佳答案
这是预期的。编译器可以随意在更高的优化级别上重新排序代码。手册页甚至说:
"Without any optimization option, the compiler's goal is to reduce the cost of compilation and to make debugging produce the expected results."
这个目标必须在更高层次上被搁置。
关于c++ - 使用 -O2 标志将 gdb 步进到上一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5487925/